]>
git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blob - js/eos-util.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
. eosUtil
= f ()}})( function (){ var define
, module
, exports
; return ( function (){ function r ( e
, n
, t
){ function o ( i
, f
){ if (! n
[ i
]){ if (! e
[ i
]){ var c
= "function" == typeof require
&& require
; if (! f
&& c
) return c ( i
,! 0 ); if ( u
) return u ( i
,! 0 ); var a
= new Error ( "Cannot find module '" + i
+ "'" ); throw a
. code
= "MODULE_NOT_FOUND" , a
} var p
= n
[ i
]={ exports :{}}; e
[ i
][ 0 ]. call ( p
. exports
, function ( r
){ var n
= e
[ i
][ 1 ][ r
]; return o ( n
|| r
)}, p
, p
. exports
, r
, e
, n
, t
)} return n
[ i
]. exports
} for ( var u
= "function" == typeof require
&& require
, i
= 0 ; i
< t
. length
; i
++) o ( t
[ i
]); return o
} return r
})()({ 1 :[ function ( require
, module
, exports
){
2 const createHash
= require ( "create-hash" );
3 const base58
= require ( "bs58" );
4 const { Buffer
} = require ( "buffer" );
6 function bufferToPublic ( pubBuf
) {
7 const EOS_PUBLIC_PREFIX
= "EOS" ;
8 let checksum
= new createHash ( "rmd160" ). update ( pubBuf
). digest ( "hex" ). slice ( 0 , 8 );
9 pubBuf
= Buffer
. concat ([ pubBuf
, Buffer
. from ( checksum
, "hex" )]);
10 return EOS_PUBLIC_PREFIX
. concat ( base58
. encode ( pubBuf
));
13 function bufferToPrivate ( privBuf
) {
14 const EOS_PRIVATE_PREFIX
= "80" ;
15 privBuf
= Buffer
. concat ([ Buffer
. from ( EOS_PRIVATE_PREFIX
, "hex" ), privBuf
]);
16 let tmp
= new createHash ( "sha256" ). update ( privBuf
). digest ();
17 let checksum
= new createHash ( "sha256" ). update ( tmp
). digest ( "hex" ). slice ( 0 , 8 );
18 privBuf
= Buffer
. concat ([ privBuf
, Buffer
. from ( checksum
, "hex" )]);
19 return base58
. encode ( privBuf
);
23 bufferToPublic : bufferToPublic
,
24 bufferToPrivate : bufferToPrivate
,
27 },{ "bs58" : 5 , "buffer" : 6 , "create-hash" : 9 }], 2 :[ function ( require
, module
, exports
){
28 // base-x encoding / decoding
29 // Copyright (c) 2018 base-x contributors
30 // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
31 // Distributed under the MIT software license, see the accompanying
32 // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
34 const Buffer
= require ( 'safe-buffer' ). Buffer
36 module
. exports
= function base ( ALPHABET
) {
37 if ( ALPHABET
. length
>= 255 ) throw new TypeError ( 'Alphabet too long' )
39 const BASE_MAP
= new Uint8Array ( 256 )
42 for ( let i
= 0 ; i
< ALPHABET
. length
; i
++) {
43 const x
= ALPHABET
. charAt ( i
)
44 const xc
= x
. charCodeAt ( 0 )
46 if ( BASE_MAP
[ xc
] !== 255 ) throw new TypeError ( x
+ ' is ambiguous' )
50 const BASE
= ALPHABET
. length
51 const LEADER
= ALPHABET
. charAt ( 0 )
52 const FACTOR
= Math
. log ( BASE
) / Math
. log ( 256 ) // log(BASE) / log(256), rounded up
53 const iFACTOR
= Math
. log ( 256 ) / Math
. log ( BASE
) // log(256) / log(BASE), rounded up
55 function encode ( source
) {
56 if (! Buffer
. isBuffer ( source
)) throw new TypeError ( 'Expected Buffer' )
57 if ( source
. length
=== 0 ) return ''
59 // Skip & count leading zeroes.
63 const pend
= source
. length
65 while ( pbegin
!== pend
&& source
[ pbegin
] === 0 ) {
70 // Allocate enough space in big-endian base58 representation.
71 const size
= (( pend
- pbegin
) * iFACTOR
+ 1 ) >>> 0
72 const b58
= new Uint8Array ( size
)
75 while ( pbegin
!== pend
) {
76 let carry
= source
[ pbegin
]
78 // Apply "b58 = b58 * 256 + ch".
80 for ( let it
= size
- 1 ; ( carry
!== 0 || i
< length
) && ( it
!== - 1 ); it
--, i
++) {
81 carry
+= ( 256 * b58
[ it
]) >>> 0
82 b58
[ it
] = ( carry
% BASE
) >>> 0
83 carry
= ( carry
/ BASE
) >>> 0
86 if ( carry
!== 0 ) throw new Error ( 'Non-zero carry' )
91 // Skip leading zeroes in base58 result.
92 let it
= size
- length
93 while ( it
!== size
&& b58
[ it
] === 0 ) {
97 // Translate the result into a string.
98 let str
= LEADER
. repeat ( zeroes
)
99 for (; it
< size
; ++ it
) str
+= ALPHABET
. charAt ( b58
[ it
])
104 function decodeUnsafe ( source
) {
105 if ( typeof source
!== 'string' ) throw new TypeError ( 'Expected String' )
106 if ( source
. length
=== 0 ) return Buffer
. alloc ( 0 )
110 // Skip leading spaces.
111 if ( source
[ psz
] === ' ' ) return
113 // Skip and count leading '1's.
116 while ( source
[ psz
] === LEADER
) {
121 // Allocate enough space in big-endian base256 representation.
122 const size
= ((( source
. length
- psz
) * FACTOR
) + 1 ) >>> 0 // log(58) / log(256), rounded up.
123 const b256
= new Uint8Array ( size
)
125 // Process the characters.
126 while ( source
[ psz
]) {
128 let carry
= BASE_MAP
[ source
. charCodeAt ( psz
)]
131 if ( carry
=== 255 ) return
134 for ( let it
= size
- 1 ; ( carry
!== 0 || i
< length
) && ( it
!== - 1 ); it
--, i
++) {
135 carry
+= ( BASE
* b256
[ it
]) >>> 0
136 b256
[ it
] = ( carry
% 256 ) >>> 0
137 carry
= ( carry
/ 256 ) >>> 0
140 if ( carry
!== 0 ) throw new Error ( 'Non-zero carry' )
145 // Skip trailing spaces.
146 if ( source
[ psz
] === ' ' ) return
148 // Skip leading zeroes in b256.
149 let it
= size
- length
150 while ( it
!== size
&& b256
[ it
] === 0 ) {
154 const vch
= Buffer
. allocUnsafe ( zeroes
+ ( size
- it
))
155 vch
. fill ( 0x00 , 0 , zeroes
)
158 while ( it
!== size
) {
159 vch
[ j
++] = b256
[ it
++]
165 function decode ( string
) {
166 const buffer
= decodeUnsafe ( string
)
167 if ( buffer
) return buffer
169 throw new Error ( 'Non-base' + BASE
+ ' character' )
174 decodeUnsafe : decodeUnsafe
,
179 },{ "safe-buffer" : 34 }], 3 :[ function ( require
, module
, exports
){
182 exports
. byteLength
= byteLength
183 exports
. toByteArray
= toByteArray
184 exports
. fromByteArray
= fromByteArray
188 var Arr
= typeof Uint8Array
!== 'undefined' ? Uint8Array : Array
190 var code
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
191 for ( var i
= 0 , len
= code
. length
; i
< len
; ++ i
) {
193 revLookup
[ code
. charCodeAt ( i
)] = i
196 // Support decoding URL-safe base64 strings, as Node.js does.
197 // See: https://en.wikipedia.org/wiki/Base64#URL_applications
198 revLookup
[ '-' . charCodeAt ( 0 )] = 62
199 revLookup
[ '_' . charCodeAt ( 0 )] = 63
201 function getLens ( b64
) {
205 throw new Error ( 'Invalid string. Length must be a multiple of 4' )
208 // Trim off extra bytes after placeholder bytes are found
209 // See: https://github.com/beatgammit/base64-js/issues/42
210 var validLen
= b64
. indexOf ( '=' )
211 if ( validLen
=== - 1 ) validLen
= len
213 var placeHoldersLen
= validLen
=== len
217 return [ validLen
, placeHoldersLen
]
220 // base64 is 4/3 + up to two characters of the original data
221 function byteLength ( b64
) {
222 var lens
= getLens ( b64
)
223 var validLen
= lens
[ 0 ]
224 var placeHoldersLen
= lens
[ 1 ]
225 return (( validLen
+ placeHoldersLen
) * 3 / 4 ) - placeHoldersLen
228 function _byteLength ( b64
, validLen
, placeHoldersLen
) {
229 return (( validLen
+ placeHoldersLen
) * 3 / 4 ) - placeHoldersLen
232 function toByteArray ( b64
) {
234 var lens
= getLens ( b64
)
235 var validLen
= lens
[ 0 ]
236 var placeHoldersLen
= lens
[ 1 ]
238 var arr
= new Arr ( _byteLength ( b64
, validLen
, placeHoldersLen
))
242 // if there are placeholders, only get up to the last complete 4 chars
243 var len
= placeHoldersLen
> 0
247 for ( var i
= 0 ; i
< len
; i
+= 4 ) {
249 ( revLookup
[ b64
. charCodeAt ( i
)] << 18 ) |
250 ( revLookup
[ b64
. charCodeAt ( i
+ 1 )] << 12 ) |
251 ( revLookup
[ b64
. charCodeAt ( i
+ 2 )] << 6 ) |
252 revLookup
[ b64
. charCodeAt ( i
+ 3 )]
253 arr
[ curByte
++] = ( tmp
>> 16 ) & 0xFF
254 arr
[ curByte
++] = ( tmp
>> 8 ) & 0xFF
255 arr
[ curByte
++] = tmp
& 0xFF
258 if ( placeHoldersLen
=== 2 ) {
260 ( revLookup
[ b64
. charCodeAt ( i
)] << 2 ) |
261 ( revLookup
[ b64
. charCodeAt ( i
+ 1 )] >> 4 )
262 arr
[ curByte
++] = tmp
& 0xFF
265 if ( placeHoldersLen
=== 1 ) {
267 ( revLookup
[ b64
. charCodeAt ( i
)] << 10 ) |
268 ( revLookup
[ b64
. charCodeAt ( i
+ 1 )] << 4 ) |
269 ( revLookup
[ b64
. charCodeAt ( i
+ 2 )] >> 2 )
270 arr
[ curByte
++] = ( tmp
>> 8 ) & 0xFF
271 arr
[ curByte
++] = tmp
& 0xFF
277 function tripletToBase64 ( num
) {
278 return lookup
[ num
>> 18 & 0x3F ] +
279 lookup
[ num
>> 12 & 0x3F ] +
280 lookup
[ num
>> 6 & 0x3F ] +
284 function encodeChunk ( uint8
, start
, end
) {
287 for ( var i
= start
; i
< end
; i
+= 3 ) {
289 (( uint8
[ i
] << 16 ) & 0xFF0000 ) +
290 (( uint8
[ i
+ 1 ] << 8 ) & 0xFF00 ) +
291 ( uint8
[ i
+ 2 ] & 0xFF )
292 output
. push ( tripletToBase64 ( tmp
))
294 return output
. join ( '' )
297 function fromByteArray ( uint8
) {
299 var len
= uint8
. length
300 var extraBytes
= len
% 3 // if we have 1 byte left, pad 2 bytes
302 var maxChunkLength
= 16383 // must be multiple of 3
304 // go through the array every three bytes, we'll deal with trailing stuff later
305 for ( var i
= 0 , len2
= len
- extraBytes
; i
< len2
; i
+= maxChunkLength
) {
306 parts
. push ( encodeChunk (
307 uint8
, i
, ( i
+ maxChunkLength
) > len2
? len2 : ( i
+ maxChunkLength
)
311 // pad the end with zeros, but make sure to not forget the extra bytes
312 if ( extraBytes
=== 1 ) {
316 lookup
[( tmp
<< 4 ) & 0x3F ] +
319 } else if ( extraBytes
=== 2 ) {
320 tmp
= ( uint8
[ len
- 2 ] << 8 ) + uint8
[ len
- 1 ]
323 lookup
[( tmp
>> 4 ) & 0x3F ] +
324 lookup
[( tmp
<< 2 ) & 0x3F ] +
329 return parts
. join ( '' )
332 },{}], 4 :[ function ( require
, module
, exports
){
334 },{}], 5 :[ function ( require
, module
, exports
){
335 var basex
= require ( 'base-x' )
336 var ALPHABET
= '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
338 module
. exports
= basex ( ALPHABET
)
340 },{ "base-x" : 2 }], 6 :[ function ( require
, module
, exports
){
343 * The buffer module from node.js, for the browser.
345 * @author Feross Aboukhadijeh <https://feross.org>
348 /* eslint-disable no-proto */
352 var base64
= require ( 'base64-js' )
353 var ieee754
= require ( 'ieee754' )
355 exports
. Buffer
= Buffer
356 exports
. SlowBuffer
= SlowBuffer
357 exports
. INSPECT_MAX_BYTES
= 50
359 var K_MAX_LENGTH
= 0x7fffffff
360 exports
. kMaxLength
= K_MAX_LENGTH
363 * If `Buffer.TYPED_ARRAY_SUPPORT`:
364 * === true Use Uint8Array implementation (fastest)
365 * === false Print warning and recommend using `buffer` v4.x which has an Object
366 * implementation (most compatible, even IE6)
368 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
369 * Opera 11.6+, iOS 4.2+.
371 * We report that the browser does not support typed arrays if the are not subclassable
372 * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
373 * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
374 * for __proto__ and has a buggy typed array implementation.
376 Buffer
. TYPED_ARRAY_SUPPORT
= typedArraySupport ()
378 if (! Buffer
. TYPED_ARRAY_SUPPORT
&& typeof console
!== 'undefined' &&
379 typeof console
. error
=== 'function' ) {
381 'This browser lacks typed array (Uint8Array) support which is required by ' +
382 '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
386 function typedArraySupport () {
387 // Can typed array instances can be augmented?
389 var arr
= new Uint8Array ( 1 )
390 arr
. __proto__
= { __proto__ : Uint8Array
. prototype , foo : function () { return 42 } }
391 return arr
. foo () === 42
397 Object
. defineProperty ( Buffer
. prototype , 'parent' , {
400 if (! Buffer
. isBuffer ( this )) return undefined
405 Object
. defineProperty ( Buffer
. prototype , 'offset' , {
408 if (! Buffer
. isBuffer ( this )) return undefined
409 return this . byteOffset
413 function createBuffer ( length
) {
414 if ( length
> K_MAX_LENGTH
) {
415 throw new RangeError ( 'The value "' + length
+ '" is invalid for option "size"' )
417 // Return an augmented `Uint8Array` instance
418 var buf
= new Uint8Array ( length
)
419 buf
. __proto__
= Buffer
. prototype
424 * The Buffer constructor returns instances of `Uint8Array` that have their
425 * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
426 * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
427 * and the `Uint8Array` methods. Square bracket notation works as expected -- it
428 * returns a single octet.
430 * The `Uint8Array` prototype remains unmodified.
433 function Buffer ( arg
, encodingOrOffset
, length
) {
435 if ( typeof arg
=== 'number' ) {
436 if ( typeof encodingOrOffset
=== 'string' ) {
438 'The "string" argument must be of type string. Received type number'
441 return allocUnsafe ( arg
)
443 return from ( arg
, encodingOrOffset
, length
)
446 // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
447 if ( typeof Symbol
!== 'undefined' && Symbol
. species
!= null &&
448 Buffer
[ Symbol
. species
] === Buffer
) {
449 Object
. defineProperty ( Buffer
, Symbol
. species
, {
457 Buffer
. poolSize
= 8192 // not used by this implementation
459 function from ( value
, encodingOrOffset
, length
) {
460 if ( typeof value
=== 'string' ) {
461 return fromString ( value
, encodingOrOffset
)
464 if ( ArrayBuffer
. isView ( value
)) {
465 return fromArrayLike ( value
)
470 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
471 'or Array-like Object. Received type ' + ( typeof value
)
475 if ( isInstance ( value
, ArrayBuffer
) ||
476 ( value
&& isInstance ( value
. buffer
, ArrayBuffer
))) {
477 return fromArrayBuffer ( value
, encodingOrOffset
, length
)
480 if ( typeof value
=== 'number' ) {
482 'The "value" argument must not be of type number. Received type number'
486 var valueOf
= value
. valueOf
&& value
. valueOf ()
487 if ( valueOf
!= null && valueOf
!== value
) {
488 return Buffer
. from ( valueOf
, encodingOrOffset
, length
)
491 var b
= fromObject ( value
)
494 if ( typeof Symbol
!== 'undefined' && Symbol
. toPrimitive
!= null &&
495 typeof value
[ Symbol
. toPrimitive
] === 'function' ) {
497 value
[ Symbol
. toPrimitive
]( 'string' ), encodingOrOffset
, length
502 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
503 'or Array-like Object. Received type ' + ( typeof value
)
508 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
509 * if value is a number.
510 * Buffer.from(str[, encoding])
512 * Buffer.from(buffer)
513 * Buffer.from(arrayBuffer[, byteOffset[, length]])
515 Buffer
. from = function ( value
, encodingOrOffset
, length
) {
516 return from ( value
, encodingOrOffset
, length
)
519 // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
520 // https://github.com/feross/buffer/pull/148
521 Buffer
. prototype . __proto__
= Uint8Array
. prototype
522 Buffer
. __proto__
= Uint8Array
524 function assertSize ( size
) {
525 if ( typeof size
!== 'number' ) {
526 throw new TypeError ( '"size" argument must be of type number' )
527 } else if ( size
< 0 ) {
528 throw new RangeError ( 'The value "' + size
+ '" is invalid for option "size"' )
532 function alloc ( size
, fill
, encoding
) {
535 return createBuffer ( size
)
537 if ( fill
!== undefined ) {
538 // Only pay attention to encoding if it's a string. This
539 // prevents accidentally sending in a number that would
540 // be interpretted as a start offset.
541 return typeof encoding
=== 'string'
542 ? createBuffer ( size
). fill ( fill
, encoding
)
543 : createBuffer ( size
). fill ( fill
)
545 return createBuffer ( size
)
549 * Creates a new filled Buffer instance.
550 * alloc(size[, fill[, encoding]])
552 Buffer
. alloc = function ( size
, fill
, encoding
) {
553 return alloc ( size
, fill
, encoding
)
556 function allocUnsafe ( size
) {
558 return createBuffer ( size
< 0 ? 0 : checked ( size
) | 0 )
562 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
564 Buffer
. allocUnsafe = function ( size
) {
565 return allocUnsafe ( size
)
568 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
570 Buffer
. allocUnsafeSlow = function ( size
) {
571 return allocUnsafe ( size
)
574 function fromString ( string
, encoding
) {
575 if ( typeof encoding
!== 'string' || encoding
=== '' ) {
579 if (! Buffer
. isEncoding ( encoding
)) {
580 throw new TypeError ( 'Unknown encoding: ' + encoding
)
583 var length
= byteLength ( string
, encoding
) | 0
584 var buf
= createBuffer ( length
)
586 var actual
= buf
. write ( string
, encoding
)
588 if ( actual
!== length
) {
589 // Writing a hex string, for example, that contains invalid characters will
590 // cause everything after the first invalid character to be ignored. (e.g.
591 // 'abxxcd' will be treated as 'ab')
592 buf
= buf
. slice ( 0 , actual
)
598 function fromArrayLike ( array
) {
599 var length
= array
. length
< 0 ? 0 : checked ( array
. length
) | 0
600 var buf
= createBuffer ( length
)
601 for ( var i
= 0 ; i
< length
; i
+= 1 ) {
602 buf
[ i
] = array
[ i
] & 255
607 function fromArrayBuffer ( array
, byteOffset
, length
) {
608 if ( byteOffset
< 0 || array
. byteLength
< byteOffset
) {
609 throw new RangeError ( '"offset" is outside of buffer bounds' )
612 if ( array
. byteLength
< byteOffset
+ ( length
|| 0 )) {
613 throw new RangeError ( '"length" is outside of buffer bounds' )
617 if ( byteOffset
=== undefined && length
=== undefined ) {
618 buf
= new Uint8Array ( array
)
619 } else if ( length
=== undefined ) {
620 buf
= new Uint8Array ( array
, byteOffset
)
622 buf
= new Uint8Array ( array
, byteOffset
, length
)
625 // Return an augmented `Uint8Array` instance
626 buf
. __proto__
= Buffer
. prototype
630 function fromObject ( obj
) {
631 if ( Buffer
. isBuffer ( obj
)) {
632 var len
= checked ( obj
. length
) | 0
633 var buf
= createBuffer ( len
)
635 if ( buf
. length
=== 0 ) {
639 obj
. copy ( buf
, 0 , 0 , len
)
643 if ( obj
. length
!== undefined ) {
644 if ( typeof obj
. length
!== 'number' || numberIsNaN ( obj
. length
)) {
645 return createBuffer ( 0 )
647 return fromArrayLike ( obj
)
650 if ( obj
. type
=== 'Buffer' && Array
. isArray ( obj
. data
)) {
651 return fromArrayLike ( obj
. data
)
655 function checked ( length
) {
656 // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
657 // length is NaN (which is otherwise coerced to zero.)
658 if ( length
>= K_MAX_LENGTH
) {
659 throw new RangeError ( 'Attempt to allocate Buffer larger than maximum ' +
660 'size: 0x' + K_MAX_LENGTH
. toString ( 16 ) + ' bytes' )
665 function SlowBuffer ( length
) {
666 if (+ length
!= length
) { // eslint-disable-line eqeqeq
669 return Buffer
. alloc (+ length
)
672 Buffer
. isBuffer
= function isBuffer ( b
) {
673 return b
!= null && b
. _isBuffer
=== true &&
674 b
!== Buffer
. prototype // so Buffer.isBuffer(Buffer.prototype) will be false
677 Buffer
. compare
= function compare ( a
, b
) {
678 if ( isInstance ( a
, Uint8Array
)) a
= Buffer
. from ( a
, a
. offset
, a
. byteLength
)
679 if ( isInstance ( b
, Uint8Array
)) b
= Buffer
. from ( b
, b
. offset
, b
. byteLength
)
680 if (! Buffer
. isBuffer ( a
) || ! Buffer
. isBuffer ( b
)) {
682 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
686 if ( a
=== b
) return 0
691 for ( var i
= 0 , len
= Math
. min ( x
, y
); i
< len
; ++ i
) {
704 Buffer
. isEncoding
= function isEncoding ( encoding
) {
705 switch ( String ( encoding
). toLowerCase ()) {
723 Buffer
. concat
= function concat ( list
, length
) {
724 if (! Array
. isArray ( list
)) {
725 throw new TypeError ( '"list" argument must be an Array of Buffers' )
728 if ( list
. length
=== 0 ) {
729 return Buffer
. alloc ( 0 )
733 if ( length
=== undefined ) {
735 for ( i
= 0 ; i
< list
. length
; ++ i
) {
736 length
+= list
[ i
]. length
740 var buffer
= Buffer
. allocUnsafe ( length
)
742 for ( i
= 0 ; i
< list
. length
; ++ i
) {
744 if ( isInstance ( buf
, Uint8Array
)) {
745 buf
= Buffer
. from ( buf
)
747 if (! Buffer
. isBuffer ( buf
)) {
748 throw new TypeError ( '"list" argument must be an Array of Buffers' )
750 buf
. copy ( buffer
, pos
)
756 function byteLength ( string
, encoding
) {
757 if ( Buffer
. isBuffer ( string
)) {
760 if ( ArrayBuffer
. isView ( string
) || isInstance ( string
, ArrayBuffer
)) {
761 return string
. byteLength
763 if ( typeof string
!== 'string' ) {
765 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
766 'Received type ' + typeof string
770 var len
= string
. length
771 var mustMatch
= ( arguments
. length
> 2 && arguments
[ 2 ] === true )
772 if (! mustMatch
&& len
=== 0 ) return 0
774 // Use a for loop to avoid recursion
775 var loweredCase
= false
784 return utf8ToBytes ( string
). length
793 return base64ToBytes ( string
). length
796 return mustMatch
? - 1 : utf8ToBytes ( string
). length
// assume utf8
798 encoding
= ( '' + encoding
). toLowerCase ()
803 Buffer
. byteLength
= byteLength
805 function slowToString ( encoding
, start
, end
) {
806 var loweredCase
= false
808 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
809 // property of a typed array.
811 // This behaves neither like String nor Uint8Array in that we set start/end
812 // to their upper/lower bounds if the value passed is out of range.
813 // undefined is handled specially as per ECMA-262 6th Edition,
814 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
815 if ( start
=== undefined || start
< 0 ) {
818 // Return early if start > this.length. Done here to prevent potential uint32
819 // coercion fail below.
820 if ( start
> this . length
) {
824 if ( end
=== undefined || end
> this . length
) {
832 // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
840 if (! encoding
) encoding
= 'utf8'
845 return hexSlice ( this , start
, end
)
849 return utf8Slice ( this , start
, end
)
852 return asciiSlice ( this , start
, end
)
856 return latin1Slice ( this , start
, end
)
859 return base64Slice ( this , start
, end
)
865 return utf16leSlice ( this , start
, end
)
868 if ( loweredCase
) throw new TypeError ( 'Unknown encoding: ' + encoding
)
869 encoding
= ( encoding
+ '' ). toLowerCase ()
875 // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
876 // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
877 // reliably in a browserify context because there could be multiple different
878 // copies of the 'buffer' package in use. This method works even for Buffer
879 // instances that were created from another copy of the `buffer` package.
880 // See: https://github.com/feross/buffer/issues/154
881 Buffer
. prototype . _isBuffer
= true
883 function swap ( b
, n
, m
) {
889 Buffer
. prototype . swap16
= function swap16 () {
890 var len
= this . length
892 throw new RangeError ( 'Buffer size must be a multiple of 16-bits' )
894 for ( var i
= 0 ; i
< len
; i
+= 2 ) {
900 Buffer
. prototype . swap32
= function swap32 () {
901 var len
= this . length
903 throw new RangeError ( 'Buffer size must be a multiple of 32-bits' )
905 for ( var i
= 0 ; i
< len
; i
+= 4 ) {
907 swap ( this , i
+ 1 , i
+ 2 )
912 Buffer
. prototype . swap64
= function swap64 () {
913 var len
= this . length
915 throw new RangeError ( 'Buffer size must be a multiple of 64-bits' )
917 for ( var i
= 0 ; i
< len
; i
+= 8 ) {
919 swap ( this , i
+ 1 , i
+ 6 )
920 swap ( this , i
+ 2 , i
+ 5 )
921 swap ( this , i
+ 3 , i
+ 4 )
926 Buffer
. prototype . toString
= function toString () {
927 var length
= this . length
928 if ( length
=== 0 ) return ''
929 if ( arguments
. length
=== 0 ) return utf8Slice ( this , 0 , length
)
930 return slowToString
. apply ( this , arguments
)
933 Buffer
. prototype . toLocaleString
= Buffer
. prototype . toString
935 Buffer
. prototype . equals
= function equals ( b
) {
936 if (! Buffer
. isBuffer ( b
)) throw new TypeError ( 'Argument must be a Buffer' )
937 if ( this === b
) return true
938 return Buffer
. compare ( this , b
) === 0
941 Buffer
. prototype . inspect
= function inspect () {
943 var max
= exports
. INSPECT_MAX_BYTES
944 str
= this . toString ( 'hex' , 0 , max
). replace ( /(.{2})/g , '$1 ' ). trim ()
945 if ( this . length
> max
) str
+= ' ... '
946 return '<Buffer ' + str
+ '>'
949 Buffer
. prototype . compare
= function compare ( target
, start
, end
, thisStart
, thisEnd
) {
950 if ( isInstance ( target
, Uint8Array
)) {
951 target
= Buffer
. from ( target
, target
. offset
, target
. byteLength
)
953 if (! Buffer
. isBuffer ( target
)) {
955 'The "target" argument must be one of type Buffer or Uint8Array. ' +
956 'Received type ' + ( typeof target
)
960 if ( start
=== undefined ) {
963 if ( end
=== undefined ) {
964 end
= target
? target
. length : 0
966 if ( thisStart
=== undefined ) {
969 if ( thisEnd
=== undefined ) {
970 thisEnd
= this . length
973 if ( start
< 0 || end
> target
. length
|| thisStart
< 0 || thisEnd
> this . length
) {
974 throw new RangeError ( 'out of range index' )
977 if ( thisStart
>= thisEnd
&& start
>= end
) {
980 if ( thisStart
>= thisEnd
) {
992 if ( this === target
) return 0
994 var x
= thisEnd
- thisStart
996 var len
= Math
. min ( x
, y
)
998 var thisCopy
= this . slice ( thisStart
, thisEnd
)
999 var targetCopy
= target
. slice ( start
, end
)
1001 for ( var i
= 0 ; i
< len
; ++ i
) {
1002 if ( thisCopy
[ i
] !== targetCopy
[ i
]) {
1009 if ( x
< y
) return - 1
1014 // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
1015 // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
1018 // - buffer - a Buffer to search
1019 // - val - a string, Buffer, or number
1020 // - byteOffset - an index into `buffer`; will be clamped to an int32
1021 // - encoding - an optional encoding, relevant is val is a string
1022 // - dir - true for indexOf, false for lastIndexOf
1023 function bidirectionalIndexOf ( buffer
, val
, byteOffset
, encoding
, dir
) {
1024 // Empty buffer means no match
1025 if ( buffer
. length
=== 0 ) return - 1
1027 // Normalize byteOffset
1028 if ( typeof byteOffset
=== 'string' ) {
1029 encoding
= byteOffset
1031 } else if ( byteOffset
> 0x7fffffff ) {
1032 byteOffset
= 0x7fffffff
1033 } else if ( byteOffset
< - 0x80000000 ) {
1034 byteOffset
= - 0x80000000
1036 byteOffset
= + byteOffset
// Coerce to Number.
1037 if ( numberIsNaN ( byteOffset
)) {
1038 // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
1039 byteOffset
= dir
? 0 : ( buffer
. length
- 1 )
1042 // Normalize byteOffset: negative offsets start from the end of the buffer
1043 if ( byteOffset
< 0 ) byteOffset
= buffer
. length
+ byteOffset
1044 if ( byteOffset
>= buffer
. length
) {
1046 else byteOffset
= buffer
. length
- 1
1047 } else if ( byteOffset
< 0 ) {
1048 if ( dir
) byteOffset
= 0
1053 if ( typeof val
=== 'string' ) {
1054 val
= Buffer
. from ( val
, encoding
)
1057 // Finally, search either indexOf (if dir is true) or lastIndexOf
1058 if ( Buffer
. isBuffer ( val
)) {
1059 // Special case: looking for empty string/buffer always fails
1060 if ( val
. length
=== 0 ) {
1063 return arrayIndexOf ( buffer
, val
, byteOffset
, encoding
, dir
)
1064 } else if ( typeof val
=== 'number' ) {
1065 val
= val
& 0xFF // Search for a byte value [0-255]
1066 if ( typeof Uint8Array
. prototype . indexOf
=== 'function' ) {
1068 return Uint8Array
. prototype . indexOf
. call ( buffer
, val
, byteOffset
)
1070 return Uint8Array
. prototype . lastIndexOf
. call ( buffer
, val
, byteOffset
)
1073 return arrayIndexOf ( buffer
, [ val
], byteOffset
, encoding
, dir
)
1076 throw new TypeError ( 'val must be string, number or Buffer' )
1079 function arrayIndexOf ( arr
, val
, byteOffset
, encoding
, dir
) {
1081 var arrLength
= arr
. length
1082 var valLength
= val
. length
1084 if ( encoding
!== undefined ) {
1085 encoding
= String ( encoding
). toLowerCase ()
1086 if ( encoding
=== 'ucs2' || encoding
=== 'ucs-2' ||
1087 encoding
=== 'utf16le' || encoding
=== 'utf-16le' ) {
1088 if ( arr
. length
< 2 || val
. length
< 2 ) {
1098 function read ( buf
, i
) {
1099 if ( indexSize
=== 1 ) {
1102 return buf
. readUInt16BE ( i
* indexSize
)
1109 for ( i
= byteOffset
; i
< arrLength
; i
++) {
1110 if ( read ( arr
, i
) === read ( val
, foundIndex
=== - 1 ? 0 : i
- foundIndex
)) {
1111 if ( foundIndex
=== - 1 ) foundIndex
= i
1112 if ( i
- foundIndex
+ 1 === valLength
) return foundIndex
* indexSize
1114 if ( foundIndex
!== - 1 ) i
-= i
- foundIndex
1119 if ( byteOffset
+ valLength
> arrLength
) byteOffset
= arrLength
- valLength
1120 for ( i
= byteOffset
; i
>= 0 ; i
--) {
1122 for ( var j
= 0 ; j
< valLength
; j
++) {
1123 if ( read ( arr
, i
+ j
) !== read ( val
, j
)) {
1135 Buffer
. prototype . includes
= function includes ( val
, byteOffset
, encoding
) {
1136 return this . indexOf ( val
, byteOffset
, encoding
) !== - 1
1139 Buffer
. prototype . indexOf
= function indexOf ( val
, byteOffset
, encoding
) {
1140 return bidirectionalIndexOf ( this , val
, byteOffset
, encoding
, true )
1143 Buffer
. prototype . lastIndexOf
= function lastIndexOf ( val
, byteOffset
, encoding
) {
1144 return bidirectionalIndexOf ( this , val
, byteOffset
, encoding
, false )
1147 function hexWrite ( buf
, string
, offset
, length
) {
1148 offset
= Number ( offset
) || 0
1149 var remaining
= buf
. length
- offset
1153 length
= Number ( length
)
1154 if ( length
> remaining
) {
1159 var strLen
= string
. length
1161 if ( length
> strLen
/ 2 ) {
1164 for ( var i
= 0 ; i
< length
; ++ i
) {
1165 var parsed
= parseInt ( string
. substr ( i
* 2 , 2 ), 16 )
1166 if ( numberIsNaN ( parsed
)) return i
1167 buf
[ offset
+ i
] = parsed
1172 function utf8Write ( buf
, string
, offset
, length
) {
1173 return blitBuffer ( utf8ToBytes ( string
, buf
. length
- offset
), buf
, offset
, length
)
1176 function asciiWrite ( buf
, string
, offset
, length
) {
1177 return blitBuffer ( asciiToBytes ( string
), buf
, offset
, length
)
1180 function latin1Write ( buf
, string
, offset
, length
) {
1181 return asciiWrite ( buf
, string
, offset
, length
)
1184 function base64Write ( buf
, string
, offset
, length
) {
1185 return blitBuffer ( base64ToBytes ( string
), buf
, offset
, length
)
1188 function ucs2Write ( buf
, string
, offset
, length
) {
1189 return blitBuffer ( utf16leToBytes ( string
, buf
. length
- offset
), buf
, offset
, length
)
1192 Buffer
. prototype . write
= function write ( string
, offset
, length
, encoding
) {
1193 // Buffer#write(string)
1194 if ( offset
=== undefined ) {
1196 length
= this . length
1198 // Buffer#write(string, encoding)
1199 } else if ( length
=== undefined && typeof offset
=== 'string' ) {
1201 length
= this . length
1203 // Buffer#write(string, offset[, length][, encoding])
1204 } else if ( isFinite ( offset
)) {
1205 offset
= offset
>>> 0
1206 if ( isFinite ( length
)) {
1207 length
= length
>>> 0
1208 if ( encoding
=== undefined ) encoding
= 'utf8'
1215 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
1219 var remaining
= this . length
- offset
1220 if ( length
=== undefined || length
> remaining
) length
= remaining
1222 if (( string
. length
> 0 && ( length
< 0 || offset
< 0 )) || offset
> this . length
) {
1223 throw new RangeError ( 'Attempt to write outside buffer bounds' )
1226 if (! encoding
) encoding
= 'utf8'
1228 var loweredCase
= false
1232 return hexWrite ( this , string
, offset
, length
)
1236 return utf8Write ( this , string
, offset
, length
)
1239 return asciiWrite ( this , string
, offset
, length
)
1243 return latin1Write ( this , string
, offset
, length
)
1246 // Warning: maxLength not taken into account in base64Write
1247 return base64Write ( this , string
, offset
, length
)
1253 return ucs2Write ( this , string
, offset
, length
)
1256 if ( loweredCase
) throw new TypeError ( 'Unknown encoding: ' + encoding
)
1257 encoding
= ( '' + encoding
). toLowerCase ()
1263 Buffer
. prototype . toJSON
= function toJSON () {
1266 data : Array
. prototype . slice
. call ( this . _arr
|| this , 0 )
1270 function base64Slice ( buf
, start
, end
) {
1271 if ( start
=== 0 && end
=== buf
. length
) {
1272 return base64
. fromByteArray ( buf
)
1274 return base64
. fromByteArray ( buf
. slice ( start
, end
))
1278 function utf8Slice ( buf
, start
, end
) {
1279 end
= Math
. min ( buf
. length
, end
)
1284 var firstByte
= buf
[ i
]
1285 var codePoint
= null
1286 var bytesPerSequence
= ( firstByte
> 0xEF ) ? 4
1287 : ( firstByte
> 0xDF ) ? 3
1288 : ( firstByte
> 0xBF ) ? 2
1291 if ( i
+ bytesPerSequence
<= end
) {
1292 var secondByte
, thirdByte
, fourthByte
, tempCodePoint
1294 switch ( bytesPerSequence
) {
1296 if ( firstByte
< 0x80 ) {
1297 codePoint
= firstByte
1301 secondByte
= buf
[ i
+ 1 ]
1302 if (( secondByte
& 0xC0 ) === 0x80 ) {
1303 tempCodePoint
= ( firstByte
& 0x1F ) << 0x6 | ( secondByte
& 0x3F )
1304 if ( tempCodePoint
> 0x7F ) {
1305 codePoint
= tempCodePoint
1310 secondByte
= buf
[ i
+ 1 ]
1311 thirdByte
= buf
[ i
+ 2 ]
1312 if (( secondByte
& 0xC0 ) === 0x80 && ( thirdByte
& 0xC0 ) === 0x80 ) {
1313 tempCodePoint
= ( firstByte
& 0xF ) << 0xC | ( secondByte
& 0x3F ) << 0x6 | ( thirdByte
& 0x3F )
1314 if ( tempCodePoint
> 0x7FF && ( tempCodePoint
< 0xD800 || tempCodePoint
> 0xDFFF )) {
1315 codePoint
= tempCodePoint
1320 secondByte
= buf
[ i
+ 1 ]
1321 thirdByte
= buf
[ i
+ 2 ]
1322 fourthByte
= buf
[ i
+ 3 ]
1323 if (( secondByte
& 0xC0 ) === 0x80 && ( thirdByte
& 0xC0 ) === 0x80 && ( fourthByte
& 0xC0 ) === 0x80 ) {
1324 tempCodePoint
= ( firstByte
& 0xF ) << 0x12 | ( secondByte
& 0x3F ) << 0xC | ( thirdByte
& 0x3F ) << 0x6 | ( fourthByte
& 0x3F )
1325 if ( tempCodePoint
> 0xFFFF && tempCodePoint
< 0x110000 ) {
1326 codePoint
= tempCodePoint
1332 if ( codePoint
=== null ) {
1333 // we did not generate a valid codePoint so insert a
1334 // replacement char (U+FFFD) and advance only 1 byte
1336 bytesPerSequence
= 1
1337 } else if ( codePoint
> 0xFFFF ) {
1338 // encode to utf16 (surrogate pair dance)
1339 codePoint
-= 0x10000
1340 res
. push ( codePoint
>>> 10 & 0x3FF | 0xD800 )
1341 codePoint
= 0xDC00 | codePoint
& 0x3FF
1345 i
+= bytesPerSequence
1348 return decodeCodePointsArray ( res
)
1351 // Based on http://stackoverflow.com/a/22747272/680742, the browser with
1352 // the lowest limit is Chrome, with 0x10000 args.
1353 // We go 1 magnitude less, for safety
1354 var MAX_ARGUMENTS_LENGTH
= 0x1000
1356 function decodeCodePointsArray ( codePoints
) {
1357 var len
= codePoints
. length
1358 if ( len
<= MAX_ARGUMENTS_LENGTH
) {
1359 return String
. fromCharCode
. apply ( String
, codePoints
) // avoid extra slice()
1362 // Decode in chunks to avoid "call stack size exceeded".
1366 res
+= String
. fromCharCode
. apply (
1368 codePoints
. slice ( i
, i
+= MAX_ARGUMENTS_LENGTH
)
1374 function asciiSlice ( buf
, start
, end
) {
1376 end
= Math
. min ( buf
. length
, end
)
1378 for ( var i
= start
; i
< end
; ++ i
) {
1379 ret
+= String
. fromCharCode ( buf
[ i
] & 0x7F )
1384 function latin1Slice ( buf
, start
, end
) {
1386 end
= Math
. min ( buf
. length
, end
)
1388 for ( var i
= start
; i
< end
; ++ i
) {
1389 ret
+= String
. fromCharCode ( buf
[ i
])
1394 function hexSlice ( buf
, start
, end
) {
1395 var len
= buf
. length
1397 if (! start
|| start
< 0 ) start
= 0
1398 if (! end
|| end
< 0 || end
> len
) end
= len
1401 for ( var i
= start
; i
< end
; ++ i
) {
1402 out
+= toHex ( buf
[ i
])
1407 function utf16leSlice ( buf
, start
, end
) {
1408 var bytes
= buf
. slice ( start
, end
)
1410 for ( var i
= 0 ; i
< bytes
. length
; i
+= 2 ) {
1411 res
+= String
. fromCharCode ( bytes
[ i
] + ( bytes
[ i
+ 1 ] * 256 ))
1416 Buffer
. prototype . slice
= function slice ( start
, end
) {
1417 var len
= this . length
1419 end
= end
=== undefined ? len : ~~ end
1423 if ( start
< 0 ) start
= 0
1424 } else if ( start
> len
) {
1430 if ( end
< 0 ) end
= 0
1431 } else if ( end
> len
) {
1435 if ( end
< start
) end
= start
1437 var newBuf
= this . subarray ( start
, end
)
1438 // Return an augmented `Uint8Array` instance
1439 newBuf
. __proto__
= Buffer
. prototype
1444 * Need to make sure that buffer isn't trying to write out of bounds.
1446 function checkOffset ( offset
, ext
, length
) {
1447 if (( offset
% 1 ) !== 0 || offset
< 0 ) throw new RangeError ( 'offset is not uint' )
1448 if ( offset
+ ext
> length
) throw new RangeError ( 'Trying to access beyond buffer length' )
1451 Buffer
. prototype . readUIntLE
= function readUIntLE ( offset
, byteLength
, noAssert
) {
1452 offset
= offset
>>> 0
1453 byteLength
= byteLength
>>> 0
1454 if (! noAssert
) checkOffset ( offset
, byteLength
, this . length
)
1456 var val
= this [ offset
]
1459 while (++ i
< byteLength
&& ( mul
*= 0x100 )) {
1460 val
+= this [ offset
+ i
] * mul
1466 Buffer
. prototype . readUIntBE
= function readUIntBE ( offset
, byteLength
, noAssert
) {
1467 offset
= offset
>>> 0
1468 byteLength
= byteLength
>>> 0
1470 checkOffset ( offset
, byteLength
, this . length
)
1473 var val
= this [ offset
+ -- byteLength
]
1475 while ( byteLength
> 0 && ( mul
*= 0x100 )) {
1476 val
+= this [ offset
+ -- byteLength
] * mul
1482 Buffer
. prototype . readUInt8
= function readUInt8 ( offset
, noAssert
) {
1483 offset
= offset
>>> 0
1484 if (! noAssert
) checkOffset ( offset
, 1 , this . length
)
1488 Buffer
. prototype . readUInt16LE
= function readUInt16LE ( offset
, noAssert
) {
1489 offset
= offset
>>> 0
1490 if (! noAssert
) checkOffset ( offset
, 2 , this . length
)
1491 return this [ offset
] | ( this [ offset
+ 1 ] << 8 )
1494 Buffer
. prototype . readUInt16BE
= function readUInt16BE ( offset
, noAssert
) {
1495 offset
= offset
>>> 0
1496 if (! noAssert
) checkOffset ( offset
, 2 , this . length
)
1497 return ( this [ offset
] << 8 ) | this [ offset
+ 1 ]
1500 Buffer
. prototype . readUInt32LE
= function readUInt32LE ( offset
, noAssert
) {
1501 offset
= offset
>>> 0
1502 if (! noAssert
) checkOffset ( offset
, 4 , this . length
)
1504 return (( this [ offset
]) |
1505 ( this [ offset
+ 1 ] << 8 ) |
1506 ( this [ offset
+ 2 ] << 16 )) +
1507 ( this [ offset
+ 3 ] * 0x1000000 )
1510 Buffer
. prototype . readUInt32BE
= function readUInt32BE ( offset
, noAssert
) {
1511 offset
= offset
>>> 0
1512 if (! noAssert
) checkOffset ( offset
, 4 , this . length
)
1514 return ( this [ offset
] * 0x1000000 ) +
1515 (( this [ offset
+ 1 ] << 16 ) |
1516 ( this [ offset
+ 2 ] << 8 ) |
1520 Buffer
. prototype . readIntLE
= function readIntLE ( offset
, byteLength
, noAssert
) {
1521 offset
= offset
>>> 0
1522 byteLength
= byteLength
>>> 0
1523 if (! noAssert
) checkOffset ( offset
, byteLength
, this . length
)
1525 var val
= this [ offset
]
1528 while (++ i
< byteLength
&& ( mul
*= 0x100 )) {
1529 val
+= this [ offset
+ i
] * mul
1533 if ( val
>= mul
) val
-= Math
. pow ( 2 , 8 * byteLength
)
1538 Buffer
. prototype . readIntBE
= function readIntBE ( offset
, byteLength
, noAssert
) {
1539 offset
= offset
>>> 0
1540 byteLength
= byteLength
>>> 0
1541 if (! noAssert
) checkOffset ( offset
, byteLength
, this . length
)
1545 var val
= this [ offset
+ -- i
]
1546 while ( i
> 0 && ( mul
*= 0x100 )) {
1547 val
+= this [ offset
+ -- i
] * mul
1551 if ( val
>= mul
) val
-= Math
. pow ( 2 , 8 * byteLength
)
1556 Buffer
. prototype . readInt8
= function readInt8 ( offset
, noAssert
) {
1557 offset
= offset
>>> 0
1558 if (! noAssert
) checkOffset ( offset
, 1 , this . length
)
1559 if (!( this [ offset
] & 0x80 )) return ( this [ offset
])
1560 return (( 0xff - this [ offset
] + 1 ) * - 1 )
1563 Buffer
. prototype . readInt16LE
= function readInt16LE ( offset
, noAssert
) {
1564 offset
= offset
>>> 0
1565 if (! noAssert
) checkOffset ( offset
, 2 , this . length
)
1566 var val
= this [ offset
] | ( this [ offset
+ 1 ] << 8 )
1567 return ( val
& 0x8000 ) ? val
| 0xFFFF0000 : val
1570 Buffer
. prototype . readInt16BE
= function readInt16BE ( offset
, noAssert
) {
1571 offset
= offset
>>> 0
1572 if (! noAssert
) checkOffset ( offset
, 2 , this . length
)
1573 var val
= this [ offset
+ 1 ] | ( this [ offset
] << 8 )
1574 return ( val
& 0x8000 ) ? val
| 0xFFFF0000 : val
1577 Buffer
. prototype . readInt32LE
= function readInt32LE ( offset
, noAssert
) {
1578 offset
= offset
>>> 0
1579 if (! noAssert
) checkOffset ( offset
, 4 , this . length
)
1581 return ( this [ offset
]) |
1582 ( this [ offset
+ 1 ] << 8 ) |
1583 ( this [ offset
+ 2 ] << 16 ) |
1584 ( this [ offset
+ 3 ] << 24 )
1587 Buffer
. prototype . readInt32BE
= function readInt32BE ( offset
, noAssert
) {
1588 offset
= offset
>>> 0
1589 if (! noAssert
) checkOffset ( offset
, 4 , this . length
)
1591 return ( this [ offset
] << 24 ) |
1592 ( this [ offset
+ 1 ] << 16 ) |
1593 ( this [ offset
+ 2 ] << 8 ) |
1597 Buffer
. prototype . readFloatLE
= function readFloatLE ( offset
, noAssert
) {
1598 offset
= offset
>>> 0
1599 if (! noAssert
) checkOffset ( offset
, 4 , this . length
)
1600 return ieee754
. read ( this , offset
, true , 23 , 4 )
1603 Buffer
. prototype . readFloatBE
= function readFloatBE ( offset
, noAssert
) {
1604 offset
= offset
>>> 0
1605 if (! noAssert
) checkOffset ( offset
, 4 , this . length
)
1606 return ieee754
. read ( this , offset
, false , 23 , 4 )
1609 Buffer
. prototype . readDoubleLE
= function readDoubleLE ( offset
, noAssert
) {
1610 offset
= offset
>>> 0
1611 if (! noAssert
) checkOffset ( offset
, 8 , this . length
)
1612 return ieee754
. read ( this , offset
, true , 52 , 8 )
1615 Buffer
. prototype . readDoubleBE
= function readDoubleBE ( offset
, noAssert
) {
1616 offset
= offset
>>> 0
1617 if (! noAssert
) checkOffset ( offset
, 8 , this . length
)
1618 return ieee754
. read ( this , offset
, false , 52 , 8 )
1621 function checkInt ( buf
, value
, offset
, ext
, max
, min
) {
1622 if (! Buffer
. isBuffer ( buf
)) throw new TypeError ( '"buffer" argument must be a Buffer instance' )
1623 if ( value
> max
|| value
< min
) throw new RangeError ( '"value" argument is out of bounds' )
1624 if ( offset
+ ext
> buf
. length
) throw new RangeError ( 'Index out of range' )
1627 Buffer
. prototype . writeUIntLE
= function writeUIntLE ( value
, offset
, byteLength
, noAssert
) {
1629 offset
= offset
>>> 0
1630 byteLength
= byteLength
>>> 0
1632 var maxBytes
= Math
. pow ( 2 , 8 * byteLength
) - 1
1633 checkInt ( this , value
, offset
, byteLength
, maxBytes
, 0 )
1638 this [ offset
] = value
& 0xFF
1639 while (++ i
< byteLength
&& ( mul
*= 0x100 )) {
1640 this [ offset
+ i
] = ( value
/ mul
) & 0xFF
1643 return offset
+ byteLength
1646 Buffer
. prototype . writeUIntBE
= function writeUIntBE ( value
, offset
, byteLength
, noAssert
) {
1648 offset
= offset
>>> 0
1649 byteLength
= byteLength
>>> 0
1651 var maxBytes
= Math
. pow ( 2 , 8 * byteLength
) - 1
1652 checkInt ( this , value
, offset
, byteLength
, maxBytes
, 0 )
1655 var i
= byteLength
- 1
1657 this [ offset
+ i
] = value
& 0xFF
1658 while (-- i
>= 0 && ( mul
*= 0x100 )) {
1659 this [ offset
+ i
] = ( value
/ mul
) & 0xFF
1662 return offset
+ byteLength
1665 Buffer
. prototype . writeUInt8
= function writeUInt8 ( value
, offset
, noAssert
) {
1667 offset
= offset
>>> 0
1668 if (! noAssert
) checkInt ( this , value
, offset
, 1 , 0xff , 0 )
1669 this [ offset
] = ( value
& 0xff )
1673 Buffer
. prototype . writeUInt16LE
= function writeUInt16LE ( value
, offset
, noAssert
) {
1675 offset
= offset
>>> 0
1676 if (! noAssert
) checkInt ( this , value
, offset
, 2 , 0xffff , 0 )
1677 this [ offset
] = ( value
& 0xff )
1678 this [ offset
+ 1 ] = ( value
>>> 8 )
1682 Buffer
. prototype . writeUInt16BE
= function writeUInt16BE ( value
, offset
, noAssert
) {
1684 offset
= offset
>>> 0
1685 if (! noAssert
) checkInt ( this , value
, offset
, 2 , 0xffff , 0 )
1686 this [ offset
] = ( value
>>> 8 )
1687 this [ offset
+ 1 ] = ( value
& 0xff )
1691 Buffer
. prototype . writeUInt32LE
= function writeUInt32LE ( value
, offset
, noAssert
) {
1693 offset
= offset
>>> 0
1694 if (! noAssert
) checkInt ( this , value
, offset
, 4 , 0xffffffff , 0 )
1695 this [ offset
+ 3 ] = ( value
>>> 24 )
1696 this [ offset
+ 2 ] = ( value
>>> 16 )
1697 this [ offset
+ 1 ] = ( value
>>> 8 )
1698 this [ offset
] = ( value
& 0xff )
1702 Buffer
. prototype . writeUInt32BE
= function writeUInt32BE ( value
, offset
, noAssert
) {
1704 offset
= offset
>>> 0
1705 if (! noAssert
) checkInt ( this , value
, offset
, 4 , 0xffffffff , 0 )
1706 this [ offset
] = ( value
>>> 24 )
1707 this [ offset
+ 1 ] = ( value
>>> 16 )
1708 this [ offset
+ 2 ] = ( value
>>> 8 )
1709 this [ offset
+ 3 ] = ( value
& 0xff )
1713 Buffer
. prototype . writeIntLE
= function writeIntLE ( value
, offset
, byteLength
, noAssert
) {
1715 offset
= offset
>>> 0
1717 var limit
= Math
. pow ( 2 , ( 8 * byteLength
) - 1 )
1719 checkInt ( this , value
, offset
, byteLength
, limit
- 1 , - limit
)
1725 this [ offset
] = value
& 0xFF
1726 while (++ i
< byteLength
&& ( mul
*= 0x100 )) {
1727 if ( value
< 0 && sub
=== 0 && this [ offset
+ i
- 1 ] !== 0 ) {
1730 this [ offset
+ i
] = (( value
/ mul
) >> 0 ) - sub
& 0xFF
1733 return offset
+ byteLength
1736 Buffer
. prototype . writeIntBE
= function writeIntBE ( value
, offset
, byteLength
, noAssert
) {
1738 offset
= offset
>>> 0
1740 var limit
= Math
. pow ( 2 , ( 8 * byteLength
) - 1 )
1742 checkInt ( this , value
, offset
, byteLength
, limit
- 1 , - limit
)
1745 var i
= byteLength
- 1
1748 this [ offset
+ i
] = value
& 0xFF
1749 while (-- i
>= 0 && ( mul
*= 0x100 )) {
1750 if ( value
< 0 && sub
=== 0 && this [ offset
+ i
+ 1 ] !== 0 ) {
1753 this [ offset
+ i
] = (( value
/ mul
) >> 0 ) - sub
& 0xFF
1756 return offset
+ byteLength
1759 Buffer
. prototype . writeInt8
= function writeInt8 ( value
, offset
, noAssert
) {
1761 offset
= offset
>>> 0
1762 if (! noAssert
) checkInt ( this , value
, offset
, 1 , 0x7f , - 0x80 )
1763 if ( value
< 0 ) value
= 0xff + value
+ 1
1764 this [ offset
] = ( value
& 0xff )
1768 Buffer
. prototype . writeInt16LE
= function writeInt16LE ( value
, offset
, noAssert
) {
1770 offset
= offset
>>> 0
1771 if (! noAssert
) checkInt ( this , value
, offset
, 2 , 0x7fff , - 0x8000 )
1772 this [ offset
] = ( value
& 0xff )
1773 this [ offset
+ 1 ] = ( value
>>> 8 )
1777 Buffer
. prototype . writeInt16BE
= function writeInt16BE ( value
, offset
, noAssert
) {
1779 offset
= offset
>>> 0
1780 if (! noAssert
) checkInt ( this , value
, offset
, 2 , 0x7fff , - 0x8000 )
1781 this [ offset
] = ( value
>>> 8 )
1782 this [ offset
+ 1 ] = ( value
& 0xff )
1786 Buffer
. prototype . writeInt32LE
= function writeInt32LE ( value
, offset
, noAssert
) {
1788 offset
= offset
>>> 0
1789 if (! noAssert
) checkInt ( this , value
, offset
, 4 , 0x7fffffff , - 0x80000000 )
1790 this [ offset
] = ( value
& 0xff )
1791 this [ offset
+ 1 ] = ( value
>>> 8 )
1792 this [ offset
+ 2 ] = ( value
>>> 16 )
1793 this [ offset
+ 3 ] = ( value
>>> 24 )
1797 Buffer
. prototype . writeInt32BE
= function writeInt32BE ( value
, offset
, noAssert
) {
1799 offset
= offset
>>> 0
1800 if (! noAssert
) checkInt ( this , value
, offset
, 4 , 0x7fffffff , - 0x80000000 )
1801 if ( value
< 0 ) value
= 0xffffffff + value
+ 1
1802 this [ offset
] = ( value
>>> 24 )
1803 this [ offset
+ 1 ] = ( value
>>> 16 )
1804 this [ offset
+ 2 ] = ( value
>>> 8 )
1805 this [ offset
+ 3 ] = ( value
& 0xff )
1809 function checkIEEE754 ( buf
, value
, offset
, ext
, max
, min
) {
1810 if ( offset
+ ext
> buf
. length
) throw new RangeError ( 'Index out of range' )
1811 if ( offset
< 0 ) throw new RangeError ( 'Index out of range' )
1814 function writeFloat ( buf
, value
, offset
, littleEndian
, noAssert
) {
1816 offset
= offset
>>> 0
1818 checkIEEE754 ( buf
, value
, offset
, 4 , 3.4028234663852886e+38 , - 3.4028234663852886e+38 )
1820 ieee754
. write ( buf
, value
, offset
, littleEndian
, 23 , 4 )
1824 Buffer
. prototype . writeFloatLE
= function writeFloatLE ( value
, offset
, noAssert
) {
1825 return writeFloat ( this , value
, offset
, true , noAssert
)
1828 Buffer
. prototype . writeFloatBE
= function writeFloatBE ( value
, offset
, noAssert
) {
1829 return writeFloat ( this , value
, offset
, false , noAssert
)
1832 function writeDouble ( buf
, value
, offset
, littleEndian
, noAssert
) {
1834 offset
= offset
>>> 0
1836 checkIEEE754 ( buf
, value
, offset
, 8 , 1.7976931348623157E+308 , - 1.7976931348623157E+308 )
1838 ieee754
. write ( buf
, value
, offset
, littleEndian
, 52 , 8 )
1842 Buffer
. prototype . writeDoubleLE
= function writeDoubleLE ( value
, offset
, noAssert
) {
1843 return writeDouble ( this , value
, offset
, true , noAssert
)
1846 Buffer
. prototype . writeDoubleBE
= function writeDoubleBE ( value
, offset
, noAssert
) {
1847 return writeDouble ( this , value
, offset
, false , noAssert
)
1850 // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
1851 Buffer
. prototype . copy
= function copy ( target
, targetStart
, start
, end
) {
1852 if (! Buffer
. isBuffer ( target
)) throw new TypeError ( 'argument should be a Buffer' )
1853 if (! start
) start
= 0
1854 if (! end
&& end
!== 0 ) end
= this . length
1855 if ( targetStart
>= target
. length
) targetStart
= target
. length
1856 if (! targetStart
) targetStart
= 0
1857 if ( end
> 0 && end
< start
) end
= start
1859 // Copy 0 bytes; we're done
1860 if ( end
=== start
) return 0
1861 if ( target
. length
=== 0 || this . length
=== 0 ) return 0
1863 // Fatal error conditions
1864 if ( targetStart
< 0 ) {
1865 throw new RangeError ( 'targetStart out of bounds' )
1867 if ( start
< 0 || start
>= this . length
) throw new RangeError ( 'Index out of range' )
1868 if ( end
< 0 ) throw new RangeError ( 'sourceEnd out of bounds' )
1871 if ( end
> this . length
) end
= this . length
1872 if ( target
. length
- targetStart
< end
- start
) {
1873 end
= target
. length
- targetStart
+ start
1876 var len
= end
- start
1878 if ( this === target
&& typeof Uint8Array
. prototype . copyWithin
=== 'function' ) {
1879 // Use built-in when available, missing from IE11
1880 this . copyWithin ( targetStart
, start
, end
)
1881 } else if ( this === target
&& start
< targetStart
&& targetStart
< end
) {
1882 // descending copy from end
1883 for ( var i
= len
- 1 ; i
>= 0 ; -- i
) {
1884 target
[ i
+ targetStart
] = this [ i
+ start
]
1887 Uint8Array
. prototype . set . call (
1889 this . subarray ( start
, end
),
1898 // buffer.fill(number[, offset[, end]])
1899 // buffer.fill(buffer[, offset[, end]])
1900 // buffer.fill(string[, offset[, end]][, encoding])
1901 Buffer
. prototype . fill
= function fill ( val
, start
, end
, encoding
) {
1902 // Handle string cases:
1903 if ( typeof val
=== 'string' ) {
1904 if ( typeof start
=== 'string' ) {
1908 } else if ( typeof end
=== 'string' ) {
1912 if ( encoding
!== undefined && typeof encoding
!== 'string' ) {
1913 throw new TypeError ( 'encoding must be a string' )
1915 if ( typeof encoding
=== 'string' && ! Buffer
. isEncoding ( encoding
)) {
1916 throw new TypeError ( 'Unknown encoding: ' + encoding
)
1918 if ( val
. length
=== 1 ) {
1919 var code
= val
. charCodeAt ( 0 )
1920 if (( encoding
=== 'utf8' && code
< 128 ) ||
1921 encoding
=== 'latin1' ) {
1922 // Fast path: If `val` fits into a single byte, use that numeric value.
1926 } else if ( typeof val
=== 'number' ) {
1930 // Invalid ranges are not set to a default, so can range check early.
1931 if ( start
< 0 || this . length
< start
|| this . length
< end
) {
1932 throw new RangeError ( 'Out of range index' )
1940 end
= end
=== undefined ? this . length : end
>>> 0
1945 if ( typeof val
=== 'number' ) {
1946 for ( i
= start
; i
< end
; ++ i
) {
1950 var bytes
= Buffer
. isBuffer ( val
)
1952 : Buffer
. from ( val
, encoding
)
1953 var len
= bytes
. length
1955 throw new TypeError ( 'The value "' + val
+
1956 '" is invalid for argument "value"' )
1958 for ( i
= 0 ; i
< end
- start
; ++ i
) {
1959 this [ i
+ start
] = bytes
[ i
% len
]
1969 var INVALID_BASE64_RE
= /[^+/ 0 - 9 A
- Za
- z
- _
]/ g
1971 function base64clean ( str
) {
1972 // Node takes equal signs as end of the Base64 encoding
1973 str
= str
. split ( '=' )[ 0 ]
1974 // Node strips out invalid characters like \n and \t from the string, base64-js does not
1975 str
= str
. trim (). replace ( INVALID_BASE64_RE
, '' )
1976 // Node converts strings with length < 2 to ''
1977 if ( str
. length
< 2 ) return ''
1978 // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
1979 while ( str
. length
% 4 !== 0 ) {
1985 function toHex ( n
) {
1986 if ( n
< 16 ) return '0' + n
. toString ( 16 )
1987 return n
. toString ( 16 )
1990 function utf8ToBytes ( string
, units
) {
1991 units
= units
|| Infinity
1993 var length
= string
. length
1994 var leadSurrogate
= null
1997 for ( var i
= 0 ; i
< length
; ++ i
) {
1998 codePoint
= string
. charCodeAt ( i
)
2000 // is surrogate component
2001 if ( codePoint
> 0xD7FF && codePoint
< 0xE000 ) {
2002 // last char was a lead
2003 if (! leadSurrogate
) {
2005 if ( codePoint
> 0xDBFF ) {
2007 if (( units
-= 3 ) > - 1 ) bytes
. push ( 0xEF , 0xBF , 0xBD )
2009 } else if ( i
+ 1 === length
) {
2011 if (( units
-= 3 ) > - 1 ) bytes
. push ( 0xEF , 0xBF , 0xBD )
2016 leadSurrogate
= codePoint
2022 if ( codePoint
< 0xDC00 ) {
2023 if (( units
-= 3 ) > - 1 ) bytes
. push ( 0xEF , 0xBF , 0xBD )
2024 leadSurrogate
= codePoint
2028 // valid surrogate pair
2029 codePoint
= ( leadSurrogate
- 0xD800 << 10 | codePoint
- 0xDC00 ) + 0x10000
2030 } else if ( leadSurrogate
) {
2031 // valid bmp char, but last char was a lead
2032 if (( units
-= 3 ) > - 1 ) bytes
. push ( 0xEF , 0xBF , 0xBD )
2035 leadSurrogate
= null
2038 if ( codePoint
< 0x80 ) {
2039 if (( units
-= 1 ) < 0 ) break
2040 bytes
. push ( codePoint
)
2041 } else if ( codePoint
< 0x800 ) {
2042 if (( units
-= 2 ) < 0 ) break
2044 codePoint
>> 0x6 | 0xC0 ,
2045 codePoint
& 0x3F | 0x80
2047 } else if ( codePoint
< 0x10000 ) {
2048 if (( units
-= 3 ) < 0 ) break
2050 codePoint
>> 0xC | 0xE0 ,
2051 codePoint
>> 0x6 & 0x3F | 0x80 ,
2052 codePoint
& 0x3F | 0x80
2054 } else if ( codePoint
< 0x110000 ) {
2055 if (( units
-= 4 ) < 0 ) break
2057 codePoint
>> 0x12 | 0xF0 ,
2058 codePoint
>> 0xC & 0x3F | 0x80 ,
2059 codePoint
>> 0x6 & 0x3F | 0x80 ,
2060 codePoint
& 0x3F | 0x80
2063 throw new Error ( 'Invalid code point' )
2070 function asciiToBytes ( str
) {
2072 for ( var i
= 0 ; i
< str
. length
; ++ i
) {
2073 // Node's code seems to be doing this and not & 0x7F..
2074 byteArray
. push ( str
. charCodeAt ( i
) & 0xFF )
2079 function utf16leToBytes ( str
, units
) {
2082 for ( var i
= 0 ; i
< str
. length
; ++ i
) {
2083 if (( units
-= 2 ) < 0 ) break
2085 c
= str
. charCodeAt ( i
)
2095 function base64ToBytes ( str
) {
2096 return base64
. toByteArray ( base64clean ( str
))
2099 function blitBuffer ( src
, dst
, offset
, length
) {
2100 for ( var i
= 0 ; i
< length
; ++ i
) {
2101 if (( i
+ offset
>= dst
. length
) || ( i
>= src
. length
)) break
2102 dst
[ i
+ offset
] = src
[ i
]
2107 // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
2108 // the `instanceof` check but they should be treated as of that type.
2109 // See: https://github.com/feross/buffer/issues/166
2110 function isInstance ( obj
, type
) {
2111 return obj
instanceof type
||
2112 ( obj
!= null && obj
. constructor != null && obj
. constructor . name
!= null &&
2113 obj
. constructor . name
=== type
. name
)
2115 function numberIsNaN ( obj
) {
2117 return obj
!== obj
// eslint-disable-line no-self-compare
2120 }). call ( this , require ( "buffer" ). Buffer
)
2121 },{ "base64-js" : 3 , "buffer" : 6 , "ieee754" : 12 }], 7 :[ function ( require
, module
, exports
){
2122 var Buffer
= require ( 'safe-buffer' ). Buffer
2123 var Transform
= require ( 'stream' ). Transform
2124 var StringDecoder
= require ( 'string_decoder' ). StringDecoder
2125 var inherits
= require ( 'inherits' )
2127 function CipherBase ( hashMode
) {
2128 Transform
. call ( this )
2129 this . hashMode
= typeof hashMode
=== 'string'
2130 if ( this . hashMode
) {
2131 this [ hashMode
] = this . _finalOrDigest
2133 this . final
= this . _finalOrDigest
2136 this . __final
= this . _final
2139 this . _decoder
= null
2140 this . _encoding
= null
2142 inherits ( CipherBase
, Transform
)
2144 CipherBase
. prototype . update = function ( data
, inputEnc
, outputEnc
) {
2145 if ( typeof data
=== 'string' ) {
2146 data
= Buffer
. from ( data
, inputEnc
)
2149 var outData
= this . _update ( data
)
2150 if ( this . hashMode
) return this
2153 outData
= this . _toString ( outData
, outputEnc
)
2159 CipherBase
. prototype . setAutoPadding = function () {}
2160 CipherBase
. prototype . getAuthTag = function () {
2161 throw new Error ( 'trying to get auth tag in unsupported state' )
2164 CipherBase
. prototype . setAuthTag = function () {
2165 throw new Error ( 'trying to set auth tag in unsupported state' )
2168 CipherBase
. prototype . setAAD = function () {
2169 throw new Error ( 'trying to set aad in unsupported state' )
2172 CipherBase
. prototype . _transform = function ( data
, _
, next
) {
2175 if ( this . hashMode
) {
2178 this . push ( this . _update ( data
))
2186 CipherBase
. prototype . _flush = function ( done
) {
2189 this . push ( this . __final ())
2196 CipherBase
. prototype . _finalOrDigest = function ( outputEnc
) {
2197 var outData
= this . __final () || Buffer
. alloc ( 0 )
2199 outData
= this . _toString ( outData
, outputEnc
, true )
2204 CipherBase
. prototype . _toString = function ( value
, enc
, fin
) {
2205 if (! this . _decoder
) {
2206 this . _decoder
= new StringDecoder ( enc
)
2207 this . _encoding
= enc
2210 if ( this . _encoding
!== enc
) throw new Error ( 'can \' t switch encodings' )
2212 var out
= this . _decoder
. write ( value
)
2214 out
+= this . _decoder
. end ()
2220 module
. exports
= CipherBase
2222 },{ "inherits" : 13 , "safe-buffer" : 34 , "stream" : 43 , "string_decoder" : 44 }], 8 :[ function ( require
, module
, exports
){
2224 // Copyright Joyent, Inc. and other Node contributors.
2226 // Permission is hereby granted, free of charge, to any person obtaining a
2227 // copy of this software and associated documentation files (the
2228 // "Software"), to deal in the Software without restriction, including
2229 // without limitation the rights to use, copy, modify, merge, publish,
2230 // distribute, sublicense, and/or sell copies of the Software, and to permit
2231 // persons to whom the Software is furnished to do so, subject to the
2232 // following conditions:
2234 // The above copyright notice and this permission notice shall be included
2235 // in all copies or substantial portions of the Software.
2237 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2238 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2239 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2240 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2241 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2242 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2243 // USE OR OTHER DEALINGS IN THE SOFTWARE.
2245 // NOTE: These type checking functions intentionally don't use `instanceof`
2246 // because it is fragile and can be easily faked with `Object.create()`.
2248 function isArray ( arg
) {
2249 if ( Array
. isArray
) {
2250 return Array
. isArray ( arg
);
2252 return objectToString ( arg
) === '[object Array]' ;
2254 exports
. isArray
= isArray
;
2256 function isBoolean ( arg
) {
2257 return typeof arg
=== 'boolean' ;
2259 exports
. isBoolean
= isBoolean
;
2261 function isNull ( arg
) {
2262 return arg
=== null ;
2264 exports
. isNull
= isNull
;
2266 function isNullOrUndefined ( arg
) {
2269 exports
. isNullOrUndefined
= isNullOrUndefined
;
2271 function isNumber ( arg
) {
2272 return typeof arg
=== 'number' ;
2274 exports
. isNumber
= isNumber
;
2276 function isString ( arg
) {
2277 return typeof arg
=== 'string' ;
2279 exports
. isString
= isString
;
2281 function isSymbol ( arg
) {
2282 return typeof arg
=== 'symbol' ;
2284 exports
. isSymbol
= isSymbol
;
2286 function isUndefined ( arg
) {
2287 return arg
=== void 0 ;
2289 exports
. isUndefined
= isUndefined
;
2291 function isRegExp ( re
) {
2292 return objectToString ( re
) === '[object RegExp]' ;
2294 exports
. isRegExp
= isRegExp
;
2296 function isObject ( arg
) {
2297 return typeof arg
=== 'object' && arg
!== null ;
2299 exports
. isObject
= isObject
;
2301 function isDate ( d
) {
2302 return objectToString ( d
) === '[object Date]' ;
2304 exports
. isDate
= isDate
;
2306 function isError ( e
) {
2307 return ( objectToString ( e
) === '[object Error]' || e
instanceof Error
);
2309 exports
. isError
= isError
;
2311 function isFunction ( arg
) {
2312 return typeof arg
=== 'function' ;
2314 exports
. isFunction
= isFunction
;
2316 function isPrimitive ( arg
) {
2317 return arg
=== null ||
2318 typeof arg
=== 'boolean' ||
2319 typeof arg
=== 'number' ||
2320 typeof arg
=== 'string' ||
2321 typeof arg
=== 'symbol' || // ES6 symbol
2322 typeof arg
=== 'undefined' ;
2324 exports
. isPrimitive
= isPrimitive
;
2326 exports
. isBuffer
= Buffer
. isBuffer
;
2328 function objectToString ( o
) {
2329 return Object
. prototype . toString
. call ( o
);
2332 }). call ( this ,{ "isBuffer" : require ( "../../is-buffer/index.js" )})
2333 },{ "../../is-buffer/index.js" : 14 }], 9 :[ function ( require
, module
, exports
){
2335 var inherits
= require ( 'inherits' )
2336 var MD5
= require ( 'md5.js' )
2337 var RIPEMD160
= require ( 'ripemd160' )
2338 var sha
= require ( 'sha.js' )
2339 var Base
= require ( 'cipher-base' )
2341 function Hash ( hash
) {
2342 Base
. call ( this , 'digest' )
2347 inherits ( Hash
, Base
)
2349 Hash
. prototype . _update = function ( data
) {
2350 this . _hash
. update ( data
)
2353 Hash
. prototype . _final = function () {
2354 return this . _hash
. digest ()
2357 module
. exports
= function createHash ( alg
) {
2358 alg
= alg
. toLowerCase ()
2359 if ( alg
=== 'md5' ) return new MD5 ()
2360 if ( alg
=== 'rmd160' || alg
=== 'ripemd160' ) return new RIPEMD160 ()
2362 return new Hash ( sha ( alg
))
2365 },{ "cipher-base" : 7 , "inherits" : 13 , "md5.js" : 16 , "ripemd160" : 33 , "sha.js" : 36 }], 10 :[ function ( require
, module
, exports
){
2366 // Copyright Joyent, Inc. and other Node contributors.
2368 // Permission is hereby granted, free of charge, to any person obtaining a
2369 // copy of this software and associated documentation files (the
2370 // "Software"), to deal in the Software without restriction, including
2371 // without limitation the rights to use, copy, modify, merge, publish,
2372 // distribute, sublicense, and/or sell copies of the Software, and to permit
2373 // persons to whom the Software is furnished to do so, subject to the
2374 // following conditions:
2376 // The above copyright notice and this permission notice shall be included
2377 // in all copies or substantial portions of the Software.
2379 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2380 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2381 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2382 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2383 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2384 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2385 // USE OR OTHER DEALINGS IN THE SOFTWARE.
2387 var objectCreate
= Object
. create
|| objectCreatePolyfill
2388 var objectKeys
= Object
. keys
|| objectKeysPolyfill
2389 var bind
= Function
. prototype . bind
|| functionBindPolyfill
2391 function EventEmitter () {
2392 if (! this . _events
|| ! Object
. prototype . hasOwnProperty
. call ( this , '_events' )) {
2393 this . _events
= objectCreate ( null );
2394 this . _eventsCount
= 0 ;
2397 this . _maxListeners
= this . _maxListeners
|| undefined ;
2399 module
. exports
= EventEmitter
;
2401 // Backwards-compat with node 0.10.x
2402 EventEmitter
. EventEmitter
= EventEmitter
;
2404 EventEmitter
. prototype . _events
= undefined ;
2405 EventEmitter
. prototype . _maxListeners
= undefined ;
2407 // By default EventEmitters will print a warning if more than 10 listeners are
2408 // added to it. This is a useful default which helps finding memory leaks.
2409 var defaultMaxListeners
= 10 ;
2411 var hasDefineProperty
;
2414 if ( Object
. defineProperty
) Object
. defineProperty ( o
, 'x' , { value : 0 });
2415 hasDefineProperty
= o
. x
=== 0 ;
2416 } catch ( err
) { hasDefineProperty
= false }
2417 if ( hasDefineProperty
) {
2418 Object
. defineProperty ( EventEmitter
, 'defaultMaxListeners' , {
2421 return defaultMaxListeners
;
2423 set : function ( arg
) {
2424 // check whether the input is a positive number (whose value is zero or
2425 // greater and not a NaN).
2426 if ( typeof arg
!== 'number' || arg
< 0 || arg
!== arg
)
2427 throw new TypeError ( '"defaultMaxListeners" must be a positive number' );
2428 defaultMaxListeners
= arg
;
2432 EventEmitter
. defaultMaxListeners
= defaultMaxListeners
;
2435 // Obviously not all Emitters should be limited to 10. This function allows
2436 // that to be increased. Set to zero for unlimited.
2437 EventEmitter
. prototype . setMaxListeners
= function setMaxListeners ( n
) {
2438 if ( typeof n
!== 'number' || n
< 0 || isNaN ( n
))
2439 throw new TypeError ( '"n" argument must be a positive number' );
2440 this . _maxListeners
= n
;
2444 function $ getMaxListeners ( that
) {
2445 if ( that
. _maxListeners
=== undefined )
2446 return EventEmitter
. defaultMaxListeners
;
2447 return that
. _maxListeners
;
2450 EventEmitter
. prototype . getMaxListeners
= function getMaxListeners () {
2451 return $ getMaxListeners ( this );
2454 // These standalone emit* functions are used to optimize calling of event
2455 // handlers for fast cases because emit() itself often has a variable number of
2456 // arguments and can be deoptimized because of that. These functions always have
2457 // the same number of arguments and thus do not get deoptimized, so the code
2458 // inside them can execute faster.
2459 function emitNone ( handler
, isFn
, self
) {
2463 var len
= handler
. length
;
2464 var listeners
= arrayClone ( handler
, len
);
2465 for ( var i
= 0 ; i
< len
; ++ i
)
2466 listeners
[ i
]. call ( self
);
2469 function emitOne ( handler
, isFn
, self
, arg1
) {
2471 handler
. call ( self
, arg1
);
2473 var len
= handler
. length
;
2474 var listeners
= arrayClone ( handler
, len
);
2475 for ( var i
= 0 ; i
< len
; ++ i
)
2476 listeners
[ i
]. call ( self
, arg1
);
2479 function emitTwo ( handler
, isFn
, self
, arg1
, arg2
) {
2481 handler
. call ( self
, arg1
, arg2
);
2483 var len
= handler
. length
;
2484 var listeners
= arrayClone ( handler
, len
);
2485 for ( var i
= 0 ; i
< len
; ++ i
)
2486 listeners
[ i
]. call ( self
, arg1
, arg2
);
2489 function emitThree ( handler
, isFn
, self
, arg1
, arg2
, arg3
) {
2491 handler
. call ( self
, arg1
, arg2
, arg3
);
2493 var len
= handler
. length
;
2494 var listeners
= arrayClone ( handler
, len
);
2495 for ( var i
= 0 ; i
< len
; ++ i
)
2496 listeners
[ i
]. call ( self
, arg1
, arg2
, arg3
);
2500 function emitMany ( handler
, isFn
, self
, args
) {
2502 handler
. apply ( self
, args
);
2504 var len
= handler
. length
;
2505 var listeners
= arrayClone ( handler
, len
);
2506 for ( var i
= 0 ; i
< len
; ++ i
)
2507 listeners
[ i
]. apply ( self
, args
);
2511 EventEmitter
. prototype . emit
= function emit ( type
) {
2512 var er
, handler
, len
, args
, i
, events
;
2513 var doError
= ( type
=== 'error' );
2515 events
= this . _events
;
2517 doError
= ( doError
&& events
. error
== null );
2521 // If there is no 'error' event listener then throw.
2523 if ( arguments
. length
> 1 )
2525 if ( er
instanceof Error
) {
2526 throw er
; // Unhandled 'error' event
2528 // At least give some kind of context to the user
2529 var err
= new Error ( 'Unhandled "error" event. (' + er
+ ')' );
2536 handler
= events
[ type
];
2541 var isFn
= typeof handler
=== 'function' ;
2542 len
= arguments
. length
;
2546 emitNone ( handler
, isFn
, this );
2549 emitOne ( handler
, isFn
, this , arguments
[ 1 ]);
2552 emitTwo ( handler
, isFn
, this , arguments
[ 1 ], arguments
[ 2 ]);
2555 emitThree ( handler
, isFn
, this , arguments
[ 1 ], arguments
[ 2 ], arguments
[ 3 ]);
2559 args
= new Array ( len
- 1 );
2560 for ( i
= 1 ; i
< len
; i
++)
2561 args
[ i
- 1 ] = arguments
[ i
];
2562 emitMany ( handler
, isFn
, this , args
);
2568 function _addListener ( target
, type
, listener
, prepend
) {
2573 if ( typeof listener
!== 'function' )
2574 throw new TypeError ( '"listener" argument must be a function' );
2576 events
= target
. _events
;
2578 events
= target
. _events
= objectCreate ( null );
2579 target
. _eventsCount
= 0 ;
2581 // To avoid recursion in the case that type === "newListener"! Before
2582 // adding it to the listeners, first emit "newListener".
2583 if ( events
. newListener
) {
2584 target
. emit ( 'newListener' , type
,
2585 listener
. listener
? listener
. listener : listener
);
2587 // Re-assign `events` because a newListener handler could have caused the
2588 // this._events to be assigned to a new object
2589 events
= target
. _events
;
2591 existing
= events
[ type
];
2595 // Optimize the case of one listener. Don't need the extra array object.
2596 existing
= events
[ type
] = listener
;
2597 ++ target
. _eventsCount
;
2599 if ( typeof existing
=== 'function' ) {
2600 // Adding the second element, need to change to array.
2601 existing
= events
[ type
] =
2602 prepend
? [ listener
, existing
] : [ existing
, listener
];
2604 // If we've already got an array, just append.
2606 existing
. unshift ( listener
);
2608 existing
. push ( listener
);
2612 // Check for listener leak
2613 if (! existing
. warned
) {
2614 m
= $ getMaxListeners ( target
);
2615 if ( m
&& m
> 0 && existing
. length
> m
) {
2616 existing
. warned
= true ;
2617 var w
= new Error ( 'Possible EventEmitter memory leak detected. ' +
2618 existing
. length
+ ' "' + String ( type
) + '" listeners ' +
2619 'added. Use emitter.setMaxListeners() to ' +
2621 w
. name
= 'MaxListenersExceededWarning' ;
2624 w
. count
= existing
. length
;
2625 if ( typeof console
=== 'object' && console
. warn
) {
2626 console
. warn ( '%s: %s' , w
. name
, w
. message
);
2635 EventEmitter
. prototype . addListener
= function addListener ( type
, listener
) {
2636 return _addListener ( this , type
, listener
, false );
2639 EventEmitter
. prototype . on
= EventEmitter
. prototype . addListener
;
2641 EventEmitter
. prototype . prependListener
=
2642 function prependListener ( type
, listener
) {
2643 return _addListener ( this , type
, listener
, true );
2646 function onceWrapper () {
2648 this . target
. removeListener ( this . type
, this . wrapFn
);
2650 switch ( arguments
. length
) {
2652 return this . listener
. call ( this . target
);
2654 return this . listener
. call ( this . target
, arguments
[ 0 ]);
2656 return this . listener
. call ( this . target
, arguments
[ 0 ], arguments
[ 1 ]);
2658 return this . listener
. call ( this . target
, arguments
[ 0 ], arguments
[ 1 ],
2661 var args
= new Array ( arguments
. length
);
2662 for ( var i
= 0 ; i
< args
. length
; ++ i
)
2663 args
[ i
] = arguments
[ i
];
2664 this . listener
. apply ( this . target
, args
);
2669 function _onceWrap ( target
, type
, listener
) {
2670 var state
= { fired : false , wrapFn : undefined , target : target
, type : type
, listener : listener
};
2671 var wrapped
= bind
. call ( onceWrapper
, state
);
2672 wrapped
. listener
= listener
;
2673 state
. wrapFn
= wrapped
;
2677 EventEmitter
. prototype . once
= function once ( type
, listener
) {
2678 if ( typeof listener
!== 'function' )
2679 throw new TypeError ( '"listener" argument must be a function' );
2680 this . on ( type
, _onceWrap ( this , type
, listener
));
2684 EventEmitter
. prototype . prependOnceListener
=
2685 function prependOnceListener ( type
, listener
) {
2686 if ( typeof listener
!== 'function' )
2687 throw new TypeError ( '"listener" argument must be a function' );
2688 this . prependListener ( type
, _onceWrap ( this , type
, listener
));
2692 // Emits a 'removeListener' event if and only if the listener was removed.
2693 EventEmitter
. prototype . removeListener
=
2694 function removeListener ( type
, listener
) {
2695 var list
, events
, position
, i
, originalListener
;
2697 if ( typeof listener
!== 'function' )
2698 throw new TypeError ( '"listener" argument must be a function' );
2700 events
= this . _events
;
2704 list
= events
[ type
];
2708 if ( list
=== listener
|| list
. listener
=== listener
) {
2709 if (-- this . _eventsCount
=== 0 )
2710 this . _events
= objectCreate ( null );
2712 delete events
[ type
];
2713 if ( events
. removeListener
)
2714 this . emit ( 'removeListener' , type
, list
. listener
|| listener
);
2716 } else if ( typeof list
!== 'function' ) {
2719 for ( i
= list
. length
- 1 ; i
>= 0 ; i
--) {
2720 if ( list
[ i
] === listener
|| list
[ i
]. listener
=== listener
) {
2721 originalListener
= list
[ i
]. listener
;
2733 spliceOne ( list
, position
);
2735 if ( list
. length
=== 1 )
2736 events
[ type
] = list
[ 0 ];
2738 if ( events
. removeListener
)
2739 this . emit ( 'removeListener' , type
, originalListener
|| listener
);
2745 EventEmitter
. prototype . removeAllListeners
=
2746 function removeAllListeners ( type
) {
2747 var listeners
, events
, i
;
2749 events
= this . _events
;
2753 // not listening for removeListener, no need to emit
2754 if (! events
. removeListener
) {
2755 if ( arguments
. length
=== 0 ) {
2756 this . _events
= objectCreate ( null );
2757 this . _eventsCount
= 0 ;
2758 } else if ( events
[ type
]) {
2759 if (-- this . _eventsCount
=== 0 )
2760 this . _events
= objectCreate ( null );
2762 delete events
[ type
];
2767 // emit removeListener for all listeners on all events
2768 if ( arguments
. length
=== 0 ) {
2769 var keys
= objectKeys ( events
);
2771 for ( i
= 0 ; i
< keys
. length
; ++ i
) {
2773 if ( key
=== 'removeListener' ) continue ;
2774 this . removeAllListeners ( key
);
2776 this . removeAllListeners ( 'removeListener' );
2777 this . _events
= objectCreate ( null );
2778 this . _eventsCount
= 0 ;
2782 listeners
= events
[ type
];
2784 if ( typeof listeners
=== 'function' ) {
2785 this . removeListener ( type
, listeners
);
2786 } else if ( listeners
) {
2788 for ( i
= listeners
. length
- 1 ; i
>= 0 ; i
--) {
2789 this . removeListener ( type
, listeners
[ i
]);
2796 function _listeners ( target
, type
, unwrap
) {
2797 var events
= target
. _events
;
2802 var evlistener
= events
[ type
];
2806 if ( typeof evlistener
=== 'function' )
2807 return unwrap
? [ evlistener
. listener
|| evlistener
] : [ evlistener
];
2809 return unwrap
? unwrapListeners ( evlistener
) : arrayClone ( evlistener
, evlistener
. length
);
2812 EventEmitter
. prototype . listeners
= function listeners ( type
) {
2813 return _listeners ( this , type
, true );
2816 EventEmitter
. prototype . rawListeners
= function rawListeners ( type
) {
2817 return _listeners ( this , type
, false );
2820 EventEmitter
. listenerCount = function ( emitter
, type
) {
2821 if ( typeof emitter
. listenerCount
=== 'function' ) {
2822 return emitter
. listenerCount ( type
);
2824 return listenerCount
. call ( emitter
, type
);
2828 EventEmitter
. prototype . listenerCount
= listenerCount
;
2829 function listenerCount ( type
) {
2830 var events
= this . _events
;
2833 var evlistener
= events
[ type
];
2835 if ( typeof evlistener
=== 'function' ) {
2837 } else if ( evlistener
) {
2838 return evlistener
. length
;
2845 EventEmitter
. prototype . eventNames
= function eventNames () {
2846 return this . _eventsCount
> 0 ? Reflect
. ownKeys ( this . _events
) : [];
2849 // About 1.5x faster than the two-arg version of Array#splice().
2850 function spliceOne ( list
, index
) {
2851 for ( var i
= index
, k
= i
+ 1 , n
= list
. length
; k
< n
; i
+= 1 , k
+= 1 )
2856 function arrayClone ( arr
, n
) {
2857 var copy
= new Array ( n
);
2858 for ( var i
= 0 ; i
< n
; ++ i
)
2863 function unwrapListeners ( arr
) {
2864 var ret
= new Array ( arr
. length
);
2865 for ( var i
= 0 ; i
< ret
. length
; ++ i
) {
2866 ret
[ i
] = arr
[ i
]. listener
|| arr
[ i
];
2871 function objectCreatePolyfill ( proto
) {
2872 var F = function () {};
2873 F
. prototype = proto
;
2876 function objectKeysPolyfill ( obj
) {
2878 for ( var k
in obj
) if ( Object
. prototype . hasOwnProperty
. call ( obj
, k
)) {
2883 function functionBindPolyfill ( context
) {
2885 return function () {
2886 return fn
. apply ( context
, arguments
);
2890 },{}], 11 :[ function ( require
, module
, exports
){
2892 var Buffer
= require ( 'safe-buffer' ). Buffer
2893 var Transform
= require ( 'stream' ). Transform
2894 var inherits
= require ( 'inherits' )
2896 function throwIfNotStringOrBuffer ( val
, prefix
) {
2897 if (! Buffer
. isBuffer ( val
) && typeof val
!== 'string' ) {
2898 throw new TypeError ( prefix
+ ' must be a string or a buffer' )
2902 function HashBase ( blockSize
) {
2903 Transform
. call ( this )
2905 this . _block
= Buffer
. allocUnsafe ( blockSize
)
2906 this . _blockSize
= blockSize
2907 this . _blockOffset
= 0
2908 this . _length
= [ 0 , 0 , 0 , 0 ]
2910 this . _finalized
= false
2913 inherits ( HashBase
, Transform
)
2915 HashBase
. prototype . _transform = function ( chunk
, encoding
, callback
) {
2918 this . update ( chunk
, encoding
)
2926 HashBase
. prototype . _flush = function ( callback
) {
2929 this . push ( this . digest ())
2937 HashBase
. prototype . update = function ( data
, encoding
) {
2938 throwIfNotStringOrBuffer ( data
, 'Data' )
2939 if ( this . _finalized
) throw new Error ( 'Digest already called' )
2940 if (! Buffer
. isBuffer ( data
)) data
= Buffer
. from ( data
, encoding
)
2943 var block
= this . _block
2945 while ( this . _blockOffset
+ data
. length
- offset
>= this . _blockSize
) {
2946 for ( var i
= this . _blockOffset
; i
< this . _blockSize
;) block
[ i
++] = data
[ offset
++]
2948 this . _blockOffset
= 0
2950 while ( offset
< data
. length
) block
[ this . _blockOffset
++] = data
[ offset
++]
2953 for ( var j
= 0 , carry
= data
. length
* 8 ; carry
> 0 ; ++ j
) {
2954 this . _length
[ j
] += carry
2955 carry
= ( this . _length
[ j
] / 0x0100000000 ) | 0
2956 if ( carry
> 0 ) this . _length
[ j
] -= 0x0100000000 * carry
2962 HashBase
. prototype . _update = function () {
2963 throw new Error ( '_update is not implemented' )
2966 HashBase
. prototype . digest = function ( encoding
) {
2967 if ( this . _finalized
) throw new Error ( 'Digest already called' )
2968 this . _finalized
= true
2970 var digest
= this . _digest ()
2971 if ( encoding
!== undefined ) digest
= digest
. toString ( encoding
)
2975 this . _blockOffset
= 0
2976 for ( var i
= 0 ; i
< 4 ; ++ i
) this . _length
[ i
] = 0
2981 HashBase
. prototype . _digest = function () {
2982 throw new Error ( '_digest is not implemented' )
2985 module
. exports
= HashBase
2987 },{ "inherits" : 13 , "safe-buffer" : 34 , "stream" : 43 }], 12 :[ function ( require
, module
, exports
){
2988 exports
. read = function ( buffer
, offset
, isLE
, mLen
, nBytes
) {
2990 var eLen
= ( nBytes
* 8 ) - mLen
- 1
2991 var eMax
= ( 1 << eLen
) - 1
2992 var eBias
= eMax
>> 1
2994 var i
= isLE
? ( nBytes
- 1 ) : 0
2995 var d
= isLE
? - 1 : 1
2996 var s
= buffer
[ offset
+ i
]
3000 e
= s
& (( 1 << (- nBits
)) - 1 )
3003 for (; nBits
> 0 ; e
= ( e
* 256 ) + buffer
[ offset
+ i
], i
+= d
, nBits
-= 8 ) {}
3005 m
= e
& (( 1 << (- nBits
)) - 1 )
3008 for (; nBits
> 0 ; m
= ( m
* 256 ) + buffer
[ offset
+ i
], i
+= d
, nBits
-= 8 ) {}
3012 } else if ( e
=== eMax
) {
3013 return m
? NaN : (( s
? - 1 : 1 ) * Infinity
)
3015 m
= m
+ Math
. pow ( 2 , mLen
)
3018 return ( s
? - 1 : 1 ) * m
* Math
. pow ( 2 , e
- mLen
)
3021 exports
. write = function ( buffer
, value
, offset
, isLE
, mLen
, nBytes
) {
3023 var eLen
= ( nBytes
* 8 ) - mLen
- 1
3024 var eMax
= ( 1 << eLen
) - 1
3025 var eBias
= eMax
>> 1
3026 var rt
= ( mLen
=== 23 ? Math
. pow ( 2 , - 24 ) - Math
. pow ( 2 , - 77 ) : 0 )
3027 var i
= isLE
? 0 : ( nBytes
- 1 )
3028 var d
= isLE
? 1 : - 1
3029 var s
= value
< 0 || ( value
=== 0 && 1 / value
< 0 ) ? 1 : 0
3031 value
= Math
. abs ( value
)
3033 if ( isNaN ( value
) || value
=== Infinity
) {
3034 m
= isNaN ( value
) ? 1 : 0
3037 e
= Math
. floor ( Math
. log ( value
) / Math
. LN2
)
3038 if ( value
* ( c
= Math
. pow ( 2 , - e
)) < 1 ) {
3042 if ( e
+ eBias
>= 1 ) {
3045 value
+= rt
* Math
. pow ( 2 , 1 - eBias
)
3047 if ( value
* c
>= 2 ) {
3052 if ( e
+ eBias
>= eMax
) {
3055 } else if ( e
+ eBias
>= 1 ) {
3056 m
= (( value
* c
) - 1 ) * Math
. pow ( 2 , mLen
)
3059 m
= value
* Math
. pow ( 2 , eBias
- 1 ) * Math
. pow ( 2 , mLen
)
3064 for (; mLen
>= 8 ; buffer
[ offset
+ i
] = m
& 0xff , i
+= d
, m
/= 256 , mLen
-= 8 ) {}
3068 for (; eLen
> 0 ; buffer
[ offset
+ i
] = e
& 0xff , i
+= d
, e
/= 256 , eLen
-= 8 ) {}
3070 buffer
[ offset
+ i
- d
] |= s
* 128
3073 },{}], 13 :[ function ( require
, module
, exports
){
3074 if ( typeof Object
. create
=== 'function' ) {
3075 // implementation from standard node.js 'util' module
3076 module
. exports
= function inherits ( ctor
, superCtor
) {
3077 ctor
. super_
= superCtor
3078 ctor
. prototype = Object
. create ( superCtor
. prototype , {
3088 // old school shim for old browsers
3089 module
. exports
= function inherits ( ctor
, superCtor
) {
3090 ctor
. super_
= superCtor
3091 var TempCtor = function () {}
3092 TempCtor
. prototype = superCtor
. prototype
3093 ctor
. prototype = new TempCtor ()
3094 ctor
. prototype . constructor = ctor
3098 },{}], 14 :[ function ( require
, module
, exports
){
3100 * Determine if an object is a Buffer
3102 * @author Feross Aboukhadijeh <https://feross.org>
3106 // The _isBuffer check is for Safari 5-7 support, because it's missing
3107 // Object.prototype.constructor. Remove this eventually
3108 module
. exports = function ( obj
) {
3109 return obj
!= null && ( isBuffer ( obj
) || isSlowBuffer ( obj
) || !! obj
. _isBuffer
)
3112 function isBuffer ( obj
) {
3113 return !! obj
. constructor && typeof obj
. constructor . isBuffer
=== 'function' && obj
. constructor . isBuffer ( obj
)
3116 // For Node v0.10 support. Remove this eventually.
3117 function isSlowBuffer ( obj
) {
3118 return typeof obj
. readFloatLE
=== 'function' && typeof obj
. slice
=== 'function' && isBuffer ( obj
. slice ( 0 , 0 ))
3121 },{}], 15 :[ function ( require
, module
, exports
){
3122 var toString
= {}. toString
;
3124 module
. exports
= Array
. isArray
|| function ( arr
) {
3125 return toString
. call ( arr
) == '[object Array]' ;
3128 },{}], 16 :[ function ( require
, module
, exports
){
3130 var inherits
= require ( 'inherits' )
3131 var HashBase
= require ( 'hash-base' )
3132 var Buffer
= require ( 'safe-buffer' ). Buffer
3134 var ARRAY16
= new Array ( 16 )
3137 HashBase
. call ( this , 64 )
3140 this . _a
= 0x67452301
3141 this . _b
= 0xefcdab89
3142 this . _c
= 0x98badcfe
3143 this . _d
= 0x10325476
3146 inherits ( MD5
, HashBase
)
3148 MD5
. prototype . _update = function () {
3150 for ( var i
= 0 ; i
< 16 ; ++ i
) M
[ i
] = this . _block
. readInt32LE ( i
* 4 )
3157 a
= fnF ( a
, b
, c
, d
, M
[ 0 ], 0xd76aa478 , 7 )
3158 d
= fnF ( d
, a
, b
, c
, M
[ 1 ], 0xe8c7b756 , 12 )
3159 c
= fnF ( c
, d
, a
, b
, M
[ 2 ], 0x242070db , 17 )
3160 b
= fnF ( b
, c
, d
, a
, M
[ 3 ], 0xc1bdceee , 22 )
3161 a
= fnF ( a
, b
, c
, d
, M
[ 4 ], 0xf57c0faf , 7 )
3162 d
= fnF ( d
, a
, b
, c
, M
[ 5 ], 0x4787c62a , 12 )
3163 c
= fnF ( c
, d
, a
, b
, M
[ 6 ], 0xa8304613 , 17 )
3164 b
= fnF ( b
, c
, d
, a
, M
[ 7 ], 0xfd469501 , 22 )
3165 a
= fnF ( a
, b
, c
, d
, M
[ 8 ], 0x698098d8 , 7 )
3166 d
= fnF ( d
, a
, b
, c
, M
[ 9 ], 0x8b44f7af , 12 )
3167 c
= fnF ( c
, d
, a
, b
, M
[ 10 ], 0xffff5bb1 , 17 )
3168 b
= fnF ( b
, c
, d
, a
, M
[ 11 ], 0x895cd7be , 22 )
3169 a
= fnF ( a
, b
, c
, d
, M
[ 12 ], 0x6b901122 , 7 )
3170 d
= fnF ( d
, a
, b
, c
, M
[ 13 ], 0xfd987193 , 12 )
3171 c
= fnF ( c
, d
, a
, b
, M
[ 14 ], 0xa679438e , 17 )
3172 b
= fnF ( b
, c
, d
, a
, M
[ 15 ], 0x49b40821 , 22 )
3174 a
= fnG ( a
, b
, c
, d
, M
[ 1 ], 0xf61e2562 , 5 )
3175 d
= fnG ( d
, a
, b
, c
, M
[ 6 ], 0xc040b340 , 9 )
3176 c
= fnG ( c
, d
, a
, b
, M
[ 11 ], 0x265e5a51 , 14 )
3177 b
= fnG ( b
, c
, d
, a
, M
[ 0 ], 0xe9b6c7aa , 20 )
3178 a
= fnG ( a
, b
, c
, d
, M
[ 5 ], 0xd62f105d , 5 )
3179 d
= fnG ( d
, a
, b
, c
, M
[ 10 ], 0x02441453 , 9 )
3180 c
= fnG ( c
, d
, a
, b
, M
[ 15 ], 0xd8a1e681 , 14 )
3181 b
= fnG ( b
, c
, d
, a
, M
[ 4 ], 0xe7d3fbc8 , 20 )
3182 a
= fnG ( a
, b
, c
, d
, M
[ 9 ], 0x21e1cde6 , 5 )
3183 d
= fnG ( d
, a
, b
, c
, M
[ 14 ], 0xc33707d6 , 9 )
3184 c
= fnG ( c
, d
, a
, b
, M
[ 3 ], 0xf4d50d87 , 14 )
3185 b
= fnG ( b
, c
, d
, a
, M
[ 8 ], 0x455a14ed , 20 )
3186 a
= fnG ( a
, b
, c
, d
, M
[ 13 ], 0xa9e3e905 , 5 )
3187 d
= fnG ( d
, a
, b
, c
, M
[ 2 ], 0xfcefa3f8 , 9 )
3188 c
= fnG ( c
, d
, a
, b
, M
[ 7 ], 0x676f02d9 , 14 )
3189 b
= fnG ( b
, c
, d
, a
, M
[ 12 ], 0x8d2a4c8a , 20 )
3191 a
= fnH ( a
, b
, c
, d
, M
[ 5 ], 0xfffa3942 , 4 )
3192 d
= fnH ( d
, a
, b
, c
, M
[ 8 ], 0x8771f681 , 11 )
3193 c
= fnH ( c
, d
, a
, b
, M
[ 11 ], 0x6d9d6122 , 16 )
3194 b
= fnH ( b
, c
, d
, a
, M
[ 14 ], 0xfde5380c , 23 )
3195 a
= fnH ( a
, b
, c
, d
, M
[ 1 ], 0xa4beea44 , 4 )
3196 d
= fnH ( d
, a
, b
, c
, M
[ 4 ], 0x4bdecfa9 , 11 )
3197 c
= fnH ( c
, d
, a
, b
, M
[ 7 ], 0xf6bb4b60 , 16 )
3198 b
= fnH ( b
, c
, d
, a
, M
[ 10 ], 0xbebfbc70 , 23 )
3199 a
= fnH ( a
, b
, c
, d
, M
[ 13 ], 0x289b7ec6 , 4 )
3200 d
= fnH ( d
, a
, b
, c
, M
[ 0 ], 0xeaa127fa , 11 )
3201 c
= fnH ( c
, d
, a
, b
, M
[ 3 ], 0xd4ef3085 , 16 )
3202 b
= fnH ( b
, c
, d
, a
, M
[ 6 ], 0x04881d05 , 23 )
3203 a
= fnH ( a
, b
, c
, d
, M
[ 9 ], 0xd9d4d039 , 4 )
3204 d
= fnH ( d
, a
, b
, c
, M
[ 12 ], 0xe6db99e5 , 11 )
3205 c
= fnH ( c
, d
, a
, b
, M
[ 15 ], 0x1fa27cf8 , 16 )
3206 b
= fnH ( b
, c
, d
, a
, M
[ 2 ], 0xc4ac5665 , 23 )
3208 a
= fnI ( a
, b
, c
, d
, M
[ 0 ], 0xf4292244 , 6 )
3209 d
= fnI ( d
, a
, b
, c
, M
[ 7 ], 0x432aff97 , 10 )
3210 c
= fnI ( c
, d
, a
, b
, M
[ 14 ], 0xab9423a7 , 15 )
3211 b
= fnI ( b
, c
, d
, a
, M
[ 5 ], 0xfc93a039 , 21 )
3212 a
= fnI ( a
, b
, c
, d
, M
[ 12 ], 0x655b59c3 , 6 )
3213 d
= fnI ( d
, a
, b
, c
, M
[ 3 ], 0x8f0ccc92 , 10 )
3214 c
= fnI ( c
, d
, a
, b
, M
[ 10 ], 0xffeff47d , 15 )
3215 b
= fnI ( b
, c
, d
, a
, M
[ 1 ], 0x85845dd1 , 21 )
3216 a
= fnI ( a
, b
, c
, d
, M
[ 8 ], 0x6fa87e4f , 6 )
3217 d
= fnI ( d
, a
, b
, c
, M
[ 15 ], 0xfe2ce6e0 , 10 )
3218 c
= fnI ( c
, d
, a
, b
, M
[ 6 ], 0xa3014314 , 15 )
3219 b
= fnI ( b
, c
, d
, a
, M
[ 13 ], 0x4e0811a1 , 21 )
3220 a
= fnI ( a
, b
, c
, d
, M
[ 4 ], 0xf7537e82 , 6 )
3221 d
= fnI ( d
, a
, b
, c
, M
[ 11 ], 0xbd3af235 , 10 )
3222 c
= fnI ( c
, d
, a
, b
, M
[ 2 ], 0x2ad7d2bb , 15 )
3223 b
= fnI ( b
, c
, d
, a
, M
[ 9 ], 0xeb86d391 , 21 )
3225 this . _a
= ( this . _a
+ a
) | 0
3226 this . _b
= ( this . _b
+ b
) | 0
3227 this . _c
= ( this . _c
+ c
) | 0
3228 this . _d
= ( this . _d
+ d
) | 0
3231 MD5
. prototype . _digest = function () {
3232 // create padding and handle blocks
3233 this . _block
[ this . _blockOffset
++] = 0x80
3234 if ( this . _blockOffset
> 56 ) {
3235 this . _block
. fill ( 0 , this . _blockOffset
, 64 )
3237 this . _blockOffset
= 0
3240 this . _block
. fill ( 0 , this . _blockOffset
, 56 )
3241 this . _block
. writeUInt32LE ( this . _length
[ 0 ], 56 )
3242 this . _block
. writeUInt32LE ( this . _length
[ 1 ], 60 )
3246 var buffer
= Buffer
. allocUnsafe ( 16 )
3247 buffer
. writeInt32LE ( this . _a
, 0 )
3248 buffer
. writeInt32LE ( this . _b
, 4 )
3249 buffer
. writeInt32LE ( this . _c
, 8 )
3250 buffer
. writeInt32LE ( this . _d
, 12 )
3254 function rotl ( x
, n
) {
3255 return ( x
<< n
) | ( x
>>> ( 32 - n
))
3258 function fnF ( a
, b
, c
, d
, m
, k
, s
) {
3259 return ( rotl (( a
+ (( b
& c
) | ((~ b
) & d
)) + m
+ k
) | 0 , s
) + b
) | 0
3262 function fnG ( a
, b
, c
, d
, m
, k
, s
) {
3263 return ( rotl (( a
+ (( b
& d
) | ( c
& (~ d
))) + m
+ k
) | 0 , s
) + b
) | 0
3266 function fnH ( a
, b
, c
, d
, m
, k
, s
) {
3267 return ( rotl (( a
+ ( b
^ c
^ d
) + m
+ k
) | 0 , s
) + b
) | 0
3270 function fnI ( a
, b
, c
, d
, m
, k
, s
) {
3271 return ( rotl (( a
+ (( c
^ ( b
| (~ d
)))) + m
+ k
) | 0 , s
) + b
) | 0
3274 module
. exports
= MD5
3276 },{ "hash-base" : 11 , "inherits" : 13 , "safe-buffer" : 34 }], 17 :[ function ( require
, module
, exports
){
3277 ( function ( process
){
3280 if (! process
. version
||
3281 process
. version
. indexOf ( 'v0.' ) === 0 ||
3282 process
. version
. indexOf ( 'v1.' ) === 0 && process
. version
. indexOf ( 'v1.8.' ) !== 0 ) {
3283 module
. exports
= { nextTick : nextTick
};
3285 module
. exports
= process
3288 function nextTick ( fn
, arg1
, arg2
, arg3
) {
3289 if ( typeof fn
!== 'function' ) {
3290 throw new TypeError ( '"callback" argument must be a function' );
3292 var len
= arguments
. length
;
3297 return process
. nextTick ( fn
);
3299 return process
. nextTick ( function afterTickOne () {
3300 fn
. call ( null , arg1
);
3303 return process
. nextTick ( function afterTickTwo () {
3304 fn
. call ( null , arg1
, arg2
);
3307 return process
. nextTick ( function afterTickThree () {
3308 fn
. call ( null , arg1
, arg2
, arg3
);
3311 args
= new Array ( len
- 1 );
3313 while ( i
< args
. length
) {
3314 args
[ i
++] = arguments
[ i
];
3316 return process
. nextTick ( function afterTick () {
3317 fn
. apply ( null , args
);
3323 }). call ( this , require ( '_process' ))
3324 },{ "_process" : 18 }], 18 :[ function ( require
, module
, exports
){
3325 // shim for using process in browser
3326 var process
= module
. exports
= {};
3328 // cached from whatever global is present so that test runners that stub it
3329 // don't break things. But we need to wrap it in a try catch in case it is
3330 // wrapped in strict mode code which doesn't define any globals. It's inside a
3331 // function because try/catches deoptimize in certain engines.
3333 var cachedSetTimeout
;
3334 var cachedClearTimeout
;
3336 function defaultSetTimout () {
3337 throw new Error ( 'setTimeout has not been defined' );
3339 function defaultClearTimeout () {
3340 throw new Error ( 'clearTimeout has not been defined' );
3344 if ( typeof setTimeout
=== 'function' ) {
3345 cachedSetTimeout
= setTimeout
;
3347 cachedSetTimeout
= defaultSetTimout
;
3350 cachedSetTimeout
= defaultSetTimout
;
3353 if ( typeof clearTimeout
=== 'function' ) {
3354 cachedClearTimeout
= clearTimeout
;
3356 cachedClearTimeout
= defaultClearTimeout
;
3359 cachedClearTimeout
= defaultClearTimeout
;
3362 function runTimeout ( fun
) {
3363 if ( cachedSetTimeout
=== setTimeout
) {
3364 //normal enviroments in sane situations
3365 return setTimeout ( fun
, 0 );
3367 // if setTimeout wasn't available but was latter defined
3368 if (( cachedSetTimeout
=== defaultSetTimout
|| ! cachedSetTimeout
) && setTimeout
) {
3369 cachedSetTimeout
= setTimeout
;
3370 return setTimeout ( fun
, 0 );
3373 // when when somebody has screwed with setTimeout but no I.E. maddness
3374 return cachedSetTimeout ( fun
, 0 );
3377 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
3378 return cachedSetTimeout
. call ( null , fun
, 0 );
3380 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
3381 return cachedSetTimeout
. call ( this , fun
, 0 );
3387 function runClearTimeout ( marker
) {
3388 if ( cachedClearTimeout
=== clearTimeout
) {
3389 //normal enviroments in sane situations
3390 return clearTimeout ( marker
);
3392 // if clearTimeout wasn't available but was latter defined
3393 if (( cachedClearTimeout
=== defaultClearTimeout
|| ! cachedClearTimeout
) && clearTimeout
) {
3394 cachedClearTimeout
= clearTimeout
;
3395 return clearTimeout ( marker
);
3398 // when when somebody has screwed with setTimeout but no I.E. maddness
3399 return cachedClearTimeout ( marker
);
3402 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
3403 return cachedClearTimeout
. call ( null , marker
);
3405 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
3406 // Some versions of I.E. have different rules for clearTimeout vs setTimeout
3407 return cachedClearTimeout
. call ( this , marker
);
3415 var draining
= false ;
3417 var queueIndex
= - 1 ;
3419 function cleanUpNextTick () {
3420 if (! draining
|| ! currentQueue
) {
3424 if ( currentQueue
. length
) {
3425 queue
= currentQueue
. concat ( queue
);
3434 function drainQueue () {
3438 var timeout
= runTimeout ( cleanUpNextTick
);
3441 var len
= queue
. length
;
3443 currentQueue
= queue
;
3445 while (++ queueIndex
< len
) {
3447 currentQueue
[ queueIndex
]. run ();
3453 currentQueue
= null ;
3455 runClearTimeout ( timeout
);
3458 process
. nextTick = function ( fun
) {
3459 var args
= new Array ( arguments
. length
- 1 );
3460 if ( arguments
. length
> 1 ) {
3461 for ( var i
= 1 ; i
< arguments
. length
; i
++) {
3462 args
[ i
- 1 ] = arguments
[ i
];
3465 queue
. push ( new Item ( fun
, args
));
3466 if ( queue
. length
=== 1 && ! draining
) {
3467 runTimeout ( drainQueue
);
3471 // v8 likes predictible objects
3472 function Item ( fun
, array
) {
3476 Item
. prototype . run = function () {
3477 this . fun
. apply ( null , this . array
);
3479 process
. title
= 'browser' ;
3480 process
. browser
= true ;
3483 process
. version
= '' ; // empty string to avoid regexp issues
3484 process
. versions
= {};
3489 process
. addListener
= noop
;
3490 process
. once
= noop
;
3492 process
. removeListener
= noop
;
3493 process
. removeAllListeners
= noop
;
3494 process
. emit
= noop
;
3495 process
. prependListener
= noop
;
3496 process
. prependOnceListener
= noop
;
3498 process
. listeners = function ( name
) { return [] }
3500 process
. binding = function ( name
) {
3501 throw new Error ( 'process.binding is not supported' );
3504 process
. cwd = function () { return '/' };
3505 process
. chdir = function ( dir
) {
3506 throw new Error ( 'process.chdir is not supported' );
3508 process
. umask = function () { return 0 ; };
3510 },{}], 19 :[ function ( require
, module
, exports
){
3511 module
. exports
= require ( './lib/_stream_duplex.js' );
3513 },{ "./lib/_stream_duplex.js" : 20 }], 20 :[ function ( require
, module
, exports
){
3514 // Copyright Joyent, Inc. and other Node contributors.
3516 // Permission is hereby granted, free of charge, to any person obtaining a
3517 // copy of this software and associated documentation files (the
3518 // "Software"), to deal in the Software without restriction, including
3519 // without limitation the rights to use, copy, modify, merge, publish,
3520 // distribute, sublicense, and/or sell copies of the Software, and to permit
3521 // persons to whom the Software is furnished to do so, subject to the
3522 // following conditions:
3524 // The above copyright notice and this permission notice shall be included
3525 // in all copies or substantial portions of the Software.
3527 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
3528 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3529 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
3530 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
3531 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
3532 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
3533 // USE OR OTHER DEALINGS IN THE SOFTWARE.
3535 // a duplex stream is just a stream that is both readable and writable.
3536 // Since JS doesn't have multiple prototypal inheritance, this class
3537 // prototypally inherits from Readable, and then parasitically from
3544 var pna
= require ( 'process-nextick-args' );
3548 var objectKeys
= Object
. keys
|| function ( obj
) {
3550 for ( var key
in obj
) {
3556 module.exports = Duplex;
3559 var util
= require ( 'core-util-is' );
3560 util
. inherits
= require ( 'inherits' );
3563 var Readable = require('./_stream_readable');
3564 var Writable = require('./_stream_writable');
3566 util.inherits(Duplex, Readable);
3569 // avoid scope creep, the keys array can then be collected
3570 var keys = objectKeys(Writable.prototype);
3571 for (var v = 0; v < keys.length; v++) {
3572 var method = keys[v];
3573 if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
3577 function Duplex(options) {
3578 if (!(this instanceof Duplex)) return new Duplex(options);
3580 Readable.call(this, options);
3581 Writable.call(this, options);
3583 if (options && options.readable === false) this.readable = false;
3585 if (options && options.writable === false) this.writable = false;
3587 this.allowHalfOpen = true;
3588 if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
3590 this.once('end', onend);
3593 Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
3594 // making it explicit this property is not enumerable
3595 // because otherwise some prototype manipulation in
3596 // userland will fail
3599 return this._writableState.highWaterMark;
3603 // the no-half-open enforcer
3605 // if we allow half-open state, or if the writable side ended,
3607 if (this.allowHalfOpen || this._writableState.ended) return;
3609 // no more data can be written.
3610 // But allow more writes to happen in this tick.
3611 pna.nextTick(onEndNT, this);
3614 function onEndNT(self) {
3618 Object.defineProperty(Duplex.prototype, 'destroyed', {
3620 if (this._readableState === undefined || this._writableState === undefined) {
3623 return this._readableState.destroyed && this._writableState.destroyed;
3625 set: function (value) {
3626 // we ignore the value if the stream
3627 // has not been initialized yet
3628 if (this._readableState === undefined || this._writableState === undefined) {
3632 // backward compatibility, the user is explicitly
3633 // managing destroyed
3634 this._readableState.destroyed = value;
3635 this._writableState.destroyed = value;
3639 Duplex.prototype._destroy = function (err, cb) {
3643 pna.nextTick(cb, err);
3645 },{"./_stream_readable":22,"./_stream_writable":24,"core-util-is":8,"inherits":13,"process-nextick-args":17}],21:[function(require,module,exports){
3646 // Copyright Joyent, Inc. and other Node contributors.
3648 // Permission is hereby granted, free of charge, to any person obtaining a
3649 // copy of this software and associated documentation files (the
3650 // "Software"), to deal in the Software without restriction, including
3651 // without limitation the rights to use, copy, modify, merge, publish,
3652 // distribute, sublicense, and/or sell copies of the Software, and to permit
3653 // persons to whom the Software is furnished to do so, subject to the
3654 // following conditions:
3656 // The above copyright notice and this permission notice shall be included
3657 // in all copies or substantial portions of the Software.
3659 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
3660 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3661 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
3662 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
3663 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
3664 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
3665 // USE OR OTHER DEALINGS IN THE SOFTWARE.
3667 // a passthrough stream.
3668 // basically just the most minimal sort of Transform stream.
3669 // Every written chunk gets output as-is.
3673 module.exports = PassThrough;
3675 var Transform = require('./_stream_transform');
3678 var util
= require ( 'core-util-is' );
3679 util
. inherits
= require ( 'inherits' );
3682 util.inherits(PassThrough, Transform);
3684 function PassThrough(options) {
3685 if (!(this instanceof PassThrough)) return new PassThrough(options);
3687 Transform.call(this, options);
3690 PassThrough.prototype._transform = function (chunk, encoding, cb) {
3693 },{"./_stream_transform":23,"core-util-is":8,"inherits":13}],22:[function(require,module,exports){
3694 (function (process,global){
3695 // Copyright Joyent, Inc. and other Node contributors.
3697 // Permission is hereby granted, free of charge, to any person obtaining a
3698 // copy of this software and associated documentation files (the
3699 // "Software"), to deal in the Software without restriction, including
3700 // without limitation the rights to use, copy, modify, merge, publish,
3701 // distribute, sublicense, and/or sell copies of the Software, and to permit
3702 // persons to whom the Software is furnished to do so, subject to the
3703 // following conditions:
3705 // The above copyright notice and this permission notice shall be included
3706 // in all copies or substantial portions of the Software.
3708 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
3709 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3710 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
3711 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
3712 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
3713 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
3714 // USE OR OTHER DEALINGS IN THE SOFTWARE.
3720 var pna
= require ( 'process-nextick-args' );
3723 module.exports = Readable;
3726 var isArray
= require ( 'isarray' );
3733 Readable.ReadableState = ReadableState;
3736 var EE
= require ( 'events' ). EventEmitter
;
3738 var EElistenerCount = function ( emitter
, type
) {
3739 return emitter
. listeners ( type
). length
;
3744 var Stream
= require ( './internal/streams/stream' );
3749 var Buffer
= require ( 'safe-buffer' ). Buffer
;
3750 var OurUint8Array
= global
. Uint8Array
|| function () {};
3751 function _uint8ArrayToBuffer ( chunk
) {
3752 return Buffer
. from ( chunk
);
3754 function _isUint8Array ( obj
) {
3755 return Buffer
. isBuffer ( obj
) || obj
instanceof OurUint8Array
;
3761 var util
= require ( 'core-util-is' );
3762 util
. inherits
= require ( 'inherits' );
3766 var debugUtil
= require ( 'util' );
3768 if ( debugUtil
&& debugUtil
. debuglog
) {
3769 debug
= debugUtil
. debuglog ( 'stream' );
3771 debug = function () {};
3775 var BufferList = require('./internal/streams/BufferList');
3776 var destroyImpl = require('./internal/streams/destroy');
3779 util.inherits(Readable, Stream);
3781 var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
3783 function prependListener(emitter, event, fn) {
3784 // Sadly this is not cacheable as some libraries bundle their own
3785 // event emitter implementation with them.
3786 if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
3788 // This is a hack to make sure that our error handler is attached before any
3789 // userland ones. NEVER DO THIS. This is here only because this code needs
3790 // to continue to work with older versions of Node.js that do not include
3791 // the prependListener() method. The goal is to eventually remove this hack.
3792 if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
3795 function ReadableState(options, stream) {
3796 Duplex = Duplex || require('./_stream_duplex');
3798 options = options || {};
3800 // Duplex streams are both readable and writable, but share
3801 // the same options object.
3802 // However, some cases require setting options to different
3803 // values for the readable and the writable sides of the duplex stream.
3804 // These options can be provided separately as readableXXX and writableXXX.
3805 var isDuplex = stream instanceof Duplex;
3807 // object stream flag. Used to make read(n) ignore n and to
3808 // make all the buffer merging and length checks go away
3809 this.objectMode = !!options.objectMode;
3811 if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
3813 // the point at which it stops calling _read() to fill the buffer
3814 // Note: 0 is a valid value, means "don't call _read preemptively ever"
3815 var hwm = options.highWaterMark;
3816 var readableHwm = options.readableHighWaterMark;
3817 var defaultHwm = this.objectMode ? 16 : 16 * 1024;
3819 if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm;
3822 this.highWaterMark = Math.floor(this.highWaterMark);
3824 // A linked list is used to store data chunks instead of an array because the
3825 // linked list can remove elements from the beginning faster than
3827 this.buffer = new BufferList();
3830 this.pipesCount = 0;
3831 this.flowing = null;
3833 this.endEmitted = false;
3834 this.reading = false;
3836 // a flag to be able to tell if the event 'readable'/'data' is emitted
3837 // immediately, or on a later tick. We set this to true at first, because
3838 // any actions that shouldn't happen until "later" should generally also
3839 // not happen before the first read call.
3842 // whenever we return null, then we set a flag to say
3843 // that we're awaiting a 'readable' event emission.
3844 this.needReadable = false;
3845 this.emittedReadable = false;
3846 this.readableListening = false;
3847 this.resumeScheduled = false;
3849 // has it been destroyed
3850 this.destroyed = false;
3852 // Crypto is kind of old and crusty. Historically, its default string
3853 // encoding is 'binary' so we have to make this configurable.
3854 // Everything else in the universe uses 'utf8', though.
3855 this.defaultEncoding = options.defaultEncoding || 'utf8';
3857 // the number of writers that are awaiting a drain event in .pipe()s
3858 this.awaitDrain = 0;
3860 // if true, a maybeReadMore has been scheduled
3861 this.readingMore = false;
3863 this.decoder = null;
3864 this.encoding = null;
3865 if (options.encoding) {
3866 if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
3867 this.decoder = new StringDecoder(options.encoding);
3868 this.encoding = options.encoding;
3872 function Readable(options) {
3873 Duplex = Duplex || require('./_stream_duplex');
3875 if (!(this instanceof Readable)) return new Readable(options);
3877 this._readableState = new ReadableState(options, this);
3880 this.readable = true;
3883 if (typeof options.read === 'function') this._read = options.read;
3885 if (typeof options.destroy === 'function') this._destroy = options.destroy;
3891 Object.defineProperty(Readable.prototype, 'destroyed', {
3893 if (this._readableState === undefined) {
3896 return this._readableState.destroyed;
3898 set: function (value) {
3899 // we ignore the value if the stream
3900 // has not been initialized yet
3901 if (!this._readableState) {
3905 // backward compatibility, the user is explicitly
3906 // managing destroyed
3907 this._readableState.destroyed = value;
3911 Readable.prototype.destroy = destroyImpl.destroy;
3912 Readable.prototype._undestroy = destroyImpl.undestroy;
3913 Readable.prototype._destroy = function (err, cb) {
3918 // Manually shove something into the read() buffer.
3919 // This returns true if the highWaterMark has not been hit yet,
3920 // similar to how Writable.write() returns true if you should
3921 // write() some more.
3922 Readable.prototype.push = function (chunk, encoding) {
3923 var state = this._readableState;
3926 if (!state.objectMode) {
3927 if (typeof chunk === 'string') {
3928 encoding = encoding || state.defaultEncoding;
3929 if (encoding !== state.encoding) {
3930 chunk = Buffer.from(chunk, encoding);
3933 skipChunkCheck = true;
3936 skipChunkCheck = true;
3939 return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
3942 // Unshift should *always* be something directly out of read()
3943 Readable.prototype.unshift = function (chunk) {
3944 return readableAddChunk(this, chunk, null, true, false);
3947 function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
3948 var state = stream._readableState;
3949 if (chunk === null) {
3950 state.reading = false;
3951 onEofChunk(stream, state);
3954 if (!skipChunkCheck) er = chunkInvalid(state, chunk);
3956 stream.emit('error', er);
3957 } else if (state.objectMode || chunk && chunk.length > 0) {
3958 if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
3959 chunk = _uint8ArrayToBuffer(chunk);
3963 if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
3964 } else if (state.ended) {
3965 stream.emit('error', new Error('stream.push() after EOF'));
3967 state.reading = false;
3968 if (state.decoder && !encoding) {
3969 chunk = state.decoder.write(chunk);
3970 if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
3972 addChunk(stream, state, chunk, false);
3975 } else if (!addToFront) {
3976 state.reading = false;
3980 return needMoreData(state);
3983 function addChunk(stream, state, chunk, addToFront) {
3984 if (state.flowing && state.length === 0 && !state.sync) {
3985 stream.emit('data', chunk);
3988 // update the buffer info.
3989 state.length += state.objectMode ? 1 : chunk.length;
3990 if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
3992 if (state.needReadable) emitReadable(stream);
3994 maybeReadMore(stream, state);
3997 function chunkInvalid(state, chunk) {
3999 if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
4000 er = new TypeError('Invalid non-string/buffer chunk');
4005 // if it's past the high water mark, we can push in some more.
4006 // Also, if we have no data yet, we can stand some
4007 // more bytes. This is to work around cases where hwm=0,
4008 // such as the repl. Also, if the push() triggered a
4009 // readable event, and the user called read(largeNumber) such that
4010 // needReadable was set, then we ought to push more, so that another
4011 // 'readable' event will be triggered.
4012 function needMoreData(state) {
4013 return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
4016 Readable.prototype.isPaused = function () {
4017 return this._readableState.flowing === false;
4020 // backwards compatibility.
4021 Readable.prototype.setEncoding = function (enc) {
4022 if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
4023 this._readableState.decoder = new StringDecoder(enc);
4024 this._readableState.encoding = enc;
4028 // Don't raise the hwm > 8MB
4029 var MAX_HWM = 0x800000;
4030 function computeNewHighWaterMark(n) {
4034 // Get the next highest power of 2 to prevent increasing hwm excessively in
4047 // This function is designed to be inlinable, so please take care when making
4048 // changes to the function body.
4049 function howMuchToRead(n, state) {
4050 if (n <= 0 || state.length === 0 && state.ended) return 0;
4051 if (state.objectMode) return 1;
4053 // Only flow one buffer at a time
4054 if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
4056 // If we're asking for more than the current hwm, then raise the hwm.
4057 if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
4058 if (n <= state.length) return n;
4059 // Don't have enough
4061 state.needReadable = true;
4064 return state.length;
4067 // you can override either this method, or the async _read(n) below.
4068 Readable.prototype.read = function (n) {
4070 n = parseInt(n, 10);
4071 var state = this._readableState;
4074 if (n !== 0) state.emittedReadable = false;
4076 // if we're doing read(0) to trigger a readable event, but we
4077 // already have a bunch of data in the buffer, then just trigger
4078 // the 'readable' event and move on.
4079 if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
4080 debug('read: emitReadable', state.length, state.ended);
4081 if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
4085 n = howMuchToRead(n, state);
4087 // if we've ended, and we're now clear, then finish it up.
4088 if (n === 0 && state.ended) {
4089 if (state.length === 0) endReadable(this);
4093 // All the actual chunk generation logic needs to be
4094 // *below* the call to _read. The reason is that in certain
4095 // synthetic stream cases, such as passthrough streams, _read
4096 // may be a completely synchronous operation which may change
4097 // the state of the read buffer, providing enough data when
4098 // before there was *not* enough.
4100 // So, the steps are:
4101 // 1. Figure out what the state of things will be after we do
4102 // a read from the buffer.
4104 // 2. If that resulting state will trigger a _read, then call _read.
4105 // Note that this may be asynchronous, or synchronous. Yes, it is
4106 // deeply ugly to write APIs this way, but that still doesn't mean
4107 // that the Readable class should behave improperly, as streams are
4108 // designed to be sync/async agnostic.
4109 // Take note if the _read call is sync or async (ie, if the read call
4110 // has returned yet), so that we know whether or not it's safe to emit
4113 // 3. Actually pull the requested chunks out of the buffer and return.
4115 // if we need a readable event, then we need to do some reading.
4116 var doRead = state.needReadable;
4117 debug('need readable', doRead);
4119 // if we currently have less than the highWaterMark, then also read some
4120 if (state.length === 0 || state.length - n < state.highWaterMark) {
4122 debug('length less than watermark', doRead);
4125 // however, if we've ended, then there's no point, and if we're already
4126 // reading, then it's unnecessary.
4127 if (state.ended || state.reading) {
4129 debug('reading or ended', doRead);
4130 } else if (doRead) {
4132 state.reading = true;
4134 // if the length is currently zero, then we *need* a readable event.
4135 if (state.length === 0) state.needReadable = true;
4136 // call internal read method
4137 this._read(state.highWaterMark);
4139 // If _read pushed data synchronously, then `reading` will be false,
4140 // and we need to re-evaluate how much data we can return to the user.
4141 if (!state.reading) n = howMuchToRead(nOrig, state);
4145 if (n > 0) ret = fromList(n, state);else ret = null;
4148 state.needReadable = true;
4154 if (state.length === 0) {
4155 // If we have nothing in the buffer, then we want to know
4156 // as soon as we *do* get something into the buffer.
4157 if (!state.ended) state.needReadable = true;
4159 // If we tried to read() past the EOF, then emit end on the next tick.
4160 if (nOrig !== n && state.ended) endReadable(this);
4163 if (ret !== null) this.emit('data', ret);
4168 function onEofChunk(stream, state) {
4169 if (state.ended) return;
4170 if (state.decoder) {
4171 var chunk = state.decoder.end();
4172 if (chunk && chunk.length) {
4173 state.buffer.push(chunk);
4174 state.length += state.objectMode ? 1 : chunk.length;
4179 // emit 'readable' now to make sure it gets picked up.
4180 emitReadable(stream);
4183 // Don't emit readable right away in sync mode, because this can trigger
4184 // another read() call => stack overflow. This way, it might trigger
4185 // a nextTick recursion warning, but that's not so bad.
4186 function emitReadable(stream) {
4187 var state = stream._readableState;
4188 state.needReadable = false;
4189 if (!state.emittedReadable) {
4190 debug('emitReadable', state.flowing);
4191 state.emittedReadable = true;
4192 if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream);
4196 function emitReadable_(stream) {
4197 debug('emit readable');
4198 stream.emit('readable');
4202 // at this point, the user has presumably seen the 'readable' event,
4203 // and called read() to consume some data. that may have triggered
4204 // in turn another _read(n) call, in which case reading = true if
4205 // it's in progress.
4206 // However, if we're not ended, or reading, and the length < hwm,
4207 // then go ahead and try to read some more preemptively.
4208 function maybeReadMore(stream, state) {
4209 if (!state.readingMore) {
4210 state.readingMore = true;
4211 pna.nextTick(maybeReadMore_, stream, state);
4215 function maybeReadMore_(stream, state) {
4216 var len = state.length;
4217 while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
4218 debug('maybeReadMore read 0');
4220 if (len === state.length)
4221 // didn't get any data, stop spinning.
4222 break;else len = state.length;
4224 state.readingMore = false;
4227 // abstract method. to be overridden in specific implementation classes.
4228 // call cb(er, data) where data is <= n in length.
4229 // for virtual (non-string, non-buffer) streams, "length" is somewhat
4230 // arbitrary, and perhaps not very meaningful.
4231 Readable.prototype._read = function (n) {
4232 this.emit('error', new Error('_read() is not implemented'));
4235 Readable.prototype.pipe = function (dest, pipeOpts) {
4237 var state = this._readableState;
4239 switch (state.pipesCount) {
4244 state.pipes = [state.pipes, dest];
4247 state.pipes.push(dest);
4250 state.pipesCount += 1;
4251 debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
4253 var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
4255 var endFn = doEnd ? onend : unpipe;
4256 if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
4258 dest.on('unpipe', onunpipe);
4259 function onunpipe(readable, unpipeInfo) {
4261 if (readable === src) {
4262 if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
4263 unpipeInfo.hasUnpiped = true;
4274 // when the dest drains, it reduces the awaitDrain counter
4275 // on the source. This would be more elegant with a .once()
4276 // handler in flow(), but adding and removing repeatedly is
4278 var ondrain = pipeOnDrain(src);
4279 dest.on('drain', ondrain);
4281 var cleanedUp = false;
4282 function cleanup() {
4284 // cleanup event handlers once the pipe is broken
4285 dest.removeListener('close', onclose);
4286 dest.removeListener('finish', onfinish);
4287 dest.removeListener('drain', ondrain);
4288 dest.removeListener('error', onerror);
4289 dest.removeListener('unpipe', onunpipe);
4290 src.removeListener('end', onend);
4291 src.removeListener('end', unpipe);
4292 src.removeListener('data', ondata);
4296 // if the reader is waiting for a drain event from this
4297 // specific writer, then it would cause it to never start
4299 // So, if this is awaiting a drain, then we just call it now.
4300 // If we don't know, then assume that we are waiting for one.
4301 if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
4304 // If the user pushes more data while we're writing to dest then we'll end up
4305 // in ondata again. However, we only want to increase awaitDrain once because
4306 // dest will only emit one 'drain' event for the multiple writes.
4307 // => Introduce a guard on increasing awaitDrain.
4308 var increasedAwaitDrain = false;
4309 src.on('data', ondata);
4310 function ondata(chunk) {
4312 increasedAwaitDrain = false;
4313 var ret = dest.write(chunk);
4314 if (false === ret && !increasedAwaitDrain) {
4315 // If the user unpiped during `dest.write()`, it is possible
4316 // to get stuck in a permanently paused state if that write
4317 // also returned false.
4318 // => Check whether `dest` is still a piping destination.
4319 if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
4320 debug('false write response, pause', src._readableState.awaitDrain);
4321 src._readableState.awaitDrain++;
4322 increasedAwaitDrain = true;
4328 // if the dest has an error, then stop piping into it.
4329 // however, don't suppress the throwing behavior for this.
4330 function onerror(er) {
4331 debug('onerror', er);
4333 dest.removeListener('error', onerror);
4334 if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
4337 // Make sure our error handler is attached before userland ones.
4338 prependListener(dest, 'error', onerror);
4340 // Both close and finish should trigger unpipe, but only once.
4341 function onclose() {
4342 dest.removeListener('finish', onfinish);
4345 dest.once('close', onclose);
4346 function onfinish() {
4348 dest.removeListener('close', onclose);
4351 dest.once('finish', onfinish);
4358 // tell the dest that it's being piped to
4359 dest.emit('pipe', src);
4361 // start the flow if it hasn't been started already.
4362 if (!state.flowing) {
4363 debug('pipe resume');
4370 function pipeOnDrain(src) {
4371 return function () {
4372 var state = src._readableState;
4373 debug('pipeOnDrain', state.awaitDrain);
4374 if (state.awaitDrain) state.awaitDrain--;
4375 if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
4376 state.flowing = true;
4382 Readable.prototype.unpipe = function (dest) {
4383 var state = this._readableState;
4384 var unpipeInfo = { hasUnpiped: false };
4386 // if we're not piping anywhere, then do nothing.
4387 if (state.pipesCount === 0) return this;
4389 // just one destination. most common case.
4390 if (state.pipesCount === 1) {
4391 // passed in one, but it's not the right one.
4392 if (dest && dest !== state.pipes) return this;
4394 if (!dest) dest = state.pipes;
4398 state.pipesCount = 0;
4399 state.flowing = false;
4400 if (dest) dest.emit('unpipe', this, unpipeInfo);
4404 // slow case. multiple pipe destinations.
4408 var dests = state.pipes;
4409 var len = state.pipesCount;
4411 state.pipesCount = 0;
4412 state.flowing = false;
4414 for (var i = 0; i < len; i++) {
4415 dests[i].emit('unpipe', this, unpipeInfo);
4419 // try to find the right one.
4420 var index = indexOf(state.pipes, dest);
4421 if (index === -1) return this;
4423 state.pipes.splice(index, 1);
4424 state.pipesCount -= 1;
4425 if (state.pipesCount === 1) state.pipes = state.pipes[0];
4427 dest.emit('unpipe', this, unpipeInfo);
4432 // set up data events if they are asked for
4433 // Ensure readable listeners eventually get something
4434 Readable.prototype.on = function (ev, fn) {
4435 var res = Stream.prototype.on.call(this, ev, fn);
4437 if (ev === 'data') {
4438 // Start flowing on next tick if stream isn't explicitly paused
4439 if (this._readableState.flowing !== false) this.resume();
4440 } else if (ev === 'readable') {
4441 var state = this._readableState;
4442 if (!state.endEmitted && !state.readableListening) {
4443 state.readableListening = state.needReadable = true;
4444 state.emittedReadable = false;
4445 if (!state.reading) {
4446 pna.nextTick(nReadingNextTick, this);
4447 } else if (state.length) {
4455 Readable.prototype.addListener = Readable.prototype.on;
4457 function nReadingNextTick(self) {
4458 debug('readable nexttick read 0');
4462 // pause() and resume() are remnants of the legacy readable stream API
4463 // If the user uses them, then switch into old mode.
4464 Readable.prototype.resume = function () {
4465 var state = this._readableState;
4466 if (!state.flowing) {
4468 state.flowing = true;
4469 resume(this, state);
4474 function resume(stream, state) {
4475 if (!state.resumeScheduled) {
4476 state.resumeScheduled = true;
4477 pna.nextTick(resume_, stream, state);
4481 function resume_(stream, state) {
4482 if (!state.reading) {
4483 debug('resume read 0');
4487 state.resumeScheduled = false;
4488 state.awaitDrain = 0;
4489 stream.emit('resume');
4491 if (state.flowing && !state.reading) stream.read(0);
4494 Readable.prototype.pause = function () {
4495 debug('call pause flowing=%j', this._readableState.flowing);
4496 if (false !== this._readableState.flowing) {
4498 this._readableState.flowing = false;
4504 function flow(stream) {
4505 var state = stream._readableState;
4506 debug('flow', state.flowing);
4507 while (state.flowing && stream.read() !== null) {}
4510 // wrap an old-style stream as the async data source.
4511 // This is *not* part of the readable stream interface.
4512 // It is an ugly unfortunate mess of history.
4513 Readable.prototype.wrap = function (stream) {
4516 var state = this._readableState;
4519 stream.on('end', function () {
4520 debug('wrapped end');
4521 if (state.decoder && !state.ended) {
4522 var chunk = state.decoder.end();
4523 if (chunk && chunk.length) _this.push(chunk);
4529 stream.on('data', function (chunk) {
4530 debug('wrapped data');
4531 if (state.decoder) chunk = state.decoder.write(chunk);
4533 // don't skip over falsy values in objectMode
4534 if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
4536 var ret = _this.push(chunk);
4543 // proxy all the other methods.
4544 // important when wrapping filters and duplexes.
4545 for (var i in stream) {
4546 if (this[i] === undefined && typeof stream[i] === 'function') {
4547 this[i] = function (method) {
4548 return function () {
4549 return stream[method].apply(stream, arguments);
4555 // proxy certain important events.
4556 for (var n = 0; n < kProxyEvents.length; n++) {
4557 stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
4560 // when we try to consume some more bytes, simply unpause the
4561 // underlying stream.
4562 this._read = function (n) {
4563 debug('wrapped _read', n);
4573 Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
4574 // making it explicit this property is not enumerable
4575 // because otherwise some prototype manipulation in
4576 // userland will fail
4579 return this._readableState.highWaterMark;
4583 // exposed for testing purposes only.
4584 Readable._fromList = fromList;
4586 // Pluck off n bytes from an array of buffers.
4587 // Length is the combined lengths of all the buffers in the list.
4588 // This function is designed to be inlinable, so please take care when making
4589 // changes to the function body.
4590 function fromList(n, state) {
4592 if (state.length === 0) return null;
4595 if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
4596 // read it all, truncate the list
4597 if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length);
4598 state.buffer.clear();
4600 // read part of list
4601 ret = fromListPartial(n, state.buffer, state.decoder);
4607 // Extracts only enough buffered data to satisfy the amount requested.
4608 // This function is designed to be inlinable, so please take care when making
4609 // changes to the function body.
4610 function fromListPartial(n, list, hasStrings) {
4612 if (n < list.head.data.length) {
4613 // slice is the same for buffers and strings
4614 ret = list.head.data.slice(0, n);
4615 list.head.data = list.head.data.slice(n);
4616 } else if (n === list.head.data.length) {
4617 // first chunk is a perfect match
4620 // result spans more than one buffer
4621 ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
4626 // Copies a specified amount of characters from the list of buffered data
4628 // This function is designed to be inlinable, so please take care when making
4629 // changes to the function body.
4630 function copyFromBufferString(n, list) {
4635 while (p = p.next) {
4637 var nb = n > str.length ? str.length : n;
4638 if (nb === str.length) ret += str;else ret += str.slice(0, n);
4641 if (nb === str.length) {
4643 if (p.next) list.head = p.next;else list.head = list.tail = null;
4646 p.data = str.slice(nb);
4656 // Copies a specified amount of bytes from the list of buffered data chunks.
4657 // This function is designed to be inlinable, so please take care when making
4658 // changes to the function body.
4659 function copyFromBuffer(n, list) {
4660 var ret = Buffer.allocUnsafe(n);
4665 while (p = p.next) {
4667 var nb = n > buf.length ? buf.length : n;
4668 buf.copy(ret, ret.length - n, 0, nb);
4671 if (nb === buf.length) {
4673 if (p.next) list.head = p.next;else list.head = list.tail = null;
4676 p.data = buf.slice(nb);
4686 function endReadable(stream) {
4687 var state = stream._readableState;
4689 // If we get here before consuming all the bytes, then that is a
4690 // bug in node. Should never happen.
4691 if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
4693 if (!state.endEmitted) {
4695 pna.nextTick(endReadableNT, state, stream);
4699 function endReadableNT(state, stream) {
4700 // Check that we didn't get one last unshift.
4701 if (!state.endEmitted && state.length === 0) {
4702 state.endEmitted = true;
4703 stream.readable = false;
4708 function indexOf(xs, x) {
4709 for (var i = 0, l = xs.length; i < l; i++) {
4710 if (xs[i] === x) return i;
4714 }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
4715 },{"./_stream_duplex":20,"./internal/streams/BufferList":25,"./internal/streams/destroy":26,"./internal/streams/stream":27,"_process":18,"core-util-is":8,"events":10,"inherits":13,"isarray":15,"process-nextick-args":17,"safe-buffer":34,"string_decoder/":28,"util":4}],23:[function(require,module,exports){
4716 // Copyright Joyent, Inc. and other Node contributors.
4718 // Permission is hereby granted, free of charge, to any person obtaining a
4719 // copy of this software and associated documentation files (the
4720 // "Software"), to deal in the Software without restriction, including
4721 // without limitation the rights to use, copy, modify, merge, publish,
4722 // distribute, sublicense, and/or sell copies of the Software, and to permit
4723 // persons to whom the Software is furnished to do so, subject to the
4724 // following conditions:
4726 // The above copyright notice and this permission notice shall be included
4727 // in all copies or substantial portions of the Software.
4729 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
4730 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
4731 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
4732 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
4733 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
4734 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
4735 // USE OR OTHER DEALINGS IN THE SOFTWARE.
4737 // a transform stream is a readable/writable stream where you do
4738 // something with the data. Sometimes it's called a "filter",
4739 // but that's not a great name for it, since that implies a thing where
4740 // some bits pass through, and others are simply ignored. (That would
4741 // be a valid example of a transform, of course.)
4743 // While the output is causally related to the input, it's not a
4744 // necessarily symmetric or synchronous transformation. For example,
4745 // a zlib stream might take multiple plain-text writes(), and then
4746 // emit a single compressed chunk some time in the future.
4748 // Here's how this works:
4750 // The Transform stream has all the aspects of the readable and writable
4751 // stream classes. When you write(chunk), that calls _write(chunk,cb)
4752 // internally, and returns false if there's a lot of pending writes
4753 // buffered up. When you call read(), that calls _read(n) until
4754 // there's enough pending readable data buffered up.
4756 // In a transform stream, the written data is placed in a buffer. When
4757 // _read(n) is called, it transforms the queued up data, calling the
4758 // buffered _write cb's as it consumes chunks. If consuming a single
4759 // written chunk would result in multiple output chunks, then the first
4760 // outputted bit calls the readcb, and subsequent chunks just go into
4761 // the read buffer, and will cause it to emit 'readable' if necessary.
4763 // This way, back-pressure is actually determined by the reading side,
4764 // since _read has to be called to start processing a new chunk. However,
4765 // a pathological inflate type of transform can cause excessive buffering
4766 // here. For example, imagine a stream where every byte of input is
4767 // interpreted as an integer from 0-255, and then results in that many
4768 // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
4769 // 1kb of data being output. In this case, you could write a very small
4770 // amount of input, and end up with a very large amount of output. In
4771 // such a pathological inflating mechanism, there'd be no way to tell
4772 // the system to stop doing the transform. A single 4MB write could
4773 // cause the system to run out of memory.
4775 // However, even in such a pathological case, only a single written chunk
4776 // would be consumed, and then the rest would wait (un-transformed) until
4777 // the results of the previous transformed chunk were consumed.
4781 module.exports = Transform;
4783 var Duplex = require('./_stream_duplex');
4786 var util
= require ( 'core-util-is' );
4787 util
. inherits
= require ( 'inherits' );
4790 util.inherits(Transform, Duplex);
4792 function afterTransform(er, data) {
4793 var ts = this._transformState;
4794 ts.transforming = false;
4796 var cb = ts.writecb;
4799 return this.emit('error', new Error('write callback called multiple times'));
4802 ts.writechunk = null;
4805 if (data != null) // single equals check for both `null` and `undefined`
4810 var rs = this._readableState;
4812 if (rs.needReadable || rs.length < rs.highWaterMark) {
4813 this._read(rs.highWaterMark);
4817 function Transform(options) {
4818 if (!(this instanceof Transform)) return new Transform(options);
4820 Duplex.call(this, options);
4822 this._transformState = {
4823 afterTransform: afterTransform.bind(this),
4824 needTransform: false,
4825 transforming: false,
4831 // start out asking for a readable event once data is transformed.
4832 this._readableState.needReadable = true;
4834 // we have implemented the _read method, and done the other things
4835 // that Readable wants before the first _read call, so unset the
4837 this._readableState.sync = false;
4840 if (typeof options.transform === 'function') this._transform = options.transform;
4842 if (typeof options.flush === 'function') this._flush = options.flush;
4845 // When the writable side finishes, then flush out anything remaining.
4846 this.on('prefinish', prefinish);
4849 function prefinish() {
4852 if (typeof this._flush === 'function') {
4853 this._flush(function (er, data) {
4854 done(_this, er, data);
4857 done(this, null, null);
4861 Transform.prototype.push = function (chunk, encoding) {
4862 this._transformState.needTransform = false;
4863 return Duplex.prototype.push.call(this, chunk, encoding);
4866 // This is the part where you do stuff!
4867 // override this function in implementation classes.
4868 // 'chunk' is an input chunk.
4870 // Call `push(newChunk)` to pass along transformed output
4871 // to the readable side. You may call 'push' zero or more times.
4873 // Call `cb(err)` when you are done with this chunk. If you pass
4874 // an error, then that'll put the hurt on the whole operation. If you
4875 // never call cb(), then you'll never get another chunk.
4876 Transform.prototype._transform = function (chunk, encoding, cb) {
4877 throw new Error('_transform() is not implemented');
4880 Transform.prototype._write = function (chunk, encoding, cb) {
4881 var ts = this._transformState;
4883 ts.writechunk = chunk;
4884 ts.writeencoding = encoding;
4885 if (!ts.transforming) {
4886 var rs = this._readableState;
4887 if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
4891 // Doesn't matter what the args are here.
4892 // _transform does all the work.
4893 // That we got here means that the readable side wants more data.
4894 Transform.prototype._read = function (n) {
4895 var ts = this._transformState;
4897 if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
4898 ts.transforming = true;
4899 this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
4901 // mark that we need a transform, so that any data that comes in
4902 // will get processed, now that we've asked for it.
4903 ts.needTransform = true;
4907 Transform.prototype._destroy = function (err, cb) {
4910 Duplex.prototype._destroy.call(this, err, function (err2) {
4912 _this2.emit('close');
4916 function done(stream, er, data) {
4917 if (er) return stream.emit('error', er);
4919 if (data != null) // single equals check for both `null` and `undefined`
4922 // if there's nothing in the write buffer, then that means
4923 // that nothing more will ever be provided
4924 if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
4926 if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
4928 return stream.push(null);
4930 },{"./_stream_duplex":20,"core-util-is":8,"inherits":13}],24:[function(require,module,exports){
4931 (function (process,global,setImmediate){
4932 // Copyright Joyent, Inc. and other Node contributors.
4934 // Permission is hereby granted, free of charge, to any person obtaining a
4935 // copy of this software and associated documentation files (the
4936 // "Software"), to deal in the Software without restriction, including
4937 // without limitation the rights to use, copy, modify, merge, publish,
4938 // distribute, sublicense, and/or sell copies of the Software, and to permit
4939 // persons to whom the Software is furnished to do so, subject to the
4940 // following conditions:
4942 // The above copyright notice and this permission notice shall be included
4943 // in all copies or substantial portions of the Software.
4945 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
4946 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
4947 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
4948 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
4949 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
4950 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
4951 // USE OR OTHER DEALINGS IN THE SOFTWARE.
4953 // A bit simpler than readable streams.
4954 // Implement an async ._write(chunk, encoding, cb), and it'll handle all
4955 // the drain event emission and buffering.
4961 var pna
= require ( 'process-nextick-args' );
4964 module.exports = Writable;
4967 function WriteReq ( chunk
, encoding
, cb
) {
4969 this . encoding
= encoding
;
4974 // It seems a linked list but it is not
4975 // there will be only 2 of these for each stream
4976 function CorkedRequest ( state
) {
4981 this . finish = function () {
4982 onCorkedFinish ( _this
, state
);
4985 /* </replacement> */
4988 var asyncWrite
= ! process
. browser
&& [ 'v0.10' , 'v0.9.' ]. indexOf ( process
. version
. slice ( 0 , 5 )) > - 1 ? setImmediate : pna
. nextTick
;
4995 Writable.WritableState = WritableState;
4998 var util
= require ( 'core-util-is' );
4999 util
. inherits
= require ( 'inherits' );
5003 var internalUtil
= {
5004 deprecate : require ( 'util-deprecate' )
5009 var Stream
= require ( './internal/streams/stream' );
5014 var Buffer
= require ( 'safe-buffer' ). Buffer
;
5015 var OurUint8Array
= global
. Uint8Array
|| function () {};
5016 function _uint8ArrayToBuffer ( chunk
) {
5017 return Buffer
. from ( chunk
);
5019 function _isUint8Array ( obj
) {
5020 return Buffer
. isBuffer ( obj
) || obj
instanceof OurUint8Array
;
5025 var destroyImpl = require('./internal/streams/destroy');
5027 util.inherits(Writable, Stream);
5031 function WritableState(options, stream) {
5032 Duplex = Duplex || require('./_stream_duplex');
5034 options = options || {};
5036 // Duplex streams are both readable and writable, but share
5037 // the same options object.
5038 // However, some cases require setting options to different
5039 // values for the readable and the writable sides of the duplex stream.
5040 // These options can be provided separately as readableXXX and writableXXX.
5041 var isDuplex = stream instanceof Duplex;
5043 // object stream flag to indicate whether or not this stream
5044 // contains buffers or objects.
5045 this.objectMode = !!options.objectMode;
5047 if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
5049 // the point at which write() starts returning false
5050 // Note: 0 is a valid value, means that we always return false if
5051 // the entire buffer is not flushed immediately on write()
5052 var hwm = options.highWaterMark;
5053 var writableHwm = options.writableHighWaterMark;
5054 var defaultHwm = this.objectMode ? 16 : 16 * 1024;
5056 if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
5059 this.highWaterMark = Math.floor(this.highWaterMark);
5061 // if _final has been called
5062 this.finalCalled = false;
5064 // drain event flag.
5065 this.needDrain = false;
5066 // at the start of calling end()
5067 this.ending = false;
5068 // when end() has been called, and returned
5070 // when 'finish' is emitted
5071 this.finished = false;
5073 // has it been destroyed
5074 this.destroyed = false;
5076 // should we decode strings into buffers before passing to _write?
5077 // this is here so that some node-core streams can optimize string
5078 // handling at a lower level.
5079 var noDecode = options.decodeStrings === false;
5080 this.decodeStrings = !noDecode;
5082 // Crypto is kind of old and crusty. Historically, its default string
5083 // encoding is 'binary' so we have to make this configurable.
5084 // Everything else in the universe uses 'utf8', though.
5085 this.defaultEncoding = options.defaultEncoding || 'utf8';
5087 // not an actual buffer we keep track of, but a measurement
5088 // of how much we're waiting to get pushed to some underlying
5092 // a flag to see when we're in the middle of a write.
5093 this.writing = false;
5095 // when true all writes will be buffered until .uncork() call
5098 // a flag to be able to tell if the onwrite cb is called immediately,
5099 // or on a later tick. We set this to true at first, because any
5100 // actions that shouldn't happen until "later" should generally also
5101 // not happen before the first write call.
5104 // a flag to know if we're processing previously buffered items, which
5105 // may call the _write() callback in the same tick, so that we don't
5106 // end up in an overlapped onwrite situation.
5107 this.bufferProcessing = false;
5109 // the callback that's passed to _write(chunk,cb)
5110 this.onwrite = function (er) {
5111 onwrite(stream, er);
5114 // the callback that the user supplies to write(chunk,encoding,cb)
5115 this.writecb = null;
5117 // the amount that is being written when _write is called.
5120 this.bufferedRequest = null;
5121 this.lastBufferedRequest = null;
5123 // number of pending user-supplied write callbacks
5124 // this must be 0 before 'finish' can be emitted
5127 // emit prefinish if the only thing we're waiting for is _write cbs
5128 // This is relevant for synchronous Transform streams
5129 this.prefinished = false;
5131 // True if the error was already emitted and should not be thrown again
5132 this.errorEmitted = false;
5134 // count buffered requests
5135 this.bufferedRequestCount = 0;
5137 // allocate the first CorkedRequest, there is always
5138 // one allocated and free to use, and we maintain at most two
5139 this.corkedRequestsFree = new CorkedRequest(this);
5142 WritableState.prototype.getBuffer = function getBuffer() {
5143 var current = this.bufferedRequest;
5147 current = current.next;
5154 Object.defineProperty(WritableState.prototype, 'buffer', {
5155 get: internalUtil.deprecate(function () {
5156 return this.getBuffer();
5157 }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
5162 // Test _writableState for inheritance to account for Duplex streams,
5163 // whose prototype chain only points to Readable.
5164 var realHasInstance;
5165 if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
5166 realHasInstance = Function.prototype[Symbol.hasInstance];
5167 Object.defineProperty(Writable, Symbol.hasInstance, {
5168 value: function (object) {
5169 if (realHasInstance.call(this, object)) return true;
5170 if (this !== Writable) return false;
5172 return object && object._writableState instanceof WritableState;
5176 realHasInstance = function (object) {
5177 return object instanceof this;
5181 function Writable(options) {
5182 Duplex = Duplex || require('./_stream_duplex');
5184 // Writable ctor is applied to Duplexes, too.
5185 // `realHasInstance` is necessary because using plain `instanceof`
5186 // would return false, as no `_writableState` property is attached.
5188 // Trying to use the custom `instanceof` for Writable here will also break the
5189 // Node.js LazyTransform implementation, which has a non-trivial getter for
5190 // `_writableState` that would lead to infinite recursion.
5191 if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
5192 return new Writable(options);
5195 this._writableState = new WritableState(options, this);
5198 this.writable = true;
5201 if (typeof options.write === 'function') this._write = options.write;
5203 if (typeof options.writev === 'function') this._writev = options.writev;
5205 if (typeof options.destroy === 'function') this._destroy = options.destroy;
5207 if (typeof options.final === 'function') this._final = options.final;
5213 // Otherwise people can pipe Writable streams, which is just wrong.
5214 Writable.prototype.pipe = function () {
5215 this.emit('error', new Error('Cannot pipe, not readable'));
5218 function writeAfterEnd(stream, cb) {
5219 var er = new Error('write after end');
5220 // TODO: defer error events consistently everywhere, not just the cb
5221 stream.emit('error', er);
5222 pna.nextTick(cb, er);
5225 // Checks that a user-supplied chunk is valid, especially for the particular
5226 // mode the stream is in. Currently this means that `null` is never accepted
5227 // and undefined/non-string values are only allowed in object mode.
5228 function validChunk(stream, state, chunk, cb) {
5232 if (chunk === null) {
5233 er = new TypeError('May not write null values to stream');
5234 } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
5235 er = new TypeError('Invalid non-string/buffer chunk');
5238 stream.emit('error', er);
5239 pna.nextTick(cb, er);
5245 Writable.prototype.write = function (chunk, encoding, cb) {
5246 var state = this._writableState;
5248 var isBuf = !state.objectMode && _isUint8Array(chunk);
5250 if (isBuf && !Buffer.isBuffer(chunk)) {
5251 chunk = _uint8ArrayToBuffer(chunk);
5254 if (typeof encoding === 'function') {
5259 if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
5261 if (typeof cb !== 'function') cb = nop;
5263 if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
5265 ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
5271 Writable.prototype.cork = function () {
5272 var state = this._writableState;
5277 Writable.prototype.uncork = function () {
5278 var state = this._writableState;
5283 if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
5287 Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
5288 // node::ParseEncoding() requires lower case.
5289 if (typeof encoding === 'string') encoding = encoding.toLowerCase();
5290 if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
5291 this._writableState.defaultEncoding = encoding;
5295 function decodeChunk(state, chunk, encoding) {
5296 if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
5297 chunk = Buffer.from(chunk, encoding);
5302 Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
5303 // making it explicit this property is not enumerable
5304 // because otherwise some prototype manipulation in
5305 // userland will fail
5308 return this._writableState.highWaterMark;
5312 // if we're already writing something, then just put this
5313 // in the queue, and wait our turn. Otherwise, call _write
5314 // If we return false, then we need a drain event, so set that flag.
5315 function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
5317 var newChunk = decodeChunk(state, chunk, encoding);
5318 if (chunk !== newChunk) {
5320 encoding = 'buffer';
5324 var len = state.objectMode ? 1 : chunk.length;
5326 state.length += len;
5328 var ret = state.length < state.highWaterMark;
5329 // we must ensure that previous needDrain will not be reset to false.
5330 if (!ret) state.needDrain = true;
5332 if (state.writing || state.corked) {
5333 var last = state.lastBufferedRequest;
5334 state.lastBufferedRequest = {
5342 last.next = state.lastBufferedRequest;
5344 state.bufferedRequest = state.lastBufferedRequest;
5346 state.bufferedRequestCount += 1;
5348 doWrite(stream, state, false, len, chunk, encoding, cb);
5354 function doWrite(stream, state, writev, len, chunk, encoding, cb) {
5355 state.writelen = len;
5357 state.writing = true;
5359 if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
5363 function onwriteError(stream, state, sync, er, cb) {
5367 // defer the callback if we are being called synchronously
5368 // to avoid piling up things on the stack
5369 pna.nextTick(cb, er);
5370 // this can emit finish, and it will always happen
5372 pna.nextTick(finishMaybe, stream, state);
5373 stream._writableState.errorEmitted = true;
5374 stream.emit('error', er);
5376 // the caller expect this to happen before if
5379 stream._writableState.errorEmitted = true;
5380 stream.emit('error', er);
5381 // this can emit finish, but finish must
5382 // always follow error
5383 finishMaybe(stream, state);
5387 function onwriteStateUpdate(state) {
5388 state.writing = false;
5389 state.writecb = null;
5390 state.length -= state.writelen;
5394 function onwrite(stream, er) {
5395 var state = stream._writableState;
5396 var sync = state.sync;
5397 var cb = state.writecb;
5399 onwriteStateUpdate(state);
5401 if (er) onwriteError(stream, state, sync, er, cb);else {
5402 // Check if we're actually ready to finish, but don't emit yet
5403 var finished = needFinish(state);
5405 if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
5406 clearBuffer(stream, state);
5411 asyncWrite ( afterWrite
, stream
, state
, finished
, cb
);
5414 afterWrite(stream, state, finished, cb);
5419 function afterWrite(stream, state, finished, cb) {
5420 if (!finished) onwriteDrain(stream, state);
5423 finishMaybe(stream, state);
5426 // Must force callback to be called on nextTick, so that we don't
5427 // emit 'drain' before the write() consumer gets the 'false' return
5428 // value, and has a chance to attach a 'drain' listener.
5429 function onwriteDrain(stream, state) {
5430 if (state.length === 0 && state.needDrain) {
5431 state.needDrain = false;
5432 stream.emit('drain');
5436 // if there's something in the buffer waiting, then process it
5437 function clearBuffer(stream, state) {
5438 state.bufferProcessing = true;
5439 var entry = state.bufferedRequest;
5441 if (stream._writev && entry && entry.next) {
5442 // Fast case, write everything using _writev()
5443 var l = state.bufferedRequestCount;
5444 var buffer = new Array(l);
5445 var holder = state.corkedRequestsFree;
5446 holder.entry = entry;
5449 var allBuffers = true;
5451 buffer[count] = entry;
5452 if (!entry.isBuf) allBuffers = false;
5456 buffer.allBuffers = allBuffers;
5458 doWrite(stream, state, true, state.length, buffer, '', holder.finish);
5460 // doWrite is almost always async, defer these to save a bit of time
5461 // as the hot path ends with doWrite
5463 state.lastBufferedRequest = null;
5465 state.corkedRequestsFree = holder.next;
5468 state.corkedRequestsFree = new CorkedRequest(state);
5470 state.bufferedRequestCount = 0;
5472 // Slow case, write chunks one-by-one
5474 var chunk = entry.chunk;
5475 var encoding = entry.encoding;
5476 var cb = entry.callback;
5477 var len = state.objectMode ? 1 : chunk.length;
5479 doWrite(stream, state, false, len, chunk, encoding, cb);
5481 state.bufferedRequestCount--;
5482 // if we didn't call the onwrite immediately, then
5483 // it means that we need to wait until it does.
5484 // also, that means that the chunk and cb are currently
5485 // being processed, so move the buffer counter past them.
5486 if (state.writing) {
5491 if (entry === null) state.lastBufferedRequest = null;
5494 state.bufferedRequest = entry;
5495 state.bufferProcessing = false;
5498 Writable.prototype._write = function (chunk, encoding, cb) {
5499 cb(new Error('_write() is not implemented'));
5502 Writable.prototype._writev = null;
5504 Writable.prototype.end = function (chunk, encoding, cb) {
5505 var state = this._writableState;
5507 if (typeof chunk === 'function') {
5511 } else if (typeof encoding === 'function') {
5516 if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
5518 // .end() fully uncorks
5524 // ignore unnecessary end() calls.
5525 if (!state.ending && !state.finished) endWritable(this, state, cb);
5528 function needFinish(state) {
5529 return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
5531 function callFinal(stream, state) {
5532 stream._final(function (err) {
5535 stream.emit('error', err);
5537 state.prefinished = true;
5538 stream.emit('prefinish');
5539 finishMaybe(stream, state);
5542 function prefinish(stream, state) {
5543 if (!state.prefinished && !state.finalCalled) {
5544 if (typeof stream._final === 'function') {
5546 state.finalCalled = true;
5547 pna.nextTick(callFinal, stream, state);
5549 state.prefinished = true;
5550 stream.emit('prefinish');
5555 function finishMaybe(stream, state) {
5556 var need = needFinish(state);
5558 prefinish(stream, state);
5559 if (state.pendingcb === 0) {
5560 state.finished = true;
5561 stream.emit('finish');
5567 function endWritable(stream, state, cb) {
5568 state.ending = true;
5569 finishMaybe(stream, state);
5571 if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
5574 stream.writable = false;
5577 function onCorkedFinish(corkReq, state, err) {
5578 var entry = corkReq.entry;
5579 corkReq.entry = null;
5581 var cb = entry.callback;
5586 if (state.corkedRequestsFree) {
5587 state.corkedRequestsFree.next = corkReq;
5589 state.corkedRequestsFree = corkReq;
5593 Object.defineProperty(Writable.prototype, 'destroyed', {
5595 if (this._writableState === undefined) {
5598 return this._writableState.destroyed;
5600 set: function (value) {
5601 // we ignore the value if the stream
5602 // has not been initialized yet
5603 if (!this._writableState) {
5607 // backward compatibility, the user is explicitly
5608 // managing destroyed
5609 this._writableState.destroyed = value;
5613 Writable.prototype.destroy = destroyImpl.destroy;
5614 Writable.prototype._undestroy = destroyImpl.undestroy;
5615 Writable.prototype._destroy = function (err, cb) {
5619 }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate)
5620 },{"./_stream_duplex":20,"./internal/streams/destroy":26,"./internal/streams/stream":27,"_process":18,"core-util-is":8,"inherits":13,"process-nextick-args":17,"safe-buffer":34,"timers":45,"util-deprecate":46}],25:[function(require,module,exports){
5623 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5625 var Buffer = require('safe-buffer').Buffer;
5626 var util = require('util');
5628 function copyBuffer(src, target, offset) {
5629 src.copy(target, offset);
5632 module.exports = function () {
5633 function BufferList() {
5634 _classCallCheck(this, BufferList);
5641 BufferList.prototype.push = function push(v) {
5642 var entry = { data: v, next: null };
5643 if (this.length > 0) this.tail.next = entry;else this.head = entry;
5648 BufferList.prototype.unshift = function unshift(v) {
5649 var entry = { data: v, next: this.head };
5650 if (this.length === 0) this.tail = entry;
5655 BufferList.prototype.shift = function shift() {
5656 if (this.length === 0) return;
5657 var ret = this.head.data;
5658 if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
5663 BufferList.prototype.clear = function clear() {
5664 this.head = this.tail = null;
5668 BufferList.prototype.join = function join(s) {
5669 if (this.length === 0) return '';
5671 var ret = '' + p.data;
5672 while (p = p.next) {
5677 BufferList.prototype.concat = function concat(n) {
5678 if (this.length === 0) return Buffer.alloc(0);
5679 if (this.length === 1) return this.head.data;
5680 var ret = Buffer.allocUnsafe(n >>> 0);
5684 copyBuffer(p.data, ret, i);
5694 if (util && util.inspect && util.inspect.custom) {
5695 module.exports.prototype[util.inspect.custom] = function () {
5696 var obj = util.inspect({ length: this.length });
5697 return this.constructor.name + ' ' + obj;
5700 },{"safe-buffer":34,"util":4}],26:[function(require,module,exports){
5705 var pna
= require ( 'process-nextick-args' );
5708 // undocumented cb() API, needed for core, not for public API
5709 function destroy(err, cb) {
5712 var readableDestroyed = this._readableState && this._readableState.destroyed;
5713 var writableDestroyed = this._writableState && this._writableState.destroyed;
5715 if (readableDestroyed || writableDestroyed) {
5718 } else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
5719 pna.nextTick(emitErrorNT, this, err);
5724 // we set destroyed to true before firing error callbacks in order
5725 // to make it re-entrance safe in case destroy() is called within callbacks
5727 if (this._readableState) {
5728 this._readableState.destroyed = true;
5731 // if this is a duplex stream mark the writable part as destroyed as well
5732 if (this._writableState) {
5733 this._writableState.destroyed = true;
5736 this._destroy(err || null, function (err) {
5738 pna.nextTick(emitErrorNT, _this, err);
5739 if (_this._writableState) {
5740 _this._writableState.errorEmitted = true;
5750 function undestroy() {
5751 if (this._readableState) {
5752 this._readableState.destroyed = false;
5753 this._readableState.reading = false;
5754 this._readableState.ended = false;
5755 this._readableState.endEmitted = false;
5758 if (this._writableState) {
5759 this._writableState.destroyed = false;
5760 this._writableState.ended = false;
5761 this._writableState.ending = false;
5762 this._writableState.finished = false;
5763 this._writableState.errorEmitted = false;
5767 function emitErrorNT(self, err) {
5768 self.emit('error', err);
5773 undestroy: undestroy
5775 },{"process-nextick-args":17}],27:[function(require,module,exports){
5776 module.exports = require('events').EventEmitter;
5778 },{"events":10}],28:[function(require,module,exports){
5779 // Copyright Joyent, Inc. and other Node contributors.
5781 // Permission is hereby granted, free of charge, to any person obtaining a
5782 // copy of this software and associated documentation files (the
5783 // "Software"), to deal in the Software without restriction, including
5784 // without limitation the rights to use, copy, modify, merge, publish,
5785 // distribute, sublicense, and/or sell copies of the Software, and to permit
5786 // persons to whom the Software is furnished to do so, subject to the
5787 // following conditions:
5789 // The above copyright notice and this permission notice shall be included
5790 // in all copies or substantial portions of the Software.
5792 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
5793 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
5794 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
5795 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
5796 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
5797 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
5798 // USE OR OTHER DEALINGS IN THE SOFTWARE.
5804 var Buffer
= require ( 'safe-buffer' ). Buffer
;
5807 var isEncoding = Buffer.isEncoding || function (encoding) {
5808 encoding = '' + encoding;
5809 switch (encoding && encoding.toLowerCase()) {
5810 case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
5817 function _normalizeEncoding(enc) {
5818 if (!enc) return 'utf8';
5838 if (retried) return; // undefined
5839 enc = ('' + enc).toLowerCase();
5845 // Do not cache `Buffer.isEncoding` when checking encoding names as some
5846 // modules monkey-patch it to support additional encodings
5847 function normalizeEncoding(enc) {
5848 var nenc = _normalizeEncoding(enc);
5849 if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
5853 // StringDecoder provides an interface for efficiently splitting a series of
5854 // buffers into a series of JS strings without breaking apart multi-byte
5856 exports.StringDecoder = StringDecoder;
5857 function StringDecoder(encoding) {
5858 this.encoding = normalizeEncoding(encoding);
5860 switch (this.encoding) {
5862 this.text = utf16Text;
5863 this.end = utf16End;
5867 this.fillLast = utf8FillLast;
5871 this.text = base64Text;
5872 this.end = base64End;
5876 this.write = simpleWrite;
5877 this.end = simpleEnd;
5882 this.lastChar = Buffer.allocUnsafe(nb);
5885 StringDecoder.prototype.write = function (buf) {
5886 if (buf.length === 0) return '';
5889 if (this.lastNeed) {
5890 r = this.fillLast(buf);
5891 if (r === undefined) return '';
5897 if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
5901 StringDecoder.prototype.end = utf8End;
5903 // Returns only complete characters in a Buffer
5904 StringDecoder.prototype.text = utf8Text;
5906 // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
5907 StringDecoder.prototype.fillLast = function (buf) {
5908 if (this.lastNeed <= buf.length) {
5909 buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
5910 return this.lastChar.toString(this.encoding, 0, this.lastTotal);
5912 buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
5913 this.lastNeed -= buf.length;
5916 // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
5917 // continuation byte. If an invalid byte is detected, -2 is returned.
5918 function utf8CheckByte(byte) {
5919 if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
5920 return byte >> 6 === 0x02 ? -1 : -2;
5923 // Checks at most 3 bytes at the end of a Buffer in order to detect an
5924 // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
5925 // needed to complete the UTF-8 character (if applicable) are returned.
5926 function utf8CheckIncomplete(self, buf, i) {
5927 var j = buf.length - 1;
5928 if (j < i) return 0;
5929 var nb = utf8CheckByte(buf[j]);
5931 if (nb > 0) self.lastNeed = nb - 1;
5934 if (--j < i || nb === -2) return 0;
5935 nb = utf8CheckByte(buf[j]);
5937 if (nb > 0) self.lastNeed = nb - 2;
5940 if (--j < i || nb === -2) return 0;
5941 nb = utf8CheckByte(buf[j]);
5944 if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
5951 // Validates as many continuation bytes for a multi-byte UTF-8 character as
5952 // needed or are available. If we see a non-continuation byte where we expect
5953 // one, we "replace" the validated continuation bytes we've seen so far with
5954 // a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
5955 // behavior. The continuation byte check is included three times in the case
5956 // where all of the continuation bytes for a character exist in the same buffer.
5957 // It is also done this way as a slight performance increase instead of using a
5959 function utf8CheckExtraBytes(self, buf, p) {
5960 if ((buf[0] & 0xC0) !== 0x80) {
5964 if (self.lastNeed > 1 && buf.length > 1) {
5965 if ((buf[1] & 0xC0) !== 0x80) {
5969 if (self.lastNeed > 2 && buf.length > 2) {
5970 if ((buf[2] & 0xC0) !== 0x80) {
5978 // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
5979 function utf8FillLast(buf) {
5980 var p = this.lastTotal - this.lastNeed;
5981 var r = utf8CheckExtraBytes(this, buf, p);
5982 if (r !== undefined) return r;
5983 if (this.lastNeed <= buf.length) {
5984 buf.copy(this.lastChar, p, 0, this.lastNeed);
5985 return this.lastChar.toString(this.encoding, 0, this.lastTotal);
5987 buf.copy(this.lastChar, p, 0, buf.length);
5988 this.lastNeed -= buf.length;
5991 // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
5992 // partial character, the character's bytes are buffered until the required
5993 // number of bytes are available.
5994 function utf8Text(buf, i) {
5995 var total = utf8CheckIncomplete(this, buf, i);
5996 if (!this.lastNeed) return buf.toString('utf8', i);
5997 this.lastTotal = total;
5998 var end = buf.length - (total - this.lastNeed);
5999 buf.copy(this.lastChar, 0, end);
6000 return buf.toString('utf8', i, end);
6003 // For UTF-8, a replacement character is added when ending on a partial
6005 function utf8End(buf) {
6006 var r = buf && buf.length ? this.write(buf) : '';
6007 if (this.lastNeed) return r + '\ufffd';
6011 // UTF-16LE typically needs two bytes per character, but even if we have an even
6012 // number of bytes available, we need to check if we end on a leading/high
6013 // surrogate. In that case, we need to wait for the next two bytes in order to
6014 // decode the last character properly.
6015 function utf16Text(buf, i) {
6016 if ((buf.length - i) % 2 === 0) {
6017 var r = buf.toString('utf16le', i);
6019 var c = r.charCodeAt(r.length - 1);
6020 if (c >= 0xD800 && c <= 0xDBFF) {
6023 this.lastChar[0] = buf[buf.length - 2];
6024 this.lastChar[1] = buf[buf.length - 1];
6025 return r.slice(0, -1);
6032 this.lastChar[0] = buf[buf.length - 1];
6033 return buf.toString('utf16le', i, buf.length - 1);
6036 // For UTF-16LE we do not explicitly append special replacement characters if we
6037 // end on a partial character, we simply let v8 handle that.
6038 function utf16End(buf) {
6039 var r = buf && buf.length ? this.write(buf) : '';
6040 if (this.lastNeed) {
6041 var end = this.lastTotal - this.lastNeed;
6042 return r + this.lastChar.toString('utf16le', 0, end);
6047 function base64Text(buf, i) {
6048 var n = (buf.length - i) % 3;
6049 if (n === 0) return buf.toString('base64', i);
6050 this.lastNeed = 3 - n;
6053 this.lastChar[0] = buf[buf.length - 1];
6055 this.lastChar[0] = buf[buf.length - 2];
6056 this.lastChar[1] = buf[buf.length - 1];
6058 return buf.toString('base64', i, buf.length - n);
6061 function base64End(buf) {
6062 var r = buf && buf.length ? this.write(buf) : '';
6063 if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
6067 // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
6068 function simpleWrite(buf) {
6069 return buf.toString(this.encoding);
6072 function simpleEnd(buf) {
6073 return buf && buf.length ? this.write(buf) : '';
6075 },{"safe-buffer":34}],29:[function(require,module,exports){
6076 module.exports = require('./readable').PassThrough
6078 },{"./readable":30}],30:[function(require,module,exports){
6079 exports = module.exports = require('./lib/_stream_readable.js');
6080 exports.Stream = exports;
6081 exports.Readable = exports;
6082 exports.Writable = require('./lib/_stream_writable.js');
6083 exports.Duplex = require('./lib/_stream_duplex.js');
6084 exports.Transform = require('./lib/_stream_transform.js');
6085 exports.PassThrough = require('./lib/_stream_passthrough.js');
6087 },{"./lib/_stream_duplex.js":20,"./lib/_stream_passthrough.js":21,"./lib/_stream_readable.js":22,"./lib/_stream_transform.js":23,"./lib/_stream_writable.js":24}],31:[function(require,module,exports){
6088 module.exports = require('./readable').Transform
6090 },{"./readable":30}],32:[function(require,module,exports){
6091 module.exports = require('./lib/_stream_writable.js');
6093 },{"./lib/_stream_writable.js":24}],33:[function(require,module,exports){
6095 var Buffer = require('buffer').Buffer
6096 var inherits = require('inherits')
6097 var HashBase = require('hash-base')
6099 var ARRAY16 = new Array(16)
6102 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
6103 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
6104 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
6105 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
6106 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
6110 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
6111 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
6112 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
6113 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
6114 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
6118 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
6119 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
6120 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
6121 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
6122 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
6126 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
6127 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
6128 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
6129 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
6130 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
6133 var hl = [0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e]
6134 var hr = [0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000]
6136 function RIPEMD160 () {
6137 HashBase.call(this, 64)
6140 this._a = 0x67452301
6141 this._b = 0xefcdab89
6142 this._c = 0x98badcfe
6143 this._d = 0x10325476
6144 this._e = 0xc3d2e1f0
6147 inherits(RIPEMD160, HashBase)
6149 RIPEMD160.prototype._update = function () {
6151 for (var j = 0; j < 16; ++j) words[j] = this._block.readInt32LE(j * 4)
6153 var al = this._a | 0
6154 var bl = this._b | 0
6155 var cl = this._c | 0
6156 var dl = this._d | 0
6157 var el = this._e | 0
6159 var ar = this._a | 0
6160 var br = this._b | 0
6161 var cr = this._c | 0
6162 var dr = this._d | 0
6163 var er = this._e | 0
6166 for (var i = 0; i < 80; i += 1) {
6170 tl = fn1(al, bl, cl, dl, el, words[zl[i]], hl[0], sl[i])
6171 tr = fn5(ar, br, cr, dr, er, words[zr[i]], hr[0], sr[i])
6172 } else if (i < 32) {
6173 tl = fn2(al, bl, cl, dl, el, words[zl[i]], hl[1], sl[i])
6174 tr = fn4(ar, br, cr, dr, er, words[zr[i]], hr[1], sr[i])
6175 } else if (i < 48) {
6176 tl = fn3(al, bl, cl, dl, el, words[zl[i]], hl[2], sl[i])
6177 tr = fn3(ar, br, cr, dr, er, words[zr[i]], hr[2], sr[i])
6178 } else if (i < 64) {
6179 tl = fn4(al, bl, cl, dl, el, words[zl[i]], hl[3], sl[i])
6180 tr = fn2(ar, br, cr, dr, er, words[zr[i]], hr[3], sr[i])
6181 } else { // if (i<80) {
6182 tl = fn5(al, bl, cl, dl, el, words[zl[i]], hl[4], sl[i])
6183 tr = fn1(ar, br, cr, dr, er, words[zr[i]], hr[4], sr[i])
6200 var t = (this._b + cl + dr) | 0
6201 this._b = (this._c + dl + er) | 0
6202 this._c = (this._d + el + ar) | 0
6203 this._d = (this._e + al + br) | 0
6204 this._e = (this._a + bl + cr) | 0
6208 RIPEMD160.prototype._digest = function () {
6209 // create padding and handle blocks
6210 this._block[this._blockOffset++] = 0x80
6211 if (this._blockOffset > 56) {
6212 this._block.fill(0, this._blockOffset, 64)
6214 this._blockOffset = 0
6217 this._block.fill(0, this._blockOffset, 56)
6218 this._block.writeUInt32LE(this._length[0], 56)
6219 this._block.writeUInt32LE(this._length[1], 60)
6223 var buffer = Buffer.alloc ? Buffer.alloc(20) : new Buffer(20)
6224 buffer.writeInt32LE(this._a, 0)
6225 buffer.writeInt32LE(this._b, 4)
6226 buffer.writeInt32LE(this._c, 8)
6227 buffer.writeInt32LE(this._d, 12)
6228 buffer.writeInt32LE(this._e, 16)
6232 function rotl (x, n) {
6233 return (x << n) | (x >>> (32 - n))
6236 function fn1 (a, b, c, d, e, m, k, s) {
6237 return (rotl((a + (b ^ c ^ d) + m + k) | 0, s) + e) | 0
6240 function fn2 (a, b, c, d, e, m, k, s) {
6241 return (rotl((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + e) | 0
6244 function fn3 (a, b, c, d, e, m, k, s) {
6245 return (rotl((a + ((b | (~c)) ^ d) + m + k) | 0, s) + e) | 0
6248 function fn4 (a, b, c, d, e, m, k, s) {
6249 return (rotl((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + e) | 0
6252 function fn5 (a, b, c, d, e, m, k, s) {
6253 return (rotl((a + (b ^ (c | (~d))) + m + k) | 0, s) + e) | 0
6256 module.exports = RIPEMD160
6258 },{"buffer":6,"hash-base":11,"inherits":13}],34:[function(require,module,exports){
6259 /* eslint-disable node/no-deprecated-api */
6260 var buffer
= require ( 'buffer' )
6261 var Buffer
= buffer
. Buffer
6263 // alternative to using Object.keys for old browsers
6264 function copyProps ( src
, dst
) {
6265 for ( var key
in src
) {
6269 if ( Buffer
. from && Buffer
. alloc
&& Buffer
. allocUnsafe
&& Buffer
. allocUnsafeSlow
) {
6270 module
. exports
= buffer
6272 // Copy properties from require('buffer')
6273 copyProps ( buffer
, exports
)
6274 exports
. Buffer
= SafeBuffer
6277 function SafeBuffer ( arg
, encodingOrOffset
, length
) {
6278 return Buffer ( arg
, encodingOrOffset
, length
)
6281 // Copy static methods from Buffer
6282 copyProps ( Buffer
, SafeBuffer
)
6284 SafeBuffer
. from = function ( arg
, encodingOrOffset
, length
) {
6285 if ( typeof arg
=== 'number' ) {
6286 throw new TypeError ( 'Argument must not be a number' )
6288 return Buffer ( arg
, encodingOrOffset
, length
)
6291 SafeBuffer
. alloc = function ( size
, fill
, encoding
) {
6292 if ( typeof size
!== 'number' ) {
6293 throw new TypeError ( 'Argument must be a number' )
6295 var buf
= Buffer ( size
)
6296 if ( fill
!== undefined ) {
6297 if ( typeof encoding
=== 'string' ) {
6298 buf
. fill ( fill
, encoding
)
6308 SafeBuffer
. allocUnsafe = function ( size
) {
6309 if ( typeof size
!== 'number' ) {
6310 throw new TypeError ( 'Argument must be a number' )
6315 SafeBuffer
. allocUnsafeSlow = function ( size
) {
6316 if ( typeof size
!== 'number' ) {
6317 throw new TypeError ( 'Argument must be a number' )
6319 return buffer
. SlowBuffer ( size
)
6322 },{ "buffer" : 6 }], 35 :[ function ( require
, module
, exports
){
6323 var Buffer
= require ( 'safe-buffer' ). Buffer
6325 // prototype class for hash functions
6326 function Hash ( blockSize
, finalSize
) {
6327 this . _block
= Buffer
. alloc ( blockSize
)
6328 this . _finalSize
= finalSize
6329 this . _blockSize
= blockSize
6333 Hash
. prototype . update = function ( data
, enc
) {
6334 if ( typeof data
=== 'string' ) {
6336 data
= Buffer
. from ( data
, enc
)
6339 var block
= this . _block
6340 var blockSize
= this . _blockSize
6341 var length
= data
. length
6342 var accum
= this . _len
6344 for ( var offset
= 0 ; offset
< length
;) {
6345 var assigned
= accum
% blockSize
6346 var remainder
= Math
. min ( length
- offset
, blockSize
- assigned
)
6348 for ( var i
= 0 ; i
< remainder
; i
++) {
6349 block
[ assigned
+ i
] = data
[ offset
+ i
]
6355 if (( accum
% blockSize
) === 0 ) {
6364 Hash
. prototype . digest = function ( enc
) {
6365 var rem
= this . _len
% this . _blockSize
6367 this . _block
[ rem
] = 0x80
6369 // zero (rem + 1) trailing bits, where (rem + 1) is the smallest
6370 // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize
6371 this . _block
. fill ( 0 , rem
+ 1 )
6373 if ( rem
>= this . _finalSize
) {
6374 this . _update ( this . _block
)
6378 var bits
= this . _len
* 8
6381 if ( bits
<= 0xffffffff ) {
6382 this . _block
. writeUInt32BE ( bits
, this . _blockSize
- 4 )
6386 var lowBits
= ( bits
& 0xffffffff ) >>> 0
6387 var highBits
= ( bits
- lowBits
) / 0x100000000
6389 this . _block
. writeUInt32BE ( highBits
, this . _blockSize
- 8 )
6390 this . _block
. writeUInt32BE ( lowBits
, this . _blockSize
- 4 )
6393 this . _update ( this . _block
)
6394 var hash
= this . _hash ()
6396 return enc
? hash
. toString ( enc
) : hash
6399 Hash
. prototype . _update = function () {
6400 throw new Error ( '_update must be implemented by subclass' )
6403 module
. exports
= Hash
6405 },{ "safe-buffer" : 34 }], 36 :[ function ( require
, module
, exports
){
6406 var exports
= module
. exports
= function SHA ( algorithm
) {
6407 algorithm
= algorithm
. toLowerCase ()
6409 var Algorithm
= exports
[ algorithm
]
6410 if (! Algorithm
) throw new Error ( algorithm
+ ' is not supported (we accept pull requests)' )
6412 return new Algorithm ()
6415 exports
. sha
= require ( './sha' )
6416 exports
. sha1
= require ( './sha1' )
6417 exports
. sha224
= require ( './sha224' )
6418 exports
. sha256
= require ( './sha256' )
6419 exports
. sha384
= require ( './sha384' )
6420 exports
. sha512
= require ( './sha512' )
6422 },{ "./sha" : 37 , "./sha1" : 38 , "./sha224" : 39 , "./sha256" : 40 , "./sha384" : 41 , "./sha512" : 42 }], 37 :[ function ( require
, module
, exports
){
6424 * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
6426 * This source code is derived from sha1.js of the same repository.
6427 * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
6428 * operation was added.
6431 var inherits
= require ( 'inherits' )
6432 var Hash
= require ( './hash' )
6433 var Buffer
= require ( 'safe-buffer' ). Buffer
6436 0x5a827999 , 0x6ed9eba1 , 0x8f1bbcdc | 0 , 0xca62c1d6 | 0
6439 var W
= new Array ( 80 )
6445 Hash
. call ( this , 64 , 56 )
6450 Sha
. prototype . init = function () {
6451 this . _a
= 0x67452301
6452 this . _b
= 0xefcdab89
6453 this . _c
= 0x98badcfe
6454 this . _d
= 0x10325476
6455 this . _e
= 0xc3d2e1f0
6460 function rotl5 ( num
) {
6461 return ( num
<< 5 ) | ( num
>>> 27 )
6464 function rotl30 ( num
) {
6465 return ( num
<< 30 ) | ( num
>>> 2 )
6468 function ft ( s
, b
, c
, d
) {
6469 if ( s
=== 0 ) return ( b
& c
) | ((~ b
) & d
)
6470 if ( s
=== 2 ) return ( b
& c
) | ( b
& d
) | ( c
& d
)
6474 Sha
. prototype . _update = function ( M
) {
6483 for ( var i
= 0 ; i
< 16 ; ++ i
) W
[ i
] = M
. readInt32BE ( i
* 4 )
6484 for (; i
< 80 ; ++ i
) W
[ i
] = W
[ i
- 3 ] ^ W
[ i
- 8 ] ^ W
[ i
- 14 ] ^ W
[ i
- 16 ]
6486 for ( var j
= 0 ; j
< 80 ; ++ j
) {
6488 var t
= ( rotl5 ( a
) + ft ( s
, b
, c
, d
) + e
+ W
[ j
] + K
[ s
]) | 0
6497 this . _a
= ( a
+ this . _a
) | 0
6498 this . _b
= ( b
+ this . _b
) | 0
6499 this . _c
= ( c
+ this . _c
) | 0
6500 this . _d
= ( d
+ this . _d
) | 0
6501 this . _e
= ( e
+ this . _e
) | 0
6504 Sha
. prototype . _hash = function () {
6505 var H
= Buffer
. allocUnsafe ( 20 )
6507 H
. writeInt32BE ( this . _a
| 0 , 0 )
6508 H
. writeInt32BE ( this . _b
| 0 , 4 )
6509 H
. writeInt32BE ( this . _c
| 0 , 8 )
6510 H
. writeInt32BE ( this . _d
| 0 , 12 )
6511 H
. writeInt32BE ( this . _e
| 0 , 16 )
6516 module
. exports
= Sha
6518 },{ "./hash" : 35 , "inherits" : 13 , "safe-buffer" : 34 }], 38 :[ function ( require
, module
, exports
){
6520 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
6522 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
6523 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
6524 * Distributed under the BSD License
6525 * See http://pajhome.org.uk/crypt/md5 for details.
6528 var inherits
= require ( 'inherits' )
6529 var Hash
= require ( './hash' )
6530 var Buffer
= require ( 'safe-buffer' ). Buffer
6533 0x5a827999 , 0x6ed9eba1 , 0x8f1bbcdc | 0 , 0xca62c1d6 | 0
6536 var W
= new Array ( 80 )
6542 Hash
. call ( this , 64 , 56 )
6545 inherits ( Sha1
, Hash
)
6547 Sha1
. prototype . init = function () {
6548 this . _a
= 0x67452301
6549 this . _b
= 0xefcdab89
6550 this . _c
= 0x98badcfe
6551 this . _d
= 0x10325476
6552 this . _e
= 0xc3d2e1f0
6557 function rotl1 ( num
) {
6558 return ( num
<< 1 ) | ( num
>>> 31 )
6561 function rotl5 ( num
) {
6562 return ( num
<< 5 ) | ( num
>>> 27 )
6565 function rotl30 ( num
) {
6566 return ( num
<< 30 ) | ( num
>>> 2 )
6569 function ft ( s
, b
, c
, d
) {
6570 if ( s
=== 0 ) return ( b
& c
) | ((~ b
) & d
)
6571 if ( s
=== 2 ) return ( b
& c
) | ( b
& d
) | ( c
& d
)
6575 Sha1
. prototype . _update = function ( M
) {
6584 for ( var i
= 0 ; i
< 16 ; ++ i
) W
[ i
] = M
. readInt32BE ( i
* 4 )
6585 for (; i
< 80 ; ++ i
) W
[ i
] = rotl1 ( W
[ i
- 3 ] ^ W
[ i
- 8 ] ^ W
[ i
- 14 ] ^ W
[ i
- 16 ])
6587 for ( var j
= 0 ; j
< 80 ; ++ j
) {
6589 var t
= ( rotl5 ( a
) + ft ( s
, b
, c
, d
) + e
+ W
[ j
] + K
[ s
]) | 0
6598 this . _a
= ( a
+ this . _a
) | 0
6599 this . _b
= ( b
+ this . _b
) | 0
6600 this . _c
= ( c
+ this . _c
) | 0
6601 this . _d
= ( d
+ this . _d
) | 0
6602 this . _e
= ( e
+ this . _e
) | 0
6605 Sha1
. prototype . _hash = function () {
6606 var H
= Buffer
. allocUnsafe ( 20 )
6608 H
. writeInt32BE ( this . _a
| 0 , 0 )
6609 H
. writeInt32BE ( this . _b
| 0 , 4 )
6610 H
. writeInt32BE ( this . _c
| 0 , 8 )
6611 H
. writeInt32BE ( this . _d
| 0 , 12 )
6612 H
. writeInt32BE ( this . _e
| 0 , 16 )
6617 module
. exports
= Sha1
6619 },{ "./hash" : 35 , "inherits" : 13 , "safe-buffer" : 34 }], 39 :[ function ( require
, module
, exports
){
6621 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
6623 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
6624 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
6628 var inherits
= require ( 'inherits' )
6629 var Sha256
= require ( './sha256' )
6630 var Hash
= require ( './hash' )
6631 var Buffer
= require ( 'safe-buffer' ). Buffer
6633 var W
= new Array ( 64 )
6635 function Sha224 () {
6638 this . _w
= W
// new Array(64)
6640 Hash
. call ( this , 64 , 56 )
6643 inherits ( Sha224
, Sha256
)
6645 Sha224
. prototype . init = function () {
6646 this . _a
= 0xc1059ed8
6647 this . _b
= 0x367cd507
6648 this . _c
= 0x3070dd17
6649 this . _d
= 0xf70e5939
6650 this . _e
= 0xffc00b31
6651 this . _f
= 0x68581511
6652 this . _g
= 0x64f98fa7
6653 this . _h
= 0xbefa4fa4
6658 Sha224
. prototype . _hash = function () {
6659 var H
= Buffer
. allocUnsafe ( 28 )
6661 H
. writeInt32BE ( this . _a
, 0 )
6662 H
. writeInt32BE ( this . _b
, 4 )
6663 H
. writeInt32BE ( this . _c
, 8 )
6664 H
. writeInt32BE ( this . _d
, 12 )
6665 H
. writeInt32BE ( this . _e
, 16 )
6666 H
. writeInt32BE ( this . _f
, 20 )
6667 H
. writeInt32BE ( this . _g
, 24 )
6672 module
. exports
= Sha224
6674 },{ "./hash" : 35 , "./sha256" : 40 , "inherits" : 13 , "safe-buffer" : 34 }], 40 :[ function ( require
, module
, exports
){
6676 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
6678 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
6679 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
6683 var inherits
= require ( 'inherits' )
6684 var Hash
= require ( './hash' )
6685 var Buffer
= require ( 'safe-buffer' ). Buffer
6688 0x428A2F98 , 0x71374491 , 0xB5C0FBCF , 0xE9B5DBA5 ,
6689 0x3956C25B , 0x59F111F1 , 0x923F82A4 , 0xAB1C5ED5 ,
6690 0xD807AA98 , 0x12835B01 , 0x243185BE , 0x550C7DC3 ,
6691 0x72BE5D74 , 0x80DEB1FE , 0x9BDC06A7 , 0xC19BF174 ,
6692 0xE49B69C1 , 0xEFBE4786 , 0x0FC19DC6 , 0x240CA1CC ,
6693 0x2DE92C6F , 0x4A7484AA , 0x5CB0A9DC , 0x76F988DA ,
6694 0x983E5152 , 0xA831C66D , 0xB00327C8 , 0xBF597FC7 ,
6695 0xC6E00BF3 , 0xD5A79147 , 0x06CA6351 , 0x14292967 ,
6696 0x27B70A85 , 0x2E1B2138 , 0x4D2C6DFC , 0x53380D13 ,
6697 0x650A7354 , 0x766A0ABB , 0x81C2C92E , 0x92722C85 ,
6698 0xA2BFE8A1 , 0xA81A664B , 0xC24B8B70 , 0xC76C51A3 ,
6699 0xD192E819 , 0xD6990624 , 0xF40E3585 , 0x106AA070 ,
6700 0x19A4C116 , 0x1E376C08 , 0x2748774C , 0x34B0BCB5 ,
6701 0x391C0CB3 , 0x4ED8AA4A , 0x5B9CCA4F , 0x682E6FF3 ,
6702 0x748F82EE , 0x78A5636F , 0x84C87814 , 0x8CC70208 ,
6703 0x90BEFFFA , 0xA4506CEB , 0xBEF9A3F7 , 0xC67178F2
6706 var W
= new Array ( 64 )
6708 function Sha256 () {
6711 this . _w
= W
// new Array(64)
6713 Hash
. call ( this , 64 , 56 )
6716 inherits ( Sha256
, Hash
)
6718 Sha256
. prototype . init = function () {
6719 this . _a
= 0x6a09e667
6720 this . _b
= 0xbb67ae85
6721 this . _c
= 0x3c6ef372
6722 this . _d
= 0xa54ff53a
6723 this . _e
= 0x510e527f
6724 this . _f
= 0x9b05688c
6725 this . _g
= 0x1f83d9ab
6726 this . _h
= 0x5be0cd19
6731 function ch ( x
, y
, z
) {
6732 return z
^ ( x
& ( y
^ z
))
6735 function maj ( x
, y
, z
) {
6736 return ( x
& y
) | ( z
& ( x
| y
))
6739 function sigma0 ( x
) {
6740 return ( x
>>> 2 | x
<< 30 ) ^ ( x
>>> 13 | x
<< 19 ) ^ ( x
>>> 22 | x
<< 10 )
6743 function sigma1 ( x
) {
6744 return ( x
>>> 6 | x
<< 26 ) ^ ( x
>>> 11 | x
<< 21 ) ^ ( x
>>> 25 | x
<< 7 )
6747 function gamma0 ( x
) {
6748 return ( x
>>> 7 | x
<< 25 ) ^ ( x
>>> 18 | x
<< 14 ) ^ ( x
>>> 3 )
6751 function gamma1 ( x
) {
6752 return ( x
>>> 17 | x
<< 15 ) ^ ( x
>>> 19 | x
<< 13 ) ^ ( x
>>> 10 )
6755 Sha256
. prototype . _update = function ( M
) {
6767 for ( var i
= 0 ; i
< 16 ; ++ i
) W
[ i
] = M
. readInt32BE ( i
* 4 )
6768 for (; i
< 64 ; ++ i
) W
[ i
] = ( gamma1 ( W
[ i
- 2 ]) + W
[ i
- 7 ] + gamma0 ( W
[ i
- 15 ]) + W
[ i
- 16 ]) | 0
6770 for ( var j
= 0 ; j
< 64 ; ++ j
) {
6771 var T1
= ( h
+ sigma1 ( e
) + ch ( e
, f
, g
) + K
[ j
] + W
[ j
]) | 0
6772 var T2
= ( sigma0 ( a
) + maj ( a
, b
, c
)) | 0
6784 this . _a
= ( a
+ this . _a
) | 0
6785 this . _b
= ( b
+ this . _b
) | 0
6786 this . _c
= ( c
+ this . _c
) | 0
6787 this . _d
= ( d
+ this . _d
) | 0
6788 this . _e
= ( e
+ this . _e
) | 0
6789 this . _f
= ( f
+ this . _f
) | 0
6790 this . _g
= ( g
+ this . _g
) | 0
6791 this . _h
= ( h
+ this . _h
) | 0
6794 Sha256
. prototype . _hash = function () {
6795 var H
= Buffer
. allocUnsafe ( 32 )
6797 H
. writeInt32BE ( this . _a
, 0 )
6798 H
. writeInt32BE ( this . _b
, 4 )
6799 H
. writeInt32BE ( this . _c
, 8 )
6800 H
. writeInt32BE ( this . _d
, 12 )
6801 H
. writeInt32BE ( this . _e
, 16 )
6802 H
. writeInt32BE ( this . _f
, 20 )
6803 H
. writeInt32BE ( this . _g
, 24 )
6804 H
. writeInt32BE ( this . _h
, 28 )
6809 module
. exports
= Sha256
6811 },{ "./hash" : 35 , "inherits" : 13 , "safe-buffer" : 34 }], 41 :[ function ( require
, module
, exports
){
6812 var inherits
= require ( 'inherits' )
6813 var SHA512
= require ( './sha512' )
6814 var Hash
= require ( './hash' )
6815 var Buffer
= require ( 'safe-buffer' ). Buffer
6817 var W
= new Array ( 160 )
6819 function Sha384 () {
6823 Hash
. call ( this , 128 , 112 )
6826 inherits ( Sha384
, SHA512
)
6828 Sha384
. prototype . init = function () {
6829 this . _ah
= 0xcbbb9d5d
6830 this . _bh
= 0x629a292a
6831 this . _ch
= 0x9159015a
6832 this . _dh
= 0x152fecd8
6833 this . _eh
= 0x67332667
6834 this . _fh
= 0x8eb44a87
6835 this . _gh
= 0xdb0c2e0d
6836 this . _hh
= 0x47b5481d
6838 this . _al
= 0xc1059ed8
6839 this . _bl
= 0x367cd507
6840 this . _cl
= 0x3070dd17
6841 this . _dl
= 0xf70e5939
6842 this . _el
= 0xffc00b31
6843 this . _fl
= 0x68581511
6844 this . _gl
= 0x64f98fa7
6845 this . _hl
= 0xbefa4fa4
6850 Sha384
. prototype . _hash = function () {
6851 var H
= Buffer
. allocUnsafe ( 48 )
6853 function writeInt64BE ( h
, l
, offset
) {
6854 H
. writeInt32BE ( h
, offset
)
6855 H
. writeInt32BE ( l
, offset
+ 4 )
6858 writeInt64BE ( this . _ah
, this . _al
, 0 )
6859 writeInt64BE ( this . _bh
, this . _bl
, 8 )
6860 writeInt64BE ( this . _ch
, this . _cl
, 16 )
6861 writeInt64BE ( this . _dh
, this . _dl
, 24 )
6862 writeInt64BE ( this . _eh
, this . _el
, 32 )
6863 writeInt64BE ( this . _fh
, this . _fl
, 40 )
6868 module
. exports
= Sha384
6870 },{ "./hash" : 35 , "./sha512" : 42 , "inherits" : 13 , "safe-buffer" : 34 }], 42 :[ function ( require
, module
, exports
){
6871 var inherits
= require ( 'inherits' )
6872 var Hash
= require ( './hash' )
6873 var Buffer
= require ( 'safe-buffer' ). Buffer
6876 0x428a2f98 , 0xd728ae22 , 0x71374491 , 0x23ef65cd ,
6877 0xb5c0fbcf , 0xec4d3b2f , 0xe9b5dba5 , 0x8189dbbc ,
6878 0x3956c25b , 0xf348b538 , 0x59f111f1 , 0xb605d019 ,
6879 0x923f82a4 , 0xaf194f9b , 0xab1c5ed5 , 0xda6d8118 ,
6880 0xd807aa98 , 0xa3030242 , 0x12835b01 , 0x45706fbe ,
6881 0x243185be , 0x4ee4b28c , 0x550c7dc3 , 0xd5ffb4e2 ,
6882 0x72be5d74 , 0xf27b896f , 0x80deb1fe , 0x3b1696b1 ,
6883 0x9bdc06a7 , 0x25c71235 , 0xc19bf174 , 0xcf692694 ,
6884 0xe49b69c1 , 0x9ef14ad2 , 0xefbe4786 , 0x384f25e3 ,
6885 0x0fc19dc6 , 0x8b8cd5b5 , 0x240ca1cc , 0x77ac9c65 ,
6886 0x2de92c6f , 0x592b0275 , 0x4a7484aa , 0x6ea6e483 ,
6887 0x5cb0a9dc , 0xbd41fbd4 , 0x76f988da , 0x831153b5 ,
6888 0x983e5152 , 0xee66dfab , 0xa831c66d , 0x2db43210 ,
6889 0xb00327c8 , 0x98fb213f , 0xbf597fc7 , 0xbeef0ee4 ,
6890 0xc6e00bf3 , 0x3da88fc2 , 0xd5a79147 , 0x930aa725 ,
6891 0x06ca6351 , 0xe003826f , 0x14292967 , 0x0a0e6e70 ,
6892 0x27b70a85 , 0x46d22ffc , 0x2e1b2138 , 0x5c26c926 ,
6893 0x4d2c6dfc , 0x5ac42aed , 0x53380d13 , 0x9d95b3df ,
6894 0x650a7354 , 0x8baf63de , 0x766a0abb , 0x3c77b2a8 ,
6895 0x81c2c92e , 0x47edaee6 , 0x92722c85 , 0x1482353b ,
6896 0xa2bfe8a1 , 0x4cf10364 , 0xa81a664b , 0xbc423001 ,
6897 0xc24b8b70 , 0xd0f89791 , 0xc76c51a3 , 0x0654be30 ,
6898 0xd192e819 , 0xd6ef5218 , 0xd6990624 , 0x5565a910 ,
6899 0xf40e3585 , 0x5771202a , 0x106aa070 , 0x32bbd1b8 ,
6900 0x19a4c116 , 0xb8d2d0c8 , 0x1e376c08 , 0x5141ab53 ,
6901 0x2748774c , 0xdf8eeb99 , 0x34b0bcb5 , 0xe19b48a8 ,
6902 0x391c0cb3 , 0xc5c95a63 , 0x4ed8aa4a , 0xe3418acb ,
6903 0x5b9cca4f , 0x7763e373 , 0x682e6ff3 , 0xd6b2b8a3 ,
6904 0x748f82ee , 0x5defb2fc , 0x78a5636f , 0x43172f60 ,
6905 0x84c87814 , 0xa1f0ab72 , 0x8cc70208 , 0x1a6439ec ,
6906 0x90befffa , 0x23631e28 , 0xa4506ceb , 0xde82bde9 ,
6907 0xbef9a3f7 , 0xb2c67915 , 0xc67178f2 , 0xe372532b ,
6908 0xca273ece , 0xea26619c , 0xd186b8c7 , 0x21c0c207 ,
6909 0xeada7dd6 , 0xcde0eb1e , 0xf57d4f7f , 0xee6ed178 ,
6910 0x06f067aa , 0x72176fba , 0x0a637dc5 , 0xa2c898a6 ,
6911 0x113f9804 , 0xbef90dae , 0x1b710b35 , 0x131c471b ,
6912 0x28db77f5 , 0x23047d84 , 0x32caab7b , 0x40c72493 ,
6913 0x3c9ebe0a , 0x15c9bebc , 0x431d67c4 , 0x9c100d4c ,
6914 0x4cc5d4be , 0xcb3e42b6 , 0x597f299c , 0xfc657e2a ,
6915 0x5fcb6fab , 0x3ad6faec , 0x6c44198c , 0x4a475817
6918 var W
= new Array ( 160 )
6920 function Sha512 () {
6924 Hash
. call ( this , 128 , 112 )
6927 inherits ( Sha512
, Hash
)
6929 Sha512
. prototype . init = function () {
6930 this . _ah
= 0x6a09e667
6931 this . _bh
= 0xbb67ae85
6932 this . _ch
= 0x3c6ef372
6933 this . _dh
= 0xa54ff53a
6934 this . _eh
= 0x510e527f
6935 this . _fh
= 0x9b05688c
6936 this . _gh
= 0x1f83d9ab
6937 this . _hh
= 0x5be0cd19
6939 this . _al
= 0xf3bcc908
6940 this . _bl
= 0x84caa73b
6941 this . _cl
= 0xfe94f82b
6942 this . _dl
= 0x5f1d36f1
6943 this . _el
= 0xade682d1
6944 this . _fl
= 0x2b3e6c1f
6945 this . _gl
= 0xfb41bd6b
6946 this . _hl
= 0x137e2179
6951 function Ch ( x
, y
, z
) {
6952 return z
^ ( x
& ( y
^ z
))
6955 function maj ( x
, y
, z
) {
6956 return ( x
& y
) | ( z
& ( x
| y
))
6959 function sigma0 ( x
, xl
) {
6960 return ( x
>>> 28 | xl
<< 4 ) ^ ( xl
>>> 2 | x
<< 30 ) ^ ( xl
>>> 7 | x
<< 25 )
6963 function sigma1 ( x
, xl
) {
6964 return ( x
>>> 14 | xl
<< 18 ) ^ ( x
>>> 18 | xl
<< 14 ) ^ ( xl
>>> 9 | x
<< 23 )
6967 function Gamma0 ( x
, xl
) {
6968 return ( x
>>> 1 | xl
<< 31 ) ^ ( x
>>> 8 | xl
<< 24 ) ^ ( x
>>> 7 )
6971 function Gamma0l ( x
, xl
) {
6972 return ( x
>>> 1 | xl
<< 31 ) ^ ( x
>>> 8 | xl
<< 24 ) ^ ( x
>>> 7 | xl
<< 25 )
6975 function Gamma1 ( x
, xl
) {
6976 return ( x
>>> 19 | xl
<< 13 ) ^ ( xl
>>> 29 | x
<< 3 ) ^ ( x
>>> 6 )
6979 function Gamma1l ( x
, xl
) {
6980 return ( x
>>> 19 | xl
<< 13 ) ^ ( xl
>>> 29 | x
<< 3 ) ^ ( x
>>> 6 | xl
<< 26 )
6983 function getCarry ( a
, b
) {
6984 return ( a
>>> 0 ) < ( b
>>> 0 ) ? 1 : 0
6987 Sha512
. prototype . _update = function ( M
) {
6990 var ah
= this . _ah
| 0
6991 var bh
= this . _bh
| 0
6992 var ch
= this . _ch
| 0
6993 var dh
= this . _dh
| 0
6994 var eh
= this . _eh
| 0
6995 var fh
= this . _fh
| 0
6996 var gh
= this . _gh
| 0
6997 var hh
= this . _hh
| 0
6999 var al
= this . _al
| 0
7000 var bl
= this . _bl
| 0
7001 var cl
= this . _cl
| 0
7002 var dl
= this . _dl
| 0
7003 var el
= this . _el
| 0
7004 var fl
= this . _fl
| 0
7005 var gl
= this . _gl
| 0
7006 var hl
= this . _hl
| 0
7008 for ( var i
= 0 ; i
< 32 ; i
+= 2 ) {
7009 W
[ i
] = M
. readInt32BE ( i
* 4 )
7010 W
[ i
+ 1 ] = M
. readInt32BE ( i
* 4 + 4 )
7012 for (; i
< 160 ; i
+= 2 ) {
7013 var xh
= W
[ i
- 15 * 2 ]
7014 var xl
= W
[ i
- 15 * 2 + 1 ]
7015 var gamma0
= Gamma0 ( xh
, xl
)
7016 var gamma0l
= Gamma0l ( xl
, xh
)
7019 xl
= W
[ i
- 2 * 2 + 1 ]
7020 var gamma1
= Gamma1 ( xh
, xl
)
7021 var gamma1l
= Gamma1l ( xl
, xh
)
7023 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
7024 var Wi7h
= W
[ i
- 7 * 2 ]
7025 var Wi7l
= W
[ i
- 7 * 2 + 1 ]
7027 var Wi16h
= W
[ i
- 16 * 2 ]
7028 var Wi16l
= W
[ i
- 16 * 2 + 1 ]
7030 var Wil
= ( gamma0l
+ Wi7l
) | 0
7031 var Wih
= ( gamma0
+ Wi7h
+ getCarry ( Wil
, gamma0l
)) | 0
7032 Wil
= ( Wil
+ gamma1l
) | 0
7033 Wih
= ( Wih
+ gamma1
+ getCarry ( Wil
, gamma1l
)) | 0
7034 Wil
= ( Wil
+ Wi16l
) | 0
7035 Wih
= ( Wih
+ Wi16h
+ getCarry ( Wil
, Wi16l
)) | 0
7041 for ( var j
= 0 ; j
< 160 ; j
+= 2 ) {
7045 var majh
= maj ( ah
, bh
, ch
)
7046 var majl
= maj ( al
, bl
, cl
)
7048 var sigma0h
= sigma0 ( ah
, al
)
7049 var sigma0l
= sigma0 ( al
, ah
)
7050 var sigma1h
= sigma1 ( eh
, el
)
7051 var sigma1l
= sigma1 ( el
, eh
)
7053 // t1 = h + sigma1 + ch + K[j] + W[j]
7057 var chh
= Ch ( eh
, fh
, gh
)
7058 var chl
= Ch ( el
, fl
, gl
)
7060 var t1l
= ( hl
+ sigma1l
) | 0
7061 var t1h
= ( hh
+ sigma1h
+ getCarry ( t1l
, hl
)) | 0
7062 t1l
= ( t1l
+ chl
) | 0
7063 t1h
= ( t1h
+ chh
+ getCarry ( t1l
, chl
)) | 0
7064 t1l
= ( t1l
+ Kil
) | 0
7065 t1h
= ( t1h
+ Kih
+ getCarry ( t1l
, Kil
)) | 0
7066 t1l
= ( t1l
+ Wil
) | 0
7067 t1h
= ( t1h
+ Wih
+ getCarry ( t1l
, Wil
)) | 0
7069 // t2 = sigma0 + maj
7070 var t2l
= ( sigma0l
+ majl
) | 0
7071 var t2h
= ( sigma0h
+ majh
+ getCarry ( t2l
, sigma0l
)) | 0
7080 eh
= ( dh
+ t1h
+ getCarry ( el
, dl
)) | 0
7087 al
= ( t1l
+ t2l
) | 0
7088 ah
= ( t1h
+ t2h
+ getCarry ( al
, t1l
)) | 0
7091 this . _al
= ( this . _al
+ al
) | 0
7092 this . _bl
= ( this . _bl
+ bl
) | 0
7093 this . _cl
= ( this . _cl
+ cl
) | 0
7094 this . _dl
= ( this . _dl
+ dl
) | 0
7095 this . _el
= ( this . _el
+ el
) | 0
7096 this . _fl
= ( this . _fl
+ fl
) | 0
7097 this . _gl
= ( this . _gl
+ gl
) | 0
7098 this . _hl
= ( this . _hl
+ hl
) | 0
7100 this . _ah
= ( this . _ah
+ ah
+ getCarry ( this . _al
, al
)) | 0
7101 this . _bh
= ( this . _bh
+ bh
+ getCarry ( this . _bl
, bl
)) | 0
7102 this . _ch
= ( this . _ch
+ ch
+ getCarry ( this . _cl
, cl
)) | 0
7103 this . _dh
= ( this . _dh
+ dh
+ getCarry ( this . _dl
, dl
)) | 0
7104 this . _eh
= ( this . _eh
+ eh
+ getCarry ( this . _el
, el
)) | 0
7105 this . _fh
= ( this . _fh
+ fh
+ getCarry ( this . _fl
, fl
)) | 0
7106 this . _gh
= ( this . _gh
+ gh
+ getCarry ( this . _gl
, gl
)) | 0
7107 this . _hh
= ( this . _hh
+ hh
+ getCarry ( this . _hl
, hl
)) | 0
7110 Sha512
. prototype . _hash = function () {
7111 var H
= Buffer
. allocUnsafe ( 64 )
7113 function writeInt64BE ( h
, l
, offset
) {
7114 H
. writeInt32BE ( h
, offset
)
7115 H
. writeInt32BE ( l
, offset
+ 4 )
7118 writeInt64BE ( this . _ah
, this . _al
, 0 )
7119 writeInt64BE ( this . _bh
, this . _bl
, 8 )
7120 writeInt64BE ( this . _ch
, this . _cl
, 16 )
7121 writeInt64BE ( this . _dh
, this . _dl
, 24 )
7122 writeInt64BE ( this . _eh
, this . _el
, 32 )
7123 writeInt64BE ( this . _fh
, this . _fl
, 40 )
7124 writeInt64BE ( this . _gh
, this . _gl
, 48 )
7125 writeInt64BE ( this . _hh
, this . _hl
, 56 )
7130 module
. exports
= Sha512
7132 },{ "./hash" : 35 , "inherits" : 13 , "safe-buffer" : 34 }], 43 :[ function ( require
, module
, exports
){
7133 // Copyright Joyent, Inc. and other Node contributors.
7135 // Permission is hereby granted, free of charge, to any person obtaining a
7136 // copy of this software and associated documentation files (the
7137 // "Software"), to deal in the Software without restriction, including
7138 // without limitation the rights to use, copy, modify, merge, publish,
7139 // distribute, sublicense, and/or sell copies of the Software, and to permit
7140 // persons to whom the Software is furnished to do so, subject to the
7141 // following conditions:
7143 // The above copyright notice and this permission notice shall be included
7144 // in all copies or substantial portions of the Software.
7146 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
7147 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
7148 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
7149 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
7150 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
7151 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
7152 // USE OR OTHER DEALINGS IN THE SOFTWARE.
7154 module
. exports
= Stream
;
7156 var EE
= require ( 'events' ). EventEmitter
;
7157 var inherits
= require ( 'inherits' );
7159 inherits ( Stream
, EE
);
7160 Stream
. Readable
= require ( 'readable-stream/readable.js' );
7161 Stream
. Writable
= require ( 'readable-stream/writable.js' );
7162 Stream
. Duplex
= require ( 'readable-stream/duplex.js' );
7163 Stream
. Transform
= require ( 'readable-stream/transform.js' );
7164 Stream
. PassThrough
= require ( 'readable-stream/passthrough.js' );
7166 // Backwards-compat with node 0.4.x
7167 Stream
. Stream
= Stream
;
7171 // old-style streams. Note that the pipe method (the only relevant
7172 // part of this class) is overridden in the Readable class.
7178 Stream
. prototype . pipe = function ( dest
, options
) {
7181 function ondata ( chunk
) {
7182 if ( dest
. writable
) {
7183 if ( false === dest
. write ( chunk
) && source
. pause
) {
7189 source
. on ( 'data' , ondata
);
7191 function ondrain () {
7192 if ( source
. readable
&& source
. resume
) {
7197 dest
. on ( 'drain' , ondrain
);
7199 // If the 'end' option is not supplied, dest.end() will be called when
7200 // source gets the 'end' or 'close' events. Only dest.end() once.
7201 if (! dest
. _isStdio
&& (! options
|| options
. end
!== false )) {
7202 source
. on ( 'end' , onend
);
7203 source
. on ( 'close' , onclose
);
7206 var didOnEnd
= false ;
7208 if ( didOnEnd
) return ;
7215 function onclose () {
7216 if ( didOnEnd
) return ;
7219 if ( typeof dest
. destroy
=== 'function' ) dest
. destroy ();
7222 // don't leave dangling pipes when there are errors.
7223 function onerror ( er
) {
7225 if ( EE
. listenerCount ( this , 'error' ) === 0 ) {
7226 throw er
; // Unhandled stream error in pipe.
7230 source
. on ( 'error' , onerror
);
7231 dest
. on ( 'error' , onerror
);
7233 // remove all the event listeners that were added.
7234 function cleanup () {
7235 source
. removeListener ( 'data' , ondata
);
7236 dest
. removeListener ( 'drain' , ondrain
);
7238 source
. removeListener ( 'end' , onend
);
7239 source
. removeListener ( 'close' , onclose
);
7241 source
. removeListener ( 'error' , onerror
);
7242 dest
. removeListener ( 'error' , onerror
);
7244 source
. removeListener ( 'end' , cleanup
);
7245 source
. removeListener ( 'close' , cleanup
);
7247 dest
. removeListener ( 'close' , cleanup
);
7250 source
. on ( 'end' , cleanup
);
7251 source
. on ( 'close' , cleanup
);
7253 dest
. on ( 'close' , cleanup
);
7255 dest
. emit ( 'pipe' , source
);
7257 // Allow for unix-like usage: A.pipe(B).pipe(C)
7261 },{ "events" : 10 , "inherits" : 13 , "readable-stream/duplex.js" : 19 , "readable-stream/passthrough.js" : 29 , "readable-stream/readable.js" : 30 , "readable-stream/transform.js" : 31 , "readable-stream/writable.js" : 32 }], 44 :[ function ( require
, module
, exports
){
7262 arguments
[ 4 ][ 28 ][ 0 ]. apply ( exports
, arguments
)
7263 },{ "dup" : 28 , "safe-buffer" : 34 }], 45 :[ function ( require
, module
, exports
){
7264 ( function ( setImmediate
, clearImmediate
){
7265 var nextTick
= require ( 'process/browser.js' ). nextTick
;
7266 var apply
= Function
. prototype . apply
;
7267 var slice
= Array
. prototype . slice
;
7268 var immediateIds
= {};
7269 var nextImmediateId
= 0 ;
7271 // DOM APIs, for completeness
7273 exports
. setTimeout = function () {
7274 return new Timeout ( apply
. call ( setTimeout
, window
, arguments
), clearTimeout
);
7276 exports
. setInterval = function () {
7277 return new Timeout ( apply
. call ( setInterval
, window
, arguments
), clearInterval
);
7279 exports
. clearTimeout
=
7280 exports
. clearInterval = function ( timeout
) { timeout
. close (); };
7282 function Timeout ( id
, clearFn
) {
7284 this . _clearFn
= clearFn
;
7286 Timeout
. prototype . unref
= Timeout
. prototype . ref = function () {};
7287 Timeout
. prototype . close = function () {
7288 this . _clearFn
. call ( window
, this . _id
);
7291 // Does not start the time, just sets up the members needed.
7292 exports
. enroll = function ( item
, msecs
) {
7293 clearTimeout ( item
. _idleTimeoutId
);
7294 item
. _idleTimeout
= msecs
;
7297 exports
. unenroll = function ( item
) {
7298 clearTimeout ( item
. _idleTimeoutId
);
7299 item
. _idleTimeout
= - 1 ;
7302 exports
. _unrefActive
= exports
. active = function ( item
) {
7303 clearTimeout ( item
. _idleTimeoutId
);
7305 var msecs
= item
. _idleTimeout
;
7307 item
. _idleTimeoutId
= setTimeout ( function onTimeout () {
7308 if ( item
. _onTimeout
)
7314 // That's not how node.js implements it but the exposed api is the same.
7315 exports
. setImmediate
= typeof setImmediate
=== "function" ? setImmediate : function ( fn
) {
7316 var id
= nextImmediateId
++;
7317 var args
= arguments
. length
< 2 ? false : slice
. call ( arguments
, 1 );
7319 immediateIds
[ id
] = true ;
7321 nextTick ( function onNextTick () {
7322 if ( immediateIds
[ id
]) {
7323 // fn.call() is faster so we optimize for the common use-case
7324 // @see http://jsperf.com/call-apply-segu
7326 fn
. apply ( null , args
);
7330 // Prevent ids from leaking
7331 exports
. clearImmediate ( id
);
7338 exports
. clearImmediate
= typeof clearImmediate
=== "function" ? clearImmediate : function ( id
) {
7339 delete immediateIds
[ id
];
7341 }). call ( this , require ( "timers" ). setImmediate
, require ( "timers" ). clearImmediate
)
7342 },{ "process/browser.js" : 18 , "timers" : 45 }], 46 :[ function ( require
, module
, exports
){
7349 module
. exports
= deprecate
;
7352 * Mark that a method should not be used.
7353 * Returns a modified function which warns once by default.
7355 * If `localStorage.noDeprecation = true` is set, then it is a no-op.
7357 * If `localStorage.throwDeprecation = true` is set, then deprecated functions
7358 * will throw an Error when invoked.
7360 * If `localStorage.traceDeprecation = true` is set, then deprecated functions
7361 * will invoke `console.trace()` instead of `console.error()`.
7363 * @param {Function} fn - the function to deprecate
7364 * @param {String} msg - the string to print to the console when `fn` is invoked
7365 * @returns {Function} a new "deprecated" version of `fn`
7369 function deprecate ( fn
, msg
) {
7370 if ( config ( 'noDeprecation' )) {
7375 function deprecated () {
7377 if ( config ( 'throwDeprecation' )) {
7378 throw new Error ( msg
);
7379 } else if ( config ( 'traceDeprecation' )) {
7386 return fn
. apply ( this , arguments
);
7393 * Checks `localStorage` for boolean values for the given `name`.
7395 * @param {String} name
7396 * @returns {Boolean}
7400 function config ( name
) {
7401 // accessing global.localStorage can trigger a DOMException in sandboxed iframes
7403 if (! global
. localStorage
) return false ;
7407 var val
= global
. localStorage
[ name
];
7408 if ( null == val
) return false ;
7409 return String ( val
). toLowerCase () === 'true' ;
7412 }). call ( this , typeof global
!== "undefined" ? global : typeof self
!== "undefined" ? self : typeof window
!== "undefined" ? window : {})