aboutsummaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js')
-rw-r--r--src/js/bitcoinjs-extensions.js52
-rw-r--r--src/js/eos-util.js7414
-rw-r--r--src/js/index.js44
-rw-r--r--src/js/segwit-parameters.js12
4 files changed, 7511 insertions, 11 deletions
diff --git a/src/js/bitcoinjs-extensions.js b/src/js/bitcoinjs-extensions.js
index d0151db..f7e708b 100644
--- a/src/js/bitcoinjs-extensions.js
+++ b/src/js/bitcoinjs-extensions.js
@@ -47,14 +47,14 @@ bitcoinjs.bitcoin.networks.crown = {
47 47
48 var addrBytes = b58.decode(oldAddress); 48 var addrBytes = b58.decode(oldAddress);
49 49
50 var hash160 = new Uint16Array(23); 50 var hash160 = new Uint16Array(23);
51 hash160[0]= 0x01; //C 51 hash160[0]= 0x01; //C
52 hash160[1]= 0x75; //R 52 hash160[1]= 0x75; //R
53 hash160[2]= 0x07; //W 53 hash160[2]= 0x07; //W
54 addrBytes.copy(hash160, 3, 1, 21); 54 addrBytes.copy(hash160, 3, 1, 21);
55 55
56 var checksum = bitcoinjs.bitcoin.crypto.hash256(hash160).subarray(0, 4); 56 var checksum = bitcoinjs.bitcoin.crypto.hash256(hash160).subarray(0, 4);
57 var binaryAddr = new Uint16Array(27); 57 var binaryAddr = new Uint16Array(27);
58 binaryAddr.set(hash160,0); 58 binaryAddr.set(hash160,0);
59 checksum.copy(binaryAddr, 23, 0, 4); 59 checksum.copy(binaryAddr, 23, 0, 4);
60 var newAddress = b58.encode(binaryAddr); 60 var newAddress = b58.encode(binaryAddr);
@@ -172,6 +172,17 @@ bitcoinjs.bitcoin.networks.dogecoin = {
172 wif: 0x9e 172 wif: 0x9e
173}; 173};
174 174
175bitcoinjs.bitcoin.networks.dogecointestnet = {
176 messagePrefix: '\x19Dogecoin Signed Message:\n',
177 bip32: {
178 public: 0x043587cf,
179 private: 0x04358394
180 },
181 pubKeyHash: 0x71,
182 scriptHash: 0xc4,
183 wif: 0xf1
184};
185
175bitcoinjs.bitcoin.networks.denarius = { 186bitcoinjs.bitcoin.networks.denarius = {
176 messagePrefix: '\x19Denarius Signed Message:\n', 187 messagePrefix: '\x19Denarius Signed Message:\n',
177 bip32: { 188 bip32: {
@@ -615,7 +626,7 @@ bitcoinjs.bitcoin.networks.diamond = {
615}; 626};
616 627
617bitcoinjs.bitcoin.networks.digibyte = { 628bitcoinjs.bitcoin.networks.digibyte = {
618 messagePrefix: '\x18DigiByte Signed Message:\n', 629 messagePrefix: '\x19DigiByte Signed Message:\n',
619 bip32: { 630 bip32: {
620 public: 0x0488B21E, 631 public: 0x0488B21E,
621 private: 0x0488ADE4, 632 private: 0x0488ADE4,
@@ -878,6 +889,17 @@ bitcoinjs.bitcoin.networks.linx = {
878 wif: 0xcb, 889 wif: 0xcb,
879}; 890};
880 891
892
893bitcoinjs.bitcoin.networks.litecointestnet = {
894 messagePrefix: '\x18Litecoin Signed Message:\n',
895 bip32: {
896 public: 0x043587cf,
897 private: 0x04358394,
898 },
899 pubKeyHash: 0x6f,
900 scriptHash: 0xc4,
901 wif: 0xef,
902};
881bitcoinjs.bitcoin.networks.litecoincash = { 903bitcoinjs.bitcoin.networks.litecoincash = {
882 messagePrefix: '\x18Litecoin Signed Message:\n', 904 messagePrefix: '\x18Litecoin Signed Message:\n',
883 bip32: { 905 bip32: {
@@ -1537,4 +1559,26 @@ bitcoinjs.bitcoin.networks.blockstamp = {
1537 pubKeyHash: 0x00, 1559 pubKeyHash: 0x00,
1538 scriptHash: 0x05, 1560 scriptHash: 0x05,
1539 wif: 0x80, 1561 wif: 0x80,
1540}; \ No newline at end of file 1562};
1563
1564bitcoinjs.bitcoin.networks.deeponion = {
1565 messagePrefix: 'x18DeepOnion Signed Message:\n',
1566 bip32: {
1567 public: 0x0488B21E,
1568 private: 0x0488ADE4,
1569 },
1570 pubKeyHash: 0x1F,
1571 scriptHash: 0x4E,
1572 wif: 0x9F,
1573};
1574
1575bitcoinjs.bitcoin.networks.monkey = {
1576 messagePrefix: 'x18DarkNet Signed Message:\n',
1577 bip32: {
1578 public: 0x0488B21E,
1579 private: 0x0488ADE4,
1580 },
1581 pubKeyHash: 0x7F,
1582 scriptHash: 0xC4,
1583 wif: 0x3F,
1584};
diff --git a/src/js/eos-util.js b/src/js/eos-util.js
new file mode 100644
index 0000000..2be3004
--- /dev/null
+++ b/src/js/eos-util.js
@@ -0,0 +1,7414 @@
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){
2const createHash = require("create-hash");
3const base58 = require("bs58");
4const { Buffer } = require("buffer");
5
6function 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));
11}
12
13function 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);
20}
21
22module.exports = {
23 bufferToPublic: bufferToPublic,
24 bufferToPrivate: bufferToPrivate,
25};
26
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.
33
34const Buffer = require('safe-buffer').Buffer
35
36module.exports = function base (ALPHABET) {
37 if (ALPHABET.length >= 255) throw new TypeError('Alphabet too long')
38
39 const BASE_MAP = new Uint8Array(256)
40 BASE_MAP.fill(255)
41
42 for (let i = 0; i < ALPHABET.length; i++) {
43 const x = ALPHABET.charAt(i)
44 const xc = x.charCodeAt(0)
45
46 if (BASE_MAP[xc] !== 255) throw new TypeError(x + ' is ambiguous')
47 BASE_MAP[xc] = i
48 }
49
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
54
55 function encode (source) {
56 if (!Buffer.isBuffer(source)) throw new TypeError('Expected Buffer')
57 if (source.length === 0) return ''
58
59 // Skip & count leading zeroes.
60 let zeroes = 0
61 let length = 0
62 let pbegin = 0
63 const pend = source.length
64
65 while (pbegin !== pend && source[pbegin] === 0) {
66 pbegin++
67 zeroes++
68 }
69
70 // Allocate enough space in big-endian base58 representation.
71 const size = ((pend - pbegin) * iFACTOR + 1) >>> 0
72 const b58 = new Uint8Array(size)
73
74 // Process the bytes.
75 while (pbegin !== pend) {
76 let carry = source[pbegin]
77
78 // Apply "b58 = b58 * 256 + ch".
79 let i = 0
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
84 }
85
86 if (carry !== 0) throw new Error('Non-zero carry')
87 length = i
88 pbegin++
89 }
90
91 // Skip leading zeroes in base58 result.
92 let it = size - length
93 while (it !== size && b58[it] === 0) {
94 it++
95 }
96
97 // Translate the result into a string.
98 let str = LEADER.repeat(zeroes)
99 for (; it < size; ++it) str += ALPHABET.charAt(b58[it])
100
101 return str
102 }
103
104 function decodeUnsafe (source) {
105 if (typeof source !== 'string') throw new TypeError('Expected String')
106 if (source.length === 0) return Buffer.alloc(0)
107
108 let psz = 0
109
110 // Skip leading spaces.
111 if (source[psz] === ' ') return
112
113 // Skip and count leading '1's.
114 let zeroes = 0
115 let length = 0
116 while (source[psz] === LEADER) {
117 zeroes++
118 psz++
119 }
120
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)
124
125 // Process the characters.
126 while (source[psz]) {
127 // Decode character
128 let carry = BASE_MAP[source.charCodeAt(psz)]
129
130 // Invalid character
131 if (carry === 255) return
132
133 let i = 0
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
138 }
139
140 if (carry !== 0) throw new Error('Non-zero carry')
141 length = i
142 psz++
143 }
144
145 // Skip trailing spaces.
146 if (source[psz] === ' ') return
147
148 // Skip leading zeroes in b256.
149 let it = size - length
150 while (it !== size && b256[it] === 0) {
151 it++
152 }
153
154 const vch = Buffer.allocUnsafe(zeroes + (size - it))
155 vch.fill(0x00, 0, zeroes)
156
157 let j = zeroes
158 while (it !== size) {
159 vch[j++] = b256[it++]
160 }
161
162 return vch
163 }
164
165 function decode (string) {
166 const buffer = decodeUnsafe(string)
167 if (buffer) return buffer
168
169 throw new Error('Non-base' + BASE + ' character')
170 }
171
172 return {
173 encode: encode,
174 decodeUnsafe: decodeUnsafe,
175 decode: decode
176 }
177}
178
179},{"safe-buffer":34}],3:[function(require,module,exports){
180'use strict'
181
182exports.byteLength = byteLength
183exports.toByteArray = toByteArray
184exports.fromByteArray = fromByteArray
185
186var lookup = []
187var revLookup = []
188var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
189
190var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
191for (var i = 0, len = code.length; i < len; ++i) {
192 lookup[i] = code[i]
193 revLookup[code.charCodeAt(i)] = i
194}
195
196// Support decoding URL-safe base64 strings, as Node.js does.
197// See: https://en.wikipedia.org/wiki/Base64#URL_applications
198revLookup['-'.charCodeAt(0)] = 62
199revLookup['_'.charCodeAt(0)] = 63
200
201function getLens (b64) {
202 var len = b64.length
203
204 if (len % 4 > 0) {
205 throw new Error('Invalid string. Length must be a multiple of 4')
206 }
207
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
212
213 var placeHoldersLen = validLen === len
214 ? 0
215 : 4 - (validLen % 4)
216
217 return [validLen, placeHoldersLen]
218}
219
220// base64 is 4/3 + up to two characters of the original data
221function byteLength (b64) {
222 var lens = getLens(b64)
223 var validLen = lens[0]
224 var placeHoldersLen = lens[1]
225 return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
226}
227
228function _byteLength (b64, validLen, placeHoldersLen) {
229 return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
230}
231
232function toByteArray (b64) {
233 var tmp
234 var lens = getLens(b64)
235 var validLen = lens[0]
236 var placeHoldersLen = lens[1]
237
238 var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
239
240 var curByte = 0
241
242 // if there are placeholders, only get up to the last complete 4 chars
243 var len = placeHoldersLen > 0
244 ? validLen - 4
245 : validLen
246
247 for (var i = 0; i < len; i += 4) {
248 tmp =
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
256 }
257
258 if (placeHoldersLen === 2) {
259 tmp =
260 (revLookup[b64.charCodeAt(i)] << 2) |
261 (revLookup[b64.charCodeAt(i + 1)] >> 4)
262 arr[curByte++] = tmp & 0xFF
263 }
264
265 if (placeHoldersLen === 1) {
266 tmp =
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
272 }
273
274 return arr
275}
276
277function tripletToBase64 (num) {
278 return lookup[num >> 18 & 0x3F] +
279 lookup[num >> 12 & 0x3F] +
280 lookup[num >> 6 & 0x3F] +
281 lookup[num & 0x3F]
282}
283
284function encodeChunk (uint8, start, end) {
285 var tmp
286 var output = []
287 for (var i = start; i < end; i += 3) {
288 tmp =
289 ((uint8[i] << 16) & 0xFF0000) +
290 ((uint8[i + 1] << 8) & 0xFF00) +
291 (uint8[i + 2] & 0xFF)
292 output.push(tripletToBase64(tmp))
293 }
294 return output.join('')
295}
296
297function fromByteArray (uint8) {
298 var tmp
299 var len = uint8.length
300 var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
301 var parts = []
302 var maxChunkLength = 16383 // must be multiple of 3
303
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)
308 ))
309 }
310
311 // pad the end with zeros, but make sure to not forget the extra bytes
312 if (extraBytes === 1) {
313 tmp = uint8[len - 1]
314 parts.push(
315 lookup[tmp >> 2] +
316 lookup[(tmp << 4) & 0x3F] +
317 '=='
318 )
319 } else if (extraBytes === 2) {
320 tmp = (uint8[len - 2] << 8) + uint8[len - 1]
321 parts.push(
322 lookup[tmp >> 10] +
323 lookup[(tmp >> 4) & 0x3F] +
324 lookup[(tmp << 2) & 0x3F] +
325 '='
326 )
327 }
328
329 return parts.join('')
330}
331
332},{}],4:[function(require,module,exports){
333
334},{}],5:[function(require,module,exports){
335var basex = require('base-x')
336var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
337
338module.exports = basex(ALPHABET)
339
340},{"base-x":2}],6:[function(require,module,exports){
341(function (Buffer){
342/*!
343 * The buffer module from node.js, for the browser.
344 *
345 * @author Feross Aboukhadijeh <https://feross.org>
346 * @license MIT
347 */
348/* eslint-disable no-proto */
349
350'use strict'
351
352var base64 = require('base64-js')
353var ieee754 = require('ieee754')
354
355exports.Buffer = Buffer
356exports.SlowBuffer = SlowBuffer
357exports.INSPECT_MAX_BYTES = 50
358
359var K_MAX_LENGTH = 0x7fffffff
360exports.kMaxLength = K_MAX_LENGTH
361
362/**
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)
367 *
368 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
369 * Opera 11.6+, iOS 4.2+.
370 *
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.
375 */
376Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
377
378if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
379 typeof console.error === 'function') {
380 console.error(
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.'
383 )
384}
385
386function typedArraySupport () {
387 // Can typed array instances can be augmented?
388 try {
389 var arr = new Uint8Array(1)
390 arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }
391 return arr.foo() === 42
392 } catch (e) {
393 return false
394 }
395}
396
397Object.defineProperty(Buffer.prototype, 'parent', {
398 enumerable: true,
399 get: function () {
400 if (!Buffer.isBuffer(this)) return undefined
401 return this.buffer
402 }
403})
404
405Object.defineProperty(Buffer.prototype, 'offset', {
406 enumerable: true,
407 get: function () {
408 if (!Buffer.isBuffer(this)) return undefined
409 return this.byteOffset
410 }
411})
412
413function createBuffer (length) {
414 if (length > K_MAX_LENGTH) {
415 throw new RangeError('The value "' + length + '" is invalid for option "size"')
416 }
417 // Return an augmented `Uint8Array` instance
418 var buf = new Uint8Array(length)
419 buf.__proto__ = Buffer.prototype
420 return buf
421}
422
423/**
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.
429 *
430 * The `Uint8Array` prototype remains unmodified.
431 */
432
433function Buffer (arg, encodingOrOffset, length) {
434 // Common case.
435 if (typeof arg === 'number') {
436 if (typeof encodingOrOffset === 'string') {
437 throw new TypeError(
438 'The "string" argument must be of type string. Received type number'
439 )
440 }
441 return allocUnsafe(arg)
442 }
443 return from(arg, encodingOrOffset, length)
444}
445
446// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
447if (typeof Symbol !== 'undefined' && Symbol.species != null &&
448 Buffer[Symbol.species] === Buffer) {
449 Object.defineProperty(Buffer, Symbol.species, {
450 value: null,
451 configurable: true,
452 enumerable: false,
453 writable: false
454 })
455}
456
457Buffer.poolSize = 8192 // not used by this implementation
458
459function from (value, encodingOrOffset, length) {
460 if (typeof value === 'string') {
461 return fromString(value, encodingOrOffset)
462 }
463
464 if (ArrayBuffer.isView(value)) {
465 return fromArrayLike(value)
466 }
467
468 if (value == null) {
469 throw TypeError(
470 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
471 'or Array-like Object. Received type ' + (typeof value)
472 )
473 }
474
475 if (isInstance(value, ArrayBuffer) ||
476 (value && isInstance(value.buffer, ArrayBuffer))) {
477 return fromArrayBuffer(value, encodingOrOffset, length)
478 }
479
480 if (typeof value === 'number') {
481 throw new TypeError(
482 'The "value" argument must not be of type number. Received type number'
483 )
484 }
485
486 var valueOf = value.valueOf && value.valueOf()
487 if (valueOf != null && valueOf !== value) {
488 return Buffer.from(valueOf, encodingOrOffset, length)
489 }
490
491 var b = fromObject(value)
492 if (b) return b
493
494 if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
495 typeof value[Symbol.toPrimitive] === 'function') {
496 return Buffer.from(
497 value[Symbol.toPrimitive]('string'), encodingOrOffset, length
498 )
499 }
500
501 throw new TypeError(
502 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
503 'or Array-like Object. Received type ' + (typeof value)
504 )
505}
506
507/**
508 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
509 * if value is a number.
510 * Buffer.from(str[, encoding])
511 * Buffer.from(array)
512 * Buffer.from(buffer)
513 * Buffer.from(arrayBuffer[, byteOffset[, length]])
514 **/
515Buffer.from = function (value, encodingOrOffset, length) {
516 return from(value, encodingOrOffset, length)
517}
518
519// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
520// https://github.com/feross/buffer/pull/148
521Buffer.prototype.__proto__ = Uint8Array.prototype
522Buffer.__proto__ = Uint8Array
523
524function 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"')
529 }
530}
531
532function alloc (size, fill, encoding) {
533 assertSize(size)
534 if (size <= 0) {
535 return createBuffer(size)
536 }
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)
544 }
545 return createBuffer(size)
546}
547
548/**
549 * Creates a new filled Buffer instance.
550 * alloc(size[, fill[, encoding]])
551 **/
552Buffer.alloc = function (size, fill, encoding) {
553 return alloc(size, fill, encoding)
554}
555
556function allocUnsafe (size) {
557 assertSize(size)
558 return createBuffer(size < 0 ? 0 : checked(size) | 0)
559}
560
561/**
562 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
563 * */
564Buffer.allocUnsafe = function (size) {
565 return allocUnsafe(size)
566}
567/**
568 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
569 */
570Buffer.allocUnsafeSlow = function (size) {
571 return allocUnsafe(size)
572}
573
574function fromString (string, encoding) {
575 if (typeof encoding !== 'string' || encoding === '') {
576 encoding = 'utf8'
577 }
578
579 if (!Buffer.isEncoding(encoding)) {
580 throw new TypeError('Unknown encoding: ' + encoding)
581 }
582
583 var length = byteLength(string, encoding) | 0
584 var buf = createBuffer(length)
585
586 var actual = buf.write(string, encoding)
587
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)
593 }
594
595 return buf
596}
597
598function 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
603 }
604 return buf
605}
606
607function fromArrayBuffer (array, byteOffset, length) {
608 if (byteOffset < 0 || array.byteLength < byteOffset) {
609 throw new RangeError('"offset" is outside of buffer bounds')
610 }
611
612 if (array.byteLength < byteOffset + (length || 0)) {
613 throw new RangeError('"length" is outside of buffer bounds')
614 }
615
616 var buf
617 if (byteOffset === undefined && length === undefined) {
618 buf = new Uint8Array(array)
619 } else if (length === undefined) {
620 buf = new Uint8Array(array, byteOffset)
621 } else {
622 buf = new Uint8Array(array, byteOffset, length)
623 }
624
625 // Return an augmented `Uint8Array` instance
626 buf.__proto__ = Buffer.prototype
627 return buf
628}
629
630function fromObject (obj) {
631 if (Buffer.isBuffer(obj)) {
632 var len = checked(obj.length) | 0
633 var buf = createBuffer(len)
634
635 if (buf.length === 0) {
636 return buf
637 }
638
639 obj.copy(buf, 0, 0, len)
640 return buf
641 }
642
643 if (obj.length !== undefined) {
644 if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
645 return createBuffer(0)
646 }
647 return fromArrayLike(obj)
648 }
649
650 if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
651 return fromArrayLike(obj.data)
652 }
653}
654
655function 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')
661 }
662 return length | 0
663}
664
665function SlowBuffer (length) {
666 if (+length != length) { // eslint-disable-line eqeqeq
667 length = 0
668 }
669 return Buffer.alloc(+length)
670}
671
672Buffer.isBuffer = function isBuffer (b) {
673 return b != null && b._isBuffer === true &&
674 b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
675}
676
677Buffer.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)) {
681 throw new TypeError(
682 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
683 )
684 }
685
686 if (a === b) return 0
687
688 var x = a.length
689 var y = b.length
690
691 for (var i = 0, len = Math.min(x, y); i < len; ++i) {
692 if (a[i] !== b[i]) {
693 x = a[i]
694 y = b[i]
695 break
696 }
697 }
698
699 if (x < y) return -1
700 if (y < x) return 1
701 return 0
702}
703
704Buffer.isEncoding = function isEncoding (encoding) {
705 switch (String(encoding).toLowerCase()) {
706 case 'hex':
707 case 'utf8':
708 case 'utf-8':
709 case 'ascii':
710 case 'latin1':
711 case 'binary':
712 case 'base64':
713 case 'ucs2':
714 case 'ucs-2':
715 case 'utf16le':
716 case 'utf-16le':
717 return true
718 default:
719 return false
720 }
721}
722
723Buffer.concat = function concat (list, length) {
724 if (!Array.isArray(list)) {
725 throw new TypeError('"list" argument must be an Array of Buffers')
726 }
727
728 if (list.length === 0) {
729 return Buffer.alloc(0)
730 }
731
732 var i
733 if (length === undefined) {
734 length = 0
735 for (i = 0; i < list.length; ++i) {
736 length += list[i].length
737 }
738 }
739
740 var buffer = Buffer.allocUnsafe(length)
741 var pos = 0
742 for (i = 0; i < list.length; ++i) {
743 var buf = list[i]
744 if (isInstance(buf, Uint8Array)) {
745 buf = Buffer.from(buf)
746 }
747 if (!Buffer.isBuffer(buf)) {
748 throw new TypeError('"list" argument must be an Array of Buffers')
749 }
750 buf.copy(buffer, pos)
751 pos += buf.length
752 }
753 return buffer
754}
755
756function byteLength (string, encoding) {
757 if (Buffer.isBuffer(string)) {
758 return string.length
759 }
760 if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
761 return string.byteLength
762 }
763 if (typeof string !== 'string') {
764 throw new TypeError(
765 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
766 'Received type ' + typeof string
767 )
768 }
769
770 var len = string.length
771 var mustMatch = (arguments.length > 2 && arguments[2] === true)
772 if (!mustMatch && len === 0) return 0
773
774 // Use a for loop to avoid recursion
775 var loweredCase = false
776 for (;;) {
777 switch (encoding) {
778 case 'ascii':
779 case 'latin1':
780 case 'binary':
781 return len
782 case 'utf8':
783 case 'utf-8':
784 return utf8ToBytes(string).length
785 case 'ucs2':
786 case 'ucs-2':
787 case 'utf16le':
788 case 'utf-16le':
789 return len * 2
790 case 'hex':
791 return len >>> 1
792 case 'base64':
793 return base64ToBytes(string).length
794 default:
795 if (loweredCase) {
796 return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
797 }
798 encoding = ('' + encoding).toLowerCase()
799 loweredCase = true
800 }
801 }
802}
803Buffer.byteLength = byteLength
804
805function slowToString (encoding, start, end) {
806 var loweredCase = false
807
808 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
809 // property of a typed array.
810
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) {
816 start = 0
817 }
818 // Return early if start > this.length. Done here to prevent potential uint32
819 // coercion fail below.
820 if (start > this.length) {
821 return ''
822 }
823
824 if (end === undefined || end > this.length) {
825 end = this.length
826 }
827
828 if (end <= 0) {
829 return ''
830 }
831
832 // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
833 end >>>= 0
834 start >>>= 0
835
836 if (end <= start) {
837 return ''
838 }
839
840 if (!encoding) encoding = 'utf8'
841
842 while (true) {
843 switch (encoding) {
844 case 'hex':
845 return hexSlice(this, start, end)
846
847 case 'utf8':
848 case 'utf-8':
849 return utf8Slice(this, start, end)
850
851 case 'ascii':
852 return asciiSlice(this, start, end)
853
854 case 'latin1':
855 case 'binary':
856 return latin1Slice(this, start, end)
857
858 case 'base64':
859 return base64Slice(this, start, end)
860
861 case 'ucs2':
862 case 'ucs-2':
863 case 'utf16le':
864 case 'utf-16le':
865 return utf16leSlice(this, start, end)
866
867 default:
868 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
869 encoding = (encoding + '').toLowerCase()
870 loweredCase = true
871 }
872 }
873}
874
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
881Buffer.prototype._isBuffer = true
882
883function swap (b, n, m) {
884 var i = b[n]
885 b[n] = b[m]
886 b[m] = i
887}
888
889Buffer.prototype.swap16 = function swap16 () {
890 var len = this.length
891 if (len % 2 !== 0) {
892 throw new RangeError('Buffer size must be a multiple of 16-bits')
893 }
894 for (var i = 0; i < len; i += 2) {
895 swap(this, i, i + 1)
896 }
897 return this
898}
899
900Buffer.prototype.swap32 = function swap32 () {
901 var len = this.length
902 if (len % 4 !== 0) {
903 throw new RangeError('Buffer size must be a multiple of 32-bits')
904 }
905 for (var i = 0; i < len; i += 4) {
906 swap(this, i, i + 3)
907 swap(this, i + 1, i + 2)
908 }
909 return this
910}
911
912Buffer.prototype.swap64 = function swap64 () {
913 var len = this.length
914 if (len % 8 !== 0) {
915 throw new RangeError('Buffer size must be a multiple of 64-bits')
916 }
917 for (var i = 0; i < len; i += 8) {
918 swap(this, i, i + 7)
919 swap(this, i + 1, i + 6)
920 swap(this, i + 2, i + 5)
921 swap(this, i + 3, i + 4)
922 }
923 return this
924}
925
926Buffer.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)
931}
932
933Buffer.prototype.toLocaleString = Buffer.prototype.toString
934
935Buffer.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
939}
940
941Buffer.prototype.inspect = function inspect () {
942 var str = ''
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 + '>'
947}
948
949Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
950 if (isInstance(target, Uint8Array)) {
951 target = Buffer.from(target, target.offset, target.byteLength)
952 }
953 if (!Buffer.isBuffer(target)) {
954 throw new TypeError(
955 'The "target" argument must be one of type Buffer or Uint8Array. ' +
956 'Received type ' + (typeof target)
957 )
958 }
959
960 if (start === undefined) {
961 start = 0
962 }
963 if (end === undefined) {
964 end = target ? target.length : 0
965 }
966 if (thisStart === undefined) {
967 thisStart = 0
968 }
969 if (thisEnd === undefined) {
970 thisEnd = this.length
971 }
972
973 if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
974 throw new RangeError('out of range index')
975 }
976
977 if (thisStart >= thisEnd && start >= end) {
978 return 0
979 }
980 if (thisStart >= thisEnd) {
981 return -1
982 }
983 if (start >= end) {
984 return 1
985 }
986
987 start >>>= 0
988 end >>>= 0
989 thisStart >>>= 0
990 thisEnd >>>= 0
991
992 if (this === target) return 0
993
994 var x = thisEnd - thisStart
995 var y = end - start
996 var len = Math.min(x, y)
997
998 var thisCopy = this.slice(thisStart, thisEnd)
999 var targetCopy = target.slice(start, end)
1000
1001 for (var i = 0; i < len; ++i) {
1002 if (thisCopy[i] !== targetCopy[i]) {
1003 x = thisCopy[i]
1004 y = targetCopy[i]
1005 break
1006 }
1007 }
1008
1009 if (x < y) return -1
1010 if (y < x) return 1
1011 return 0
1012}
1013
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`.
1016//
1017// Arguments:
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
1023function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
1024 // Empty buffer means no match
1025 if (buffer.length === 0) return -1
1026
1027 // Normalize byteOffset
1028 if (typeof byteOffset === 'string') {
1029 encoding = byteOffset
1030 byteOffset = 0
1031 } else if (byteOffset > 0x7fffffff) {
1032 byteOffset = 0x7fffffff
1033 } else if (byteOffset < -0x80000000) {
1034 byteOffset = -0x80000000
1035 }
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)
1040 }
1041
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) {
1045 if (dir) return -1
1046 else byteOffset = buffer.length - 1
1047 } else if (byteOffset < 0) {
1048 if (dir) byteOffset = 0
1049 else return -1
1050 }
1051
1052 // Normalize val
1053 if (typeof val === 'string') {
1054 val = Buffer.from(val, encoding)
1055 }
1056
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) {
1061 return -1
1062 }
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') {
1067 if (dir) {
1068 return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
1069 } else {
1070 return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
1071 }
1072 }
1073 return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
1074 }
1075
1076 throw new TypeError('val must be string, number or Buffer')
1077}
1078
1079function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
1080 var indexSize = 1
1081 var arrLength = arr.length
1082 var valLength = val.length
1083
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) {
1089 return -1
1090 }
1091 indexSize = 2
1092 arrLength /= 2
1093 valLength /= 2
1094 byteOffset /= 2
1095 }
1096 }
1097
1098 function read (buf, i) {
1099 if (indexSize === 1) {
1100 return buf[i]
1101 } else {
1102 return buf.readUInt16BE(i * indexSize)
1103 }
1104 }
1105
1106 var i
1107 if (dir) {
1108 var foundIndex = -1
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
1113 } else {
1114 if (foundIndex !== -1) i -= i - foundIndex
1115 foundIndex = -1
1116 }
1117 }
1118 } else {
1119 if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
1120 for (i = byteOffset; i >= 0; i--) {
1121 var found = true
1122 for (var j = 0; j < valLength; j++) {
1123 if (read(arr, i + j) !== read(val, j)) {
1124 found = false
1125 break
1126 }
1127 }
1128 if (found) return i
1129 }
1130 }
1131
1132 return -1
1133}
1134
1135Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
1136 return this.indexOf(val, byteOffset, encoding) !== -1
1137}
1138
1139Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
1140 return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
1141}
1142
1143Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
1144 return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
1145}
1146
1147function hexWrite (buf, string, offset, length) {
1148 offset = Number(offset) || 0
1149 var remaining = buf.length - offset
1150 if (!length) {
1151 length = remaining
1152 } else {
1153 length = Number(length)
1154 if (length > remaining) {
1155 length = remaining
1156 }
1157 }
1158
1159 var strLen = string.length
1160
1161 if (length > strLen / 2) {
1162 length = strLen / 2
1163 }
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
1168 }
1169 return i
1170}
1171
1172function utf8Write (buf, string, offset, length) {
1173 return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
1174}
1175
1176function asciiWrite (buf, string, offset, length) {
1177 return blitBuffer(asciiToBytes(string), buf, offset, length)
1178}
1179
1180function latin1Write (buf, string, offset, length) {
1181 return asciiWrite(buf, string, offset, length)
1182}
1183
1184function base64Write (buf, string, offset, length) {
1185 return blitBuffer(base64ToBytes(string), buf, offset, length)
1186}
1187
1188function ucs2Write (buf, string, offset, length) {
1189 return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
1190}
1191
1192Buffer.prototype.write = function write (string, offset, length, encoding) {
1193 // Buffer#write(string)
1194 if (offset === undefined) {
1195 encoding = 'utf8'
1196 length = this.length
1197 offset = 0
1198 // Buffer#write(string, encoding)
1199 } else if (length === undefined && typeof offset === 'string') {
1200 encoding = offset
1201 length = this.length
1202 offset = 0
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'
1209 } else {
1210 encoding = length
1211 length = undefined
1212 }
1213 } else {
1214 throw new Error(
1215 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
1216 )
1217 }
1218
1219 var remaining = this.length - offset
1220 if (length === undefined || length > remaining) length = remaining
1221
1222 if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
1223 throw new RangeError('Attempt to write outside buffer bounds')
1224 }
1225
1226 if (!encoding) encoding = 'utf8'
1227
1228 var loweredCase = false
1229 for (;;) {
1230 switch (encoding) {
1231 case 'hex':
1232 return hexWrite(this, string, offset, length)
1233
1234 case 'utf8':
1235 case 'utf-8':
1236 return utf8Write(this, string, offset, length)
1237
1238 case 'ascii':
1239 return asciiWrite(this, string, offset, length)
1240
1241 case 'latin1':
1242 case 'binary':
1243 return latin1Write(this, string, offset, length)
1244
1245 case 'base64':
1246 // Warning: maxLength not taken into account in base64Write
1247 return base64Write(this, string, offset, length)
1248
1249 case 'ucs2':
1250 case 'ucs-2':
1251 case 'utf16le':
1252 case 'utf-16le':
1253 return ucs2Write(this, string, offset, length)
1254
1255 default:
1256 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
1257 encoding = ('' + encoding).toLowerCase()
1258 loweredCase = true
1259 }
1260 }
1261}
1262
1263Buffer.prototype.toJSON = function toJSON () {
1264 return {
1265 type: 'Buffer',
1266 data: Array.prototype.slice.call(this._arr || this, 0)
1267 }
1268}
1269
1270function base64Slice (buf, start, end) {
1271 if (start === 0 && end === buf.length) {
1272 return base64.fromByteArray(buf)
1273 } else {
1274 return base64.fromByteArray(buf.slice(start, end))
1275 }
1276}
1277
1278function utf8Slice (buf, start, end) {
1279 end = Math.min(buf.length, end)
1280 var res = []
1281
1282 var i = start
1283 while (i < end) {
1284 var firstByte = buf[i]
1285 var codePoint = null
1286 var bytesPerSequence = (firstByte > 0xEF) ? 4
1287 : (firstByte > 0xDF) ? 3
1288 : (firstByte > 0xBF) ? 2
1289 : 1
1290
1291 if (i + bytesPerSequence <= end) {
1292 var secondByte, thirdByte, fourthByte, tempCodePoint
1293
1294 switch (bytesPerSequence) {
1295 case 1:
1296 if (firstByte < 0x80) {
1297 codePoint = firstByte
1298 }
1299 break
1300 case 2:
1301 secondByte = buf[i + 1]
1302 if ((secondByte & 0xC0) === 0x80) {
1303 tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
1304 if (tempCodePoint > 0x7F) {
1305 codePoint = tempCodePoint
1306 }
1307 }
1308 break
1309 case 3:
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
1316 }
1317 }
1318 break
1319 case 4:
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
1327 }
1328 }
1329 }
1330 }
1331
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
1335 codePoint = 0xFFFD
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
1342 }
1343
1344 res.push(codePoint)
1345 i += bytesPerSequence
1346 }
1347
1348 return decodeCodePointsArray(res)
1349}
1350
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
1354var MAX_ARGUMENTS_LENGTH = 0x1000
1355
1356function decodeCodePointsArray (codePoints) {
1357 var len = codePoints.length
1358 if (len <= MAX_ARGUMENTS_LENGTH) {
1359 return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
1360 }
1361
1362 // Decode in chunks to avoid "call stack size exceeded".
1363 var res = ''
1364 var i = 0
1365 while (i < len) {
1366 res += String.fromCharCode.apply(
1367 String,
1368 codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
1369 )
1370 }
1371 return res
1372}
1373
1374function asciiSlice (buf, start, end) {
1375 var ret = ''
1376 end = Math.min(buf.length, end)
1377
1378 for (var i = start; i < end; ++i) {
1379 ret += String.fromCharCode(buf[i] & 0x7F)
1380 }
1381 return ret
1382}
1383
1384function latin1Slice (buf, start, end) {
1385 var ret = ''
1386 end = Math.min(buf.length, end)
1387
1388 for (var i = start; i < end; ++i) {
1389 ret += String.fromCharCode(buf[i])
1390 }
1391 return ret
1392}
1393
1394function hexSlice (buf, start, end) {
1395 var len = buf.length
1396
1397 if (!start || start < 0) start = 0
1398 if (!end || end < 0 || end > len) end = len
1399
1400 var out = ''
1401 for (var i = start; i < end; ++i) {
1402 out += toHex(buf[i])
1403 }
1404 return out
1405}
1406
1407function utf16leSlice (buf, start, end) {
1408 var bytes = buf.slice(start, end)
1409 var res = ''
1410 for (var i = 0; i < bytes.length; i += 2) {
1411 res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
1412 }
1413 return res
1414}
1415
1416Buffer.prototype.slice = function slice (start, end) {
1417 var len = this.length
1418 start = ~~start
1419 end = end === undefined ? len : ~~end
1420
1421 if (start < 0) {
1422 start += len
1423 if (start < 0) start = 0
1424 } else if (start > len) {
1425 start = len
1426 }
1427
1428 if (end < 0) {
1429 end += len
1430 if (end < 0) end = 0
1431 } else if (end > len) {
1432 end = len
1433 }
1434
1435 if (end < start) end = start
1436
1437 var newBuf = this.subarray(start, end)
1438 // Return an augmented `Uint8Array` instance
1439 newBuf.__proto__ = Buffer.prototype
1440 return newBuf
1441}
1442
1443/*
1444 * Need to make sure that buffer isn't trying to write out of bounds.
1445 */
1446function 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')
1449}
1450
1451Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
1452 offset = offset >>> 0
1453 byteLength = byteLength >>> 0
1454 if (!noAssert) checkOffset(offset, byteLength, this.length)
1455
1456 var val = this[offset]
1457 var mul = 1
1458 var i = 0
1459 while (++i < byteLength && (mul *= 0x100)) {
1460 val += this[offset + i] * mul
1461 }
1462
1463 return val
1464}
1465
1466Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
1467 offset = offset >>> 0
1468 byteLength = byteLength >>> 0
1469 if (!noAssert) {
1470 checkOffset(offset, byteLength, this.length)
1471 }
1472
1473 var val = this[offset + --byteLength]
1474 var mul = 1
1475 while (byteLength > 0 && (mul *= 0x100)) {
1476 val += this[offset + --byteLength] * mul
1477 }
1478
1479 return val
1480}
1481
1482Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
1483 offset = offset >>> 0
1484 if (!noAssert) checkOffset(offset, 1, this.length)
1485 return this[offset]
1486}
1487
1488Buffer.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)
1492}
1493
1494Buffer.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]
1498}
1499
1500Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
1501 offset = offset >>> 0
1502 if (!noAssert) checkOffset(offset, 4, this.length)
1503
1504 return ((this[offset]) |
1505 (this[offset + 1] << 8) |
1506 (this[offset + 2] << 16)) +
1507 (this[offset + 3] * 0x1000000)
1508}
1509
1510Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
1511 offset = offset >>> 0
1512 if (!noAssert) checkOffset(offset, 4, this.length)
1513
1514 return (this[offset] * 0x1000000) +
1515 ((this[offset + 1] << 16) |
1516 (this[offset + 2] << 8) |
1517 this[offset + 3])
1518}
1519
1520Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
1521 offset = offset >>> 0
1522 byteLength = byteLength >>> 0
1523 if (!noAssert) checkOffset(offset, byteLength, this.length)
1524
1525 var val = this[offset]
1526 var mul = 1
1527 var i = 0
1528 while (++i < byteLength && (mul *= 0x100)) {
1529 val += this[offset + i] * mul
1530 }
1531 mul *= 0x80
1532
1533 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
1534
1535 return val
1536}
1537
1538Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
1539 offset = offset >>> 0
1540 byteLength = byteLength >>> 0
1541 if (!noAssert) checkOffset(offset, byteLength, this.length)
1542
1543 var i = byteLength
1544 var mul = 1
1545 var val = this[offset + --i]
1546 while (i > 0 && (mul *= 0x100)) {
1547 val += this[offset + --i] * mul
1548 }
1549 mul *= 0x80
1550
1551 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
1552
1553 return val
1554}
1555
1556Buffer.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)
1561}
1562
1563Buffer.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
1568}
1569
1570Buffer.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
1575}
1576
1577Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
1578 offset = offset >>> 0
1579 if (!noAssert) checkOffset(offset, 4, this.length)
1580
1581 return (this[offset]) |
1582 (this[offset + 1] << 8) |
1583 (this[offset + 2] << 16) |
1584 (this[offset + 3] << 24)
1585}
1586
1587Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
1588 offset = offset >>> 0
1589 if (!noAssert) checkOffset(offset, 4, this.length)
1590
1591 return (this[offset] << 24) |
1592 (this[offset + 1] << 16) |
1593 (this[offset + 2] << 8) |
1594 (this[offset + 3])
1595}
1596
1597Buffer.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)
1601}
1602
1603Buffer.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)
1607}
1608
1609Buffer.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)
1613}
1614
1615Buffer.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)
1619}
1620
1621function 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')
1625}
1626
1627Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
1628 value = +value
1629 offset = offset >>> 0
1630 byteLength = byteLength >>> 0
1631 if (!noAssert) {
1632 var maxBytes = Math.pow(2, 8 * byteLength) - 1
1633 checkInt(this, value, offset, byteLength, maxBytes, 0)
1634 }
1635
1636 var mul = 1
1637 var i = 0
1638 this[offset] = value & 0xFF
1639 while (++i < byteLength && (mul *= 0x100)) {
1640 this[offset + i] = (value / mul) & 0xFF
1641 }
1642
1643 return offset + byteLength
1644}
1645
1646Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
1647 value = +value
1648 offset = offset >>> 0
1649 byteLength = byteLength >>> 0
1650 if (!noAssert) {
1651 var maxBytes = Math.pow(2, 8 * byteLength) - 1
1652 checkInt(this, value, offset, byteLength, maxBytes, 0)
1653 }
1654
1655 var i = byteLength - 1
1656 var mul = 1
1657 this[offset + i] = value & 0xFF
1658 while (--i >= 0 && (mul *= 0x100)) {
1659 this[offset + i] = (value / mul) & 0xFF
1660 }
1661
1662 return offset + byteLength
1663}
1664
1665Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
1666 value = +value
1667 offset = offset >>> 0
1668 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
1669 this[offset] = (value & 0xff)
1670 return offset + 1
1671}
1672
1673Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
1674 value = +value
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)
1679 return offset + 2
1680}
1681
1682Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
1683 value = +value
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)
1688 return offset + 2
1689}
1690
1691Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
1692 value = +value
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)
1699 return offset + 4
1700}
1701
1702Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
1703 value = +value
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)
1710 return offset + 4
1711}
1712
1713Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
1714 value = +value
1715 offset = offset >>> 0
1716 if (!noAssert) {
1717 var limit = Math.pow(2, (8 * byteLength) - 1)
1718
1719 checkInt(this, value, offset, byteLength, limit - 1, -limit)
1720 }
1721
1722 var i = 0
1723 var mul = 1
1724 var sub = 0
1725 this[offset] = value & 0xFF
1726 while (++i < byteLength && (mul *= 0x100)) {
1727 if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
1728 sub = 1
1729 }
1730 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
1731 }
1732
1733 return offset + byteLength
1734}
1735
1736Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
1737 value = +value
1738 offset = offset >>> 0
1739 if (!noAssert) {
1740 var limit = Math.pow(2, (8 * byteLength) - 1)
1741
1742 checkInt(this, value, offset, byteLength, limit - 1, -limit)
1743 }
1744
1745 var i = byteLength - 1
1746 var mul = 1
1747 var sub = 0
1748 this[offset + i] = value & 0xFF
1749 while (--i >= 0 && (mul *= 0x100)) {
1750 if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
1751 sub = 1
1752 }
1753 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
1754 }
1755
1756 return offset + byteLength
1757}
1758
1759Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
1760 value = +value
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)
1765 return offset + 1
1766}
1767
1768Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
1769 value = +value
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)
1774 return offset + 2
1775}
1776
1777Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
1778 value = +value
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)
1783 return offset + 2
1784}
1785
1786Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
1787 value = +value
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)
1794 return offset + 4
1795}
1796
1797Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
1798 value = +value
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)
1806 return offset + 4
1807}
1808
1809function 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')
1812}
1813
1814function writeFloat (buf, value, offset, littleEndian, noAssert) {
1815 value = +value
1816 offset = offset >>> 0
1817 if (!noAssert) {
1818 checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
1819 }
1820 ieee754.write(buf, value, offset, littleEndian, 23, 4)
1821 return offset + 4
1822}
1823
1824Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
1825 return writeFloat(this, value, offset, true, noAssert)
1826}
1827
1828Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
1829 return writeFloat(this, value, offset, false, noAssert)
1830}
1831
1832function writeDouble (buf, value, offset, littleEndian, noAssert) {
1833 value = +value
1834 offset = offset >>> 0
1835 if (!noAssert) {
1836 checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
1837 }
1838 ieee754.write(buf, value, offset, littleEndian, 52, 8)
1839 return offset + 8
1840}
1841
1842Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
1843 return writeDouble(this, value, offset, true, noAssert)
1844}
1845
1846Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
1847 return writeDouble(this, value, offset, false, noAssert)
1848}
1849
1850// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
1851Buffer.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
1858
1859 // Copy 0 bytes; we're done
1860 if (end === start) return 0
1861 if (target.length === 0 || this.length === 0) return 0
1862
1863 // Fatal error conditions
1864 if (targetStart < 0) {
1865 throw new RangeError('targetStart out of bounds')
1866 }
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')
1869
1870 // Are we oob?
1871 if (end > this.length) end = this.length
1872 if (target.length - targetStart < end - start) {
1873 end = target.length - targetStart + start
1874 }
1875
1876 var len = end - start
1877
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]
1885 }
1886 } else {
1887 Uint8Array.prototype.set.call(
1888 target,
1889 this.subarray(start, end),
1890 targetStart
1891 )
1892 }
1893
1894 return len
1895}
1896
1897// Usage:
1898// buffer.fill(number[, offset[, end]])
1899// buffer.fill(buffer[, offset[, end]])
1900// buffer.fill(string[, offset[, end]][, encoding])
1901Buffer.prototype.fill = function fill (val, start, end, encoding) {
1902 // Handle string cases:
1903 if (typeof val === 'string') {
1904 if (typeof start === 'string') {
1905 encoding = start
1906 start = 0
1907 end = this.length
1908 } else if (typeof end === 'string') {
1909 encoding = end
1910 end = this.length
1911 }
1912 if (encoding !== undefined && typeof encoding !== 'string') {
1913 throw new TypeError('encoding must be a string')
1914 }
1915 if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
1916 throw new TypeError('Unknown encoding: ' + encoding)
1917 }
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.
1923 val = code
1924 }
1925 }
1926 } else if (typeof val === 'number') {
1927 val = val & 255
1928 }
1929
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')
1933 }
1934
1935 if (end <= start) {
1936 return this
1937 }
1938
1939 start = start >>> 0
1940 end = end === undefined ? this.length : end >>> 0
1941
1942 if (!val) val = 0
1943
1944 var i
1945 if (typeof val === 'number') {
1946 for (i = start; i < end; ++i) {
1947 this[i] = val
1948 }
1949 } else {
1950 var bytes = Buffer.isBuffer(val)
1951 ? val
1952 : Buffer.from(val, encoding)
1953 var len = bytes.length
1954 if (len === 0) {
1955 throw new TypeError('The value "' + val +
1956 '" is invalid for argument "value"')
1957 }
1958 for (i = 0; i < end - start; ++i) {
1959 this[i + start] = bytes[i % len]
1960 }
1961 }
1962
1963 return this
1964}
1965
1966// HELPER FUNCTIONS
1967// ================
1968
1969var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
1970
1971function 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) {
1980 str = str + '='
1981 }
1982 return str
1983}
1984
1985function toHex (n) {
1986 if (n < 16) return '0' + n.toString(16)
1987 return n.toString(16)
1988}
1989
1990function utf8ToBytes (string, units) {
1991 units = units || Infinity
1992 var codePoint
1993 var length = string.length
1994 var leadSurrogate = null
1995 var bytes = []
1996
1997 for (var i = 0; i < length; ++i) {
1998 codePoint = string.charCodeAt(i)
1999
2000 // is surrogate component
2001 if (codePoint > 0xD7FF && codePoint < 0xE000) {
2002 // last char was a lead
2003 if (!leadSurrogate) {
2004 // no lead yet
2005 if (codePoint > 0xDBFF) {
2006 // unexpected trail
2007 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
2008 continue
2009 } else if (i + 1 === length) {
2010 // unpaired lead
2011 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
2012 continue
2013 }
2014
2015 // valid lead
2016 leadSurrogate = codePoint
2017
2018 continue
2019 }
2020
2021 // 2 leads in a row
2022 if (codePoint < 0xDC00) {
2023 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
2024 leadSurrogate = codePoint
2025 continue
2026 }
2027
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)
2033 }
2034
2035 leadSurrogate = null
2036
2037 // encode utf8
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
2043 bytes.push(
2044 codePoint >> 0x6 | 0xC0,
2045 codePoint & 0x3F | 0x80
2046 )
2047 } else if (codePoint < 0x10000) {
2048 if ((units -= 3) < 0) break
2049 bytes.push(
2050 codePoint >> 0xC | 0xE0,
2051 codePoint >> 0x6 & 0x3F | 0x80,
2052 codePoint & 0x3F | 0x80
2053 )
2054 } else if (codePoint < 0x110000) {
2055 if ((units -= 4) < 0) break
2056 bytes.push(
2057 codePoint >> 0x12 | 0xF0,
2058 codePoint >> 0xC & 0x3F | 0x80,
2059 codePoint >> 0x6 & 0x3F | 0x80,
2060 codePoint & 0x3F | 0x80
2061 )
2062 } else {
2063 throw new Error('Invalid code point')
2064 }
2065 }
2066
2067 return bytes
2068}
2069
2070function asciiToBytes (str) {
2071 var byteArray = []
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)
2075 }
2076 return byteArray
2077}
2078
2079function utf16leToBytes (str, units) {
2080 var c, hi, lo
2081 var byteArray = []
2082 for (var i = 0; i < str.length; ++i) {
2083 if ((units -= 2) < 0) break
2084
2085 c = str.charCodeAt(i)
2086 hi = c >> 8
2087 lo = c % 256
2088 byteArray.push(lo)
2089 byteArray.push(hi)
2090 }
2091
2092 return byteArray
2093}
2094
2095function base64ToBytes (str) {
2096 return base64.toByteArray(base64clean(str))
2097}
2098
2099function 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]
2103 }
2104 return i
2105}
2106
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
2110function isInstance (obj, type) {
2111 return obj instanceof type ||
2112 (obj != null && obj.constructor != null && obj.constructor.name != null &&
2113 obj.constructor.name === type.name)
2114}
2115function numberIsNaN (obj) {
2116 // For IE11 support
2117 return obj !== obj // eslint-disable-line no-self-compare
2118}
2119
2120}).call(this,require("buffer").Buffer)
2121},{"base64-js":3,"buffer":6,"ieee754":12}],7:[function(require,module,exports){
2122var Buffer = require('safe-buffer').Buffer
2123var Transform = require('stream').Transform
2124var StringDecoder = require('string_decoder').StringDecoder
2125var inherits = require('inherits')
2126
2127function CipherBase (hashMode) {
2128 Transform.call(this)
2129 this.hashMode = typeof hashMode === 'string'
2130 if (this.hashMode) {
2131 this[hashMode] = this._finalOrDigest
2132 } else {
2133 this.final = this._finalOrDigest
2134 }
2135 if (this._final) {
2136 this.__final = this._final
2137 this._final = null
2138 }
2139 this._decoder = null
2140 this._encoding = null
2141}
2142inherits(CipherBase, Transform)
2143
2144CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
2145 if (typeof data === 'string') {
2146 data = Buffer.from(data, inputEnc)
2147 }
2148
2149 var outData = this._update(data)
2150 if (this.hashMode) return this
2151
2152 if (outputEnc) {
2153 outData = this._toString(outData, outputEnc)
2154 }
2155
2156 return outData
2157}
2158
2159CipherBase.prototype.setAutoPadding = function () {}
2160CipherBase.prototype.getAuthTag = function () {
2161 throw new Error('trying to get auth tag in unsupported state')
2162}
2163
2164CipherBase.prototype.setAuthTag = function () {
2165 throw new Error('trying to set auth tag in unsupported state')
2166}
2167
2168CipherBase.prototype.setAAD = function () {
2169 throw new Error('trying to set aad in unsupported state')
2170}
2171
2172CipherBase.prototype._transform = function (data, _, next) {
2173 var err
2174 try {
2175 if (this.hashMode) {
2176 this._update(data)
2177 } else {
2178 this.push(this._update(data))
2179 }
2180 } catch (e) {
2181 err = e
2182 } finally {
2183 next(err)
2184 }
2185}
2186CipherBase.prototype._flush = function (done) {
2187 var err
2188 try {
2189 this.push(this.__final())
2190 } catch (e) {
2191 err = e
2192 }
2193
2194 done(err)
2195}
2196CipherBase.prototype._finalOrDigest = function (outputEnc) {
2197 var outData = this.__final() || Buffer.alloc(0)
2198 if (outputEnc) {
2199 outData = this._toString(outData, outputEnc, true)
2200 }
2201 return outData
2202}
2203
2204CipherBase.prototype._toString = function (value, enc, fin) {
2205 if (!this._decoder) {
2206 this._decoder = new StringDecoder(enc)
2207 this._encoding = enc
2208 }
2209
2210 if (this._encoding !== enc) throw new Error('can\'t switch encodings')
2211
2212 var out = this._decoder.write(value)
2213 if (fin) {
2214 out += this._decoder.end()
2215 }
2216
2217 return out
2218}
2219
2220module.exports = CipherBase
2221
2222},{"inherits":13,"safe-buffer":34,"stream":43,"string_decoder":44}],8:[function(require,module,exports){
2223(function (Buffer){
2224// Copyright Joyent, Inc. and other Node contributors.
2225//
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:
2233//
2234// The above copyright notice and this permission notice shall be included
2235// in all copies or substantial portions of the Software.
2236//
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.
2244
2245// NOTE: These type checking functions intentionally don't use `instanceof`
2246// because it is fragile and can be easily faked with `Object.create()`.
2247
2248function isArray(arg) {
2249 if (Array.isArray) {
2250 return Array.isArray(arg);
2251 }
2252 return objectToString(arg) === '[object Array]';
2253}
2254exports.isArray = isArray;
2255
2256function isBoolean(arg) {
2257 return typeof arg === 'boolean';
2258}
2259exports.isBoolean = isBoolean;
2260
2261function isNull(arg) {
2262 return arg === null;
2263}
2264exports.isNull = isNull;
2265
2266function isNullOrUndefined(arg) {
2267 return arg == null;
2268}
2269exports.isNullOrUndefined = isNullOrUndefined;
2270
2271function isNumber(arg) {
2272 return typeof arg === 'number';
2273}
2274exports.isNumber = isNumber;
2275
2276function isString(arg) {
2277 return typeof arg === 'string';
2278}
2279exports.isString = isString;
2280
2281function isSymbol(arg) {
2282 return typeof arg === 'symbol';
2283}
2284exports.isSymbol = isSymbol;
2285
2286function isUndefined(arg) {
2287 return arg === void 0;
2288}
2289exports.isUndefined = isUndefined;
2290
2291function isRegExp(re) {
2292 return objectToString(re) === '[object RegExp]';
2293}
2294exports.isRegExp = isRegExp;
2295
2296function isObject(arg) {
2297 return typeof arg === 'object' && arg !== null;
2298}
2299exports.isObject = isObject;
2300
2301function isDate(d) {
2302 return objectToString(d) === '[object Date]';
2303}
2304exports.isDate = isDate;
2305
2306function isError(e) {
2307 return (objectToString(e) === '[object Error]' || e instanceof Error);
2308}
2309exports.isError = isError;
2310
2311function isFunction(arg) {
2312 return typeof arg === 'function';
2313}
2314exports.isFunction = isFunction;
2315
2316function 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';
2323}
2324exports.isPrimitive = isPrimitive;
2325
2326exports.isBuffer = Buffer.isBuffer;
2327
2328function objectToString(o) {
2329 return Object.prototype.toString.call(o);
2330}
2331
2332}).call(this,{"isBuffer":require("../../is-buffer/index.js")})
2333},{"../../is-buffer/index.js":14}],9:[function(require,module,exports){
2334'use strict'
2335var inherits = require('inherits')
2336var MD5 = require('md5.js')
2337var RIPEMD160 = require('ripemd160')
2338var sha = require('sha.js')
2339var Base = require('cipher-base')
2340
2341function Hash (hash) {
2342 Base.call(this, 'digest')
2343
2344 this._hash = hash
2345}
2346
2347inherits(Hash, Base)
2348
2349Hash.prototype._update = function (data) {
2350 this._hash.update(data)
2351}
2352
2353Hash.prototype._final = function () {
2354 return this._hash.digest()
2355}
2356
2357module.exports = function createHash (alg) {
2358 alg = alg.toLowerCase()
2359 if (alg === 'md5') return new MD5()
2360 if (alg === 'rmd160' || alg === 'ripemd160') return new RIPEMD160()
2361
2362 return new Hash(sha(alg))
2363}
2364
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.
2367//
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:
2375//
2376// The above copyright notice and this permission notice shall be included
2377// in all copies or substantial portions of the Software.
2378//
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.
2386
2387var objectCreate = Object.create || objectCreatePolyfill
2388var objectKeys = Object.keys || objectKeysPolyfill
2389var bind = Function.prototype.bind || functionBindPolyfill
2390
2391function EventEmitter() {
2392 if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
2393 this._events = objectCreate(null);
2394 this._eventsCount = 0;
2395 }
2396
2397 this._maxListeners = this._maxListeners || undefined;
2398}
2399module.exports = EventEmitter;
2400
2401// Backwards-compat with node 0.10.x
2402EventEmitter.EventEmitter = EventEmitter;
2403
2404EventEmitter.prototype._events = undefined;
2405EventEmitter.prototype._maxListeners = undefined;
2406
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.
2409var defaultMaxListeners = 10;
2410
2411var hasDefineProperty;
2412try {
2413 var o = {};
2414 if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 });
2415 hasDefineProperty = o.x === 0;
2416} catch (err) { hasDefineProperty = false }
2417if (hasDefineProperty) {
2418 Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
2419 enumerable: true,
2420 get: function() {
2421 return defaultMaxListeners;
2422 },
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;
2429 }
2430 });
2431} else {
2432 EventEmitter.defaultMaxListeners = defaultMaxListeners;
2433}
2434
2435// Obviously not all Emitters should be limited to 10. This function allows
2436// that to be increased. Set to zero for unlimited.
2437EventEmitter.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;
2441 return this;
2442};
2443
2444function $getMaxListeners(that) {
2445 if (that._maxListeners === undefined)
2446 return EventEmitter.defaultMaxListeners;
2447 return that._maxListeners;
2448}
2449
2450EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
2451 return $getMaxListeners(this);
2452};
2453
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.
2459function emitNone(handler, isFn, self) {
2460 if (isFn)
2461 handler.call(self);
2462 else {
2463 var len = handler.length;
2464 var listeners = arrayClone(handler, len);
2465 for (var i = 0; i < len; ++i)
2466 listeners[i].call(self);
2467 }
2468}
2469function emitOne(handler, isFn, self, arg1) {
2470 if (isFn)
2471 handler.call(self, arg1);
2472 else {
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);
2477 }
2478}
2479function emitTwo(handler, isFn, self, arg1, arg2) {
2480 if (isFn)
2481 handler.call(self, arg1, arg2);
2482 else {
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);
2487 }
2488}
2489function emitThree(handler, isFn, self, arg1, arg2, arg3) {
2490 if (isFn)
2491 handler.call(self, arg1, arg2, arg3);
2492 else {
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);
2497 }
2498}
2499
2500function emitMany(handler, isFn, self, args) {
2501 if (isFn)
2502 handler.apply(self, args);
2503 else {
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);
2508 }
2509}
2510
2511EventEmitter.prototype.emit = function emit(type) {
2512 var er, handler, len, args, i, events;
2513 var doError = (type === 'error');
2514
2515 events = this._events;
2516 if (events)
2517 doError = (doError && events.error == null);
2518 else if (!doError)
2519 return false;
2520
2521 // If there is no 'error' event listener then throw.
2522 if (doError) {
2523 if (arguments.length > 1)
2524 er = arguments[1];
2525 if (er instanceof Error) {
2526 throw er; // Unhandled 'error' event
2527 } else {
2528 // At least give some kind of context to the user
2529 var err = new Error('Unhandled "error" event. (' + er + ')');
2530 err.context = er;
2531 throw err;
2532 }
2533 return false;
2534 }
2535
2536 handler = events[type];
2537
2538 if (!handler)
2539 return false;
2540
2541 var isFn = typeof handler === 'function';
2542 len = arguments.length;
2543 switch (len) {
2544 // fast cases
2545 case 1:
2546 emitNone(handler, isFn, this);
2547 break;
2548 case 2:
2549 emitOne(handler, isFn, this, arguments[1]);
2550 break;
2551 case 3:
2552 emitTwo(handler, isFn, this, arguments[1], arguments[2]);
2553 break;
2554 case 4:
2555 emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
2556 break;
2557 // slower
2558 default:
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);
2563 }
2564
2565 return true;
2566};
2567
2568function _addListener(target, type, listener, prepend) {
2569 var m;
2570 var events;
2571 var existing;
2572
2573 if (typeof listener !== 'function')
2574 throw new TypeError('"listener" argument must be a function');
2575
2576 events = target._events;
2577 if (!events) {
2578 events = target._events = objectCreate(null);
2579 target._eventsCount = 0;
2580 } else {
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);
2586
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;
2590 }
2591 existing = events[type];
2592 }
2593
2594 if (!existing) {
2595 // Optimize the case of one listener. Don't need the extra array object.
2596 existing = events[type] = listener;
2597 ++target._eventsCount;
2598 } else {
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];
2603 } else {
2604 // If we've already got an array, just append.
2605 if (prepend) {
2606 existing.unshift(listener);
2607 } else {
2608 existing.push(listener);
2609 }
2610 }
2611
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 ' +
2620 'increase limit.');
2621 w.name = 'MaxListenersExceededWarning';
2622 w.emitter = target;
2623 w.type = type;
2624 w.count = existing.length;
2625 if (typeof console === 'object' && console.warn) {
2626 console.warn('%s: %s', w.name, w.message);
2627 }
2628 }
2629 }
2630 }
2631
2632 return target;
2633}
2634
2635EventEmitter.prototype.addListener = function addListener(type, listener) {
2636 return _addListener(this, type, listener, false);
2637};
2638
2639EventEmitter.prototype.on = EventEmitter.prototype.addListener;
2640
2641EventEmitter.prototype.prependListener =
2642 function prependListener(type, listener) {
2643 return _addListener(this, type, listener, true);
2644 };
2645
2646function onceWrapper() {
2647 if (!this.fired) {
2648 this.target.removeListener(this.type, this.wrapFn);
2649 this.fired = true;
2650 switch (arguments.length) {
2651 case 0:
2652 return this.listener.call(this.target);
2653 case 1:
2654 return this.listener.call(this.target, arguments[0]);
2655 case 2:
2656 return this.listener.call(this.target, arguments[0], arguments[1]);
2657 case 3:
2658 return this.listener.call(this.target, arguments[0], arguments[1],
2659 arguments[2]);
2660 default:
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);
2665 }
2666 }
2667}
2668
2669function _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;
2674 return wrapped;
2675}
2676
2677EventEmitter.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));
2681 return this;
2682};
2683
2684EventEmitter.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));
2689 return this;
2690 };
2691
2692// Emits a 'removeListener' event if and only if the listener was removed.
2693EventEmitter.prototype.removeListener =
2694 function removeListener(type, listener) {
2695 var list, events, position, i, originalListener;
2696
2697 if (typeof listener !== 'function')
2698 throw new TypeError('"listener" argument must be a function');
2699
2700 events = this._events;
2701 if (!events)
2702 return this;
2703
2704 list = events[type];
2705 if (!list)
2706 return this;
2707
2708 if (list === listener || list.listener === listener) {
2709 if (--this._eventsCount === 0)
2710 this._events = objectCreate(null);
2711 else {
2712 delete events[type];
2713 if (events.removeListener)
2714 this.emit('removeListener', type, list.listener || listener);
2715 }
2716 } else if (typeof list !== 'function') {
2717 position = -1;
2718
2719 for (i = list.length - 1; i >= 0; i--) {
2720 if (list[i] === listener || list[i].listener === listener) {
2721 originalListener = list[i].listener;
2722 position = i;
2723 break;
2724 }
2725 }
2726
2727 if (position < 0)
2728 return this;
2729
2730 if (position === 0)
2731 list.shift();
2732 else
2733 spliceOne(list, position);
2734
2735 if (list.length === 1)
2736 events[type] = list[0];
2737
2738 if (events.removeListener)
2739 this.emit('removeListener', type, originalListener || listener);
2740 }
2741
2742 return this;
2743 };
2744
2745EventEmitter.prototype.removeAllListeners =
2746 function removeAllListeners(type) {
2747 var listeners, events, i;
2748
2749 events = this._events;
2750 if (!events)
2751 return this;
2752
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);
2761 else
2762 delete events[type];
2763 }
2764 return this;
2765 }
2766
2767 // emit removeListener for all listeners on all events
2768 if (arguments.length === 0) {
2769 var keys = objectKeys(events);
2770 var key;
2771 for (i = 0; i < keys.length; ++i) {
2772 key = keys[i];
2773 if (key === 'removeListener') continue;
2774 this.removeAllListeners(key);
2775 }
2776 this.removeAllListeners('removeListener');
2777 this._events = objectCreate(null);
2778 this._eventsCount = 0;
2779 return this;
2780 }
2781
2782 listeners = events[type];
2783
2784 if (typeof listeners === 'function') {
2785 this.removeListener(type, listeners);
2786 } else if (listeners) {
2787 // LIFO order
2788 for (i = listeners.length - 1; i >= 0; i--) {
2789 this.removeListener(type, listeners[i]);
2790 }
2791 }
2792
2793 return this;
2794 };
2795
2796function _listeners(target, type, unwrap) {
2797 var events = target._events;
2798
2799 if (!events)
2800 return [];
2801
2802 var evlistener = events[type];
2803 if (!evlistener)
2804 return [];
2805
2806 if (typeof evlistener === 'function')
2807 return unwrap ? [evlistener.listener || evlistener] : [evlistener];
2808
2809 return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
2810}
2811
2812EventEmitter.prototype.listeners = function listeners(type) {
2813 return _listeners(this, type, true);
2814};
2815
2816EventEmitter.prototype.rawListeners = function rawListeners(type) {
2817 return _listeners(this, type, false);
2818};
2819
2820EventEmitter.listenerCount = function(emitter, type) {
2821 if (typeof emitter.listenerCount === 'function') {
2822 return emitter.listenerCount(type);
2823 } else {
2824 return listenerCount.call(emitter, type);
2825 }
2826};
2827
2828EventEmitter.prototype.listenerCount = listenerCount;
2829function listenerCount(type) {
2830 var events = this._events;
2831
2832 if (events) {
2833 var evlistener = events[type];
2834
2835 if (typeof evlistener === 'function') {
2836 return 1;
2837 } else if (evlistener) {
2838 return evlistener.length;
2839 }
2840 }
2841
2842 return 0;
2843}
2844
2845EventEmitter.prototype.eventNames = function eventNames() {
2846 return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
2847};
2848
2849// About 1.5x faster than the two-arg version of Array#splice().
2850function spliceOne(list, index) {
2851 for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
2852 list[i] = list[k];
2853 list.pop();
2854}
2855
2856function arrayClone(arr, n) {
2857 var copy = new Array(n);
2858 for (var i = 0; i < n; ++i)
2859 copy[i] = arr[i];
2860 return copy;
2861}
2862
2863function 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];
2867 }
2868 return ret;
2869}
2870
2871function objectCreatePolyfill(proto) {
2872 var F = function() {};
2873 F.prototype = proto;
2874 return new F;
2875}
2876function objectKeysPolyfill(obj) {
2877 var keys = [];
2878 for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {
2879 keys.push(k);
2880 }
2881 return k;
2882}
2883function functionBindPolyfill(context) {
2884 var fn = this;
2885 return function () {
2886 return fn.apply(context, arguments);
2887 };
2888}
2889
2890},{}],11:[function(require,module,exports){
2891'use strict'
2892var Buffer = require('safe-buffer').Buffer
2893var Transform = require('stream').Transform
2894var inherits = require('inherits')
2895
2896function throwIfNotStringOrBuffer (val, prefix) {
2897 if (!Buffer.isBuffer(val) && typeof val !== 'string') {
2898 throw new TypeError(prefix + ' must be a string or a buffer')
2899 }
2900}
2901
2902function HashBase (blockSize) {
2903 Transform.call(this)
2904
2905 this._block = Buffer.allocUnsafe(blockSize)
2906 this._blockSize = blockSize
2907 this._blockOffset = 0
2908 this._length = [0, 0, 0, 0]
2909
2910 this._finalized = false
2911}
2912
2913inherits(HashBase, Transform)
2914
2915HashBase.prototype._transform = function (chunk, encoding, callback) {
2916 var error = null
2917 try {
2918 this.update(chunk, encoding)
2919 } catch (err) {
2920 error = err
2921 }
2922
2923 callback(error)
2924}
2925
2926HashBase.prototype._flush = function (callback) {
2927 var error = null
2928 try {
2929 this.push(this.digest())
2930 } catch (err) {
2931 error = err
2932 }
2933
2934 callback(error)
2935}
2936
2937HashBase.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)
2941
2942 // consume data
2943 var block = this._block
2944 var offset = 0
2945 while (this._blockOffset + data.length - offset >= this._blockSize) {
2946 for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++]
2947 this._update()
2948 this._blockOffset = 0
2949 }
2950 while (offset < data.length) block[this._blockOffset++] = data[offset++]
2951
2952 // update length
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
2957 }
2958
2959 return this
2960}
2961
2962HashBase.prototype._update = function () {
2963 throw new Error('_update is not implemented')
2964}
2965
2966HashBase.prototype.digest = function (encoding) {
2967 if (this._finalized) throw new Error('Digest already called')
2968 this._finalized = true
2969
2970 var digest = this._digest()
2971 if (encoding !== undefined) digest = digest.toString(encoding)
2972
2973 // reset state
2974 this._block.fill(0)
2975 this._blockOffset = 0
2976 for (var i = 0; i < 4; ++i) this._length[i] = 0
2977
2978 return digest
2979}
2980
2981HashBase.prototype._digest = function () {
2982 throw new Error('_digest is not implemented')
2983}
2984
2985module.exports = HashBase
2986
2987},{"inherits":13,"safe-buffer":34,"stream":43}],12:[function(require,module,exports){
2988exports.read = function (buffer, offset, isLE, mLen, nBytes) {
2989 var e, m
2990 var eLen = (nBytes * 8) - mLen - 1
2991 var eMax = (1 << eLen) - 1
2992 var eBias = eMax >> 1
2993 var nBits = -7
2994 var i = isLE ? (nBytes - 1) : 0
2995 var d = isLE ? -1 : 1
2996 var s = buffer[offset + i]
2997
2998 i += d
2999
3000 e = s & ((1 << (-nBits)) - 1)
3001 s >>= (-nBits)
3002 nBits += eLen
3003 for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
3004
3005 m = e & ((1 << (-nBits)) - 1)
3006 e >>= (-nBits)
3007 nBits += mLen
3008 for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
3009
3010 if (e === 0) {
3011 e = 1 - eBias
3012 } else if (e === eMax) {
3013 return m ? NaN : ((s ? -1 : 1) * Infinity)
3014 } else {
3015 m = m + Math.pow(2, mLen)
3016 e = e - eBias
3017 }
3018 return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
3019}
3020
3021exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
3022 var e, m, c
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
3030
3031 value = Math.abs(value)
3032
3033 if (isNaN(value) || value === Infinity) {
3034 m = isNaN(value) ? 1 : 0
3035 e = eMax
3036 } else {
3037 e = Math.floor(Math.log(value) / Math.LN2)
3038 if (value * (c = Math.pow(2, -e)) < 1) {
3039 e--
3040 c *= 2
3041 }
3042 if (e + eBias >= 1) {
3043 value += rt / c
3044 } else {
3045 value += rt * Math.pow(2, 1 - eBias)
3046 }
3047 if (value * c >= 2) {
3048 e++
3049 c /= 2
3050 }
3051
3052 if (e + eBias >= eMax) {
3053 m = 0
3054 e = eMax
3055 } else if (e + eBias >= 1) {
3056 m = ((value * c) - 1) * Math.pow(2, mLen)
3057 e = e + eBias
3058 } else {
3059 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
3060 e = 0
3061 }
3062 }
3063
3064 for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
3065
3066 e = (e << mLen) | m
3067 eLen += mLen
3068 for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
3069
3070 buffer[offset + i - d] |= s * 128
3071}
3072
3073},{}],13:[function(require,module,exports){
3074if (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, {
3079 constructor: {
3080 value: ctor,
3081 enumerable: false,
3082 writable: true,
3083 configurable: true
3084 }
3085 });
3086 };
3087} else {
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
3095 }
3096}
3097
3098},{}],14:[function(require,module,exports){
3099/*!
3100 * Determine if an object is a Buffer
3101 *
3102 * @author Feross Aboukhadijeh <https://feross.org>
3103 * @license MIT
3104 */
3105
3106// The _isBuffer check is for Safari 5-7 support, because it's missing
3107// Object.prototype.constructor. Remove this eventually
3108module.exports = function (obj) {
3109 return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
3110}
3111
3112function isBuffer (obj) {
3113 return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
3114}
3115
3116// For Node v0.10 support. Remove this eventually.
3117function isSlowBuffer (obj) {
3118 return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
3119}
3120
3121},{}],15:[function(require,module,exports){
3122var toString = {}.toString;
3123
3124module.exports = Array.isArray || function (arr) {
3125 return toString.call(arr) == '[object Array]';
3126};
3127
3128},{}],16:[function(require,module,exports){
3129'use strict'
3130var inherits = require('inherits')
3131var HashBase = require('hash-base')
3132var Buffer = require('safe-buffer').Buffer
3133
3134var ARRAY16 = new Array(16)
3135
3136function MD5 () {
3137 HashBase.call(this, 64)
3138
3139 // state
3140 this._a = 0x67452301
3141 this._b = 0xefcdab89
3142 this._c = 0x98badcfe
3143 this._d = 0x10325476
3144}
3145
3146inherits(MD5, HashBase)
3147
3148MD5.prototype._update = function () {
3149 var M = ARRAY16
3150 for (var i = 0; i < 16; ++i) M[i] = this._block.readInt32LE(i * 4)
3151
3152 var a = this._a
3153 var b = this._b
3154 var c = this._c
3155 var d = this._d
3156
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)
3173
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)
3190
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)
3207
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)
3224
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
3229}
3230
3231MD5.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)
3236 this._update()
3237 this._blockOffset = 0
3238 }
3239
3240 this._block.fill(0, this._blockOffset, 56)
3241 this._block.writeUInt32LE(this._length[0], 56)
3242 this._block.writeUInt32LE(this._length[1], 60)
3243 this._update()
3244
3245 // produce result
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)
3251 return buffer
3252}
3253
3254function rotl (x, n) {
3255 return (x << n) | (x >>> (32 - n))
3256}
3257
3258function fnF (a, b, c, d, m, k, s) {
3259 return (rotl((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + b) | 0
3260}
3261
3262function fnG (a, b, c, d, m, k, s) {
3263 return (rotl((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + b) | 0
3264}
3265
3266function fnH (a, b, c, d, m, k, s) {
3267 return (rotl((a + (b ^ c ^ d) + m + k) | 0, s) + b) | 0
3268}
3269
3270function fnI (a, b, c, d, m, k, s) {
3271 return (rotl((a + ((c ^ (b | (~d)))) + m + k) | 0, s) + b) | 0
3272}
3273
3274module.exports = MD5
3275
3276},{"hash-base":11,"inherits":13,"safe-buffer":34}],17:[function(require,module,exports){
3277(function (process){
3278'use strict';
3279
3280if (!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 };
3284} else {
3285 module.exports = process
3286}
3287
3288function nextTick(fn, arg1, arg2, arg3) {
3289 if (typeof fn !== 'function') {
3290 throw new TypeError('"callback" argument must be a function');
3291 }
3292 var len = arguments.length;
3293 var args, i;
3294 switch (len) {
3295 case 0:
3296 case 1:
3297 return process.nextTick(fn);
3298 case 2:
3299 return process.nextTick(function afterTickOne() {
3300 fn.call(null, arg1);
3301 });
3302 case 3:
3303 return process.nextTick(function afterTickTwo() {
3304 fn.call(null, arg1, arg2);
3305 });
3306 case 4:
3307 return process.nextTick(function afterTickThree() {
3308 fn.call(null, arg1, arg2, arg3);
3309 });
3310 default:
3311 args = new Array(len - 1);
3312 i = 0;
3313 while (i < args.length) {
3314 args[i++] = arguments[i];
3315 }
3316 return process.nextTick(function afterTick() {
3317 fn.apply(null, args);
3318 });
3319 }
3320}
3321
3322
3323}).call(this,require('_process'))
3324},{"_process":18}],18:[function(require,module,exports){
3325// shim for using process in browser
3326var process = module.exports = {};
3327
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.
3332
3333var cachedSetTimeout;
3334var cachedClearTimeout;
3335
3336function defaultSetTimout() {
3337 throw new Error('setTimeout has not been defined');
3338}
3339function defaultClearTimeout () {
3340 throw new Error('clearTimeout has not been defined');
3341}
3342(function () {
3343 try {
3344 if (typeof setTimeout === 'function') {
3345 cachedSetTimeout = setTimeout;
3346 } else {
3347 cachedSetTimeout = defaultSetTimout;
3348 }
3349 } catch (e) {
3350 cachedSetTimeout = defaultSetTimout;
3351 }
3352 try {
3353 if (typeof clearTimeout === 'function') {
3354 cachedClearTimeout = clearTimeout;
3355 } else {
3356 cachedClearTimeout = defaultClearTimeout;
3357 }
3358 } catch (e) {
3359 cachedClearTimeout = defaultClearTimeout;
3360 }
3361} ())
3362function runTimeout(fun) {
3363 if (cachedSetTimeout === setTimeout) {
3364 //normal enviroments in sane situations
3365 return setTimeout(fun, 0);
3366 }
3367 // if setTimeout wasn't available but was latter defined
3368 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
3369 cachedSetTimeout = setTimeout;
3370 return setTimeout(fun, 0);
3371 }
3372 try {
3373 // when when somebody has screwed with setTimeout but no I.E. maddness
3374 return cachedSetTimeout(fun, 0);
3375 } catch(e){
3376 try {
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);
3379 } catch(e){
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);
3382 }
3383 }
3384
3385
3386}
3387function runClearTimeout(marker) {
3388 if (cachedClearTimeout === clearTimeout) {
3389 //normal enviroments in sane situations
3390 return clearTimeout(marker);
3391 }
3392 // if clearTimeout wasn't available but was latter defined
3393 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
3394 cachedClearTimeout = clearTimeout;
3395 return clearTimeout(marker);
3396 }
3397 try {
3398 // when when somebody has screwed with setTimeout but no I.E. maddness
3399 return cachedClearTimeout(marker);
3400 } catch (e){
3401 try {
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);
3404 } catch (e){
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);
3408 }
3409 }
3410
3411
3412
3413}
3414var queue = [];
3415var draining = false;
3416var currentQueue;
3417var queueIndex = -1;
3418
3419function cleanUpNextTick() {
3420 if (!draining || !currentQueue) {
3421 return;
3422 }
3423 draining = false;
3424 if (currentQueue.length) {
3425 queue = currentQueue.concat(queue);
3426 } else {
3427 queueIndex = -1;
3428 }
3429 if (queue.length) {
3430 drainQueue();
3431 }
3432}
3433
3434function drainQueue() {
3435 if (draining) {
3436 return;
3437 }
3438 var timeout = runTimeout(cleanUpNextTick);
3439 draining = true;
3440
3441 var len = queue.length;
3442 while(len) {
3443 currentQueue = queue;
3444 queue = [];
3445 while (++queueIndex < len) {
3446 if (currentQueue) {
3447 currentQueue[queueIndex].run();
3448 }
3449 }
3450 queueIndex = -1;
3451 len = queue.length;
3452 }
3453 currentQueue = null;
3454 draining = false;
3455 runClearTimeout(timeout);
3456}
3457
3458process.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];
3463 }
3464 }
3465 queue.push(new Item(fun, args));
3466 if (queue.length === 1 && !draining) {
3467 runTimeout(drainQueue);
3468 }
3469};
3470
3471// v8 likes predictible objects
3472function Item(fun, array) {
3473 this.fun = fun;
3474 this.array = array;
3475}
3476Item.prototype.run = function () {
3477 this.fun.apply(null, this.array);
3478};
3479process.title = 'browser';
3480process.browser = true;
3481process.env = {};
3482process.argv = [];
3483process.version = ''; // empty string to avoid regexp issues
3484process.versions = {};
3485
3486function noop() {}
3487
3488process.on = noop;
3489process.addListener = noop;
3490process.once = noop;
3491process.off = noop;
3492process.removeListener = noop;
3493process.removeAllListeners = noop;
3494process.emit = noop;
3495process.prependListener = noop;
3496process.prependOnceListener = noop;
3497
3498process.listeners = function (name) { return [] }
3499
3500process.binding = function (name) {
3501 throw new Error('process.binding is not supported');
3502};
3503
3504process.cwd = function () { return '/' };
3505process.chdir = function (dir) {
3506 throw new Error('process.chdir is not supported');
3507};
3508process.umask = function() { return 0; };
3509
3510},{}],19:[function(require,module,exports){
3511module.exports = require('./lib/_stream_duplex.js');
3512
3513},{"./lib/_stream_duplex.js":20}],20:[function(require,module,exports){
3514// Copyright Joyent, Inc. and other Node contributors.
3515//
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:
3523//
3524// The above copyright notice and this permission notice shall be included
3525// in all copies or substantial portions of the Software.
3526//
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.
3534
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
3538// Writable.
3539
3540'use strict';
3541
3542/*<replacement>*/
3543
3544var pna = require('process-nextick-args');
3545/*</replacement>*/
3546
3547/*<replacement>*/
3548var objectKeys = Object.keys || function (obj) {
3549 var keys = [];
3550 for (var key in obj) {
3551 keys.push(key);
3552 }return keys;
3553};
3554/*</replacement>*/
3555
3556module.exports = Duplex;
3557
3558/*<replacement>*/
3559var util = require('core-util-is');
3560util.inherits = require('inherits');
3561/*</replacement>*/
3562
3563var Readable = require('./_stream_readable');
3564var Writable = require('./_stream_writable');
3565
3566util.inherits(Duplex, Readable);
3567
3568{
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];
3574 }
3575}
3576
3577function Duplex(options) {
3578 if (!(this instanceof Duplex)) return new Duplex(options);
3579
3580 Readable.call(this, options);
3581 Writable.call(this, options);
3582
3583 if (options && options.readable === false) this.readable = false;
3584
3585 if (options && options.writable === false) this.writable = false;
3586
3587 this.allowHalfOpen = true;
3588 if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
3589
3590 this.once('end', onend);
3591}
3592
3593Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
3594 // making it explicit this property is not enumerable
3595 // because otherwise some prototype manipulation in
3596 // userland will fail
3597 enumerable: false,
3598 get: function () {
3599 return this._writableState.highWaterMark;
3600 }
3601});
3602
3603// the no-half-open enforcer
3604function onend() {
3605 // if we allow half-open state, or if the writable side ended,
3606 // then we're ok.
3607 if (this.allowHalfOpen || this._writableState.ended) return;
3608
3609 // no more data can be written.
3610 // But allow more writes to happen in this tick.
3611 pna.nextTick(onEndNT, this);
3612}
3613
3614function onEndNT(self) {
3615 self.end();
3616}
3617
3618Object.defineProperty(Duplex.prototype, 'destroyed', {
3619 get: function () {
3620 if (this._readableState === undefined || this._writableState === undefined) {
3621 return false;
3622 }
3623 return this._readableState.destroyed && this._writableState.destroyed;
3624 },
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) {
3629 return;
3630 }
3631
3632 // backward compatibility, the user is explicitly
3633 // managing destroyed
3634 this._readableState.destroyed = value;
3635 this._writableState.destroyed = value;
3636 }
3637});
3638
3639Duplex.prototype._destroy = function (err, cb) {
3640 this.push(null);
3641 this.end();
3642
3643 pna.nextTick(cb, err);
3644};
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.
3647//
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:
3655//
3656// The above copyright notice and this permission notice shall be included
3657// in all copies or substantial portions of the Software.
3658//
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.
3666
3667// a passthrough stream.
3668// basically just the most minimal sort of Transform stream.
3669// Every written chunk gets output as-is.
3670
3671'use strict';
3672
3673module.exports = PassThrough;
3674
3675var Transform = require('./_stream_transform');
3676
3677/*<replacement>*/
3678var util = require('core-util-is');
3679util.inherits = require('inherits');
3680/*</replacement>*/
3681
3682util.inherits(PassThrough, Transform);
3683
3684function PassThrough(options) {
3685 if (!(this instanceof PassThrough)) return new PassThrough(options);
3686
3687 Transform.call(this, options);
3688}
3689
3690PassThrough.prototype._transform = function (chunk, encoding, cb) {
3691 cb(null, chunk);
3692};
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.
3696//
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:
3704//
3705// The above copyright notice and this permission notice shall be included
3706// in all copies or substantial portions of the Software.
3707//
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.
3715
3716'use strict';
3717
3718/*<replacement>*/
3719
3720var pna = require('process-nextick-args');
3721/*</replacement>*/
3722
3723module.exports = Readable;
3724
3725/*<replacement>*/
3726var isArray = require('isarray');
3727/*</replacement>*/
3728
3729/*<replacement>*/
3730var Duplex;
3731/*</replacement>*/
3732
3733Readable.ReadableState = ReadableState;
3734
3735/*<replacement>*/
3736var EE = require('events').EventEmitter;
3737
3738var EElistenerCount = function (emitter, type) {
3739 return emitter.listeners(type).length;
3740};
3741/*</replacement>*/
3742
3743/*<replacement>*/
3744var Stream = require('./internal/streams/stream');
3745/*</replacement>*/
3746
3747/*<replacement>*/
3748
3749var Buffer = require('safe-buffer').Buffer;
3750var OurUint8Array = global.Uint8Array || function () {};
3751function _uint8ArrayToBuffer(chunk) {
3752 return Buffer.from(chunk);
3753}
3754function _isUint8Array(obj) {
3755 return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
3756}
3757
3758/*</replacement>*/
3759
3760/*<replacement>*/
3761var util = require('core-util-is');
3762util.inherits = require('inherits');
3763/*</replacement>*/
3764
3765/*<replacement>*/
3766var debugUtil = require('util');
3767var debug = void 0;
3768if (debugUtil && debugUtil.debuglog) {
3769 debug = debugUtil.debuglog('stream');
3770} else {
3771 debug = function () {};
3772}
3773/*</replacement>*/
3774
3775var BufferList = require('./internal/streams/BufferList');
3776var destroyImpl = require('./internal/streams/destroy');
3777var StringDecoder;
3778
3779util.inherits(Readable, Stream);
3780
3781var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
3782
3783function 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);
3787
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]];
3793}
3794
3795function ReadableState(options, stream) {
3796 Duplex = Duplex || require('./_stream_duplex');
3797
3798 options = options || {};
3799
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;
3806
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;
3810
3811 if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
3812
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;
3818
3819 if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm;
3820
3821 // cast to ints.
3822 this.highWaterMark = Math.floor(this.highWaterMark);
3823
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
3826 // array.shift()
3827 this.buffer = new BufferList();
3828 this.length = 0;
3829 this.pipes = null;
3830 this.pipesCount = 0;
3831 this.flowing = null;
3832 this.ended = false;
3833 this.endEmitted = false;
3834 this.reading = false;
3835
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.
3840 this.sync = true;
3841
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;
3848
3849 // has it been destroyed
3850 this.destroyed = false;
3851
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';
3856
3857 // the number of writers that are awaiting a drain event in .pipe()s
3858 this.awaitDrain = 0;
3859
3860 // if true, a maybeReadMore has been scheduled
3861 this.readingMore = false;
3862
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;
3869 }
3870}
3871
3872function Readable(options) {
3873 Duplex = Duplex || require('./_stream_duplex');
3874
3875 if (!(this instanceof Readable)) return new Readable(options);
3876
3877 this._readableState = new ReadableState(options, this);
3878
3879 // legacy
3880 this.readable = true;
3881
3882 if (options) {
3883 if (typeof options.read === 'function') this._read = options.read;
3884
3885 if (typeof options.destroy === 'function') this._destroy = options.destroy;
3886 }
3887
3888 Stream.call(this);
3889}
3890
3891Object.defineProperty(Readable.prototype, 'destroyed', {
3892 get: function () {
3893 if (this._readableState === undefined) {
3894 return false;
3895 }
3896 return this._readableState.destroyed;
3897 },
3898 set: function (value) {
3899 // we ignore the value if the stream
3900 // has not been initialized yet
3901 if (!this._readableState) {
3902 return;
3903 }
3904
3905 // backward compatibility, the user is explicitly
3906 // managing destroyed
3907 this._readableState.destroyed = value;
3908 }
3909});
3910
3911Readable.prototype.destroy = destroyImpl.destroy;
3912Readable.prototype._undestroy = destroyImpl.undestroy;
3913Readable.prototype._destroy = function (err, cb) {
3914 this.push(null);
3915 cb(err);
3916};
3917
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.
3922Readable.prototype.push = function (chunk, encoding) {
3923 var state = this._readableState;
3924 var skipChunkCheck;
3925
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);
3931 encoding = '';
3932 }
3933 skipChunkCheck = true;
3934 }
3935 } else {
3936 skipChunkCheck = true;
3937 }
3938
3939 return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
3940};
3941
3942// Unshift should *always* be something directly out of read()
3943Readable.prototype.unshift = function (chunk) {
3944 return readableAddChunk(this, chunk, null, true, false);
3945};
3946
3947function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
3948 var state = stream._readableState;
3949 if (chunk === null) {
3950 state.reading = false;
3951 onEofChunk(stream, state);
3952 } else {
3953 var er;
3954 if (!skipChunkCheck) er = chunkInvalid(state, chunk);
3955 if (er) {
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);
3960 }
3961
3962 if (addToFront) {
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'));
3966 } else {
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);
3971 } else {
3972 addChunk(stream, state, chunk, false);
3973 }
3974 }
3975 } else if (!addToFront) {
3976 state.reading = false;
3977 }
3978 }
3979
3980 return needMoreData(state);
3981}
3982
3983function addChunk(stream, state, chunk, addToFront) {
3984 if (state.flowing && state.length === 0 && !state.sync) {
3985 stream.emit('data', chunk);
3986 stream.read(0);
3987 } else {
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);
3991
3992 if (state.needReadable) emitReadable(stream);
3993 }
3994 maybeReadMore(stream, state);
3995}
3996
3997function chunkInvalid(state, chunk) {
3998 var er;
3999 if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
4000 er = new TypeError('Invalid non-string/buffer chunk');
4001 }
4002 return er;
4003}
4004
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.
4012function needMoreData(state) {
4013 return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
4014}
4015
4016Readable.prototype.isPaused = function () {
4017 return this._readableState.flowing === false;
4018};
4019
4020// backwards compatibility.
4021Readable.prototype.setEncoding = function (enc) {
4022 if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
4023 this._readableState.decoder = new StringDecoder(enc);
4024 this._readableState.encoding = enc;
4025 return this;
4026};
4027
4028// Don't raise the hwm > 8MB
4029var MAX_HWM = 0x800000;
4030function computeNewHighWaterMark(n) {
4031 if (n >= MAX_HWM) {
4032 n = MAX_HWM;
4033 } else {
4034 // Get the next highest power of 2 to prevent increasing hwm excessively in
4035 // tiny amounts
4036 n--;
4037 n |= n >>> 1;
4038 n |= n >>> 2;
4039 n |= n >>> 4;
4040 n |= n >>> 8;
4041 n |= n >>> 16;
4042 n++;
4043 }
4044 return n;
4045}
4046
4047// This function is designed to be inlinable, so please take care when making
4048// changes to the function body.
4049function howMuchToRead(n, state) {
4050 if (n <= 0 || state.length === 0 && state.ended) return 0;
4051 if (state.objectMode) return 1;
4052 if (n !== n) {
4053 // Only flow one buffer at a time
4054 if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
4055 }
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
4060 if (!state.ended) {
4061 state.needReadable = true;
4062 return 0;
4063 }
4064 return state.length;
4065}
4066
4067// you can override either this method, or the async _read(n) below.
4068Readable.prototype.read = function (n) {
4069 debug('read', n);
4070 n = parseInt(n, 10);
4071 var state = this._readableState;
4072 var nOrig = n;
4073
4074 if (n !== 0) state.emittedReadable = false;
4075
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);
4082 return null;
4083 }
4084
4085 n = howMuchToRead(n, state);
4086
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);
4090 return null;
4091 }
4092
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.
4099 //
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.
4103 //
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
4111 // 'readable' etc.
4112 //
4113 // 3. Actually pull the requested chunks out of the buffer and return.
4114
4115 // if we need a readable event, then we need to do some reading.
4116 var doRead = state.needReadable;
4117 debug('need readable', doRead);
4118
4119 // if we currently have less than the highWaterMark, then also read some
4120 if (state.length === 0 || state.length - n < state.highWaterMark) {
4121 doRead = true;
4122 debug('length less than watermark', doRead);
4123 }
4124
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) {
4128 doRead = false;
4129 debug('reading or ended', doRead);
4130 } else if (doRead) {
4131 debug('do read');
4132 state.reading = true;
4133 state.sync = 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);
4138 state.sync = false;
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);
4142 }
4143
4144 var ret;
4145 if (n > 0) ret = fromList(n, state);else ret = null;
4146
4147 if (ret === null) {
4148 state.needReadable = true;
4149 n = 0;
4150 } else {
4151 state.length -= n;
4152 }
4153
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;
4158
4159 // If we tried to read() past the EOF, then emit end on the next tick.
4160 if (nOrig !== n && state.ended) endReadable(this);
4161 }
4162
4163 if (ret !== null) this.emit('data', ret);
4164
4165 return ret;
4166};
4167
4168function 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;
4175 }
4176 }
4177 state.ended = true;
4178
4179 // emit 'readable' now to make sure it gets picked up.
4180 emitReadable(stream);
4181}
4182
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.
4186function 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);
4193 }
4194}
4195
4196function emitReadable_(stream) {
4197 debug('emit readable');
4198 stream.emit('readable');
4199 flow(stream);
4200}
4201
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.
4208function maybeReadMore(stream, state) {
4209 if (!state.readingMore) {
4210 state.readingMore = true;
4211 pna.nextTick(maybeReadMore_, stream, state);
4212 }
4213}
4214
4215function 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');
4219 stream.read(0);
4220 if (len === state.length)
4221 // didn't get any data, stop spinning.
4222 break;else len = state.length;
4223 }
4224 state.readingMore = false;
4225}
4226
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.
4231Readable.prototype._read = function (n) {
4232 this.emit('error', new Error('_read() is not implemented'));
4233};
4234
4235Readable.prototype.pipe = function (dest, pipeOpts) {
4236 var src = this;
4237 var state = this._readableState;
4238
4239 switch (state.pipesCount) {
4240 case 0:
4241 state.pipes = dest;
4242 break;
4243 case 1:
4244 state.pipes = [state.pipes, dest];
4245 break;
4246 default:
4247 state.pipes.push(dest);
4248 break;
4249 }
4250 state.pipesCount += 1;
4251 debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
4252
4253 var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
4254
4255 var endFn = doEnd ? onend : unpipe;
4256 if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
4257
4258 dest.on('unpipe', onunpipe);
4259 function onunpipe(readable, unpipeInfo) {
4260 debug('onunpipe');
4261 if (readable === src) {
4262 if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
4263 unpipeInfo.hasUnpiped = true;
4264 cleanup();
4265 }
4266 }
4267 }
4268
4269 function onend() {
4270 debug('onend');
4271 dest.end();
4272 }
4273
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
4277 // too slow.
4278 var ondrain = pipeOnDrain(src);
4279 dest.on('drain', ondrain);
4280
4281 var cleanedUp = false;
4282 function cleanup() {
4283 debug('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);
4293
4294 cleanedUp = true;
4295
4296 // if the reader is waiting for a drain event from this
4297 // specific writer, then it would cause it to never start
4298 // flowing again.
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();
4302 }
4303
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) {
4311 debug('ondata');
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;
4323 }
4324 src.pause();
4325 }
4326 }
4327
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);
4332 unpipe();
4333 dest.removeListener('error', onerror);
4334 if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
4335 }
4336
4337 // Make sure our error handler is attached before userland ones.
4338 prependListener(dest, 'error', onerror);
4339
4340 // Both close and finish should trigger unpipe, but only once.
4341 function onclose() {
4342 dest.removeListener('finish', onfinish);
4343 unpipe();
4344 }
4345 dest.once('close', onclose);
4346 function onfinish() {
4347 debug('onfinish');
4348 dest.removeListener('close', onclose);
4349 unpipe();
4350 }
4351 dest.once('finish', onfinish);
4352
4353 function unpipe() {
4354 debug('unpipe');
4355 src.unpipe(dest);
4356 }
4357
4358 // tell the dest that it's being piped to
4359 dest.emit('pipe', src);
4360
4361 // start the flow if it hasn't been started already.
4362 if (!state.flowing) {
4363 debug('pipe resume');
4364 src.resume();
4365 }
4366
4367 return dest;
4368};
4369
4370function 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;
4377 flow(src);
4378 }
4379 };
4380}
4381
4382Readable.prototype.unpipe = function (dest) {
4383 var state = this._readableState;
4384 var unpipeInfo = { hasUnpiped: false };
4385
4386 // if we're not piping anywhere, then do nothing.
4387 if (state.pipesCount === 0) return this;
4388
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;
4393
4394 if (!dest) dest = state.pipes;
4395
4396 // got a match.
4397 state.pipes = null;
4398 state.pipesCount = 0;
4399 state.flowing = false;
4400 if (dest) dest.emit('unpipe', this, unpipeInfo);
4401 return this;
4402 }
4403
4404 // slow case. multiple pipe destinations.
4405
4406 if (!dest) {
4407 // remove all.
4408 var dests = state.pipes;
4409 var len = state.pipesCount;
4410 state.pipes = null;
4411 state.pipesCount = 0;
4412 state.flowing = false;
4413
4414 for (var i = 0; i < len; i++) {
4415 dests[i].emit('unpipe', this, unpipeInfo);
4416 }return this;
4417 }
4418
4419 // try to find the right one.
4420 var index = indexOf(state.pipes, dest);
4421 if (index === -1) return this;
4422
4423 state.pipes.splice(index, 1);
4424 state.pipesCount -= 1;
4425 if (state.pipesCount === 1) state.pipes = state.pipes[0];
4426
4427 dest.emit('unpipe', this, unpipeInfo);
4428
4429 return this;
4430};
4431
4432// set up data events if they are asked for
4433// Ensure readable listeners eventually get something
4434Readable.prototype.on = function (ev, fn) {
4435 var res = Stream.prototype.on.call(this, ev, fn);
4436
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) {
4448 emitReadable(this);
4449 }
4450 }
4451 }
4452
4453 return res;
4454};
4455Readable.prototype.addListener = Readable.prototype.on;
4456
4457function nReadingNextTick(self) {
4458 debug('readable nexttick read 0');
4459 self.read(0);
4460}
4461
4462// pause() and resume() are remnants of the legacy readable stream API
4463// If the user uses them, then switch into old mode.
4464Readable.prototype.resume = function () {
4465 var state = this._readableState;
4466 if (!state.flowing) {
4467 debug('resume');
4468 state.flowing = true;
4469 resume(this, state);
4470 }
4471 return this;
4472};
4473
4474function resume(stream, state) {
4475 if (!state.resumeScheduled) {
4476 state.resumeScheduled = true;
4477 pna.nextTick(resume_, stream, state);
4478 }
4479}
4480
4481function resume_(stream, state) {
4482 if (!state.reading) {
4483 debug('resume read 0');
4484 stream.read(0);
4485 }
4486
4487 state.resumeScheduled = false;
4488 state.awaitDrain = 0;
4489 stream.emit('resume');
4490 flow(stream);
4491 if (state.flowing && !state.reading) stream.read(0);
4492}
4493
4494Readable.prototype.pause = function () {
4495 debug('call pause flowing=%j', this._readableState.flowing);
4496 if (false !== this._readableState.flowing) {
4497 debug('pause');
4498 this._readableState.flowing = false;
4499 this.emit('pause');
4500 }
4501 return this;
4502};
4503
4504function flow(stream) {
4505 var state = stream._readableState;
4506 debug('flow', state.flowing);
4507 while (state.flowing && stream.read() !== null) {}
4508}
4509
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.
4513Readable.prototype.wrap = function (stream) {
4514 var _this = this;
4515
4516 var state = this._readableState;
4517 var paused = false;
4518
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);
4524 }
4525
4526 _this.push(null);
4527 });
4528
4529 stream.on('data', function (chunk) {
4530 debug('wrapped data');
4531 if (state.decoder) chunk = state.decoder.write(chunk);
4532
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;
4535
4536 var ret = _this.push(chunk);
4537 if (!ret) {
4538 paused = true;
4539 stream.pause();
4540 }
4541 });
4542
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);
4550 };
4551 }(i);
4552 }
4553 }
4554
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]));
4558 }
4559
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);
4564 if (paused) {
4565 paused = false;
4566 stream.resume();
4567 }
4568 };
4569
4570 return this;
4571};
4572
4573Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
4574 // making it explicit this property is not enumerable
4575 // because otherwise some prototype manipulation in
4576 // userland will fail
4577 enumerable: false,
4578 get: function () {
4579 return this._readableState.highWaterMark;
4580 }
4581});
4582
4583// exposed for testing purposes only.
4584Readable._fromList = fromList;
4585
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.
4590function fromList(n, state) {
4591 // nothing buffered
4592 if (state.length === 0) return null;
4593
4594 var ret;
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();
4599 } else {
4600 // read part of list
4601 ret = fromListPartial(n, state.buffer, state.decoder);
4602 }
4603
4604 return ret;
4605}
4606
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.
4610function fromListPartial(n, list, hasStrings) {
4611 var ret;
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
4618 ret = list.shift();
4619 } else {
4620 // result spans more than one buffer
4621 ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
4622 }
4623 return ret;
4624}
4625
4626// Copies a specified amount of characters from the list of buffered data
4627// chunks.
4628// This function is designed to be inlinable, so please take care when making
4629// changes to the function body.
4630function copyFromBufferString(n, list) {
4631 var p = list.head;
4632 var c = 1;
4633 var ret = p.data;
4634 n -= ret.length;
4635 while (p = p.next) {
4636 var str = p.data;
4637 var nb = n > str.length ? str.length : n;
4638 if (nb === str.length) ret += str;else ret += str.slice(0, n);
4639 n -= nb;
4640 if (n === 0) {
4641 if (nb === str.length) {
4642 ++c;
4643 if (p.next) list.head = p.next;else list.head = list.tail = null;
4644 } else {
4645 list.head = p;
4646 p.data = str.slice(nb);
4647 }
4648 break;
4649 }
4650 ++c;
4651 }
4652 list.length -= c;
4653 return ret;
4654}
4655
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.
4659function copyFromBuffer(n, list) {
4660 var ret = Buffer.allocUnsafe(n);
4661 var p = list.head;
4662 var c = 1;
4663 p.data.copy(ret);
4664 n -= p.data.length;
4665 while (p = p.next) {
4666 var buf = p.data;
4667 var nb = n > buf.length ? buf.length : n;
4668 buf.copy(ret, ret.length - n, 0, nb);
4669 n -= nb;
4670 if (n === 0) {
4671 if (nb === buf.length) {
4672 ++c;
4673 if (p.next) list.head = p.next;else list.head = list.tail = null;
4674 } else {
4675 list.head = p;
4676 p.data = buf.slice(nb);
4677 }
4678 break;
4679 }
4680 ++c;
4681 }
4682 list.length -= c;
4683 return ret;
4684}
4685
4686function endReadable(stream) {
4687 var state = stream._readableState;
4688
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');
4692
4693 if (!state.endEmitted) {
4694 state.ended = true;
4695 pna.nextTick(endReadableNT, state, stream);
4696 }
4697}
4698
4699function 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;
4704 stream.emit('end');
4705 }
4706}
4707
4708function indexOf(xs, x) {
4709 for (var i = 0, l = xs.length; i < l; i++) {
4710 if (xs[i] === x) return i;
4711 }
4712 return -1;
4713}
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.
4717//
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:
4725//
4726// The above copyright notice and this permission notice shall be included
4727// in all copies or substantial portions of the Software.
4728//
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.
4736
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.)
4742//
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.
4747//
4748// Here's how this works:
4749//
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.
4755//
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.
4762//
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.
4774//
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.
4778
4779'use strict';
4780
4781module.exports = Transform;
4782
4783var Duplex = require('./_stream_duplex');
4784
4785/*<replacement>*/
4786var util = require('core-util-is');
4787util.inherits = require('inherits');
4788/*</replacement>*/
4789
4790util.inherits(Transform, Duplex);
4791
4792function afterTransform(er, data) {
4793 var ts = this._transformState;
4794 ts.transforming = false;
4795
4796 var cb = ts.writecb;
4797
4798 if (!cb) {
4799 return this.emit('error', new Error('write callback called multiple times'));
4800 }
4801
4802 ts.writechunk = null;
4803 ts.writecb = null;
4804
4805 if (data != null) // single equals check for both `null` and `undefined`
4806 this.push(data);
4807
4808 cb(er);
4809
4810 var rs = this._readableState;
4811 rs.reading = false;
4812 if (rs.needReadable || rs.length < rs.highWaterMark) {
4813 this._read(rs.highWaterMark);
4814 }
4815}
4816
4817function Transform(options) {
4818 if (!(this instanceof Transform)) return new Transform(options);
4819
4820 Duplex.call(this, options);
4821
4822 this._transformState = {
4823 afterTransform: afterTransform.bind(this),
4824 needTransform: false,
4825 transforming: false,
4826 writecb: null,
4827 writechunk: null,
4828 writeencoding: null
4829 };
4830
4831 // start out asking for a readable event once data is transformed.
4832 this._readableState.needReadable = true;
4833
4834 // we have implemented the _read method, and done the other things
4835 // that Readable wants before the first _read call, so unset the
4836 // sync guard flag.
4837 this._readableState.sync = false;
4838
4839 if (options) {
4840 if (typeof options.transform === 'function') this._transform = options.transform;
4841
4842 if (typeof options.flush === 'function') this._flush = options.flush;
4843 }
4844
4845 // When the writable side finishes, then flush out anything remaining.
4846 this.on('prefinish', prefinish);
4847}
4848
4849function prefinish() {
4850 var _this = this;
4851
4852 if (typeof this._flush === 'function') {
4853 this._flush(function (er, data) {
4854 done(_this, er, data);
4855 });
4856 } else {
4857 done(this, null, null);
4858 }
4859}
4860
4861Transform.prototype.push = function (chunk, encoding) {
4862 this._transformState.needTransform = false;
4863 return Duplex.prototype.push.call(this, chunk, encoding);
4864};
4865
4866// This is the part where you do stuff!
4867// override this function in implementation classes.
4868// 'chunk' is an input chunk.
4869//
4870// Call `push(newChunk)` to pass along transformed output
4871// to the readable side. You may call 'push' zero or more times.
4872//
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.
4876Transform.prototype._transform = function (chunk, encoding, cb) {
4877 throw new Error('_transform() is not implemented');
4878};
4879
4880Transform.prototype._write = function (chunk, encoding, cb) {
4881 var ts = this._transformState;
4882 ts.writecb = cb;
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);
4888 }
4889};
4890
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.
4894Transform.prototype._read = function (n) {
4895 var ts = this._transformState;
4896
4897 if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
4898 ts.transforming = true;
4899 this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
4900 } else {
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;
4904 }
4905};
4906
4907Transform.prototype._destroy = function (err, cb) {
4908 var _this2 = this;
4909
4910 Duplex.prototype._destroy.call(this, err, function (err2) {
4911 cb(err2);
4912 _this2.emit('close');
4913 });
4914};
4915
4916function done(stream, er, data) {
4917 if (er) return stream.emit('error', er);
4918
4919 if (data != null) // single equals check for both `null` and `undefined`
4920 stream.push(data);
4921
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');
4925
4926 if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
4927
4928 return stream.push(null);
4929}
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.
4933//
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:
4941//
4942// The above copyright notice and this permission notice shall be included
4943// in all copies or substantial portions of the Software.
4944//
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.
4952
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.
4956
4957'use strict';
4958
4959/*<replacement>*/
4960
4961var pna = require('process-nextick-args');
4962/*</replacement>*/
4963
4964module.exports = Writable;
4965
4966/* <replacement> */
4967function WriteReq(chunk, encoding, cb) {
4968 this.chunk = chunk;
4969 this.encoding = encoding;
4970 this.callback = cb;
4971 this.next = null;
4972}
4973
4974// It seems a linked list but it is not
4975// there will be only 2 of these for each stream
4976function CorkedRequest(state) {
4977 var _this = this;
4978
4979 this.next = null;
4980 this.entry = null;
4981 this.finish = function () {
4982 onCorkedFinish(_this, state);
4983 };
4984}
4985/* </replacement> */
4986
4987/*<replacement>*/
4988var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
4989/*</replacement>*/
4990
4991/*<replacement>*/
4992var Duplex;
4993/*</replacement>*/
4994
4995Writable.WritableState = WritableState;
4996
4997/*<replacement>*/
4998var util = require('core-util-is');
4999util.inherits = require('inherits');
5000/*</replacement>*/
5001
5002/*<replacement>*/
5003var internalUtil = {
5004 deprecate: require('util-deprecate')
5005};
5006/*</replacement>*/
5007
5008/*<replacement>*/
5009var Stream = require('./internal/streams/stream');
5010/*</replacement>*/
5011
5012/*<replacement>*/
5013
5014var Buffer = require('safe-buffer').Buffer;
5015var OurUint8Array = global.Uint8Array || function () {};
5016function _uint8ArrayToBuffer(chunk) {
5017 return Buffer.from(chunk);
5018}
5019function _isUint8Array(obj) {
5020 return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
5021}
5022
5023/*</replacement>*/
5024
5025var destroyImpl = require('./internal/streams/destroy');
5026
5027util.inherits(Writable, Stream);
5028
5029function nop() {}
5030
5031function WritableState(options, stream) {
5032 Duplex = Duplex || require('./_stream_duplex');
5033
5034 options = options || {};
5035
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;
5042
5043 // object stream flag to indicate whether or not this stream
5044 // contains buffers or objects.
5045 this.objectMode = !!options.objectMode;
5046
5047 if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
5048
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;
5055
5056 if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
5057
5058 // cast to ints.
5059 this.highWaterMark = Math.floor(this.highWaterMark);
5060
5061 // if _final has been called
5062 this.finalCalled = false;
5063
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
5069 this.ended = false;
5070 // when 'finish' is emitted
5071 this.finished = false;
5072
5073 // has it been destroyed
5074 this.destroyed = false;
5075
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;
5081
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';
5086
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
5089 // socket or file.
5090 this.length = 0;
5091
5092 // a flag to see when we're in the middle of a write.
5093 this.writing = false;
5094
5095 // when true all writes will be buffered until .uncork() call
5096 this.corked = 0;
5097
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.
5102 this.sync = true;
5103
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;
5108
5109 // the callback that's passed to _write(chunk,cb)
5110 this.onwrite = function (er) {
5111 onwrite(stream, er);
5112 };
5113
5114 // the callback that the user supplies to write(chunk,encoding,cb)
5115 this.writecb = null;
5116
5117 // the amount that is being written when _write is called.
5118 this.writelen = 0;
5119
5120 this.bufferedRequest = null;
5121 this.lastBufferedRequest = null;
5122
5123 // number of pending user-supplied write callbacks
5124 // this must be 0 before 'finish' can be emitted
5125 this.pendingcb = 0;
5126
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;
5130
5131 // True if the error was already emitted and should not be thrown again
5132 this.errorEmitted = false;
5133
5134 // count buffered requests
5135 this.bufferedRequestCount = 0;
5136
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);
5140}
5141
5142WritableState.prototype.getBuffer = function getBuffer() {
5143 var current = this.bufferedRequest;
5144 var out = [];
5145 while (current) {
5146 out.push(current);
5147 current = current.next;
5148 }
5149 return out;
5150};
5151
5152(function () {
5153 try {
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')
5158 });
5159 } catch (_) {}
5160})();
5161
5162// Test _writableState for inheritance to account for Duplex streams,
5163// whose prototype chain only points to Readable.
5164var realHasInstance;
5165if (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;
5171
5172 return object && object._writableState instanceof WritableState;
5173 }
5174 });
5175} else {
5176 realHasInstance = function (object) {
5177 return object instanceof this;
5178 };
5179}
5180
5181function Writable(options) {
5182 Duplex = Duplex || require('./_stream_duplex');
5183
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.
5187
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);
5193 }
5194
5195 this._writableState = new WritableState(options, this);
5196
5197 // legacy.
5198 this.writable = true;
5199
5200 if (options) {
5201 if (typeof options.write === 'function') this._write = options.write;
5202
5203 if (typeof options.writev === 'function') this._writev = options.writev;
5204
5205 if (typeof options.destroy === 'function') this._destroy = options.destroy;
5206
5207 if (typeof options.final === 'function') this._final = options.final;
5208 }
5209
5210 Stream.call(this);
5211}
5212
5213// Otherwise people can pipe Writable streams, which is just wrong.
5214Writable.prototype.pipe = function () {
5215 this.emit('error', new Error('Cannot pipe, not readable'));
5216};
5217
5218function 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);
5223}
5224
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.
5228function validChunk(stream, state, chunk, cb) {
5229 var valid = true;
5230 var er = false;
5231
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');
5236 }
5237 if (er) {
5238 stream.emit('error', er);
5239 pna.nextTick(cb, er);
5240 valid = false;
5241 }
5242 return valid;
5243}
5244
5245Writable.prototype.write = function (chunk, encoding, cb) {
5246 var state = this._writableState;
5247 var ret = false;
5248 var isBuf = !state.objectMode && _isUint8Array(chunk);
5249
5250 if (isBuf && !Buffer.isBuffer(chunk)) {
5251 chunk = _uint8ArrayToBuffer(chunk);
5252 }
5253
5254 if (typeof encoding === 'function') {
5255 cb = encoding;
5256 encoding = null;
5257 }
5258
5259 if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
5260
5261 if (typeof cb !== 'function') cb = nop;
5262
5263 if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
5264 state.pendingcb++;
5265 ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
5266 }
5267
5268 return ret;
5269};
5270
5271Writable.prototype.cork = function () {
5272 var state = this._writableState;
5273
5274 state.corked++;
5275};
5276
5277Writable.prototype.uncork = function () {
5278 var state = this._writableState;
5279
5280 if (state.corked) {
5281 state.corked--;
5282
5283 if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
5284 }
5285};
5286
5287Writable.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;
5292 return this;
5293};
5294
5295function decodeChunk(state, chunk, encoding) {
5296 if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
5297 chunk = Buffer.from(chunk, encoding);
5298 }
5299 return chunk;
5300}
5301
5302Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
5303 // making it explicit this property is not enumerable
5304 // because otherwise some prototype manipulation in
5305 // userland will fail
5306 enumerable: false,
5307 get: function () {
5308 return this._writableState.highWaterMark;
5309 }
5310});
5311
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.
5315function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
5316 if (!isBuf) {
5317 var newChunk = decodeChunk(state, chunk, encoding);
5318 if (chunk !== newChunk) {
5319 isBuf = true;
5320 encoding = 'buffer';
5321 chunk = newChunk;
5322 }
5323 }
5324 var len = state.objectMode ? 1 : chunk.length;
5325
5326 state.length += len;
5327
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;
5331
5332 if (state.writing || state.corked) {
5333 var last = state.lastBufferedRequest;
5334 state.lastBufferedRequest = {
5335 chunk: chunk,
5336 encoding: encoding,
5337 isBuf: isBuf,
5338 callback: cb,
5339 next: null
5340 };
5341 if (last) {
5342 last.next = state.lastBufferedRequest;
5343 } else {
5344 state.bufferedRequest = state.lastBufferedRequest;
5345 }
5346 state.bufferedRequestCount += 1;
5347 } else {
5348 doWrite(stream, state, false, len, chunk, encoding, cb);
5349 }
5350
5351 return ret;
5352}
5353
5354function doWrite(stream, state, writev, len, chunk, encoding, cb) {
5355 state.writelen = len;
5356 state.writecb = cb;
5357 state.writing = true;
5358 state.sync = true;
5359 if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
5360 state.sync = false;
5361}
5362
5363function onwriteError(stream, state, sync, er, cb) {
5364 --state.pendingcb;
5365
5366 if (sync) {
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
5371 // after error
5372 pna.nextTick(finishMaybe, stream, state);
5373 stream._writableState.errorEmitted = true;
5374 stream.emit('error', er);
5375 } else {
5376 // the caller expect this to happen before if
5377 // it is async
5378 cb(er);
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);
5384 }
5385}
5386
5387function onwriteStateUpdate(state) {
5388 state.writing = false;
5389 state.writecb = null;
5390 state.length -= state.writelen;
5391 state.writelen = 0;
5392}
5393
5394function onwrite(stream, er) {
5395 var state = stream._writableState;
5396 var sync = state.sync;
5397 var cb = state.writecb;
5398
5399 onwriteStateUpdate(state);
5400
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);
5404
5405 if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
5406 clearBuffer(stream, state);
5407 }
5408
5409 if (sync) {
5410 /*<replacement>*/
5411 asyncWrite(afterWrite, stream, state, finished, cb);
5412 /*</replacement>*/
5413 } else {
5414 afterWrite(stream, state, finished, cb);
5415 }
5416 }
5417}
5418
5419function afterWrite(stream, state, finished, cb) {
5420 if (!finished) onwriteDrain(stream, state);
5421 state.pendingcb--;
5422 cb();
5423 finishMaybe(stream, state);
5424}
5425
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.
5429function onwriteDrain(stream, state) {
5430 if (state.length === 0 && state.needDrain) {
5431 state.needDrain = false;
5432 stream.emit('drain');
5433 }
5434}
5435
5436// if there's something in the buffer waiting, then process it
5437function clearBuffer(stream, state) {
5438 state.bufferProcessing = true;
5439 var entry = state.bufferedRequest;
5440
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;
5447
5448 var count = 0;
5449 var allBuffers = true;
5450 while (entry) {
5451 buffer[count] = entry;
5452 if (!entry.isBuf) allBuffers = false;
5453 entry = entry.next;
5454 count += 1;
5455 }
5456 buffer.allBuffers = allBuffers;
5457
5458 doWrite(stream, state, true, state.length, buffer, '', holder.finish);
5459
5460 // doWrite is almost always async, defer these to save a bit of time
5461 // as the hot path ends with doWrite
5462 state.pendingcb++;
5463 state.lastBufferedRequest = null;
5464 if (holder.next) {
5465 state.corkedRequestsFree = holder.next;
5466 holder.next = null;
5467 } else {
5468 state.corkedRequestsFree = new CorkedRequest(state);
5469 }
5470 state.bufferedRequestCount = 0;
5471 } else {
5472 // Slow case, write chunks one-by-one
5473 while (entry) {
5474 var chunk = entry.chunk;
5475 var encoding = entry.encoding;
5476 var cb = entry.callback;
5477 var len = state.objectMode ? 1 : chunk.length;
5478
5479 doWrite(stream, state, false, len, chunk, encoding, cb);
5480 entry = entry.next;
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) {
5487 break;
5488 }
5489 }
5490
5491 if (entry === null) state.lastBufferedRequest = null;
5492 }
5493
5494 state.bufferedRequest = entry;
5495 state.bufferProcessing = false;
5496}
5497
5498Writable.prototype._write = function (chunk, encoding, cb) {
5499 cb(new Error('_write() is not implemented'));
5500};
5501
5502Writable.prototype._writev = null;
5503
5504Writable.prototype.end = function (chunk, encoding, cb) {
5505 var state = this._writableState;
5506
5507 if (typeof chunk === 'function') {
5508 cb = chunk;
5509 chunk = null;
5510 encoding = null;
5511 } else if (typeof encoding === 'function') {
5512 cb = encoding;
5513 encoding = null;
5514 }
5515
5516 if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
5517
5518 // .end() fully uncorks
5519 if (state.corked) {
5520 state.corked = 1;
5521 this.uncork();
5522 }
5523
5524 // ignore unnecessary end() calls.
5525 if (!state.ending && !state.finished) endWritable(this, state, cb);
5526};
5527
5528function needFinish(state) {
5529 return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
5530}
5531function callFinal(stream, state) {
5532 stream._final(function (err) {
5533 state.pendingcb--;
5534 if (err) {
5535 stream.emit('error', err);
5536 }
5537 state.prefinished = true;
5538 stream.emit('prefinish');
5539 finishMaybe(stream, state);
5540 });
5541}
5542function prefinish(stream, state) {
5543 if (!state.prefinished && !state.finalCalled) {
5544 if (typeof stream._final === 'function') {
5545 state.pendingcb++;
5546 state.finalCalled = true;
5547 pna.nextTick(callFinal, stream, state);
5548 } else {
5549 state.prefinished = true;
5550 stream.emit('prefinish');
5551 }
5552 }
5553}
5554
5555function finishMaybe(stream, state) {
5556 var need = needFinish(state);
5557 if (need) {
5558 prefinish(stream, state);
5559 if (state.pendingcb === 0) {
5560 state.finished = true;
5561 stream.emit('finish');
5562 }
5563 }
5564 return need;
5565}
5566
5567function endWritable(stream, state, cb) {
5568 state.ending = true;
5569 finishMaybe(stream, state);
5570 if (cb) {
5571 if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
5572 }
5573 state.ended = true;
5574 stream.writable = false;
5575}
5576
5577function onCorkedFinish(corkReq, state, err) {
5578 var entry = corkReq.entry;
5579 corkReq.entry = null;
5580 while (entry) {
5581 var cb = entry.callback;
5582 state.pendingcb--;
5583 cb(err);
5584 entry = entry.next;
5585 }
5586 if (state.corkedRequestsFree) {
5587 state.corkedRequestsFree.next = corkReq;
5588 } else {
5589 state.corkedRequestsFree = corkReq;
5590 }
5591}
5592
5593Object.defineProperty(Writable.prototype, 'destroyed', {
5594 get: function () {
5595 if (this._writableState === undefined) {
5596 return false;
5597 }
5598 return this._writableState.destroyed;
5599 },
5600 set: function (value) {
5601 // we ignore the value if the stream
5602 // has not been initialized yet
5603 if (!this._writableState) {
5604 return;
5605 }
5606
5607 // backward compatibility, the user is explicitly
5608 // managing destroyed
5609 this._writableState.destroyed = value;
5610 }
5611});
5612
5613Writable.prototype.destroy = destroyImpl.destroy;
5614Writable.prototype._undestroy = destroyImpl.undestroy;
5615Writable.prototype._destroy = function (err, cb) {
5616 this.end();
5617 cb(err);
5618};
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){
5621'use strict';
5622
5623function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5624
5625var Buffer = require('safe-buffer').Buffer;
5626var util = require('util');
5627
5628function copyBuffer(src, target, offset) {
5629 src.copy(target, offset);
5630}
5631
5632module.exports = function () {
5633 function BufferList() {
5634 _classCallCheck(this, BufferList);
5635
5636 this.head = null;
5637 this.tail = null;
5638 this.length = 0;
5639 }
5640
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;
5644 this.tail = entry;
5645 ++this.length;
5646 };
5647
5648 BufferList.prototype.unshift = function unshift(v) {
5649 var entry = { data: v, next: this.head };
5650 if (this.length === 0) this.tail = entry;
5651 this.head = entry;
5652 ++this.length;
5653 };
5654
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;
5659 --this.length;
5660 return ret;
5661 };
5662
5663 BufferList.prototype.clear = function clear() {
5664 this.head = this.tail = null;
5665 this.length = 0;
5666 };
5667
5668 BufferList.prototype.join = function join(s) {
5669 if (this.length === 0) return '';
5670 var p = this.head;
5671 var ret = '' + p.data;
5672 while (p = p.next) {
5673 ret += s + p.data;
5674 }return ret;
5675 };
5676
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);
5681 var p = this.head;
5682 var i = 0;
5683 while (p) {
5684 copyBuffer(p.data, ret, i);
5685 i += p.data.length;
5686 p = p.next;
5687 }
5688 return ret;
5689 };
5690
5691 return BufferList;
5692}();
5693
5694if (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;
5698 };
5699}
5700},{"safe-buffer":34,"util":4}],26:[function(require,module,exports){
5701'use strict';
5702
5703/*<replacement>*/
5704
5705var pna = require('process-nextick-args');
5706/*</replacement>*/
5707
5708// undocumented cb() API, needed for core, not for public API
5709function destroy(err, cb) {
5710 var _this = this;
5711
5712 var readableDestroyed = this._readableState && this._readableState.destroyed;
5713 var writableDestroyed = this._writableState && this._writableState.destroyed;
5714
5715 if (readableDestroyed || writableDestroyed) {
5716 if (cb) {
5717 cb(err);
5718 } else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
5719 pna.nextTick(emitErrorNT, this, err);
5720 }
5721 return this;
5722 }
5723
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
5726
5727 if (this._readableState) {
5728 this._readableState.destroyed = true;
5729 }
5730
5731 // if this is a duplex stream mark the writable part as destroyed as well
5732 if (this._writableState) {
5733 this._writableState.destroyed = true;
5734 }
5735
5736 this._destroy(err || null, function (err) {
5737 if (!cb && err) {
5738 pna.nextTick(emitErrorNT, _this, err);
5739 if (_this._writableState) {
5740 _this._writableState.errorEmitted = true;
5741 }
5742 } else if (cb) {
5743 cb(err);
5744 }
5745 });
5746
5747 return this;
5748}
5749
5750function 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;
5756 }
5757
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;
5764 }
5765}
5766
5767function emitErrorNT(self, err) {
5768 self.emit('error', err);
5769}
5770
5771module.exports = {
5772 destroy: destroy,
5773 undestroy: undestroy
5774};
5775},{"process-nextick-args":17}],27:[function(require,module,exports){
5776module.exports = require('events').EventEmitter;
5777
5778},{"events":10}],28:[function(require,module,exports){
5779// Copyright Joyent, Inc. and other Node contributors.
5780//
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:
5788//
5789// The above copyright notice and this permission notice shall be included
5790// in all copies or substantial portions of the Software.
5791//
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.
5799
5800'use strict';
5801
5802/*<replacement>*/
5803
5804var Buffer = require('safe-buffer').Buffer;
5805/*</replacement>*/
5806
5807var 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':
5811 return true;
5812 default:
5813 return false;
5814 }
5815};
5816
5817function _normalizeEncoding(enc) {
5818 if (!enc) return 'utf8';
5819 var retried;
5820 while (true) {
5821 switch (enc) {
5822 case 'utf8':
5823 case 'utf-8':
5824 return 'utf8';
5825 case 'ucs2':
5826 case 'ucs-2':
5827 case 'utf16le':
5828 case 'utf-16le':
5829 return 'utf16le';
5830 case 'latin1':
5831 case 'binary':
5832 return 'latin1';
5833 case 'base64':
5834 case 'ascii':
5835 case 'hex':
5836 return enc;
5837 default:
5838 if (retried) return; // undefined
5839 enc = ('' + enc).toLowerCase();
5840 retried = true;
5841 }
5842 }
5843};
5844
5845// Do not cache `Buffer.isEncoding` when checking encoding names as some
5846// modules monkey-patch it to support additional encodings
5847function normalizeEncoding(enc) {
5848 var nenc = _normalizeEncoding(enc);
5849 if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
5850 return nenc || enc;
5851}
5852
5853// StringDecoder provides an interface for efficiently splitting a series of
5854// buffers into a series of JS strings without breaking apart multi-byte
5855// characters.
5856exports.StringDecoder = StringDecoder;
5857function StringDecoder(encoding) {
5858 this.encoding = normalizeEncoding(encoding);
5859 var nb;
5860 switch (this.encoding) {
5861 case 'utf16le':
5862 this.text = utf16Text;
5863 this.end = utf16End;
5864 nb = 4;
5865 break;
5866 case 'utf8':
5867 this.fillLast = utf8FillLast;
5868 nb = 4;
5869 break;
5870 case 'base64':
5871 this.text = base64Text;
5872 this.end = base64End;
5873 nb = 3;
5874 break;
5875 default:
5876 this.write = simpleWrite;
5877 this.end = simpleEnd;
5878 return;
5879 }
5880 this.lastNeed = 0;
5881 this.lastTotal = 0;
5882 this.lastChar = Buffer.allocUnsafe(nb);
5883}
5884
5885StringDecoder.prototype.write = function (buf) {
5886 if (buf.length === 0) return '';
5887 var r;
5888 var i;
5889 if (this.lastNeed) {
5890 r = this.fillLast(buf);
5891 if (r === undefined) return '';
5892 i = this.lastNeed;
5893 this.lastNeed = 0;
5894 } else {
5895 i = 0;
5896 }
5897 if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
5898 return r || '';
5899};
5900
5901StringDecoder.prototype.end = utf8End;
5902
5903// Returns only complete characters in a Buffer
5904StringDecoder.prototype.text = utf8Text;
5905
5906// Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
5907StringDecoder.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);
5911 }
5912 buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
5913 this.lastNeed -= buf.length;
5914};
5915
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.
5918function 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;
5921}
5922
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.
5926function utf8CheckIncomplete(self, buf, i) {
5927 var j = buf.length - 1;
5928 if (j < i) return 0;
5929 var nb = utf8CheckByte(buf[j]);
5930 if (nb >= 0) {
5931 if (nb > 0) self.lastNeed = nb - 1;
5932 return nb;
5933 }
5934 if (--j < i || nb === -2) return 0;
5935 nb = utf8CheckByte(buf[j]);
5936 if (nb >= 0) {
5937 if (nb > 0) self.lastNeed = nb - 2;
5938 return nb;
5939 }
5940 if (--j < i || nb === -2) return 0;
5941 nb = utf8CheckByte(buf[j]);
5942 if (nb >= 0) {
5943 if (nb > 0) {
5944 if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
5945 }
5946 return nb;
5947 }
5948 return 0;
5949}
5950
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
5958// loop.
5959function utf8CheckExtraBytes(self, buf, p) {
5960 if ((buf[0] & 0xC0) !== 0x80) {
5961 self.lastNeed = 0;
5962 return '\ufffd';
5963 }
5964 if (self.lastNeed > 1 && buf.length > 1) {
5965 if ((buf[1] & 0xC0) !== 0x80) {
5966 self.lastNeed = 1;
5967 return '\ufffd';
5968 }
5969 if (self.lastNeed > 2 && buf.length > 2) {
5970 if ((buf[2] & 0xC0) !== 0x80) {
5971 self.lastNeed = 2;
5972 return '\ufffd';
5973 }
5974 }
5975 }
5976}
5977
5978// Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
5979function 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);
5986 }
5987 buf.copy(this.lastChar, p, 0, buf.length);
5988 this.lastNeed -= buf.length;
5989}
5990
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.
5994function 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);
6001}
6002
6003// For UTF-8, a replacement character is added when ending on a partial
6004// character.
6005function utf8End(buf) {
6006 var r = buf && buf.length ? this.write(buf) : '';
6007 if (this.lastNeed) return r + '\ufffd';
6008 return r;
6009}
6010
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.
6015function utf16Text(buf, i) {
6016 if ((buf.length - i) % 2 === 0) {
6017 var r = buf.toString('utf16le', i);
6018 if (r) {
6019 var c = r.charCodeAt(r.length - 1);
6020 if (c >= 0xD800 && c <= 0xDBFF) {
6021 this.lastNeed = 2;
6022 this.lastTotal = 4;
6023 this.lastChar[0] = buf[buf.length - 2];
6024 this.lastChar[1] = buf[buf.length - 1];
6025 return r.slice(0, -1);
6026 }
6027 }
6028 return r;
6029 }
6030 this.lastNeed = 1;
6031 this.lastTotal = 2;
6032 this.lastChar[0] = buf[buf.length - 1];
6033 return buf.toString('utf16le', i, buf.length - 1);
6034}
6035
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.
6038function 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);
6043 }
6044 return r;
6045}
6046
6047function base64Text(buf, i) {
6048 var n = (buf.length - i) % 3;
6049 if (n === 0) return buf.toString('base64', i);
6050 this.lastNeed = 3 - n;
6051 this.lastTotal = 3;
6052 if (n === 1) {
6053 this.lastChar[0] = buf[buf.length - 1];
6054 } else {
6055 this.lastChar[0] = buf[buf.length - 2];
6056 this.lastChar[1] = buf[buf.length - 1];
6057 }
6058 return buf.toString('base64', i, buf.length - n);
6059}
6060
6061function 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);
6064 return r;
6065}
6066
6067// Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
6068function simpleWrite(buf) {
6069 return buf.toString(this.encoding);
6070}
6071
6072function simpleEnd(buf) {
6073 return buf && buf.length ? this.write(buf) : '';
6074}
6075},{"safe-buffer":34}],29:[function(require,module,exports){
6076module.exports = require('./readable').PassThrough
6077
6078},{"./readable":30}],30:[function(require,module,exports){
6079exports = module.exports = require('./lib/_stream_readable.js');
6080exports.Stream = exports;
6081exports.Readable = exports;
6082exports.Writable = require('./lib/_stream_writable.js');
6083exports.Duplex = require('./lib/_stream_duplex.js');
6084exports.Transform = require('./lib/_stream_transform.js');
6085exports.PassThrough = require('./lib/_stream_passthrough.js');
6086
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){
6088module.exports = require('./readable').Transform
6089
6090},{"./readable":30}],32:[function(require,module,exports){
6091module.exports = require('./lib/_stream_writable.js');
6092
6093},{"./lib/_stream_writable.js":24}],33:[function(require,module,exports){
6094'use strict'
6095var Buffer = require('buffer').Buffer
6096var inherits = require('inherits')
6097var HashBase = require('hash-base')
6098
6099var ARRAY16 = new Array(16)
6100
6101var zl = [
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
6107]
6108
6109var zr = [
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
6115]
6116
6117var sl = [
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
6123]
6124
6125var sr = [
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
6131]
6132
6133var hl = [0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e]
6134var hr = [0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000]
6135
6136function RIPEMD160 () {
6137 HashBase.call(this, 64)
6138
6139 // state
6140 this._a = 0x67452301
6141 this._b = 0xefcdab89
6142 this._c = 0x98badcfe
6143 this._d = 0x10325476
6144 this._e = 0xc3d2e1f0
6145}
6146
6147inherits(RIPEMD160, HashBase)
6148
6149RIPEMD160.prototype._update = function () {
6150 var words = ARRAY16
6151 for (var j = 0; j < 16; ++j) words[j] = this._block.readInt32LE(j * 4)
6152
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
6158
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
6164
6165 // computation
6166 for (var i = 0; i < 80; i += 1) {
6167 var tl
6168 var tr
6169 if (i < 16) {
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])
6184 }
6185
6186 al = el
6187 el = dl
6188 dl = rotl(cl, 10)
6189 cl = bl
6190 bl = tl
6191
6192 ar = er
6193 er = dr
6194 dr = rotl(cr, 10)
6195 cr = br
6196 br = tr
6197 }
6198
6199 // update state
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
6205 this._a = t
6206}
6207
6208RIPEMD160.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)
6213 this._update()
6214 this._blockOffset = 0
6215 }
6216
6217 this._block.fill(0, this._blockOffset, 56)
6218 this._block.writeUInt32LE(this._length[0], 56)
6219 this._block.writeUInt32LE(this._length[1], 60)
6220 this._update()
6221
6222 // produce result
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)
6229 return buffer
6230}
6231
6232function rotl (x, n) {
6233 return (x << n) | (x >>> (32 - n))
6234}
6235
6236function fn1 (a, b, c, d, e, m, k, s) {
6237 return (rotl((a + (b ^ c ^ d) + m + k) | 0, s) + e) | 0
6238}
6239
6240function fn2 (a, b, c, d, e, m, k, s) {
6241 return (rotl((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + e) | 0
6242}
6243
6244function fn3 (a, b, c, d, e, m, k, s) {
6245 return (rotl((a + ((b | (~c)) ^ d) + m + k) | 0, s) + e) | 0
6246}
6247
6248function fn4 (a, b, c, d, e, m, k, s) {
6249 return (rotl((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + e) | 0
6250}
6251
6252function fn5 (a, b, c, d, e, m, k, s) {
6253 return (rotl((a + (b ^ (c | (~d))) + m + k) | 0, s) + e) | 0
6254}
6255
6256module.exports = RIPEMD160
6257
6258},{"buffer":6,"hash-base":11,"inherits":13}],34:[function(require,module,exports){
6259/* eslint-disable node/no-deprecated-api */
6260var buffer = require('buffer')
6261var Buffer = buffer.Buffer
6262
6263// alternative to using Object.keys for old browsers
6264function copyProps (src, dst) {
6265 for (var key in src) {
6266 dst[key] = src[key]
6267 }
6268}
6269if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
6270 module.exports = buffer
6271} else {
6272 // Copy properties from require('buffer')
6273 copyProps(buffer, exports)
6274 exports.Buffer = SafeBuffer
6275}
6276
6277function SafeBuffer (arg, encodingOrOffset, length) {
6278 return Buffer(arg, encodingOrOffset, length)
6279}
6280
6281// Copy static methods from Buffer
6282copyProps(Buffer, SafeBuffer)
6283
6284SafeBuffer.from = function (arg, encodingOrOffset, length) {
6285 if (typeof arg === 'number') {
6286 throw new TypeError('Argument must not be a number')
6287 }
6288 return Buffer(arg, encodingOrOffset, length)
6289}
6290
6291SafeBuffer.alloc = function (size, fill, encoding) {
6292 if (typeof size !== 'number') {
6293 throw new TypeError('Argument must be a number')
6294 }
6295 var buf = Buffer(size)
6296 if (fill !== undefined) {
6297 if (typeof encoding === 'string') {
6298 buf.fill(fill, encoding)
6299 } else {
6300 buf.fill(fill)
6301 }
6302 } else {
6303 buf.fill(0)
6304 }
6305 return buf
6306}
6307
6308SafeBuffer.allocUnsafe = function (size) {
6309 if (typeof size !== 'number') {
6310 throw new TypeError('Argument must be a number')
6311 }
6312 return Buffer(size)
6313}
6314
6315SafeBuffer.allocUnsafeSlow = function (size) {
6316 if (typeof size !== 'number') {
6317 throw new TypeError('Argument must be a number')
6318 }
6319 return buffer.SlowBuffer(size)
6320}
6321
6322},{"buffer":6}],35:[function(require,module,exports){
6323var Buffer = require('safe-buffer').Buffer
6324
6325// prototype class for hash functions
6326function Hash (blockSize, finalSize) {
6327 this._block = Buffer.alloc(blockSize)
6328 this._finalSize = finalSize
6329 this._blockSize = blockSize
6330 this._len = 0
6331}
6332
6333Hash.prototype.update = function (data, enc) {
6334 if (typeof data === 'string') {
6335 enc = enc || 'utf8'
6336 data = Buffer.from(data, enc)
6337 }
6338
6339 var block = this._block
6340 var blockSize = this._blockSize
6341 var length = data.length
6342 var accum = this._len
6343
6344 for (var offset = 0; offset < length;) {
6345 var assigned = accum % blockSize
6346 var remainder = Math.min(length - offset, blockSize - assigned)
6347
6348 for (var i = 0; i < remainder; i++) {
6349 block[assigned + i] = data[offset + i]
6350 }
6351
6352 accum += remainder
6353 offset += remainder
6354
6355 if ((accum % blockSize) === 0) {
6356 this._update(block)
6357 }
6358 }
6359
6360 this._len += length
6361 return this
6362}
6363
6364Hash.prototype.digest = function (enc) {
6365 var rem = this._len % this._blockSize
6366
6367 this._block[rem] = 0x80
6368
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)
6372
6373 if (rem >= this._finalSize) {
6374 this._update(this._block)
6375 this._block.fill(0)
6376 }
6377
6378 var bits = this._len * 8
6379
6380 // uint32
6381 if (bits <= 0xffffffff) {
6382 this._block.writeUInt32BE(bits, this._blockSize - 4)
6383
6384 // uint64
6385 } else {
6386 var lowBits = (bits & 0xffffffff) >>> 0
6387 var highBits = (bits - lowBits) / 0x100000000
6388
6389 this._block.writeUInt32BE(highBits, this._blockSize - 8)
6390 this._block.writeUInt32BE(lowBits, this._blockSize - 4)
6391 }
6392
6393 this._update(this._block)
6394 var hash = this._hash()
6395
6396 return enc ? hash.toString(enc) : hash
6397}
6398
6399Hash.prototype._update = function () {
6400 throw new Error('_update must be implemented by subclass')
6401}
6402
6403module.exports = Hash
6404
6405},{"safe-buffer":34}],36:[function(require,module,exports){
6406var exports = module.exports = function SHA (algorithm) {
6407 algorithm = algorithm.toLowerCase()
6408
6409 var Algorithm = exports[algorithm]
6410 if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)')
6411
6412 return new Algorithm()
6413}
6414
6415exports.sha = require('./sha')
6416exports.sha1 = require('./sha1')
6417exports.sha224 = require('./sha224')
6418exports.sha256 = require('./sha256')
6419exports.sha384 = require('./sha384')
6420exports.sha512 = require('./sha512')
6421
6422},{"./sha":37,"./sha1":38,"./sha224":39,"./sha256":40,"./sha384":41,"./sha512":42}],37:[function(require,module,exports){
6423/*
6424 * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
6425 * in FIPS PUB 180-1
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.
6429 */
6430
6431var inherits = require('inherits')
6432var Hash = require('./hash')
6433var Buffer = require('safe-buffer').Buffer
6434
6435var K = [
6436 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
6437]
6438
6439var W = new Array(80)
6440
6441function Sha () {
6442 this.init()
6443 this._w = W
6444
6445 Hash.call(this, 64, 56)
6446}
6447
6448inherits(Sha, Hash)
6449
6450Sha.prototype.init = function () {
6451 this._a = 0x67452301
6452 this._b = 0xefcdab89
6453 this._c = 0x98badcfe
6454 this._d = 0x10325476
6455 this._e = 0xc3d2e1f0
6456
6457 return this
6458}
6459
6460function rotl5 (num) {
6461 return (num << 5) | (num >>> 27)
6462}
6463
6464function rotl30 (num) {
6465 return (num << 30) | (num >>> 2)
6466}
6467
6468function 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)
6471 return b ^ c ^ d
6472}
6473
6474Sha.prototype._update = function (M) {
6475 var W = this._w
6476
6477 var a = this._a | 0
6478 var b = this._b | 0
6479 var c = this._c | 0
6480 var d = this._d | 0
6481 var e = this._e | 0
6482
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]
6485
6486 for (var j = 0; j < 80; ++j) {
6487 var s = ~~(j / 20)
6488 var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
6489
6490 e = d
6491 d = c
6492 c = rotl30(b)
6493 b = a
6494 a = t
6495 }
6496
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
6502}
6503
6504Sha.prototype._hash = function () {
6505 var H = Buffer.allocUnsafe(20)
6506
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)
6512
6513 return H
6514}
6515
6516module.exports = Sha
6517
6518},{"./hash":35,"inherits":13,"safe-buffer":34}],38:[function(require,module,exports){
6519/*
6520 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
6521 * in FIPS PUB 180-1
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.
6526 */
6527
6528var inherits = require('inherits')
6529var Hash = require('./hash')
6530var Buffer = require('safe-buffer').Buffer
6531
6532var K = [
6533 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
6534]
6535
6536var W = new Array(80)
6537
6538function Sha1 () {
6539 this.init()
6540 this._w = W
6541
6542 Hash.call(this, 64, 56)
6543}
6544
6545inherits(Sha1, Hash)
6546
6547Sha1.prototype.init = function () {
6548 this._a = 0x67452301
6549 this._b = 0xefcdab89
6550 this._c = 0x98badcfe
6551 this._d = 0x10325476
6552 this._e = 0xc3d2e1f0
6553
6554 return this
6555}
6556
6557function rotl1 (num) {
6558 return (num << 1) | (num >>> 31)
6559}
6560
6561function rotl5 (num) {
6562 return (num << 5) | (num >>> 27)
6563}
6564
6565function rotl30 (num) {
6566 return (num << 30) | (num >>> 2)
6567}
6568
6569function 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)
6572 return b ^ c ^ d
6573}
6574
6575Sha1.prototype._update = function (M) {
6576 var W = this._w
6577
6578 var a = this._a | 0
6579 var b = this._b | 0
6580 var c = this._c | 0
6581 var d = this._d | 0
6582 var e = this._e | 0
6583
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])
6586
6587 for (var j = 0; j < 80; ++j) {
6588 var s = ~~(j / 20)
6589 var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
6590
6591 e = d
6592 d = c
6593 c = rotl30(b)
6594 b = a
6595 a = t
6596 }
6597
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
6603}
6604
6605Sha1.prototype._hash = function () {
6606 var H = Buffer.allocUnsafe(20)
6607
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)
6613
6614 return H
6615}
6616
6617module.exports = Sha1
6618
6619},{"./hash":35,"inherits":13,"safe-buffer":34}],39:[function(require,module,exports){
6620/**
6621 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
6622 * in FIPS 180-2
6623 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
6624 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
6625 *
6626 */
6627
6628var inherits = require('inherits')
6629var Sha256 = require('./sha256')
6630var Hash = require('./hash')
6631var Buffer = require('safe-buffer').Buffer
6632
6633var W = new Array(64)
6634
6635function Sha224 () {
6636 this.init()
6637
6638 this._w = W // new Array(64)
6639
6640 Hash.call(this, 64, 56)
6641}
6642
6643inherits(Sha224, Sha256)
6644
6645Sha224.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
6654
6655 return this
6656}
6657
6658Sha224.prototype._hash = function () {
6659 var H = Buffer.allocUnsafe(28)
6660
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)
6668
6669 return H
6670}
6671
6672module.exports = Sha224
6673
6674},{"./hash":35,"./sha256":40,"inherits":13,"safe-buffer":34}],40:[function(require,module,exports){
6675/**
6676 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
6677 * in FIPS 180-2
6678 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
6679 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
6680 *
6681 */
6682
6683var inherits = require('inherits')
6684var Hash = require('./hash')
6685var Buffer = require('safe-buffer').Buffer
6686
6687var K = [
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
6704]
6705
6706var W = new Array(64)
6707
6708function Sha256 () {
6709 this.init()
6710
6711 this._w = W // new Array(64)
6712
6713 Hash.call(this, 64, 56)
6714}
6715
6716inherits(Sha256, Hash)
6717
6718Sha256.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
6727
6728 return this
6729}
6730
6731function ch (x, y, z) {
6732 return z ^ (x & (y ^ z))
6733}
6734
6735function maj (x, y, z) {
6736 return (x & y) | (z & (x | y))
6737}
6738
6739function sigma0 (x) {
6740 return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10)
6741}
6742
6743function sigma1 (x) {
6744 return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7)
6745}
6746
6747function gamma0 (x) {
6748 return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3)
6749}
6750
6751function gamma1 (x) {
6752 return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10)
6753}
6754
6755Sha256.prototype._update = function (M) {
6756 var W = this._w
6757
6758 var a = this._a | 0
6759 var b = this._b | 0
6760 var c = this._c | 0
6761 var d = this._d | 0
6762 var e = this._e | 0
6763 var f = this._f | 0
6764 var g = this._g | 0
6765 var h = this._h | 0
6766
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
6769
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
6773
6774 h = g
6775 g = f
6776 f = e
6777 e = (d + T1) | 0
6778 d = c
6779 c = b
6780 b = a
6781 a = (T1 + T2) | 0
6782 }
6783
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
6792}
6793
6794Sha256.prototype._hash = function () {
6795 var H = Buffer.allocUnsafe(32)
6796
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)
6805
6806 return H
6807}
6808
6809module.exports = Sha256
6810
6811},{"./hash":35,"inherits":13,"safe-buffer":34}],41:[function(require,module,exports){
6812var inherits = require('inherits')
6813var SHA512 = require('./sha512')
6814var Hash = require('./hash')
6815var Buffer = require('safe-buffer').Buffer
6816
6817var W = new Array(160)
6818
6819function Sha384 () {
6820 this.init()
6821 this._w = W
6822
6823 Hash.call(this, 128, 112)
6824}
6825
6826inherits(Sha384, SHA512)
6827
6828Sha384.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
6837
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
6846
6847 return this
6848}
6849
6850Sha384.prototype._hash = function () {
6851 var H = Buffer.allocUnsafe(48)
6852
6853 function writeInt64BE (h, l, offset) {
6854 H.writeInt32BE(h, offset)
6855 H.writeInt32BE(l, offset + 4)
6856 }
6857
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)
6864
6865 return H
6866}
6867
6868module.exports = Sha384
6869
6870},{"./hash":35,"./sha512":42,"inherits":13,"safe-buffer":34}],42:[function(require,module,exports){
6871var inherits = require('inherits')
6872var Hash = require('./hash')
6873var Buffer = require('safe-buffer').Buffer
6874
6875var K = [
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
6916]
6917
6918var W = new Array(160)
6919
6920function Sha512 () {
6921 this.init()
6922 this._w = W
6923
6924 Hash.call(this, 128, 112)
6925}
6926
6927inherits(Sha512, Hash)
6928
6929Sha512.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
6938
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
6947
6948 return this
6949}
6950
6951function Ch (x, y, z) {
6952 return z ^ (x & (y ^ z))
6953}
6954
6955function maj (x, y, z) {
6956 return (x & y) | (z & (x | y))
6957}
6958
6959function sigma0 (x, xl) {
6960 return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25)
6961}
6962
6963function sigma1 (x, xl) {
6964 return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23)
6965}
6966
6967function Gamma0 (x, xl) {
6968 return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7)
6969}
6970
6971function Gamma0l (x, xl) {
6972 return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25)
6973}
6974
6975function Gamma1 (x, xl) {
6976 return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6)
6977}
6978
6979function Gamma1l (x, xl) {
6980 return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26)
6981}
6982
6983function getCarry (a, b) {
6984 return (a >>> 0) < (b >>> 0) ? 1 : 0
6985}
6986
6987Sha512.prototype._update = function (M) {
6988 var W = this._w
6989
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
6998
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
7007
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)
7011 }
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)
7017
7018 xh = W[i - 2 * 2]
7019 xl = W[i - 2 * 2 + 1]
7020 var gamma1 = Gamma1(xh, xl)
7021 var gamma1l = Gamma1l(xl, xh)
7022
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]
7026
7027 var Wi16h = W[i - 16 * 2]
7028 var Wi16l = W[i - 16 * 2 + 1]
7029
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
7036
7037 W[i] = Wih
7038 W[i + 1] = Wil
7039 }
7040
7041 for (var j = 0; j < 160; j += 2) {
7042 Wih = W[j]
7043 Wil = W[j + 1]
7044
7045 var majh = maj(ah, bh, ch)
7046 var majl = maj(al, bl, cl)
7047
7048 var sigma0h = sigma0(ah, al)
7049 var sigma0l = sigma0(al, ah)
7050 var sigma1h = sigma1(eh, el)
7051 var sigma1l = sigma1(el, eh)
7052
7053 // t1 = h + sigma1 + ch + K[j] + W[j]
7054 var Kih = K[j]
7055 var Kil = K[j + 1]
7056
7057 var chh = Ch(eh, fh, gh)
7058 var chl = Ch(el, fl, gl)
7059
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
7068
7069 // t2 = sigma0 + maj
7070 var t2l = (sigma0l + majl) | 0
7071 var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0
7072
7073 hh = gh
7074 hl = gl
7075 gh = fh
7076 gl = fl
7077 fh = eh
7078 fl = el
7079 el = (dl + t1l) | 0
7080 eh = (dh + t1h + getCarry(el, dl)) | 0
7081 dh = ch
7082 dl = cl
7083 ch = bh
7084 cl = bl
7085 bh = ah
7086 bl = al
7087 al = (t1l + t2l) | 0
7088 ah = (t1h + t2h + getCarry(al, t1l)) | 0
7089 }
7090
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
7099
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
7108}
7109
7110Sha512.prototype._hash = function () {
7111 var H = Buffer.allocUnsafe(64)
7112
7113 function writeInt64BE (h, l, offset) {
7114 H.writeInt32BE(h, offset)
7115 H.writeInt32BE(l, offset + 4)
7116 }
7117
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)
7126
7127 return H
7128}
7129
7130module.exports = Sha512
7131
7132},{"./hash":35,"inherits":13,"safe-buffer":34}],43:[function(require,module,exports){
7133// Copyright Joyent, Inc. and other Node contributors.
7134//
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:
7142//
7143// The above copyright notice and this permission notice shall be included
7144// in all copies or substantial portions of the Software.
7145//
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.
7153
7154module.exports = Stream;
7155
7156var EE = require('events').EventEmitter;
7157var inherits = require('inherits');
7158
7159inherits(Stream, EE);
7160Stream.Readable = require('readable-stream/readable.js');
7161Stream.Writable = require('readable-stream/writable.js');
7162Stream.Duplex = require('readable-stream/duplex.js');
7163Stream.Transform = require('readable-stream/transform.js');
7164Stream.PassThrough = require('readable-stream/passthrough.js');
7165
7166// Backwards-compat with node 0.4.x
7167Stream.Stream = Stream;
7168
7169
7170
7171// old-style streams. Note that the pipe method (the only relevant
7172// part of this class) is overridden in the Readable class.
7173
7174function Stream() {
7175 EE.call(this);
7176}
7177
7178Stream.prototype.pipe = function(dest, options) {
7179 var source = this;
7180
7181 function ondata(chunk) {
7182 if (dest.writable) {
7183 if (false === dest.write(chunk) && source.pause) {
7184 source.pause();
7185 }
7186 }
7187 }
7188
7189 source.on('data', ondata);
7190
7191 function ondrain() {
7192 if (source.readable && source.resume) {
7193 source.resume();
7194 }
7195 }
7196
7197 dest.on('drain', ondrain);
7198
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);
7204 }
7205
7206 var didOnEnd = false;
7207 function onend() {
7208 if (didOnEnd) return;
7209 didOnEnd = true;
7210
7211 dest.end();
7212 }
7213
7214
7215 function onclose() {
7216 if (didOnEnd) return;
7217 didOnEnd = true;
7218
7219 if (typeof dest.destroy === 'function') dest.destroy();
7220 }
7221
7222 // don't leave dangling pipes when there are errors.
7223 function onerror(er) {
7224 cleanup();
7225 if (EE.listenerCount(this, 'error') === 0) {
7226 throw er; // Unhandled stream error in pipe.
7227 }
7228 }
7229
7230 source.on('error', onerror);
7231 dest.on('error', onerror);
7232
7233 // remove all the event listeners that were added.
7234 function cleanup() {
7235 source.removeListener('data', ondata);
7236 dest.removeListener('drain', ondrain);
7237
7238 source.removeListener('end', onend);
7239 source.removeListener('close', onclose);
7240
7241 source.removeListener('error', onerror);
7242 dest.removeListener('error', onerror);
7243
7244 source.removeListener('end', cleanup);
7245 source.removeListener('close', cleanup);
7246
7247 dest.removeListener('close', cleanup);
7248 }
7249
7250 source.on('end', cleanup);
7251 source.on('close', cleanup);
7252
7253 dest.on('close', cleanup);
7254
7255 dest.emit('pipe', source);
7256
7257 // Allow for unix-like usage: A.pipe(B).pipe(C)
7258 return dest;
7259};
7260
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){
7262arguments[4][28][0].apply(exports,arguments)
7263},{"dup":28,"safe-buffer":34}],45:[function(require,module,exports){
7264(function (setImmediate,clearImmediate){
7265var nextTick = require('process/browser.js').nextTick;
7266var apply = Function.prototype.apply;
7267var slice = Array.prototype.slice;
7268var immediateIds = {};
7269var nextImmediateId = 0;
7270
7271// DOM APIs, for completeness
7272
7273exports.setTimeout = function() {
7274 return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
7275};
7276exports.setInterval = function() {
7277 return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
7278};
7279exports.clearTimeout =
7280exports.clearInterval = function(timeout) { timeout.close(); };
7281
7282function Timeout(id, clearFn) {
7283 this._id = id;
7284 this._clearFn = clearFn;
7285}
7286Timeout.prototype.unref = Timeout.prototype.ref = function() {};
7287Timeout.prototype.close = function() {
7288 this._clearFn.call(window, this._id);
7289};
7290
7291// Does not start the time, just sets up the members needed.
7292exports.enroll = function(item, msecs) {
7293 clearTimeout(item._idleTimeoutId);
7294 item._idleTimeout = msecs;
7295};
7296
7297exports.unenroll = function(item) {
7298 clearTimeout(item._idleTimeoutId);
7299 item._idleTimeout = -1;
7300};
7301
7302exports._unrefActive = exports.active = function(item) {
7303 clearTimeout(item._idleTimeoutId);
7304
7305 var msecs = item._idleTimeout;
7306 if (msecs >= 0) {
7307 item._idleTimeoutId = setTimeout(function onTimeout() {
7308 if (item._onTimeout)
7309 item._onTimeout();
7310 }, msecs);
7311 }
7312};
7313
7314// That's not how node.js implements it but the exposed api is the same.
7315exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function(fn) {
7316 var id = nextImmediateId++;
7317 var args = arguments.length < 2 ? false : slice.call(arguments, 1);
7318
7319 immediateIds[id] = true;
7320
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
7325 if (args) {
7326 fn.apply(null, args);
7327 } else {
7328 fn.call(null);
7329 }
7330 // Prevent ids from leaking
7331 exports.clearImmediate(id);
7332 }
7333 });
7334
7335 return id;
7336};
7337
7338exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) {
7339 delete immediateIds[id];
7340};
7341}).call(this,require("timers").setImmediate,require("timers").clearImmediate)
7342},{"process/browser.js":18,"timers":45}],46:[function(require,module,exports){
7343(function (global){
7344
7345/**
7346 * Module exports.
7347 */
7348
7349module.exports = deprecate;
7350
7351/**
7352 * Mark that a method should not be used.
7353 * Returns a modified function which warns once by default.
7354 *
7355 * If `localStorage.noDeprecation = true` is set, then it is a no-op.
7356 *
7357 * If `localStorage.throwDeprecation = true` is set, then deprecated functions
7358 * will throw an Error when invoked.
7359 *
7360 * If `localStorage.traceDeprecation = true` is set, then deprecated functions
7361 * will invoke `console.trace()` instead of `console.error()`.
7362 *
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`
7366 * @api public
7367 */
7368
7369function deprecate (fn, msg) {
7370 if (config('noDeprecation')) {
7371 return fn;
7372 }
7373
7374 var warned = false;
7375 function deprecated() {
7376 if (!warned) {
7377 if (config('throwDeprecation')) {
7378 throw new Error(msg);
7379 } else if (config('traceDeprecation')) {
7380 console.trace(msg);
7381 } else {
7382 console.warn(msg);
7383 }
7384 warned = true;
7385 }
7386 return fn.apply(this, arguments);
7387 }
7388
7389 return deprecated;
7390}
7391
7392/**
7393 * Checks `localStorage` for boolean values for the given `name`.
7394 *
7395 * @param {String} name
7396 * @returns {Boolean}
7397 * @api private
7398 */
7399
7400function config (name) {
7401 // accessing global.localStorage can trigger a DOMException in sandboxed iframes
7402 try {
7403 if (!global.localStorage) return false;
7404 } catch (_) {
7405 return false;
7406 }
7407 var val = global.localStorage[name];
7408 if (null == val) return false;
7409 return String(val).toLowerCase() === 'true';
7410}
7411
7412}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
7413},{}]},{},[1])(1)
7414});
diff --git a/src/js/index.js b/src/js/index.js
index 64075d3..599e8d1 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -993,10 +993,16 @@
993 address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network) 993 address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network)
994 } 994 }
995 } 995 }
996 996
997 if ((networks[DOM.network.val()].name == "CRW - Crown")) { 997 if ((networks[DOM.network.val()].name == "CRW - Crown")) {
998 address = bitcoinjs.bitcoin.networks.crown.toNewAddress(address); 998 address = bitcoinjs.bitcoin.networks.crown.toNewAddress(address);
999 } 999 }
1000
1001 if (networks[DOM.network.val()].name == "EOS - EOSIO") {
1002 address = ""
1003 pubkey = eosUtil.bufferToPublic(keyPair.getPublicKeyBuffer());
1004 privkey = eosUtil.bufferToPrivate(keyPair.d.toBuffer(32));
1005 }
1000 1006
1001 addAddressToList(indexText, address, pubkey, privkey); 1007 addAddressToList(indexText, address, pubkey, privkey);
1002 if (isLast) { 1008 if (isLast) {
@@ -1973,6 +1979,13 @@
1973 }, 1979 },
1974 }, 1980 },
1975 { 1981 {
1982 name: "DOGEt - Dogecoin Testnet",
1983 onSelect: function() {
1984 network = bitcoinjs.bitcoin.networks.dogecointestnet;
1985 setHdCoin(1);
1986 },
1987 },
1988 {
1976 name: "DXN - DEXON", 1989 name: "DXN - DEXON",
1977 onSelect: function() { 1990 onSelect: function() {
1978 network = bitcoinjs.bitcoin.networks.bitcoin; 1991 network = bitcoinjs.bitcoin.networks.bitcoin;
@@ -2023,6 +2036,13 @@
2023 }, 2036 },
2024 }, 2037 },
2025 { 2038 {
2039 name: "EOS - EOSIO",
2040 onSelect: function() {
2041 network = bitcoinjs.bitcoin.networks.bitcoin;
2042 setHdCoin(194);
2043 },
2044 },
2045 {
2026 name: "ESN - Ethersocial Network", 2046 name: "ESN - Ethersocial Network",
2027 segwitAvailable: false, 2047 segwitAvailable: false,
2028 onSelect: function() { 2048 onSelect: function() {
@@ -2226,6 +2246,14 @@
2226 }, 2246 },
2227 }, 2247 },
2228 { 2248 {
2249 name: "LTCt - Litecoin Testnet",
2250 onSelect: function() {
2251 network = bitcoinjs.bitcoin.networks.litecointestnet;
2252 setHdCoin(1);
2253 DOM.litecoinLtubContainer.removeClass("hidden");
2254 },
2255 },
2256 {
2229 name: "LTZ - LitecoinZ", 2257 name: "LTZ - LitecoinZ",
2230 onSelect: function() { 2258 onSelect: function() {
2231 network = bitcoinjs.bitcoin.networks.litecoinz; 2259 network = bitcoinjs.bitcoin.networks.litecoinz;
@@ -2382,6 +2410,13 @@
2382 }, 2410 },
2383 }, 2411 },
2384 { 2412 {
2413 name: "ONION - DeepOnion",
2414 onSelect: function() {
2415 network = bitcoinjs.bitcoin.networks.deeponion;
2416 setHdCoin(305);
2417 },
2418 },
2419 {
2385 name: "ONX - Onixcoin", 2420 name: "ONX - Onixcoin",
2386 onSelect: function() { 2421 onSelect: function() {
2387 network = bitcoinjs.bitcoin.networks.onixcoin; 2422 network = bitcoinjs.bitcoin.networks.onixcoin;
@@ -2769,6 +2804,13 @@
2769 setHdCoin(121); 2804 setHdCoin(121);
2770 }, 2805 },
2771 }, 2806 },
2807 {
2808 name: "MONK - Monkey Project",
2809 onSelect: function() {
2810 network = bitcoinjs.bitcoin.networks.monkey;
2811 setHdCoin(214);
2812 },
2813 }
2772 ] 2814 ]
2773 2815
2774 var clients = [ 2816 var clients = [
diff --git a/src/js/segwit-parameters.js b/src/js/segwit-parameters.js
index a9bdcbc..b2c72c2 100644
--- a/src/js/segwit-parameters.js
+++ b/src/js/segwit-parameters.js
@@ -161,11 +161,11 @@ bitcoinjs.bitcoin.networks.bgold.p2wpkhInP2sh = {
161 161
162bitcoinjs.bitcoin.networks.digibyte.p2wpkh = { 162bitcoinjs.bitcoin.networks.digibyte.p2wpkh = {
163 baseNetwork: "digibyte", 163 baseNetwork: "digibyte",
164 messagePrefix: '\x18DigiByte Signed Message:\n', 164 messagePrefix: 'x19DigiByte Signed Message:\n',
165 bech32: 'dgb', 165 bech32: 'dgb',
166 bip32: { 166 bip32: {
167 public: 0x0488B21E, 167 public: 0x04b24746,
168 private: 0x0488ADE4 168 private: 0x04b2430c
169 }, 169 },
170 pubKeyHash: 0x1e, 170 pubKeyHash: 0x1e,
171 scriptHash: 0x3f, 171 scriptHash: 0x3f,
@@ -174,11 +174,11 @@ bitcoinjs.bitcoin.networks.digibyte.p2wpkh = {
174 174
175bitcoinjs.bitcoin.networks.digibyte.p2wpkhInP2sh = { 175bitcoinjs.bitcoin.networks.digibyte.p2wpkhInP2sh = {
176 baseNetwork: "digibyte", 176 baseNetwork: "digibyte",
177 messagePrefix: '\x18DigiByte Signed Message:\n', 177 messagePrefix: '\x19DigiByte Signed Message:\n',
178 bech32: 'dgb', 178 bech32: 'dgb',
179 bip32: { 179 bip32: {
180 public: 0x0488B21E, 180 public: 0x049d7cb2,
181 private: 0x0488ADE4 181 private: 0x049d7878
182 }, 182 },
183 pubKeyHash: 0x1e, 183 pubKeyHash: 0x1e,
184 scriptHash: 0x3f, 184 scriptHash: 0x3f,