]>
git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blob - src/js/basex.js
1 (function(f
){if(typeof exports
==="object"&&typeof module
!=="undefined"){module
.exports
=f()}else if(typeof define
==="function"&&define
.amd
){define([],f
)}else{var g
;if(typeof window
!=="undefined"){g
=window
}else if(typeof global
!=="undefined"){g
=global
}else if(typeof self
!=="undefined"){g
=self
}else{g
=this}g
.foo
= f()}})(function(){var define
,module
,exports
;return (function e(t
,n
,r
){function s(o
,u
){if(!n
[o
]){if(!t
[o
]){var a
=typeof require
=="function"&&require
;if(!u
&&a
)return a(o
,!0);if(i
)return i(o
,!0);var f
=new Error("Cannot find module '"+o
+"'");throw f
.code
="MODULE_NOT_FOUND",f
}var l
=n
[o
]={exports:{}};t
[o
][0].call(l
.exports
,function(e
){var n
=t
[o
][1][e
];return s(n
?n:e
)},l
,l
.exports
,e
,t
,n
,r
)}return n
[o
].exports
}var i
=typeof require
=="function"&&require
;for(var o
=0;o
<r
.length
;o
++)s(r
[o
]);return s
})({1:[function(require
,module
,exports
){
4 exports
.byteLength
= byteLength
5 exports
.toByteArray
= toByteArray
6 exports
.fromByteArray
= fromByteArray
10 var Arr
= typeof Uint8Array
!== 'undefined' ? Uint8Array : Array
12 var code
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
13 for (var i
= 0, len
= code
.length
; i
< len
; ++i
) {
15 revLookup
[code
.charCodeAt(i
)] = i
18 revLookup
['-'.charCodeAt(0)] = 62
19 revLookup
['_'.charCodeAt(0)] = 63
21 function placeHoldersCount (b64
) {
24 throw new Error('Invalid string. Length must be a multiple of 4')
27 // the number of equal signs (place holders)
28 // if there are two placeholders, than the two characters before it
30 // if there is only one, then the three characters before it represent 2 bytes
31 // this is just a cheap hack to not do indexOf twice
32 return b64
[len
- 2] === '=' ? 2 : b64
[len
- 1] === '=' ? 1 : 0
35 function byteLength (b64
) {
36 // base64 is 4/3 + up to two characters of the original data
37 return b64
.length
* 3 / 4 - placeHoldersCount(b64
)
40 function toByteArray (b64
) {
41 var i
, j
, l
, tmp
, placeHolders
, arr
43 placeHolders
= placeHoldersCount(b64
)
45 arr
= new Arr(len
* 3 / 4 - placeHolders
)
47 // if there are placeholders, only get up to the last complete 4 chars
48 l
= placeHolders
> 0 ? len
- 4 : len
52 for (i
= 0, j
= 0; i
< l
; i
+= 4, j
+= 3) {
53 tmp
= (revLookup
[b64
.charCodeAt(i
)] << 18) | (revLookup
[b64
.charCodeAt(i
+ 1)] << 12) | (revLookup
[b64
.charCodeAt(i
+ 2)] << 6) | revLookup
[b64
.charCodeAt(i
+ 3)]
54 arr
[L
++] = (tmp
>> 16) & 0xFF
55 arr
[L
++] = (tmp
>> 8) & 0xFF
59 if (placeHolders
=== 2) {
60 tmp
= (revLookup
[b64
.charCodeAt(i
)] << 2) | (revLookup
[b64
.charCodeAt(i
+ 1)] >> 4)
62 } else if (placeHolders
=== 1) {
63 tmp
= (revLookup
[b64
.charCodeAt(i
)] << 10) | (revLookup
[b64
.charCodeAt(i
+ 1)] << 4) | (revLookup
[b64
.charCodeAt(i
+ 2)] >> 2)
64 arr
[L
++] = (tmp
>> 8) & 0xFF
71 function tripletToBase64 (num
) {
72 return lookup
[num
>> 18 & 0x3F] + lookup
[num
>> 12 & 0x3F] + lookup
[num
>> 6 & 0x3F] + lookup
[num
& 0x3F]
75 function encodeChunk (uint8
, start
, end
) {
78 for (var i
= start
; i
< end
; i
+= 3) {
79 tmp
= (uint8
[i
] << 16) + (uint8
[i
+ 1] << 8) + (uint8
[i
+ 2])
80 output
.push(tripletToBase64(tmp
))
82 return output
.join('')
85 function fromByteArray (uint8
) {
87 var len
= uint8
.length
88 var extraBytes
= len
% 3 // if we have 1 byte left, pad 2 bytes
91 var maxChunkLength
= 16383 // must be multiple of 3
93 // go through the array every three bytes, we'll deal with trailing stuff later
94 for (var i
= 0, len2
= len
- extraBytes
; i
< len2
; i
+= maxChunkLength
) {
95 parts
.push(encodeChunk(uint8
, i
, (i
+ maxChunkLength
) > len2
? len2 : (i
+ maxChunkLength
)))
98 // pad the end with zeros, but make sure to not forget the extra bytes
99 if (extraBytes
=== 1) {
101 output
+= lookup
[tmp
>> 2]
102 output
+= lookup
[(tmp
<< 4) & 0x3F]
104 } else if (extraBytes
=== 2) {
105 tmp
= (uint8
[len
- 2] << 8) + (uint8
[len
- 1])
106 output
+= lookup
[tmp
>> 10]
107 output
+= lookup
[(tmp
>> 4) & 0x3F]
108 output
+= lookup
[(tmp
<< 2) & 0x3F]
114 return parts
.join('')
117 },{}],2:[function(require
,module
,exports
){
119 * The buffer module from node.js, for the browser.
121 * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
124 /* eslint-disable no-proto */
128 var base64
= require('base64-js')
129 var ieee754
= require('ieee754')
131 exports
.Buffer
= Buffer
132 exports
.SlowBuffer
= SlowBuffer
133 exports
.INSPECT_MAX_BYTES
= 50
135 var K_MAX_LENGTH
= 0x7fffffff
136 exports
.kMaxLength
= K_MAX_LENGTH
139 * If `Buffer.TYPED_ARRAY_SUPPORT`:
140 * === true Use Uint8Array implementation (fastest)
141 * === false Print warning and recommend using `buffer` v4.x which has an Object
142 * implementation (most compatible, even IE6)
144 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
145 * Opera 11.6+, iOS 4.2+.
147 * We report that the browser does not support typed arrays if the are not subclassable
148 * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
149 * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
150 * for __proto__ and has a buggy typed array implementation.
152 Buffer
.TYPED_ARRAY_SUPPORT
= typedArraySupport()
154 if (!Buffer
.TYPED_ARRAY_SUPPORT
&& typeof console
!== 'undefined' &&
155 typeof console
.error
=== 'function') {
157 'This browser lacks typed array (Uint8Array) support which is required by ' +
158 '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
162 function typedArraySupport () {
163 // Can typed array instances can be augmented?
165 var arr
= new Uint8Array(1)
166 arr
.__proto__
= {__proto__: Uint8Array
.prototype, foo: function () { return 42 }}
167 return arr
.foo() === 42
173 function createBuffer (length
) {
174 if (length
> K_MAX_LENGTH
) {
175 throw new RangeError('Invalid typed array length')
177 // Return an augmented `Uint8Array` instance
178 var buf
= new Uint8Array(length
)
179 buf
.__proto__
= Buffer
.prototype
184 * The Buffer constructor returns instances of `Uint8Array` that have their
185 * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
186 * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
187 * and the `Uint8Array` methods. Square bracket notation works as expected -- it
188 * returns a single octet.
190 * The `Uint8Array` prototype remains unmodified.
193 function Buffer (arg
, encodingOrOffset
, length
) {
195 if (typeof arg
=== 'number') {
196 if (typeof encodingOrOffset
=== 'string') {
198 'If encoding is specified then the first argument must be a string'
201 return allocUnsafe(arg
)
203 return from(arg
, encodingOrOffset
, length
)
206 // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
207 if (typeof Symbol
!== 'undefined' && Symbol
.species
&&
208 Buffer
[Symbol
.species
] === Buffer
) {
209 Object
.defineProperty(Buffer
, Symbol
.species
, {
217 Buffer
.poolSize
= 8192 // not used by this implementation
219 function from (value
, encodingOrOffset
, length
) {
220 if (typeof value
=== 'number') {
221 throw new TypeError('"value" argument must not be a number')
224 if (value
instanceof ArrayBuffer
) {
225 return fromArrayBuffer(value
, encodingOrOffset
, length
)
228 if (typeof value
=== 'string') {
229 return fromString(value
, encodingOrOffset
)
232 return fromObject(value
)
236 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
237 * if value is a number.
238 * Buffer.from(str[, encoding])
240 * Buffer.from(buffer)
241 * Buffer.from(arrayBuffer[, byteOffset[, length]])
243 Buffer
.from = function (value
, encodingOrOffset
, length
) {
244 return from(value
, encodingOrOffset
, length
)
247 // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
248 // https://github.com/feross/buffer/pull/148
249 Buffer
.prototype.__proto__
= Uint8Array
.prototype
250 Buffer
.__proto__
= Uint8Array
252 function assertSize (size
) {
253 if (typeof size
!== 'number') {
254 throw new TypeError('"size" argument must be a number')
255 } else if (size
< 0) {
256 throw new RangeError('"size" argument must not be negative')
260 function alloc (size
, fill
, encoding
) {
263 return createBuffer(size
)
265 if (fill
!== undefined) {
266 // Only pay attention to encoding if it's a string. This
267 // prevents accidentally sending in a number that would
268 // be interpretted as a start offset.
269 return typeof encoding
=== 'string'
270 ? createBuffer(size
).fill(fill
, encoding
)
271 : createBuffer(size
).fill(fill
)
273 return createBuffer(size
)
277 * Creates a new filled Buffer instance.
278 * alloc(size[, fill[, encoding]])
280 Buffer
.alloc = function (size
, fill
, encoding
) {
281 return alloc(size
, fill
, encoding
)
284 function allocUnsafe (size
) {
286 return createBuffer(size
< 0 ? 0 : checked(size
) | 0)
290 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
292 Buffer
.allocUnsafe = function (size
) {
293 return allocUnsafe(size
)
296 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
298 Buffer
.allocUnsafeSlow = function (size
) {
299 return allocUnsafe(size
)
302 function fromString (string
, encoding
) {
303 if (typeof encoding
!== 'string' || encoding
=== '') {
307 if (!Buffer
.isEncoding(encoding
)) {
308 throw new TypeError('"encoding" must be a valid string encoding')
311 var length
= byteLength(string
, encoding
) | 0
312 var buf
= createBuffer(length
)
314 var actual
= buf
.write(string
, encoding
)
316 if (actual
!== length
) {
317 // Writing a hex string, for example, that contains invalid characters will
318 // cause everything after the first invalid character to be ignored. (e.g.
319 // 'abxxcd' will be treated as 'ab')
320 buf
= buf
.slice(0, actual
)
326 function fromArrayLike (array
) {
327 var length
= array
.length
< 0 ? 0 : checked(array
.length
) | 0
328 var buf
= createBuffer(length
)
329 for (var i
= 0; i
< length
; i
+= 1) {
330 buf
[i
] = array
[i
] & 255
335 function fromArrayBuffer (array
, byteOffset
, length
) {
336 if (byteOffset
< 0 || array
.byteLength
< byteOffset
) {
337 throw new RangeError('\'offset\' is out of bounds')
340 if (array
.byteLength
< byteOffset
+ (length
|| 0)) {
341 throw new RangeError('\'length\' is out of bounds')
345 if (byteOffset
=== undefined && length
=== undefined) {
346 buf
= new Uint8Array(array
)
347 } else if (length
=== undefined) {
348 buf
= new Uint8Array(array
, byteOffset
)
350 buf
= new Uint8Array(array
, byteOffset
, length
)
353 // Return an augmented `Uint8Array` instance
354 buf
.__proto__
= Buffer
.prototype
358 function fromObject (obj
) {
359 if (Buffer
.isBuffer(obj
)) {
360 var len
= checked(obj
.length
) | 0
361 var buf
= createBuffer(len
)
363 if (buf
.length
=== 0) {
367 obj
.copy(buf
, 0, 0, len
)
372 if (isArrayBufferView(obj
) || 'length' in obj
) {
373 if (typeof obj
.length
!== 'number' || numberIsNaN(obj
.length
)) {
374 return createBuffer(0)
376 return fromArrayLike(obj
)
379 if (obj
.type
=== 'Buffer' && Array
.isArray(obj
.data
)) {
380 return fromArrayLike(obj
.data
)
384 throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
387 function checked (length
) {
388 // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
389 // length is NaN (which is otherwise coerced to zero.)
390 if (length
>= K_MAX_LENGTH
) {
391 throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
392 'size: 0x' + K_MAX_LENGTH
.toString(16) + ' bytes')
397 function SlowBuffer (length
) {
398 if (+length
!= length
) { // eslint-disable-line eqeqeq
401 return Buffer
.alloc(+length
)
404 Buffer
.isBuffer
= function isBuffer (b
) {
405 return b
!= null && b
._isBuffer
=== true
408 Buffer
.compare
= function compare (a
, b
) {
409 if (!Buffer
.isBuffer(a
) || !Buffer
.isBuffer(b
)) {
410 throw new TypeError('Arguments must be Buffers')
413 if (a
=== b
) return 0
418 for (var i
= 0, len
= Math
.min(x
, y
); i
< len
; ++i
) {
431 Buffer
.isEncoding
= function isEncoding (encoding
) {
432 switch (String(encoding
).toLowerCase()) {
450 Buffer
.concat
= function concat (list
, length
) {
451 if (!Array
.isArray(list
)) {
452 throw new TypeError('"list" argument must be an Array of Buffers')
455 if (list
.length
=== 0) {
456 return Buffer
.alloc(0)
460 if (length
=== undefined) {
462 for (i
= 0; i
< list
.length
; ++i
) {
463 length
+= list
[i
].length
467 var buffer
= Buffer
.allocUnsafe(length
)
469 for (i
= 0; i
< list
.length
; ++i
) {
471 if (!Buffer
.isBuffer(buf
)) {
472 throw new TypeError('"list" argument must be an Array of Buffers')
474 buf
.copy(buffer
, pos
)
480 function byteLength (string
, encoding
) {
481 if (Buffer
.isBuffer(string
)) {
484 if (isArrayBufferView(string
) || string
instanceof ArrayBuffer
) {
485 return string
.byteLength
487 if (typeof string
!== 'string') {
491 var len
= string
.length
492 if (len
=== 0) return 0
494 // Use a for loop to avoid recursion
495 var loweredCase
= false
505 return utf8ToBytes(string
).length
514 return base64ToBytes(string
).length
516 if (loweredCase
) return utf8ToBytes(string
).length
// assume utf8
517 encoding
= ('' + encoding
).toLowerCase()
522 Buffer
.byteLength
= byteLength
524 function slowToString (encoding
, start
, end
) {
525 var loweredCase
= false
527 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
528 // property of a typed array.
530 // This behaves neither like String nor Uint8Array in that we set start/end
531 // to their upper/lower bounds if the value passed is out of range.
532 // undefined is handled specially as per ECMA-262 6th Edition,
533 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
534 if (start
=== undefined || start
< 0) {
537 // Return early if start > this.length. Done here to prevent potential uint32
538 // coercion fail below.
539 if (start
> this.length
) {
543 if (end
=== undefined || end
> this.length
) {
551 // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
559 if (!encoding
) encoding
= 'utf8'
564 return hexSlice(this, start
, end
)
568 return utf8Slice(this, start
, end
)
571 return asciiSlice(this, start
, end
)
575 return latin1Slice(this, start
, end
)
578 return base64Slice(this, start
, end
)
584 return utf16leSlice(this, start
, end
)
587 if (loweredCase
) throw new TypeError('Unknown encoding: ' + encoding
)
588 encoding
= (encoding
+ '').toLowerCase()
594 // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
595 // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
596 // reliably in a browserify context because there could be multiple different
597 // copies of the 'buffer' package in use. This method works even for Buffer
598 // instances that were created from another copy of the `buffer` package.
599 // See: https://github.com/feross/buffer/issues/154
600 Buffer
.prototype._isBuffer
= true
602 function swap (b
, n
, m
) {
608 Buffer
.prototype.swap16
= function swap16 () {
609 var len
= this.length
611 throw new RangeError('Buffer size must be a multiple of 16-bits')
613 for (var i
= 0; i
< len
; i
+= 2) {
619 Buffer
.prototype.swap32
= function swap32 () {
620 var len
= this.length
622 throw new RangeError('Buffer size must be a multiple of 32-bits')
624 for (var i
= 0; i
< len
; i
+= 4) {
626 swap(this, i
+ 1, i
+ 2)
631 Buffer
.prototype.swap64
= function swap64 () {
632 var len
= this.length
634 throw new RangeError('Buffer size must be a multiple of 64-bits')
636 for (var i
= 0; i
< len
; i
+= 8) {
638 swap(this, i
+ 1, i
+ 6)
639 swap(this, i
+ 2, i
+ 5)
640 swap(this, i
+ 3, i
+ 4)
645 Buffer
.prototype.toString
= function toString () {
646 var length
= this.length
647 if (length
=== 0) return ''
648 if (arguments
.length
=== 0) return utf8Slice(this, 0, length
)
649 return slowToString
.apply(this, arguments
)
652 Buffer
.prototype.equals
= function equals (b
) {
653 if (!Buffer
.isBuffer(b
)) throw new TypeError('Argument must be a Buffer')
654 if (this === b
) return true
655 return Buffer
.compare(this, b
) === 0
658 Buffer
.prototype.inspect
= function inspect () {
660 var max
= exports
.INSPECT_MAX_BYTES
661 if (this.length
> 0) {
662 str
= this.toString('hex', 0, max
).match(/.{2}/g).join(' ')
663 if (this.length
> max
) str
+= ' ... '
665 return '<Buffer ' + str
+ '>'
668 Buffer
.prototype.compare
= function compare (target
, start
, end
, thisStart
, thisEnd
) {
669 if (!Buffer
.isBuffer(target
)) {
670 throw new TypeError('Argument must be a Buffer')
673 if (start
=== undefined) {
676 if (end
=== undefined) {
677 end
= target
? target
.length : 0
679 if (thisStart
=== undefined) {
682 if (thisEnd
=== undefined) {
683 thisEnd
= this.length
686 if (start
< 0 || end
> target
.length
|| thisStart
< 0 || thisEnd
> this.length
) {
687 throw new RangeError('out of range index')
690 if (thisStart
>= thisEnd
&& start
>= end
) {
693 if (thisStart
>= thisEnd
) {
705 if (this === target
) return 0
707 var x
= thisEnd
- thisStart
709 var len
= Math
.min(x
, y
)
711 var thisCopy
= this.slice(thisStart
, thisEnd
)
712 var targetCopy
= target
.slice(start
, end
)
714 for (var i
= 0; i
< len
; ++i
) {
715 if (thisCopy
[i
] !== targetCopy
[i
]) {
727 // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
728 // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
731 // - buffer - a Buffer to search
732 // - val - a string, Buffer, or number
733 // - byteOffset - an index into `buffer`; will be clamped to an int32
734 // - encoding - an optional encoding, relevant is val is a string
735 // - dir - true for indexOf, false for lastIndexOf
736 function bidirectionalIndexOf (buffer
, val
, byteOffset
, encoding
, dir
) {
737 // Empty buffer means no match
738 if (buffer
.length
=== 0) return -1
740 // Normalize byteOffset
741 if (typeof byteOffset
=== 'string') {
742 encoding
= byteOffset
744 } else if (byteOffset
> 0x7fffffff) {
745 byteOffset
= 0x7fffffff
746 } else if (byteOffset
< -0x80000000) {
747 byteOffset
= -0x80000000
749 byteOffset
= +byteOffset
// Coerce to Number.
750 if (numberIsNaN(byteOffset
)) {
751 // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
752 byteOffset
= dir
? 0 : (buffer
.length
- 1)
755 // Normalize byteOffset: negative offsets start from the end of the buffer
756 if (byteOffset
< 0) byteOffset
= buffer
.length
+ byteOffset
757 if (byteOffset
>= buffer
.length
) {
759 else byteOffset
= buffer
.length
- 1
760 } else if (byteOffset
< 0) {
761 if (dir
) byteOffset
= 0
766 if (typeof val
=== 'string') {
767 val
= Buffer
.from(val
, encoding
)
770 // Finally, search either indexOf (if dir is true) or lastIndexOf
771 if (Buffer
.isBuffer(val
)) {
772 // Special case: looking for empty string/buffer always fails
773 if (val
.length
=== 0) {
776 return arrayIndexOf(buffer
, val
, byteOffset
, encoding
, dir
)
777 } else if (typeof val
=== 'number') {
778 val
= val
& 0xFF // Search for a byte value [0-255]
779 if (typeof Uint8Array
.prototype.indexOf
=== 'function') {
781 return Uint8Array
.prototype.indexOf
.call(buffer
, val
, byteOffset
)
783 return Uint8Array
.prototype.lastIndexOf
.call(buffer
, val
, byteOffset
)
786 return arrayIndexOf(buffer
, [ val
], byteOffset
, encoding
, dir
)
789 throw new TypeError('val must be string, number or Buffer')
792 function arrayIndexOf (arr
, val
, byteOffset
, encoding
, dir
) {
794 var arrLength
= arr
.length
795 var valLength
= val
.length
797 if (encoding
!== undefined) {
798 encoding
= String(encoding
).toLowerCase()
799 if (encoding
=== 'ucs2' || encoding
=== 'ucs-2' ||
800 encoding
=== 'utf16le' || encoding
=== 'utf-16le') {
801 if (arr
.length
< 2 || val
.length
< 2) {
811 function read (buf
, i
) {
812 if (indexSize
=== 1) {
815 return buf
.readUInt16BE(i
* indexSize
)
822 for (i
= byteOffset
; i
< arrLength
; i
++) {
823 if (read(arr
, i
) === read(val
, foundIndex
=== -1 ? 0 : i
- foundIndex
)) {
824 if (foundIndex
=== -1) foundIndex
= i
825 if (i
- foundIndex
+ 1 === valLength
) return foundIndex
* indexSize
827 if (foundIndex
!== -1) i
-= i
- foundIndex
832 if (byteOffset
+ valLength
> arrLength
) byteOffset
= arrLength
- valLength
833 for (i
= byteOffset
; i
>= 0; i
--) {
835 for (var j
= 0; j
< valLength
; j
++) {
836 if (read(arr
, i
+ j
) !== read(val
, j
)) {
848 Buffer
.prototype.includes
= function includes (val
, byteOffset
, encoding
) {
849 return this.indexOf(val
, byteOffset
, encoding
) !== -1
852 Buffer
.prototype.indexOf
= function indexOf (val
, byteOffset
, encoding
) {
853 return bidirectionalIndexOf(this, val
, byteOffset
, encoding
, true)
856 Buffer
.prototype.lastIndexOf
= function lastIndexOf (val
, byteOffset
, encoding
) {
857 return bidirectionalIndexOf(this, val
, byteOffset
, encoding
, false)
860 function hexWrite (buf
, string
, offset
, length
) {
861 offset
= Number(offset
) || 0
862 var remaining
= buf
.length
- offset
866 length
= Number(length
)
867 if (length
> remaining
) {
872 // must be an even number of digits
873 var strLen
= string
.length
874 if (strLen
% 2 !== 0) throw new TypeError('Invalid hex string')
876 if (length
> strLen
/ 2) {
879 for (var i
= 0; i
< length
; ++i
) {
880 var parsed
= parseInt(string
.substr(i
* 2, 2), 16)
881 if (numberIsNaN(parsed
)) return i
882 buf
[offset
+ i
] = parsed
887 function utf8Write (buf
, string
, offset
, length
) {
888 return blitBuffer(utf8ToBytes(string
, buf
.length
- offset
), buf
, offset
, length
)
891 function asciiWrite (buf
, string
, offset
, length
) {
892 return blitBuffer(asciiToBytes(string
), buf
, offset
, length
)
895 function latin1Write (buf
, string
, offset
, length
) {
896 return asciiWrite(buf
, string
, offset
, length
)
899 function base64Write (buf
, string
, offset
, length
) {
900 return blitBuffer(base64ToBytes(string
), buf
, offset
, length
)
903 function ucs2Write (buf
, string
, offset
, length
) {
904 return blitBuffer(utf16leToBytes(string
, buf
.length
- offset
), buf
, offset
, length
)
907 Buffer
.prototype.write
= function write (string
, offset
, length
, encoding
) {
908 // Buffer#write(string)
909 if (offset
=== undefined) {
913 // Buffer#write(string, encoding)
914 } else if (length
=== undefined && typeof offset
=== 'string') {
918 // Buffer#write(string, offset[, length][, encoding])
919 } else if (isFinite(offset
)) {
920 offset
= offset
>>> 0
921 if (isFinite(length
)) {
922 length
= length
>>> 0
923 if (encoding
=== undefined) encoding
= 'utf8'
930 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
934 var remaining
= this.length
- offset
935 if (length
=== undefined || length
> remaining
) length
= remaining
937 if ((string
.length
> 0 && (length
< 0 || offset
< 0)) || offset
> this.length
) {
938 throw new RangeError('Attempt to write outside buffer bounds')
941 if (!encoding
) encoding
= 'utf8'
943 var loweredCase
= false
947 return hexWrite(this, string
, offset
, length
)
951 return utf8Write(this, string
, offset
, length
)
954 return asciiWrite(this, string
, offset
, length
)
958 return latin1Write(this, string
, offset
, length
)
961 // Warning: maxLength not taken into account in base64Write
962 return base64Write(this, string
, offset
, length
)
968 return ucs2Write(this, string
, offset
, length
)
971 if (loweredCase
) throw new TypeError('Unknown encoding: ' + encoding
)
972 encoding
= ('' + encoding
).toLowerCase()
978 Buffer
.prototype.toJSON
= function toJSON () {
981 data: Array
.prototype.slice
.call(this._arr
|| this, 0)
985 function base64Slice (buf
, start
, end
) {
986 if (start
=== 0 && end
=== buf
.length
) {
987 return base64
.fromByteArray(buf
)
989 return base64
.fromByteArray(buf
.slice(start
, end
))
993 function utf8Slice (buf
, start
, end
) {
994 end
= Math
.min(buf
.length
, end
)
999 var firstByte
= buf
[i
]
1000 var codePoint
= null
1001 var bytesPerSequence
= (firstByte
> 0xEF) ? 4
1002 : (firstByte
> 0xDF) ? 3
1003 : (firstByte
> 0xBF) ? 2
1006 if (i
+ bytesPerSequence
<= end
) {
1007 var secondByte
, thirdByte
, fourthByte
, tempCodePoint
1009 switch (bytesPerSequence
) {
1011 if (firstByte
< 0x80) {
1012 codePoint
= firstByte
1016 secondByte
= buf
[i
+ 1]
1017 if ((secondByte
& 0xC0) === 0x80) {
1018 tempCodePoint
= (firstByte
& 0x1F) << 0x6 | (secondByte
& 0x3F)
1019 if (tempCodePoint
> 0x7F) {
1020 codePoint
= tempCodePoint
1025 secondByte
= buf
[i
+ 1]
1026 thirdByte
= buf
[i
+ 2]
1027 if ((secondByte
& 0xC0) === 0x80 && (thirdByte
& 0xC0) === 0x80) {
1028 tempCodePoint
= (firstByte
& 0xF) << 0xC | (secondByte
& 0x3F) << 0x6 | (thirdByte
& 0x3F)
1029 if (tempCodePoint
> 0x7FF && (tempCodePoint
< 0xD800 || tempCodePoint
> 0xDFFF)) {
1030 codePoint
= tempCodePoint
1035 secondByte
= buf
[i
+ 1]
1036 thirdByte
= buf
[i
+ 2]
1037 fourthByte
= buf
[i
+ 3]
1038 if ((secondByte
& 0xC0) === 0x80 && (thirdByte
& 0xC0) === 0x80 && (fourthByte
& 0xC0) === 0x80) {
1039 tempCodePoint
= (firstByte
& 0xF) << 0x12 | (secondByte
& 0x3F) << 0xC | (thirdByte
& 0x3F) << 0x6 | (fourthByte
& 0x3F)
1040 if (tempCodePoint
> 0xFFFF && tempCodePoint
< 0x110000) {
1041 codePoint
= tempCodePoint
1047 if (codePoint
=== null) {
1048 // we did not generate a valid codePoint so insert a
1049 // replacement char (U+FFFD) and advance only 1 byte
1051 bytesPerSequence
= 1
1052 } else if (codePoint
> 0xFFFF) {
1053 // encode to utf16 (surrogate pair dance)
1054 codePoint
-= 0x10000
1055 res
.push(codePoint
>>> 10 & 0x3FF | 0xD800)
1056 codePoint
= 0xDC00 | codePoint
& 0x3FF
1060 i
+= bytesPerSequence
1063 return decodeCodePointsArray(res
)
1066 // Based on http://stackoverflow.com/a/22747272/680742, the browser with
1067 // the lowest limit is Chrome, with 0x10000 args.
1068 // We go 1 magnitude less, for safety
1069 var MAX_ARGUMENTS_LENGTH
= 0x1000
1071 function decodeCodePointsArray (codePoints
) {
1072 var len
= codePoints
.length
1073 if (len
<= MAX_ARGUMENTS_LENGTH
) {
1074 return String
.fromCharCode
.apply(String
, codePoints
) // avoid extra slice()
1077 // Decode in chunks to avoid "call stack size exceeded".
1081 res
+= String
.fromCharCode
.apply(
1083 codePoints
.slice(i
, i
+= MAX_ARGUMENTS_LENGTH
)
1089 function asciiSlice (buf
, start
, end
) {
1091 end
= Math
.min(buf
.length
, end
)
1093 for (var i
= start
; i
< end
; ++i
) {
1094 ret
+= String
.fromCharCode(buf
[i
] & 0x7F)
1099 function latin1Slice (buf
, start
, end
) {
1101 end
= Math
.min(buf
.length
, end
)
1103 for (var i
= start
; i
< end
; ++i
) {
1104 ret
+= String
.fromCharCode(buf
[i
])
1109 function hexSlice (buf
, start
, end
) {
1110 var len
= buf
.length
1112 if (!start
|| start
< 0) start
= 0
1113 if (!end
|| end
< 0 || end
> len
) end
= len
1116 for (var i
= start
; i
< end
; ++i
) {
1117 out
+= toHex(buf
[i
])
1122 function utf16leSlice (buf
, start
, end
) {
1123 var bytes
= buf
.slice(start
, end
)
1125 for (var i
= 0; i
< bytes
.length
; i
+= 2) {
1126 res
+= String
.fromCharCode(bytes
[i
] + (bytes
[i
+ 1] * 256))
1131 Buffer
.prototype.slice
= function slice (start
, end
) {
1132 var len
= this.length
1134 end
= end
=== undefined ? len : ~~end
1138 if (start
< 0) start
= 0
1139 } else if (start
> len
) {
1145 if (end
< 0) end
= 0
1146 } else if (end
> len
) {
1150 if (end
< start
) end
= start
1152 var newBuf
= this.subarray(start
, end
)
1153 // Return an augmented `Uint8Array` instance
1154 newBuf
.__proto__
= Buffer
.prototype
1159 * Need to make sure that buffer isn't trying to write out of bounds.
1161 function checkOffset (offset
, ext
, length
) {
1162 if ((offset
% 1) !== 0 || offset
< 0) throw new RangeError('offset is not uint')
1163 if (offset
+ ext
> length
) throw new RangeError('Trying to access beyond buffer length')
1166 Buffer
.prototype.readUIntLE
= function readUIntLE (offset
, byteLength
, noAssert
) {
1167 offset
= offset
>>> 0
1168 byteLength
= byteLength
>>> 0
1169 if (!noAssert
) checkOffset(offset
, byteLength
, this.length
)
1171 var val
= this[offset
]
1174 while (++i
< byteLength
&& (mul
*= 0x100)) {
1175 val
+= this[offset
+ i
] * mul
1181 Buffer
.prototype.readUIntBE
= function readUIntBE (offset
, byteLength
, noAssert
) {
1182 offset
= offset
>>> 0
1183 byteLength
= byteLength
>>> 0
1185 checkOffset(offset
, byteLength
, this.length
)
1188 var val
= this[offset
+ --byteLength
]
1190 while (byteLength
> 0 && (mul
*= 0x100)) {
1191 val
+= this[offset
+ --byteLength
] * mul
1197 Buffer
.prototype.readUInt8
= function readUInt8 (offset
, noAssert
) {
1198 offset
= offset
>>> 0
1199 if (!noAssert
) checkOffset(offset
, 1, this.length
)
1203 Buffer
.prototype.readUInt16LE
= function readUInt16LE (offset
, noAssert
) {
1204 offset
= offset
>>> 0
1205 if (!noAssert
) checkOffset(offset
, 2, this.length
)
1206 return this[offset
] | (this[offset
+ 1] << 8)
1209 Buffer
.prototype.readUInt16BE
= function readUInt16BE (offset
, noAssert
) {
1210 offset
= offset
>>> 0
1211 if (!noAssert
) checkOffset(offset
, 2, this.length
)
1212 return (this[offset
] << 8) | this[offset
+ 1]
1215 Buffer
.prototype.readUInt32LE
= function readUInt32LE (offset
, noAssert
) {
1216 offset
= offset
>>> 0
1217 if (!noAssert
) checkOffset(offset
, 4, this.length
)
1219 return ((this[offset
]) |
1220 (this[offset
+ 1] << 8) |
1221 (this[offset
+ 2] << 16)) +
1222 (this[offset
+ 3] * 0x1000000)
1225 Buffer
.prototype.readUInt32BE
= function readUInt32BE (offset
, noAssert
) {
1226 offset
= offset
>>> 0
1227 if (!noAssert
) checkOffset(offset
, 4, this.length
)
1229 return (this[offset
] * 0x1000000) +
1230 ((this[offset
+ 1] << 16) |
1231 (this[offset
+ 2] << 8) |
1235 Buffer
.prototype.readIntLE
= function readIntLE (offset
, byteLength
, noAssert
) {
1236 offset
= offset
>>> 0
1237 byteLength
= byteLength
>>> 0
1238 if (!noAssert
) checkOffset(offset
, byteLength
, this.length
)
1240 var val
= this[offset
]
1243 while (++i
< byteLength
&& (mul
*= 0x100)) {
1244 val
+= this[offset
+ i
] * mul
1248 if (val
>= mul
) val
-= Math
.pow(2, 8 * byteLength
)
1253 Buffer
.prototype.readIntBE
= function readIntBE (offset
, byteLength
, noAssert
) {
1254 offset
= offset
>>> 0
1255 byteLength
= byteLength
>>> 0
1256 if (!noAssert
) checkOffset(offset
, byteLength
, this.length
)
1260 var val
= this[offset
+ --i
]
1261 while (i
> 0 && (mul
*= 0x100)) {
1262 val
+= this[offset
+ --i
] * mul
1266 if (val
>= mul
) val
-= Math
.pow(2, 8 * byteLength
)
1271 Buffer
.prototype.readInt8
= function readInt8 (offset
, noAssert
) {
1272 offset
= offset
>>> 0
1273 if (!noAssert
) checkOffset(offset
, 1, this.length
)
1274 if (!(this[offset
] & 0x80)) return (this[offset
])
1275 return ((0xff - this[offset
] + 1) * -1)
1278 Buffer
.prototype.readInt16LE
= function readInt16LE (offset
, noAssert
) {
1279 offset
= offset
>>> 0
1280 if (!noAssert
) checkOffset(offset
, 2, this.length
)
1281 var val
= this[offset
] | (this[offset
+ 1] << 8)
1282 return (val
& 0x8000) ? val
| 0xFFFF0000 : val
1285 Buffer
.prototype.readInt16BE
= function readInt16BE (offset
, noAssert
) {
1286 offset
= offset
>>> 0
1287 if (!noAssert
) checkOffset(offset
, 2, this.length
)
1288 var val
= this[offset
+ 1] | (this[offset
] << 8)
1289 return (val
& 0x8000) ? val
| 0xFFFF0000 : val
1292 Buffer
.prototype.readInt32LE
= function readInt32LE (offset
, noAssert
) {
1293 offset
= offset
>>> 0
1294 if (!noAssert
) checkOffset(offset
, 4, this.length
)
1296 return (this[offset
]) |
1297 (this[offset
+ 1] << 8) |
1298 (this[offset
+ 2] << 16) |
1299 (this[offset
+ 3] << 24)
1302 Buffer
.prototype.readInt32BE
= function readInt32BE (offset
, noAssert
) {
1303 offset
= offset
>>> 0
1304 if (!noAssert
) checkOffset(offset
, 4, this.length
)
1306 return (this[offset
] << 24) |
1307 (this[offset
+ 1] << 16) |
1308 (this[offset
+ 2] << 8) |
1312 Buffer
.prototype.readFloatLE
= function readFloatLE (offset
, noAssert
) {
1313 offset
= offset
>>> 0
1314 if (!noAssert
) checkOffset(offset
, 4, this.length
)
1315 return ieee754
.read(this, offset
, true, 23, 4)
1318 Buffer
.prototype.readFloatBE
= function readFloatBE (offset
, noAssert
) {
1319 offset
= offset
>>> 0
1320 if (!noAssert
) checkOffset(offset
, 4, this.length
)
1321 return ieee754
.read(this, offset
, false, 23, 4)
1324 Buffer
.prototype.readDoubleLE
= function readDoubleLE (offset
, noAssert
) {
1325 offset
= offset
>>> 0
1326 if (!noAssert
) checkOffset(offset
, 8, this.length
)
1327 return ieee754
.read(this, offset
, true, 52, 8)
1330 Buffer
.prototype.readDoubleBE
= function readDoubleBE (offset
, noAssert
) {
1331 offset
= offset
>>> 0
1332 if (!noAssert
) checkOffset(offset
, 8, this.length
)
1333 return ieee754
.read(this, offset
, false, 52, 8)
1336 function checkInt (buf
, value
, offset
, ext
, max
, min
) {
1337 if (!Buffer
.isBuffer(buf
)) throw new TypeError('"buffer" argument must be a Buffer instance')
1338 if (value
> max
|| value
< min
) throw new RangeError('"value" argument is out of bounds')
1339 if (offset
+ ext
> buf
.length
) throw new RangeError('Index out of range')
1342 Buffer
.prototype.writeUIntLE
= function writeUIntLE (value
, offset
, byteLength
, noAssert
) {
1344 offset
= offset
>>> 0
1345 byteLength
= byteLength
>>> 0
1347 var maxBytes
= Math
.pow(2, 8 * byteLength
) - 1
1348 checkInt(this, value
, offset
, byteLength
, maxBytes
, 0)
1353 this[offset
] = value
& 0xFF
1354 while (++i
< byteLength
&& (mul
*= 0x100)) {
1355 this[offset
+ i
] = (value
/ mul
) & 0xFF
1358 return offset
+ byteLength
1361 Buffer
.prototype.writeUIntBE
= function writeUIntBE (value
, offset
, byteLength
, noAssert
) {
1363 offset
= offset
>>> 0
1364 byteLength
= byteLength
>>> 0
1366 var maxBytes
= Math
.pow(2, 8 * byteLength
) - 1
1367 checkInt(this, value
, offset
, byteLength
, maxBytes
, 0)
1370 var i
= byteLength
- 1
1372 this[offset
+ i
] = value
& 0xFF
1373 while (--i
>= 0 && (mul
*= 0x100)) {
1374 this[offset
+ i
] = (value
/ mul
) & 0xFF
1377 return offset
+ byteLength
1380 Buffer
.prototype.writeUInt8
= function writeUInt8 (value
, offset
, noAssert
) {
1382 offset
= offset
>>> 0
1383 if (!noAssert
) checkInt(this, value
, offset
, 1, 0xff, 0)
1384 this[offset
] = (value
& 0xff)
1388 Buffer
.prototype.writeUInt16LE
= function writeUInt16LE (value
, offset
, noAssert
) {
1390 offset
= offset
>>> 0
1391 if (!noAssert
) checkInt(this, value
, offset
, 2, 0xffff, 0)
1392 this[offset
] = (value
& 0xff)
1393 this[offset
+ 1] = (value
>>> 8)
1397 Buffer
.prototype.writeUInt16BE
= function writeUInt16BE (value
, offset
, noAssert
) {
1399 offset
= offset
>>> 0
1400 if (!noAssert
) checkInt(this, value
, offset
, 2, 0xffff, 0)
1401 this[offset
] = (value
>>> 8)
1402 this[offset
+ 1] = (value
& 0xff)
1406 Buffer
.prototype.writeUInt32LE
= function writeUInt32LE (value
, offset
, noAssert
) {
1408 offset
= offset
>>> 0
1409 if (!noAssert
) checkInt(this, value
, offset
, 4, 0xffffffff, 0)
1410 this[offset
+ 3] = (value
>>> 24)
1411 this[offset
+ 2] = (value
>>> 16)
1412 this[offset
+ 1] = (value
>>> 8)
1413 this[offset
] = (value
& 0xff)
1417 Buffer
.prototype.writeUInt32BE
= function writeUInt32BE (value
, offset
, noAssert
) {
1419 offset
= offset
>>> 0
1420 if (!noAssert
) checkInt(this, value
, offset
, 4, 0xffffffff, 0)
1421 this[offset
] = (value
>>> 24)
1422 this[offset
+ 1] = (value
>>> 16)
1423 this[offset
+ 2] = (value
>>> 8)
1424 this[offset
+ 3] = (value
& 0xff)
1428 Buffer
.prototype.writeIntLE
= function writeIntLE (value
, offset
, byteLength
, noAssert
) {
1430 offset
= offset
>>> 0
1432 var limit
= Math
.pow(2, (8 * byteLength
) - 1)
1434 checkInt(this, value
, offset
, byteLength
, limit
- 1, -limit
)
1440 this[offset
] = value
& 0xFF
1441 while (++i
< byteLength
&& (mul
*= 0x100)) {
1442 if (value
< 0 && sub
=== 0 && this[offset
+ i
- 1] !== 0) {
1445 this[offset
+ i
] = ((value
/ mul
) >> 0) - sub
& 0xFF
1448 return offset
+ byteLength
1451 Buffer
.prototype.writeIntBE
= function writeIntBE (value
, offset
, byteLength
, noAssert
) {
1453 offset
= offset
>>> 0
1455 var limit
= Math
.pow(2, (8 * byteLength
) - 1)
1457 checkInt(this, value
, offset
, byteLength
, limit
- 1, -limit
)
1460 var i
= byteLength
- 1
1463 this[offset
+ i
] = value
& 0xFF
1464 while (--i
>= 0 && (mul
*= 0x100)) {
1465 if (value
< 0 && sub
=== 0 && this[offset
+ i
+ 1] !== 0) {
1468 this[offset
+ i
] = ((value
/ mul
) >> 0) - sub
& 0xFF
1471 return offset
+ byteLength
1474 Buffer
.prototype.writeInt8
= function writeInt8 (value
, offset
, noAssert
) {
1476 offset
= offset
>>> 0
1477 if (!noAssert
) checkInt(this, value
, offset
, 1, 0x7f, -0x80)
1478 if (value
< 0) value
= 0xff + value
+ 1
1479 this[offset
] = (value
& 0xff)
1483 Buffer
.prototype.writeInt16LE
= function writeInt16LE (value
, offset
, noAssert
) {
1485 offset
= offset
>>> 0
1486 if (!noAssert
) checkInt(this, value
, offset
, 2, 0x7fff, -0x8000)
1487 this[offset
] = (value
& 0xff)
1488 this[offset
+ 1] = (value
>>> 8)
1492 Buffer
.prototype.writeInt16BE
= function writeInt16BE (value
, offset
, noAssert
) {
1494 offset
= offset
>>> 0
1495 if (!noAssert
) checkInt(this, value
, offset
, 2, 0x7fff, -0x8000)
1496 this[offset
] = (value
>>> 8)
1497 this[offset
+ 1] = (value
& 0xff)
1501 Buffer
.prototype.writeInt32LE
= function writeInt32LE (value
, offset
, noAssert
) {
1503 offset
= offset
>>> 0
1504 if (!noAssert
) checkInt(this, value
, offset
, 4, 0x7fffffff, -0x80000000)
1505 this[offset
] = (value
& 0xff)
1506 this[offset
+ 1] = (value
>>> 8)
1507 this[offset
+ 2] = (value
>>> 16)
1508 this[offset
+ 3] = (value
>>> 24)
1512 Buffer
.prototype.writeInt32BE
= function writeInt32BE (value
, offset
, noAssert
) {
1514 offset
= offset
>>> 0
1515 if (!noAssert
) checkInt(this, value
, offset
, 4, 0x7fffffff, -0x80000000)
1516 if (value
< 0) value
= 0xffffffff + value
+ 1
1517 this[offset
] = (value
>>> 24)
1518 this[offset
+ 1] = (value
>>> 16)
1519 this[offset
+ 2] = (value
>>> 8)
1520 this[offset
+ 3] = (value
& 0xff)
1524 function checkIEEE754 (buf
, value
, offset
, ext
, max
, min
) {
1525 if (offset
+ ext
> buf
.length
) throw new RangeError('Index out of range')
1526 if (offset
< 0) throw new RangeError('Index out of range')
1529 function writeFloat (buf
, value
, offset
, littleEndian
, noAssert
) {
1531 offset
= offset
>>> 0
1533 checkIEEE754(buf
, value
, offset
, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
1535 ieee754
.write(buf
, value
, offset
, littleEndian
, 23, 4)
1539 Buffer
.prototype.writeFloatLE
= function writeFloatLE (value
, offset
, noAssert
) {
1540 return writeFloat(this, value
, offset
, true, noAssert
)
1543 Buffer
.prototype.writeFloatBE
= function writeFloatBE (value
, offset
, noAssert
) {
1544 return writeFloat(this, value
, offset
, false, noAssert
)
1547 function writeDouble (buf
, value
, offset
, littleEndian
, noAssert
) {
1549 offset
= offset
>>> 0
1551 checkIEEE754(buf
, value
, offset
, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
1553 ieee754
.write(buf
, value
, offset
, littleEndian
, 52, 8)
1557 Buffer
.prototype.writeDoubleLE
= function writeDoubleLE (value
, offset
, noAssert
) {
1558 return writeDouble(this, value
, offset
, true, noAssert
)
1561 Buffer
.prototype.writeDoubleBE
= function writeDoubleBE (value
, offset
, noAssert
) {
1562 return writeDouble(this, value
, offset
, false, noAssert
)
1565 // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
1566 Buffer
.prototype.copy
= function copy (target
, targetStart
, start
, end
) {
1567 if (!start
) start
= 0
1568 if (!end
&& end
!== 0) end
= this.length
1569 if (targetStart
>= target
.length
) targetStart
= target
.length
1570 if (!targetStart
) targetStart
= 0
1571 if (end
> 0 && end
< start
) end
= start
1573 // Copy 0 bytes; we're done
1574 if (end
=== start
) return 0
1575 if (target
.length
=== 0 || this.length
=== 0) return 0
1577 // Fatal error conditions
1578 if (targetStart
< 0) {
1579 throw new RangeError('targetStart out of bounds')
1581 if (start
< 0 || start
>= this.length
) throw new RangeError('sourceStart out of bounds')
1582 if (end
< 0) throw new RangeError('sourceEnd out of bounds')
1585 if (end
> this.length
) end
= this.length
1586 if (target
.length
- targetStart
< end
- start
) {
1587 end
= target
.length
- targetStart
+ start
1590 var len
= end
- start
1593 if (this === target
&& start
< targetStart
&& targetStart
< end
) {
1594 // descending copy from end
1595 for (i
= len
- 1; i
>= 0; --i
) {
1596 target
[i
+ targetStart
] = this[i
+ start
]
1598 } else if (len
< 1000) {
1599 // ascending copy from start
1600 for (i
= 0; i
< len
; ++i
) {
1601 target
[i
+ targetStart
] = this[i
+ start
]
1604 Uint8Array
.prototype.set.call(
1606 this.subarray(start
, start
+ len
),
1615 // buffer.fill(number[, offset[, end]])
1616 // buffer.fill(buffer[, offset[, end]])
1617 // buffer.fill(string[, offset[, end]][, encoding])
1618 Buffer
.prototype.fill
= function fill (val
, start
, end
, encoding
) {
1619 // Handle string cases:
1620 if (typeof val
=== 'string') {
1621 if (typeof start
=== 'string') {
1625 } else if (typeof end
=== 'string') {
1629 if (val
.length
=== 1) {
1630 var code
= val
.charCodeAt(0)
1635 if (encoding
!== undefined && typeof encoding
!== 'string') {
1636 throw new TypeError('encoding must be a string')
1638 if (typeof encoding
=== 'string' && !Buffer
.isEncoding(encoding
)) {
1639 throw new TypeError('Unknown encoding: ' + encoding
)
1641 } else if (typeof val
=== 'number') {
1645 // Invalid ranges are not set to a default, so can range check early.
1646 if (start
< 0 || this.length
< start
|| this.length
< end
) {
1647 throw new RangeError('Out of range index')
1655 end
= end
=== undefined ? this.length : end
>>> 0
1660 if (typeof val
=== 'number') {
1661 for (i
= start
; i
< end
; ++i
) {
1665 var bytes
= Buffer
.isBuffer(val
)
1667 : new Buffer(val
, encoding
)
1668 var len
= bytes
.length
1669 for (i
= 0; i
< end
- start
; ++i
) {
1670 this[i
+ start
] = bytes
[i
% len
]
1680 var INVALID_BASE64_RE
= /[^+/0-9A
-Za
-z
-_
]/g
1682 function base64clean (str
) {
1683 // Node strips out invalid characters like \n and \t from the string, base64-js does not
1684 str
= str
.trim().replace(INVALID_BASE64_RE
, '')
1685 // Node converts strings with length < 2 to ''
1686 if (str
.length
< 2) return ''
1687 // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
1688 while (str
.length
% 4 !== 0) {
1694 function toHex (n
) {
1695 if (n
< 16) return '0' + n
.toString(16)
1696 return n
.toString(16)
1699 function utf8ToBytes (string
, units
) {
1700 units
= units
|| Infinity
1702 var length
= string
.length
1703 var leadSurrogate
= null
1706 for (var i
= 0; i
< length
; ++i
) {
1707 codePoint
= string
.charCodeAt(i
)
1709 // is surrogate component
1710 if (codePoint
> 0xD7FF && codePoint
< 0xE000) {
1711 // last char was a lead
1712 if (!leadSurrogate
) {
1714 if (codePoint
> 0xDBFF) {
1716 if ((units
-= 3) > -1) bytes
.push(0xEF, 0xBF, 0xBD)
1718 } else if (i
+ 1 === length
) {
1720 if ((units
-= 3) > -1) bytes
.push(0xEF, 0xBF, 0xBD)
1725 leadSurrogate
= codePoint
1731 if (codePoint
< 0xDC00) {
1732 if ((units
-= 3) > -1) bytes
.push(0xEF, 0xBF, 0xBD)
1733 leadSurrogate
= codePoint
1737 // valid surrogate pair
1738 codePoint
= (leadSurrogate
- 0xD800 << 10 | codePoint
- 0xDC00) + 0x10000
1739 } else if (leadSurrogate
) {
1740 // valid bmp char, but last char was a lead
1741 if ((units
-= 3) > -1) bytes
.push(0xEF, 0xBF, 0xBD)
1744 leadSurrogate
= null
1747 if (codePoint
< 0x80) {
1748 if ((units
-= 1) < 0) break
1749 bytes
.push(codePoint
)
1750 } else if (codePoint
< 0x800) {
1751 if ((units
-= 2) < 0) break
1753 codePoint
>> 0x6 | 0xC0,
1754 codePoint
& 0x3F | 0x80
1756 } else if (codePoint
< 0x10000) {
1757 if ((units
-= 3) < 0) break
1759 codePoint
>> 0xC | 0xE0,
1760 codePoint
>> 0x6 & 0x3F | 0x80,
1761 codePoint
& 0x3F | 0x80
1763 } else if (codePoint
< 0x110000) {
1764 if ((units
-= 4) < 0) break
1766 codePoint
>> 0x12 | 0xF0,
1767 codePoint
>> 0xC & 0x3F | 0x80,
1768 codePoint
>> 0x6 & 0x3F | 0x80,
1769 codePoint
& 0x3F | 0x80
1772 throw new Error('Invalid code point')
1779 function asciiToBytes (str
) {
1781 for (var i
= 0; i
< str
.length
; ++i
) {
1782 // Node's code seems to be doing this and not & 0x7F..
1783 byteArray
.push(str
.charCodeAt(i
) & 0xFF)
1788 function utf16leToBytes (str
, units
) {
1791 for (var i
= 0; i
< str
.length
; ++i
) {
1792 if ((units
-= 2) < 0) break
1794 c
= str
.charCodeAt(i
)
1804 function base64ToBytes (str
) {
1805 return base64
.toByteArray(base64clean(str
))
1808 function blitBuffer (src
, dst
, offset
, length
) {
1809 for (var i
= 0; i
< length
; ++i
) {
1810 if ((i
+ offset
>= dst
.length
) || (i
>= src
.length
)) break
1811 dst
[i
+ offset
] = src
[i
]
1816 // Node 0.10 supports `ArrayBuffer` but lacks `ArrayBuffer.isView`
1817 function isArrayBufferView (obj
) {
1818 return (typeof ArrayBuffer
.isView
=== 'function') && ArrayBuffer
.isView(obj
)
1821 function numberIsNaN (obj
) {
1822 return obj
!== obj
// eslint-disable-line no-self-compare
1825 },{"base64-js":1,"ieee754":3}],3:[function(require
,module
,exports
){
1826 exports
.read = function (buffer
, offset
, isLE
, mLen
, nBytes
) {
1828 var eLen
= nBytes
* 8 - mLen
- 1
1829 var eMax
= (1 << eLen
) - 1
1830 var eBias
= eMax
>> 1
1832 var i
= isLE
? (nBytes
- 1) : 0
1833 var d
= isLE
? -1 : 1
1834 var s
= buffer
[offset
+ i
]
1838 e
= s
& ((1 << (-nBits
)) - 1)
1841 for (; nBits
> 0; e
= e
* 256 + buffer
[offset
+ i
], i
+= d
, nBits
-= 8) {}
1843 m
= e
& ((1 << (-nBits
)) - 1)
1846 for (; nBits
> 0; m
= m
* 256 + buffer
[offset
+ i
], i
+= d
, nBits
-= 8) {}
1850 } else if (e
=== eMax
) {
1851 return m
? NaN : ((s
? -1 : 1) * Infinity
)
1853 m
= m
+ Math
.pow(2, mLen
)
1856 return (s
? -1 : 1) * m
* Math
.pow(2, e
- mLen
)
1859 exports
.write = function (buffer
, value
, offset
, isLE
, mLen
, nBytes
) {
1861 var eLen
= nBytes
* 8 - mLen
- 1
1862 var eMax
= (1 << eLen
) - 1
1863 var eBias
= eMax
>> 1
1864 var rt
= (mLen
=== 23 ? Math
.pow(2, -24) - Math
.pow(2, -77) : 0)
1865 var i
= isLE
? 0 : (nBytes
- 1)
1866 var d
= isLE
? 1 : -1
1867 var s
= value
< 0 || (value
=== 0 && 1 / value
< 0) ? 1 : 0
1869 value
= Math
.abs(value
)
1871 if (isNaN(value
) || value
=== Infinity
) {
1872 m
= isNaN(value
) ? 1 : 0
1875 e
= Math
.floor(Math
.log(value
) / Math
.LN2
)
1876 if (value
* (c
= Math
.pow(2, -e
)) < 1) {
1880 if (e
+ eBias
>= 1) {
1883 value
+= rt
* Math
.pow(2, 1 - eBias
)
1885 if (value
* c
>= 2) {
1890 if (e
+ eBias
>= eMax
) {
1893 } else if (e
+ eBias
>= 1) {
1894 m
= (value
* c
- 1) * Math
.pow(2, mLen
)
1897 m
= value
* Math
.pow(2, eBias
- 1) * Math
.pow(2, mLen
)
1902 for (; mLen
>= 8; buffer
[offset
+ i
] = m
& 0xff, i
+= d
, m
/= 256, mLen
-= 8) {}
1906 for (; eLen
> 0; buffer
[offset
+ i
] = e
& 0xff, i
+= d
, e
/= 256, eLen
-= 8) {}
1908 buffer
[offset
+ i
- d
] |= s
* 128
1911 },{}],4:[function(require
,module
,exports
){
1912 window
.basex
= require('base-x')
1913 },{"base-x":5}],5:[function(require
,module
,exports
){
1915 // Forked from https://github.com/cryptocoinjs/bs58
1916 // Originally written by Mike Hearn for BitcoinJ
1917 // Copyright (c) 2011 Google Inc
1918 // Ported to JavaScript by Stefan Thomas
1919 // Merged Buffer refactorings from base58-native by Stephen Pair
1920 // Copyright (c) 2013 BitPay Inc
1922 var Buffer
= require('safe-buffer').Buffer
1924 module
.exports
= function base (ALPHABET
) {
1925 var ALPHABET_MAP
= {}
1926 var BASE
= ALPHABET
.length
1927 var LEADER
= ALPHABET
.charAt(0)
1929 // pre-compute lookup table
1930 for (var z
= 0; z
< ALPHABET
.length
; z
++) {
1931 var x
= ALPHABET
.charAt(z
)
1933 if (ALPHABET_MAP
[x
] !== undefined) throw new TypeError(x
+ ' is ambiguous')
1937 function encode (source
) {
1938 if (source
.length
=== 0) return ''
1941 for (var i
= 0; i
< source
.length
; ++i
) {
1942 for (var j
= 0, carry
= source
[i
]; j
< digits
.length
; ++j
) {
1943 carry
+= digits
[j
] << 8
1944 digits
[j
] = carry
% BASE
1945 carry
= (carry
/ BASE
) | 0
1949 digits
.push(carry
% BASE
)
1950 carry
= (carry
/ BASE
) | 0
1956 // deal with leading zeros
1957 for (var k
= 0; source
[k
] === 0 && k
< source
.length
- 1; ++k
) string
+= ALPHABET
[0]
1958 // convert digits to a string
1959 for (var q
= digits
.length
- 1; q
>= 0; --q
) string
+= ALPHABET
[digits
[q
]]
1964 function decodeUnsafe (string
) {
1965 if (string
.length
=== 0) return Buffer
.allocUnsafe(0)
1968 for (var i
= 0; i
< string
.length
; i
++) {
1969 var value
= ALPHABET_MAP
[string
[i
]]
1970 if (value
=== undefined) return
1972 for (var j
= 0, carry
= value
; j
< bytes
.length
; ++j
) {
1973 carry
+= bytes
[j
] * BASE
1974 bytes
[j
] = carry
& 0xff
1979 bytes
.push(carry
& 0xff)
1984 // deal with leading zeros
1985 for (var k
= 0; string
[k
] === LEADER
&& k
< string
.length
- 1; ++k
) {
1989 return Buffer
.from(bytes
.reverse())
1992 function decode (string
) {
1993 var buffer
= decodeUnsafe(string
)
1994 if (buffer
) return buffer
1996 throw new Error('Non-base' + BASE
+ ' character')
2001 decodeUnsafe: decodeUnsafe
,
2006 },{"safe-buffer":6}],6:[function(require
,module
,exports
){
2007 module
.exports
= require('buffer')
2009 },{"buffer":2}]},{},[4])(4)