Guest User

getPNG

a guest
Jul 1st, 2019
870
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  2. (function (global){
  3. 'use strict';
  4.  
  5. var objectAssign = require('object-assign');
  6.  
  7. // compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js
  8. // original notice:
  9.  
  10. /*!
  11.  * The buffer module from node.js, for the browser.
  12.  *
  13.  * @author   Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  14.  * @license  MIT
  15.  */
  16. function compare(a, b) {
  17.   if (a === b) {
  18.     return 0;
  19.   }
  20.  
  21.   var x = a.length;
  22.   var y = b.length;
  23.  
  24.   for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  25.     if (a[i] !== b[i]) {
  26.       x = a[i];
  27.       y = b[i];
  28.       break;
  29.     }
  30.   }
  31.  
  32.   if (x < y) {
  33.     return -1;
  34.   }
  35.   if (y < x) {
  36.     return 1;
  37.   }
  38.   return 0;
  39. }
  40. function isBuffer(b) {
  41.   if (global.Buffer && typeof global.Buffer.isBuffer === 'function') {
  42.     return global.Buffer.isBuffer(b);
  43.   }
  44.   return !!(b != null && b._isBuffer);
  45. }
  46.  
  47. // based on node assert, original notice:
  48. // NB: The URL to the CommonJS spec is kept just for tradition.
  49. //     node-assert has evolved a lot since then, both in API and behavior.
  50.  
  51. // http://wiki.commonjs.org/wiki/Unit_Testing/1.0
  52. //
  53. // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
  54. //
  55. // Originally from narwhal.js (http://narwhaljs.org)
  56. // Copyright (c) 2009 Thomas Robinson <280north.com>
  57. //
  58. // Permission is hereby granted, free of charge, to any person obtaining a copy
  59. // of this software and associated documentation files (the 'Software'), to
  60. // deal in the Software without restriction, including without limitation the
  61. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  62. // sell copies of the Software, and to permit persons to whom the Software is
  63. // furnished to do so, subject to the following conditions:
  64. //
  65. // The above copyright notice and this permission notice shall be included in
  66. // all copies or substantial portions of the Software.
  67. //
  68. // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  69. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  70. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  71. // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  72. // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  73. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  74.  
  75. var util = require('util/');
  76. var hasOwn = Object.prototype.hasOwnProperty;
  77. var pSlice = Array.prototype.slice;
  78. var functionsHaveNames = (function () {
  79.   return function foo() {}.name === 'foo';
  80. }());
  81. function pToString (obj) {
  82.   return Object.prototype.toString.call(obj);
  83. }
  84. function isView(arrbuf) {
  85.   if (isBuffer(arrbuf)) {
  86.     return false;
  87.   }
  88.   if (typeof global.ArrayBuffer !== 'function') {
  89.     return false;
  90.   }
  91.   if (typeof ArrayBuffer.isView === 'function') {
  92.     return ArrayBuffer.isView(arrbuf);
  93.   }
  94.   if (!arrbuf) {
  95.     return false;
  96.   }
  97.   if (arrbuf instanceof DataView) {
  98.     return true;
  99.   }
  100.   if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) {
  101.     return true;
  102.   }
  103.   return false;
  104. }
  105. // 1. The assert module provides functions that throw
  106. // AssertionError's when particular conditions are not met. The
  107. // assert module must conform to the following interface.
  108.  
  109. var assert = module.exports = ok;
  110.  
  111. // 2. The AssertionError is defined in assert.
  112. // new assert.AssertionError({ message: message,
  113. //                             actual: actual,
  114. //                             expected: expected })
  115.  
  116. var regex = /\s*function\s+([^\(\s]*)\s*/;
  117. // based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js
  118. function getName(func) {
  119.   if (!util.isFunction(func)) {
  120.     return;
  121.   }
  122.   if (functionsHaveNames) {
  123.     return func.name;
  124.   }
  125.   var str = func.toString();
  126.   var match = str.match(regex);
  127.   return match && match[1];
  128. }
  129. assert.AssertionError = function AssertionError(options) {
  130.   this.name = 'AssertionError';
  131.   this.actual = options.actual;
  132.   this.expected = options.expected;
  133.   this.operator = options.operator;
  134.   if (options.message) {
  135.     this.message = options.message;
  136.     this.generatedMessage = false;
  137.   } else {
  138.     this.message = getMessage(this);
  139.     this.generatedMessage = true;
  140.   }
  141.   var stackStartFunction = options.stackStartFunction || fail;
  142.   if (Error.captureStackTrace) {
  143.     Error.captureStackTrace(this, stackStartFunction);
  144.   } else {
  145.     // non v8 browsers so we can have a stacktrace
  146.     var err = new Error();
  147.     if (err.stack) {
  148.       var out = err.stack;
  149.  
  150.       // try to strip useless frames
  151.       var fn_name = getName(stackStartFunction);
  152.       var idx = out.indexOf('\n' + fn_name);
  153.       if (idx >= 0) {
  154.         // once we have located the function frame
  155.         // we need to strip out everything before it (and its line)
  156.         var next_line = out.indexOf('\n', idx + 1);
  157.         out = out.substring(next_line + 1);
  158.       }
  159.  
  160.       this.stack = out;
  161.     }
  162.   }
  163. };
  164.  
  165. // assert.AssertionError instanceof Error
  166. util.inherits(assert.AssertionError, Error);
  167.  
  168. function truncate(s, n) {
  169.   if (typeof s === 'string') {
  170.     return s.length < n ? s : s.slice(0, n);
  171.   } else {
  172.     return s;
  173.   }
  174. }
  175. function inspect(something) {
  176.   if (functionsHaveNames || !util.isFunction(something)) {
  177.     return util.inspect(something);
  178.   }
  179.   var rawname = getName(something);
  180.   var name = rawname ? ': ' + rawname : '';
  181.   return '[Function' +  name + ']';
  182. }
  183. function getMessage(self) {
  184.   return truncate(inspect(self.actual), 128) + ' ' +
  185.          self.operator + ' ' +
  186.          truncate(inspect(self.expected), 128);
  187. }
  188.  
  189. // At present only the three keys mentioned above are used and
  190. // understood by the spec. Implementations or sub modules can pass
  191. // other keys to the AssertionError's constructor - they will be
  192. // ignored.
  193.  
  194. // 3. All of the following functions must throw an AssertionError
  195. // when a corresponding condition is not met, with a message that
  196. // may be undefined if not provided.  All assertion methods provide
  197. // both the actual and expected values to the assertion error for
  198. // display purposes.
  199.  
  200. function fail(actual, expected, message, operator, stackStartFunction) {
  201.   throw new assert.AssertionError({
  202.     message: message,
  203.     actual: actual,
  204.     expected: expected,
  205.     operator: operator,
  206.     stackStartFunction: stackStartFunction
  207.   });
  208. }
  209.  
  210. // EXTENSION! allows for well behaved errors defined elsewhere.
  211. assert.fail = fail;
  212.  
  213. // 4. Pure assertion tests whether a value is truthy, as determined
  214. // by !!guard.
  215. // assert.ok(guard, message_opt);
  216. // This statement is equivalent to assert.equal(true, !!guard,
  217. // message_opt);. To test strictly for the value true, use
  218. // assert.strictEqual(true, guard, message_opt);.
  219.  
  220. function ok(value, message) {
  221.   if (!value) fail(value, true, message, '==', assert.ok);
  222. }
  223. assert.ok = ok;
  224.  
  225. // 5. The equality assertion tests shallow, coercive equality with
  226. // ==.
  227. // assert.equal(actual, expected, message_opt);
  228.  
  229. assert.equal = function equal(actual, expected, message) {
  230.   if (actual != expected) fail(actual, expected, message, '==', assert.equal);
  231. };
  232.  
  233. // 6. The non-equality assertion tests for whether two objects are not equal
  234. // with != assert.notEqual(actual, expected, message_opt);
  235.  
  236. assert.notEqual = function notEqual(actual, expected, message) {
  237.   if (actual == expected) {
  238.     fail(actual, expected, message, '!=', assert.notEqual);
  239.   }
  240. };
  241.  
  242. // 7. The equivalence assertion tests a deep equality relation.
  243. // assert.deepEqual(actual, expected, message_opt);
  244.  
  245. assert.deepEqual = function deepEqual(actual, expected, message) {
  246.   if (!_deepEqual(actual, expected, false)) {
  247.     fail(actual, expected, message, 'deepEqual', assert.deepEqual);
  248.   }
  249. };
  250.  
  251. assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
  252.   if (!_deepEqual(actual, expected, true)) {
  253.     fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual);
  254.   }
  255. };
  256.  
  257. function _deepEqual(actual, expected, strict, memos) {
  258.   // 7.1. All identical values are equivalent, as determined by ===.
  259.   if (actual === expected) {
  260.     return true;
  261.   } else if (isBuffer(actual) && isBuffer(expected)) {
  262.     return compare(actual, expected) === 0;
  263.  
  264.   // 7.2. If the expected value is a Date object, the actual value is
  265.   // equivalent if it is also a Date object that refers to the same time.
  266.   } else if (util.isDate(actual) && util.isDate(expected)) {
  267.     return actual.getTime() === expected.getTime();
  268.  
  269.   // 7.3 If the expected value is a RegExp object, the actual value is
  270.   // equivalent if it is also a RegExp object with the same source and
  271.   // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
  272.   } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
  273.     return actual.source === expected.source &&
  274.            actual.global === expected.global &&
  275.            actual.multiline === expected.multiline &&
  276.            actual.lastIndex === expected.lastIndex &&
  277.            actual.ignoreCase === expected.ignoreCase;
  278.  
  279.   // 7.4. Other pairs that do not both pass typeof value == 'object',
  280.   // equivalence is determined by ==.
  281.   } else if ((actual === null || typeof actual !== 'object') &&
  282.              (expected === null || typeof expected !== 'object')) {
  283.     return strict ? actual === expected : actual == expected;
  284.  
  285.   // If both values are instances of typed arrays, wrap their underlying
  286.   // ArrayBuffers in a Buffer each to increase performance
  287.   // This optimization requires the arrays to have the same type as checked by
  288.   // Object.prototype.toString (aka pToString). Never perform binary
  289.   // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their
  290.   // bit patterns are not identical.
  291.   } else if (isView(actual) && isView(expected) &&
  292.              pToString(actual) === pToString(expected) &&
  293.              !(actual instanceof Float32Array ||
  294.                actual instanceof Float64Array)) {
  295.     return compare(new Uint8Array(actual.buffer),
  296.                    new Uint8Array(expected.buffer)) === 0;
  297.  
  298.   // 7.5 For all other Object pairs, including Array objects, equivalence is
  299.   // determined by having the same number of owned properties (as verified
  300.   // with Object.prototype.hasOwnProperty.call), the same set of keys
  301.   // (although not necessarily the same order), equivalent values for every
  302.   // corresponding key, and an identical 'prototype' property. Note: this
  303.   // accounts for both named and indexed properties on Arrays.
  304.   } else if (isBuffer(actual) !== isBuffer(expected)) {
  305.     return false;
  306.   } else {
  307.     memos = memos || {actual: [], expected: []};
  308.  
  309.     var actualIndex = memos.actual.indexOf(actual);
  310.     if (actualIndex !== -1) {
  311.       if (actualIndex === memos.expected.indexOf(expected)) {
  312.         return true;
  313.       }
  314.     }
  315.  
  316.     memos.actual.push(actual);
  317.     memos.expected.push(expected);
  318.  
  319.     return objEquiv(actual, expected, strict, memos);
  320.   }
  321. }
  322.  
  323. function isArguments(object) {
  324.   return Object.prototype.toString.call(object) == '[object Arguments]';
  325. }
  326.  
  327. function objEquiv(a, b, strict, actualVisitedObjects) {
  328.   if (a === null || a === undefined || b === null || b === undefined)
  329.     return false;
  330.   // if one is a primitive, the other must be same
  331.   if (util.isPrimitive(a) || util.isPrimitive(b))
  332.     return a === b;
  333.   if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
  334.     return false;
  335.   var aIsArgs = isArguments(a);
  336.   var bIsArgs = isArguments(b);
  337.   if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
  338.     return false;
  339.   if (aIsArgs) {
  340.     a = pSlice.call(a);
  341.     b = pSlice.call(b);
  342.     return _deepEqual(a, b, strict);
  343.   }
  344.   var ka = objectKeys(a);
  345.   var kb = objectKeys(b);
  346.   var key, i;
  347.   // having the same number of owned properties (keys incorporates
  348.   // hasOwnProperty)
  349.   if (ka.length !== kb.length)
  350.     return false;
  351.   //the same set of keys (although not necessarily the same order),
  352.   ka.sort();
  353.   kb.sort();
  354.   //~~~cheap key test
  355.   for (i = ka.length - 1; i >= 0; i--) {
  356.     if (ka[i] !== kb[i])
  357.       return false;
  358.   }
  359.   //equivalent values for every corresponding key, and
  360.   //~~~possibly expensive deep test
  361.   for (i = ka.length - 1; i >= 0; i--) {
  362.     key = ka[i];
  363.     if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects))
  364.       return false;
  365.   }
  366.   return true;
  367. }
  368.  
  369. // 8. The non-equivalence assertion tests for any deep inequality.
  370. // assert.notDeepEqual(actual, expected, message_opt);
  371.  
  372. assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
  373.   if (_deepEqual(actual, expected, false)) {
  374.     fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
  375.   }
  376. };
  377.  
  378. assert.notDeepStrictEqual = notDeepStrictEqual;
  379. function notDeepStrictEqual(actual, expected, message) {
  380.   if (_deepEqual(actual, expected, true)) {
  381.     fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual);
  382.   }
  383. }
  384.  
  385.  
  386. // 9. The strict equality assertion tests strict equality, as determined by ===.
  387. // assert.strictEqual(actual, expected, message_opt);
  388.  
  389. assert.strictEqual = function strictEqual(actual, expected, message) {
  390.   if (actual !== expected) {
  391.     fail(actual, expected, message, '===', assert.strictEqual);
  392.   }
  393. };
  394.  
  395. // 10. The strict non-equality assertion tests for strict inequality, as
  396. // determined by !==.  assert.notStrictEqual(actual, expected, message_opt);
  397.  
  398. assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
  399.   if (actual === expected) {
  400.     fail(actual, expected, message, '!==', assert.notStrictEqual);
  401.   }
  402. };
  403.  
  404. function expectedException(actual, expected) {
  405.   if (!actual || !expected) {
  406.     return false;
  407.   }
  408.  
  409.   if (Object.prototype.toString.call(expected) == '[object RegExp]') {
  410.     return expected.test(actual);
  411.   }
  412.  
  413.   try {
  414.     if (actual instanceof expected) {
  415.       return true;
  416.     }
  417.   } catch (e) {
  418.     // Ignore.  The instanceof check doesn't work for arrow functions.
  419.   }
  420.  
  421.   if (Error.isPrototypeOf(expected)) {
  422.     return false;
  423.   }
  424.  
  425.   return expected.call({}, actual) === true;
  426. }
  427.  
  428. function _tryBlock(block) {
  429.   var error;
  430.   try {
  431.     block();
  432.   } catch (e) {
  433.     error = e;
  434.   }
  435.   return error;
  436. }
  437.  
  438. function _throws(shouldThrow, block, expected, message) {
  439.   var actual;
  440.  
  441.   if (typeof block !== 'function') {
  442.     throw new TypeError('"block" argument must be a function');
  443.   }
  444.  
  445.   if (typeof expected === 'string') {
  446.     message = expected;
  447.     expected = null;
  448.   }
  449.  
  450.   actual = _tryBlock(block);
  451.  
  452.   message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
  453.             (message ? ' ' + message : '.');
  454.  
  455.   if (shouldThrow && !actual) {
  456.     fail(actual, expected, 'Missing expected exception' + message);
  457.   }
  458.  
  459.   var userProvidedMessage = typeof message === 'string';
  460.   var isUnwantedException = !shouldThrow && util.isError(actual);
  461.   var isUnexpectedException = !shouldThrow && actual && !expected;
  462.  
  463.   if ((isUnwantedException &&
  464.       userProvidedMessage &&
  465.       expectedException(actual, expected)) ||
  466.       isUnexpectedException) {
  467.     fail(actual, expected, 'Got unwanted exception' + message);
  468.   }
  469.  
  470.   if ((shouldThrow && actual && expected &&
  471.       !expectedException(actual, expected)) || (!shouldThrow && actual)) {
  472.     throw actual;
  473.   }
  474. }
  475.  
  476. // 11. Expected to throw an error:
  477. // assert.throws(block, Error_opt, message_opt);
  478.  
  479. assert.throws = function(block, /*optional*/error, /*optional*/message) {
  480.   _throws(true, block, error, message);
  481. };
  482.  
  483. // EXTENSION! This is annoying to write outside this module.
  484. assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
  485.   _throws(false, block, error, message);
  486. };
  487.  
  488. assert.ifError = function(err) { if (err) throw err; };
  489.  
  490. // Expose a strict only variant of assert
  491. function strict(value, message) {
  492.   if (!value) fail(value, true, message, '==', strict);
  493. }
  494. assert.strict = objectAssign(strict, assert, {
  495.   equal: assert.strictEqual,
  496.   deepEqual: assert.deepStrictEqual,
  497.   notEqual: assert.notStrictEqual,
  498.   notDeepEqual: assert.notDeepStrictEqual
  499. });
  500. assert.strict.strict = assert.strict;
  501.  
  502. var objectKeys = Object.keys || function (obj) {
  503.   var keys = [];
  504.   for (var key in obj) {
  505.     if (hasOwn.call(obj, key)) keys.push(key);
  506.   }
  507.   return keys;
  508. };
  509.  
  510. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  511. },{"object-assign":16,"util/":4}],2:[function(require,module,exports){
  512. if (typeof Object.create === 'function') {
  513.   // implementation from standard node.js 'util' module
  514.   module.exports = function inherits(ctor, superCtor) {
  515.     ctor.super_ = superCtor
  516.     ctor.prototype = Object.create(superCtor.prototype, {
  517.       constructor: {
  518.         value: ctor,
  519.         enumerable: false,
  520.         writable: true,
  521.         configurable: true
  522.       }
  523.     });
  524.   };
  525. } else {
  526.   // old school shim for old browsers
  527.   module.exports = function inherits(ctor, superCtor) {
  528.     ctor.super_ = superCtor
  529.     var TempCtor = function () {}
  530.     TempCtor.prototype = superCtor.prototype
  531.     ctor.prototype = new TempCtor()
  532.     ctor.prototype.constructor = ctor
  533.   }
  534. }
  535.  
  536. },{}],3:[function(require,module,exports){
  537. module.exports = function isBuffer(arg) {
  538.   return arg && typeof arg === 'object'
  539.     && typeof arg.copy === 'function'
  540.     && typeof arg.fill === 'function'
  541.     && typeof arg.readUInt8 === 'function';
  542. }
  543. },{}],4:[function(require,module,exports){
  544. (function (process,global){
  545. // Copyright Joyent, Inc. and other Node contributors.
  546. //
  547. // Permission is hereby granted, free of charge, to any person obtaining a
  548. // copy of this software and associated documentation files (the
  549. // "Software"), to deal in the Software without restriction, including
  550. // without limitation the rights to use, copy, modify, merge, publish,
  551. // distribute, sublicense, and/or sell copies of the Software, and to permit
  552. // persons to whom the Software is furnished to do so, subject to the
  553. // following conditions:
  554. //
  555. // The above copyright notice and this permission notice shall be included
  556. // in all copies or substantial portions of the Software.
  557. //
  558. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  559. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  560. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  561. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  562. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  563. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  564. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  565.  
  566. var formatRegExp = /%[sdj%]/g;
  567. exports.format = function(f) {
  568.   if (!isString(f)) {
  569.     var objects = [];
  570.     for (var i = 0; i < arguments.length; i++) {
  571.       objects.push(inspect(arguments[i]));
  572.     }
  573.     return objects.join(' ');
  574.   }
  575.  
  576.   var i = 1;
  577.   var args = arguments;
  578.   var len = args.length;
  579.   var str = String(f).replace(formatRegExp, function(x) {
  580.     if (x === '%%') return '%';
  581.     if (i >= len) return x;
  582.     switch (x) {
  583.       case '%s': return String(args[i++]);
  584.       case '%d': return Number(args[i++]);
  585.       case '%j':
  586.         try {
  587.           return JSON.stringify(args[i++]);
  588.         } catch (_) {
  589.           return '[Circular]';
  590.         }
  591.       default:
  592.         return x;
  593.     }
  594.   });
  595.   for (var x = args[i]; i < len; x = args[++i]) {
  596.     if (isNull(x) || !isObject(x)) {
  597.       str += ' ' + x;
  598.     } else {
  599.       str += ' ' + inspect(x);
  600.     }
  601.   }
  602.   return str;
  603. };
  604.  
  605.  
  606. // Mark that a method should not be used.
  607. // Returns a modified function which warns once by default.
  608. // If --no-deprecation is set, then it is a no-op.
  609. exports.deprecate = function(fn, msg) {
  610.   // Allow for deprecating things in the process of starting up.
  611.   if (isUndefined(global.process)) {
  612.     return function() {
  613.       return exports.deprecate(fn, msg).apply(this, arguments);
  614.     };
  615.   }
  616.  
  617.   if (process.noDeprecation === true) {
  618.     return fn;
  619.   }
  620.  
  621.   var warned = false;
  622.   function deprecated() {
  623.     if (!warned) {
  624.       if (process.throwDeprecation) {
  625.         throw new Error(msg);
  626.       } else if (process.traceDeprecation) {
  627.         console.trace(msg);
  628.       } else {
  629.         console.error(msg);
  630.       }
  631.       warned = true;
  632.     }
  633.     return fn.apply(this, arguments);
  634.   }
  635.  
  636.   return deprecated;
  637. };
  638.  
  639.  
  640. var debugs = {};
  641. var debugEnviron;
  642. exports.debuglog = function(set) {
  643.   if (isUndefined(debugEnviron))
  644.     debugEnviron = process.env.NODE_DEBUG || '';
  645.   set = set.toUpperCase();
  646.   if (!debugs[set]) {
  647.     if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  648.       var pid = process.pid;
  649.       debugs[set] = function() {
  650.         var msg = exports.format.apply(exports, arguments);
  651.         console.error('%s %d: %s', set, pid, msg);
  652.       };
  653.     } else {
  654.       debugs[set] = function() {};
  655.     }
  656.   }
  657.   return debugs[set];
  658. };
  659.  
  660.  
  661. /**
  662.  * Echos the value of a value. Trys to print the value out
  663.  * in the best way possible given the different types.
  664.  *
  665.  * @param {Object} obj The object to print out.
  666.  * @param {Object} opts Optional options object that alters the output.
  667.  */
  668. /* legacy: obj, showHidden, depth, colors*/
  669. function inspect(obj, opts) {
  670.   // default options
  671.   var ctx = {
  672.     seen: [],
  673.     stylize: stylizeNoColor
  674.   };
  675.   // legacy...
  676.   if (arguments.length >= 3) ctx.depth = arguments[2];
  677.   if (arguments.length >= 4) ctx.colors = arguments[3];
  678.   if (isBoolean(opts)) {
  679.     // legacy...
  680.     ctx.showHidden = opts;
  681.   } else if (opts) {
  682.     // got an "options" object
  683.     exports._extend(ctx, opts);
  684.   }
  685.   // set default options
  686.   if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  687.   if (isUndefined(ctx.depth)) ctx.depth = 2;
  688.   if (isUndefined(ctx.colors)) ctx.colors = false;
  689.   if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  690.   if (ctx.colors) ctx.stylize = stylizeWithColor;
  691.   return formatValue(ctx, obj, ctx.depth);
  692. }
  693. exports.inspect = inspect;
  694.  
  695.  
  696. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  697. inspect.colors = {
  698.   'bold' : [1, 22],
  699.   'italic' : [3, 23],
  700.   'underline' : [4, 24],
  701.   'inverse' : [7, 27],
  702.   'white' : [37, 39],
  703.   'grey' : [90, 39],
  704.   'black' : [30, 39],
  705.   'blue' : [34, 39],
  706.   'cyan' : [36, 39],
  707.   'green' : [32, 39],
  708.   'magenta' : [35, 39],
  709.   'red' : [31, 39],
  710.   'yellow' : [33, 39]
  711. };
  712.  
  713. // Don't use 'blue' not visible on cmd.exe
  714. inspect.styles = {
  715.   'special': 'cyan',
  716.   'number': 'yellow',
  717.   'boolean': 'yellow',
  718.   'undefined': 'grey',
  719.   'null': 'bold',
  720.   'string': 'green',
  721.   'date': 'magenta',
  722.   // "name": intentionally not styling
  723.   'regexp': 'red'
  724. };
  725.  
  726.  
  727. function stylizeWithColor(str, styleType) {
  728.   var style = inspect.styles[styleType];
  729.  
  730.   if (style) {
  731.     return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  732.            '\u001b[' + inspect.colors[style][1] + 'm';
  733.   } else {
  734.     return str;
  735.   }
  736. }
  737.  
  738.  
  739. function stylizeNoColor(str, styleType) {
  740.   return str;
  741. }
  742.  
  743.  
  744. function arrayToHash(array) {
  745.   var hash = {};
  746.  
  747.   array.forEach(function(val, idx) {
  748.     hash[val] = true;
  749.   });
  750.  
  751.   return hash;
  752. }
  753.  
  754.  
  755. function formatValue(ctx, value, recurseTimes) {
  756.   // Provide a hook for user-specified inspect functions.
  757.   // Check that value is an object with an inspect function on it
  758.   if (ctx.customInspect &&
  759.       value &&
  760.       isFunction(value.inspect) &&
  761.       // Filter out the util module, it's inspect function is special
  762.       value.inspect !== exports.inspect &&
  763.       // Also filter out any prototype objects using the circular check.
  764.       !(value.constructor && value.constructor.prototype === value)) {
  765.     var ret = value.inspect(recurseTimes, ctx);
  766.     if (!isString(ret)) {
  767.       ret = formatValue(ctx, ret, recurseTimes);
  768.     }
  769.     return ret;
  770.   }
  771.  
  772.   // Primitive types cannot have properties
  773.   var primitive = formatPrimitive(ctx, value);
  774.   if (primitive) {
  775.     return primitive;
  776.   }
  777.  
  778.   // Look up the keys of the object.
  779.   var keys = Object.keys(value);
  780.   var visibleKeys = arrayToHash(keys);
  781.  
  782.   if (ctx.showHidden) {
  783.     keys = Object.getOwnPropertyNames(value);
  784.   }
  785.  
  786.   // IE doesn't make error fields non-enumerable
  787.   // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  788.   if (isError(value)
  789.       && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  790.     return formatError(value);
  791.   }
  792.  
  793.   // Some type of object without properties can be shortcutted.
  794.   if (keys.length === 0) {
  795.     if (isFunction(value)) {
  796.       var name = value.name ? ': ' + value.name : '';
  797.       return ctx.stylize('[Function' + name + ']', 'special');
  798.     }
  799.     if (isRegExp(value)) {
  800.       return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  801.     }
  802.     if (isDate(value)) {
  803.       return ctx.stylize(Date.prototype.toString.call(value), 'date');
  804.     }
  805.     if (isError(value)) {
  806.       return formatError(value);
  807.     }
  808.   }
  809.  
  810.   var base = '', array = false, braces = ['{', '}'];
  811.  
  812.   // Make Array say that they are Array
  813.   if (isArray(value)) {
  814.     array = true;
  815.     braces = ['[', ']'];
  816.   }
  817.  
  818.   // Make functions say that they are functions
  819.   if (isFunction(value)) {
  820.     var n = value.name ? ': ' + value.name : '';
  821.     base = ' [Function' + n + ']';
  822.   }
  823.  
  824.   // Make RegExps say that they are RegExps
  825.   if (isRegExp(value)) {
  826.     base = ' ' + RegExp.prototype.toString.call(value);
  827.   }
  828.  
  829.   // Make dates with properties first say the date
  830.   if (isDate(value)) {
  831.     base = ' ' + Date.prototype.toUTCString.call(value);
  832.   }
  833.  
  834.   // Make error with message first say the error
  835.   if (isError(value)) {
  836.     base = ' ' + formatError(value);
  837.   }
  838.  
  839.   if (keys.length === 0 && (!array || value.length == 0)) {
  840.     return braces[0] + base + braces[1];
  841.   }
  842.  
  843.   if (recurseTimes < 0) {
  844.     if (isRegExp(value)) {
  845.       return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  846.     } else {
  847.       return ctx.stylize('[Object]', 'special');
  848.     }
  849.   }
  850.  
  851.   ctx.seen.push(value);
  852.  
  853.   var output;
  854.   if (array) {
  855.     output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  856.   } else {
  857.     output = keys.map(function(key) {
  858.       return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  859.     });
  860.   }
  861.  
  862.   ctx.seen.pop();
  863.  
  864.   return reduceToSingleString(output, base, braces);
  865. }
  866.  
  867.  
  868. function formatPrimitive(ctx, value) {
  869.   if (isUndefined(value))
  870.     return ctx.stylize('undefined', 'undefined');
  871.   if (isString(value)) {
  872.     var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  873.                                              .replace(/'/g, "\\'")
  874.                                              .replace(/\\"/g, '"') + '\'';
  875.     return ctx.stylize(simple, 'string');
  876.   }
  877.   if (isNumber(value))
  878.     return ctx.stylize('' + value, 'number');
  879.   if (isBoolean(value))
  880.     return ctx.stylize('' + value, 'boolean');
  881.   // For some reason typeof null is "object", so special case here.
  882.   if (isNull(value))
  883.     return ctx.stylize('null', 'null');
  884. }
  885.  
  886.  
  887. function formatError(value) {
  888.   return '[' + Error.prototype.toString.call(value) + ']';
  889. }
  890.  
  891.  
  892. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  893.   var output = [];
  894.   for (var i = 0, l = value.length; i < l; ++i) {
  895.     if (hasOwnProperty(value, String(i))) {
  896.       output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  897.           String(i), true));
  898.     } else {
  899.       output.push('');
  900.     }
  901.   }
  902.   keys.forEach(function(key) {
  903.     if (!key.match(/^\d+$/)) {
  904.       output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  905.           key, true));
  906.     }
  907.   });
  908.   return output;
  909. }
  910.  
  911.  
  912. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  913.   var name, str, desc;
  914.   desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  915.   if (desc.get) {
  916.     if (desc.set) {
  917.       str = ctx.stylize('[Getter/Setter]', 'special');
  918.     } else {
  919.       str = ctx.stylize('[Getter]', 'special');
  920.     }
  921.   } else {
  922.     if (desc.set) {
  923.       str = ctx.stylize('[Setter]', 'special');
  924.     }
  925.   }
  926.   if (!hasOwnProperty(visibleKeys, key)) {
  927.     name = '[' + key + ']';
  928.   }
  929.   if (!str) {
  930.     if (ctx.seen.indexOf(desc.value) < 0) {
  931.       if (isNull(recurseTimes)) {
  932.         str = formatValue(ctx, desc.value, null);
  933.       } else {
  934.         str = formatValue(ctx, desc.value, recurseTimes - 1);
  935.       }
  936.       if (str.indexOf('\n') > -1) {
  937.         if (array) {
  938.           str = str.split('\n').map(function(line) {
  939.             return '  ' + line;
  940.           }).join('\n').substr(2);
  941.         } else {
  942.           str = '\n' + str.split('\n').map(function(line) {
  943.             return '   ' + line;
  944.           }).join('\n');
  945.         }
  946.       }
  947.     } else {
  948.       str = ctx.stylize('[Circular]', 'special');
  949.     }
  950.   }
  951.   if (isUndefined(name)) {
  952.     if (array && key.match(/^\d+$/)) {
  953.       return str;
  954.     }
  955.     name = JSON.stringify('' + key);
  956.     if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  957.       name = name.substr(1, name.length - 2);
  958.       name = ctx.stylize(name, 'name');
  959.     } else {
  960.       name = name.replace(/'/g, "\\'")
  961.                  .replace(/\\"/g, '"')
  962.                  .replace(/(^"|"$)/g, "'");
  963.       name = ctx.stylize(name, 'string');
  964.     }
  965.   }
  966.  
  967.   return name + ': ' + str;
  968. }
  969.  
  970.  
  971. function reduceToSingleString(output, base, braces) {
  972.   var numLinesEst = 0;
  973.   var length = output.reduce(function(prev, cur) {
  974.     numLinesEst++;
  975.     if (cur.indexOf('\n') >= 0) numLinesEst++;
  976.     return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  977.   }, 0);
  978.  
  979.   if (length > 60) {
  980.     return braces[0] +
  981.            (base === '' ? '' : base + '\n ') +
  982.            ' ' +
  983.            output.join(',\n  ') +
  984.            ' ' +
  985.            braces[1];
  986.   }
  987.  
  988.   return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  989. }
  990.  
  991.  
  992. // NOTE: These type checking functions intentionally don't use `instanceof`
  993. // because it is fragile and can be easily faked with `Object.create()`.
  994. function isArray(ar) {
  995.   return Array.isArray(ar);
  996. }
  997. exports.isArray = isArray;
  998.  
  999. function isBoolean(arg) {
  1000.   return typeof arg === 'boolean';
  1001. }
  1002. exports.isBoolean = isBoolean;
  1003.  
  1004. function isNull(arg) {
  1005.   return arg === null;
  1006. }
  1007. exports.isNull = isNull;
  1008.  
  1009. function isNullOrUndefined(arg) {
  1010.   return arg == null;
  1011. }
  1012. exports.isNullOrUndefined = isNullOrUndefined;
  1013.  
  1014. function isNumber(arg) {
  1015.   return typeof arg === 'number';
  1016. }
  1017. exports.isNumber = isNumber;
  1018.  
  1019. function isString(arg) {
  1020.   return typeof arg === 'string';
  1021. }
  1022. exports.isString = isString;
  1023.  
  1024. function isSymbol(arg) {
  1025.   return typeof arg === 'symbol';
  1026. }
  1027. exports.isSymbol = isSymbol;
  1028.  
  1029. function isUndefined(arg) {
  1030.   return arg === void 0;
  1031. }
  1032. exports.isUndefined = isUndefined;
  1033.  
  1034. function isRegExp(re) {
  1035.   return isObject(re) && objectToString(re) === '[object RegExp]';
  1036. }
  1037. exports.isRegExp = isRegExp;
  1038.  
  1039. function isObject(arg) {
  1040.   return typeof arg === 'object' && arg !== null;
  1041. }
  1042. exports.isObject = isObject;
  1043.  
  1044. function isDate(d) {
  1045.   return isObject(d) && objectToString(d) === '[object Date]';
  1046. }
  1047. exports.isDate = isDate;
  1048.  
  1049. function isError(e) {
  1050.   return isObject(e) &&
  1051.       (objectToString(e) === '[object Error]' || e instanceof Error);
  1052. }
  1053. exports.isError = isError;
  1054.  
  1055. function isFunction(arg) {
  1056.   return typeof arg === 'function';
  1057. }
  1058. exports.isFunction = isFunction;
  1059.  
  1060. function isPrimitive(arg) {
  1061.   return arg === null ||
  1062.          typeof arg === 'boolean' ||
  1063.          typeof arg === 'number' ||
  1064.          typeof arg === 'string' ||
  1065.          typeof arg === 'symbol' ||  // ES6 symbol
  1066.          typeof arg === 'undefined';
  1067. }
  1068. exports.isPrimitive = isPrimitive;
  1069.  
  1070. exports.isBuffer = require('./support/isBuffer');
  1071.  
  1072. function objectToString(o) {
  1073.   return Object.prototype.toString.call(o);
  1074. }
  1075.  
  1076.  
  1077. function pad(n) {
  1078.   return n < 10 ? '0' + n.toString(10) : n.toString(10);
  1079. }
  1080.  
  1081.  
  1082. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  1083.               'Oct', 'Nov', 'Dec'];
  1084.  
  1085. // 26 Feb 16:19:34
  1086. function timestamp() {
  1087.   var d = new Date();
  1088.   var time = [pad(d.getHours()),
  1089.               pad(d.getMinutes()),
  1090.               pad(d.getSeconds())].join(':');
  1091.   return [d.getDate(), months[d.getMonth()], time].join(' ');
  1092. }
  1093.  
  1094.  
  1095. // log is just a thin wrapper to console.log that prepends a timestamp
  1096. exports.log = function() {
  1097.   console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  1098. };
  1099.  
  1100.  
  1101. /**
  1102.  * Inherit the prototype methods from one constructor into another.
  1103.  *
  1104.  * The Function.prototype.inherits from lang.js rewritten as a standalone
  1105.  * function (not on Function.prototype). NOTE: If this file is to be loaded
  1106.  * during bootstrapping this function needs to be rewritten using some native
  1107.  * functions as prototype setup using normal JavaScript does not work as
  1108.  * expected during bootstrapping (see mirror.js in r114903).
  1109.  *
  1110.  * @param {function} ctor Constructor function which needs to inherit the
  1111.  *     prototype.
  1112.  * @param {function} superCtor Constructor function to inherit prototype from.
  1113.  */
  1114. exports.inherits = require('inherits');
  1115.  
  1116. exports._extend = function(origin, add) {
  1117.   // Don't do anything if add isn't an object
  1118.   if (!add || !isObject(add)) return origin;
  1119.  
  1120.   var keys = Object.keys(add);
  1121.   var i = keys.length;
  1122.   while (i--) {
  1123.     origin[keys[i]] = add[keys[i]];
  1124.   }
  1125.   return origin;
  1126. };
  1127.  
  1128. function hasOwnProperty(obj, prop) {
  1129.   return Object.prototype.hasOwnProperty.call(obj, prop);
  1130. }
  1131.  
  1132. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1133. },{"./support/isBuffer":3,"_process":29,"inherits":2}],5:[function(require,module,exports){
  1134. 'use strict'
  1135.  
  1136. exports.byteLength = byteLength
  1137. exports.toByteArray = toByteArray
  1138. exports.fromByteArray = fromByteArray
  1139.  
  1140. var lookup = []
  1141. var revLookup = []
  1142. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  1143.  
  1144. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  1145. for (var i = 0, len = code.length; i < len; ++i) {
  1146.   lookup[i] = code[i]
  1147.   revLookup[code.charCodeAt(i)] = i
  1148. }
  1149.  
  1150. // Support decoding URL-safe base64 strings, as Node.js does.
  1151. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  1152. revLookup['-'.charCodeAt(0)] = 62
  1153. revLookup['_'.charCodeAt(0)] = 63
  1154.  
  1155. function getLens (b64) {
  1156.   var len = b64.length
  1157.  
  1158.   if (len % 4 > 0) {
  1159.     throw new Error('Invalid string. Length must be a multiple of 4')
  1160.   }
  1161.  
  1162.   // Trim off extra bytes after placeholder bytes are found
  1163.   // See: https://github.com/beatgammit/base64-js/issues/42
  1164.   var validLen = b64.indexOf('=')
  1165.   if (validLen === -1) validLen = len
  1166.  
  1167.   var placeHoldersLen = validLen === len
  1168.     ? 0
  1169.     : 4 - (validLen % 4)
  1170.  
  1171.   return [validLen, placeHoldersLen]
  1172. }
  1173.  
  1174. // base64 is 4/3 + up to two characters of the original data
  1175. function byteLength (b64) {
  1176.   var lens = getLens(b64)
  1177.   var validLen = lens[0]
  1178.   var placeHoldersLen = lens[1]
  1179.   return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  1180. }
  1181.  
  1182. function _byteLength (b64, validLen, placeHoldersLen) {
  1183.   return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  1184. }
  1185.  
  1186. function toByteArray (b64) {
  1187.   var tmp
  1188.   var lens = getLens(b64)
  1189.   var validLen = lens[0]
  1190.   var placeHoldersLen = lens[1]
  1191.  
  1192.   var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
  1193.  
  1194.   var curByte = 0
  1195.  
  1196.   // if there are placeholders, only get up to the last complete 4 chars
  1197.   var len = placeHoldersLen > 0
  1198.     ? validLen - 4
  1199.     : validLen
  1200.  
  1201.   for (var i = 0; i < len; i += 4) {
  1202.     tmp =
  1203.       (revLookup[b64.charCodeAt(i)] << 18) |
  1204.       (revLookup[b64.charCodeAt(i + 1)] << 12) |
  1205.       (revLookup[b64.charCodeAt(i + 2)] << 6) |
  1206.       revLookup[b64.charCodeAt(i + 3)]
  1207.     arr[curByte++] = (tmp >> 16) & 0xFF
  1208.     arr[curByte++] = (tmp >> 8) & 0xFF
  1209.     arr[curByte++] = tmp & 0xFF
  1210.   }
  1211.  
  1212.   if (placeHoldersLen === 2) {
  1213.     tmp =
  1214.       (revLookup[b64.charCodeAt(i)] << 2) |
  1215.       (revLookup[b64.charCodeAt(i + 1)] >> 4)
  1216.     arr[curByte++] = tmp & 0xFF
  1217.   }
  1218.  
  1219.   if (placeHoldersLen === 1) {
  1220.     tmp =
  1221.       (revLookup[b64.charCodeAt(i)] << 10) |
  1222.       (revLookup[b64.charCodeAt(i + 1)] << 4) |
  1223.       (revLookup[b64.charCodeAt(i + 2)] >> 2)
  1224.     arr[curByte++] = (tmp >> 8) & 0xFF
  1225.     arr[curByte++] = tmp & 0xFF
  1226.   }
  1227.  
  1228.   return arr
  1229. }
  1230.  
  1231. function tripletToBase64 (num) {
  1232.   return lookup[num >> 18 & 0x3F] +
  1233.     lookup[num >> 12 & 0x3F] +
  1234.     lookup[num >> 6 & 0x3F] +
  1235.     lookup[num & 0x3F]
  1236. }
  1237.  
  1238. function encodeChunk (uint8, start, end) {
  1239.   var tmp
  1240.   var output = []
  1241.   for (var i = start; i < end; i += 3) {
  1242.     tmp =
  1243.       ((uint8[i] << 16) & 0xFF0000) +
  1244.       ((uint8[i + 1] << 8) & 0xFF00) +
  1245.       (uint8[i + 2] & 0xFF)
  1246.     output.push(tripletToBase64(tmp))
  1247.   }
  1248.   return output.join('')
  1249. }
  1250.  
  1251. function fromByteArray (uint8) {
  1252.   var tmp
  1253.   var len = uint8.length
  1254.   var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  1255.   var parts = []
  1256.   var maxChunkLength = 16383 // must be multiple of 3
  1257.  
  1258.   // go through the array every three bytes, we'll deal with trailing stuff later
  1259.   for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  1260.     parts.push(encodeChunk(
  1261.       uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
  1262.     ))
  1263.   }
  1264.  
  1265.   // pad the end with zeros, but make sure to not forget the extra bytes
  1266.   if (extraBytes === 1) {
  1267.     tmp = uint8[len - 1]
  1268.     parts.push(
  1269.       lookup[tmp >> 2] +
  1270.       lookup[(tmp << 4) & 0x3F] +
  1271.       '=='
  1272.     )
  1273.   } else if (extraBytes === 2) {
  1274.     tmp = (uint8[len - 2] << 8) + uint8[len - 1]
  1275.     parts.push(
  1276.       lookup[tmp >> 10] +
  1277.       lookup[(tmp >> 4) & 0x3F] +
  1278.       lookup[(tmp << 2) & 0x3F] +
  1279.       '='
  1280.     )
  1281.   }
  1282.  
  1283.   return parts.join('')
  1284. }
  1285.  
  1286. },{}],6:[function(require,module,exports){
  1287.  
  1288. },{}],7:[function(require,module,exports){
  1289. (function (process,Buffer){
  1290. 'use strict';
  1291. /* eslint camelcase: "off" */
  1292.  
  1293. var assert = require('assert');
  1294.  
  1295. var Zstream = require('pako/lib/zlib/zstream');
  1296. var zlib_deflate = require('pako/lib/zlib/deflate.js');
  1297. var zlib_inflate = require('pako/lib/zlib/inflate.js');
  1298. var constants = require('pako/lib/zlib/constants');
  1299.  
  1300. for (var key in constants) {
  1301.   exports[key] = constants[key];
  1302. }
  1303.  
  1304. // zlib modes
  1305. exports.NONE = 0;
  1306. exports.DEFLATE = 1;
  1307. exports.INFLATE = 2;
  1308. exports.GZIP = 3;
  1309. exports.GUNZIP = 4;
  1310. exports.DEFLATERAW = 5;
  1311. exports.INFLATERAW = 6;
  1312. exports.UNZIP = 7;
  1313.  
  1314. var GZIP_HEADER_ID1 = 0x1f;
  1315. var GZIP_HEADER_ID2 = 0x8b;
  1316.  
  1317. /**
  1318.  * Emulate Node's zlib C++ layer for use by the JS layer in index.js
  1319.  */
  1320. function Zlib(mode) {
  1321.   if (typeof mode !== 'number' || mode < exports.DEFLATE || mode > exports.UNZIP) {
  1322.     throw new TypeError('Bad argument');
  1323.   }
  1324.  
  1325.   this.dictionary = null;
  1326.   this.err = 0;
  1327.   this.flush = 0;
  1328.   this.init_done = false;
  1329.   this.level = 0;
  1330.   this.memLevel = 0;
  1331.   this.mode = mode;
  1332.   this.strategy = 0;
  1333.   this.windowBits = 0;
  1334.   this.write_in_progress = false;
  1335.   this.pending_close = false;
  1336.   this.gzip_id_bytes_read = 0;
  1337. }
  1338.  
  1339. Zlib.prototype.close = function () {
  1340.   if (this.write_in_progress) {
  1341.     this.pending_close = true;
  1342.     return;
  1343.   }
  1344.  
  1345.   this.pending_close = false;
  1346.  
  1347.   assert(this.init_done, 'close before init');
  1348.   assert(this.mode <= exports.UNZIP);
  1349.  
  1350.   if (this.mode === exports.DEFLATE || this.mode === exports.GZIP || this.mode === exports.DEFLATERAW) {
  1351.     zlib_deflate.deflateEnd(this.strm);
  1352.   } else if (this.mode === exports.INFLATE || this.mode === exports.GUNZIP || this.mode === exports.INFLATERAW || this.mode === exports.UNZIP) {
  1353.     zlib_inflate.inflateEnd(this.strm);
  1354.   }
  1355.  
  1356.   this.mode = exports.NONE;
  1357.  
  1358.   this.dictionary = null;
  1359. };
  1360.  
  1361. Zlib.prototype.write = function (flush, input, in_off, in_len, out, out_off, out_len) {
  1362.   return this._write(true, flush, input, in_off, in_len, out, out_off, out_len);
  1363. };
  1364.  
  1365. Zlib.prototype.writeSync = function (flush, input, in_off, in_len, out, out_off, out_len) {
  1366.   return this._write(false, flush, input, in_off, in_len, out, out_off, out_len);
  1367. };
  1368.  
  1369. Zlib.prototype._write = function (async, flush, input, in_off, in_len, out, out_off, out_len) {
  1370.   assert.equal(arguments.length, 8);
  1371.  
  1372.   assert(this.init_done, 'write before init');
  1373.   assert(this.mode !== exports.NONE, 'already finalized');
  1374.   assert.equal(false, this.write_in_progress, 'write already in progress');
  1375.   assert.equal(false, this.pending_close, 'close is pending');
  1376.  
  1377.   this.write_in_progress = true;
  1378.  
  1379.   assert.equal(false, flush === undefined, 'must provide flush value');
  1380.  
  1381.   this.write_in_progress = true;
  1382.  
  1383.   if (flush !== exports.Z_NO_FLUSH && flush !== exports.Z_PARTIAL_FLUSH && flush !== exports.Z_SYNC_FLUSH && flush !== exports.Z_FULL_FLUSH && flush !== exports.Z_FINISH && flush !== exports.Z_BLOCK) {
  1384.     throw new Error('Invalid flush value');
  1385.   }
  1386.  
  1387.   if (input == null) {
  1388.     input = Buffer.alloc(0);
  1389.     in_len = 0;
  1390.     in_off = 0;
  1391.   }
  1392.  
  1393.   this.strm.avail_in = in_len;
  1394.   this.strm.input = input;
  1395.   this.strm.next_in = in_off;
  1396.   this.strm.avail_out = out_len;
  1397.   this.strm.output = out;
  1398.   this.strm.next_out = out_off;
  1399.   this.flush = flush;
  1400.  
  1401.   if (!async) {
  1402.     // sync version
  1403.     this._process();
  1404.  
  1405.     if (this._checkError()) {
  1406.       return this._afterSync();
  1407.     }
  1408.     return;
  1409.   }
  1410.  
  1411.   // async version
  1412.   var self = this;
  1413.   process.nextTick(function () {
  1414.     self._process();
  1415.     self._after();
  1416.   });
  1417.  
  1418.   return this;
  1419. };
  1420.  
  1421. Zlib.prototype._afterSync = function () {
  1422.   var avail_out = this.strm.avail_out;
  1423.   var avail_in = this.strm.avail_in;
  1424.  
  1425.   this.write_in_progress = false;
  1426.  
  1427.   return [avail_in, avail_out];
  1428. };
  1429.  
  1430. Zlib.prototype._process = function () {
  1431.   var next_expected_header_byte = null;
  1432.  
  1433.   // If the avail_out is left at 0, then it means that it ran out
  1434.   // of room.  If there was avail_out left over, then it means
  1435.   // that all of the input was consumed.
  1436.   switch (this.mode) {
  1437.     case exports.DEFLATE:
  1438.     case exports.GZIP:
  1439.     case exports.DEFLATERAW:
  1440.       this.err = zlib_deflate.deflate(this.strm, this.flush);
  1441.       break;
  1442.     case exports.UNZIP:
  1443.       if (this.strm.avail_in > 0) {
  1444.         next_expected_header_byte = this.strm.next_in;
  1445.       }
  1446.  
  1447.       switch (this.gzip_id_bytes_read) {
  1448.         case 0:
  1449.           if (next_expected_header_byte === null) {
  1450.             break;
  1451.           }
  1452.  
  1453.           if (this.strm.input[next_expected_header_byte] === GZIP_HEADER_ID1) {
  1454.             this.gzip_id_bytes_read = 1;
  1455.             next_expected_header_byte++;
  1456.  
  1457.             if (this.strm.avail_in === 1) {
  1458.               // The only available byte was already read.
  1459.               break;
  1460.             }
  1461.           } else {
  1462.             this.mode = exports.INFLATE;
  1463.             break;
  1464.           }
  1465.  
  1466.         // fallthrough
  1467.         case 1:
  1468.           if (next_expected_header_byte === null) {
  1469.             break;
  1470.           }
  1471.  
  1472.           if (this.strm.input[next_expected_header_byte] === GZIP_HEADER_ID2) {
  1473.             this.gzip_id_bytes_read = 2;
  1474.             this.mode = exports.GUNZIP;
  1475.           } else {
  1476.             // There is no actual difference between INFLATE and INFLATERAW
  1477.             // (after initialization).
  1478.             this.mode = exports.INFLATE;
  1479.           }
  1480.  
  1481.           break;
  1482.         default:
  1483.           throw new Error('invalid number of gzip magic number bytes read');
  1484.       }
  1485.  
  1486.     // fallthrough
  1487.     case exports.INFLATE:
  1488.     case exports.GUNZIP:
  1489.     case exports.INFLATERAW:
  1490.       this.err = zlib_inflate.inflate(this.strm, this.flush
  1491.  
  1492.       // If data was encoded with dictionary
  1493.       );if (this.err === exports.Z_NEED_DICT && this.dictionary) {
  1494.         // Load it
  1495.         this.err = zlib_inflate.inflateSetDictionary(this.strm, this.dictionary);
  1496.         if (this.err === exports.Z_OK) {
  1497.           // And try to decode again
  1498.           this.err = zlib_inflate.inflate(this.strm, this.flush);
  1499.         } else if (this.err === exports.Z_DATA_ERROR) {
  1500.           // Both inflateSetDictionary() and inflate() return Z_DATA_ERROR.
  1501.           // Make it possible for After() to tell a bad dictionary from bad
  1502.           // input.
  1503.           this.err = exports.Z_NEED_DICT;
  1504.         }
  1505.       }
  1506.       while (this.strm.avail_in > 0 && this.mode === exports.GUNZIP && this.err === exports.Z_STREAM_END && this.strm.next_in[0] !== 0x00) {
  1507.         // Bytes remain in input buffer. Perhaps this is another compressed
  1508.         // member in the same archive, or just trailing garbage.
  1509.         // Trailing zero bytes are okay, though, since they are frequently
  1510.         // used for padding.
  1511.  
  1512.         this.reset();
  1513.         this.err = zlib_inflate.inflate(this.strm, this.flush);
  1514.       }
  1515.       break;
  1516.     default:
  1517.       throw new Error('Unknown mode ' + this.mode);
  1518.   }
  1519. };
  1520.  
  1521. Zlib.prototype._checkError = function () {
  1522.   // Acceptable error states depend on the type of zlib stream.
  1523.   switch (this.err) {
  1524.     case exports.Z_OK:
  1525.     case exports.Z_BUF_ERROR:
  1526.       if (this.strm.avail_out !== 0 && this.flush === exports.Z_FINISH) {
  1527.         this._error('unexpected end of file');
  1528.         return false;
  1529.       }
  1530.       break;
  1531.     case exports.Z_STREAM_END:
  1532.       // normal statuses, not fatal
  1533.       break;
  1534.     case exports.Z_NEED_DICT:
  1535.       if (this.dictionary == null) {
  1536.         this._error('Missing dictionary');
  1537.       } else {
  1538.         this._error('Bad dictionary');
  1539.       }
  1540.       return false;
  1541.     default:
  1542.       // something else.
  1543.       this._error('Zlib error');
  1544.       return false;
  1545.   }
  1546.  
  1547.   return true;
  1548. };
  1549.  
  1550. Zlib.prototype._after = function () {
  1551.   if (!this._checkError()) {
  1552.     return;
  1553.   }
  1554.  
  1555.   var avail_out = this.strm.avail_out;
  1556.   var avail_in = this.strm.avail_in;
  1557.  
  1558.   this.write_in_progress = false;
  1559.  
  1560.   // call the write() cb
  1561.   this.callback(avail_in, avail_out);
  1562.  
  1563.   if (this.pending_close) {
  1564.     this.close();
  1565.   }
  1566. };
  1567.  
  1568. Zlib.prototype._error = function (message) {
  1569.   if (this.strm.msg) {
  1570.     message = this.strm.msg;
  1571.   }
  1572.   this.onerror(message, this.err
  1573.  
  1574.   // no hope of rescue.
  1575.   );this.write_in_progress = false;
  1576.   if (this.pending_close) {
  1577.     this.close();
  1578.   }
  1579. };
  1580.  
  1581. Zlib.prototype.init = function (windowBits, level, memLevel, strategy, dictionary) {
  1582.   assert(arguments.length === 4 || arguments.length === 5, 'init(windowBits, level, memLevel, strategy, [dictionary])');
  1583.  
  1584.   assert(windowBits >= 8 && windowBits <= 15, 'invalid windowBits');
  1585.   assert(level >= -1 && level <= 9, 'invalid compression level');
  1586.  
  1587.   assert(memLevel >= 1 && memLevel <= 9, 'invalid memlevel');
  1588.  
  1589.   assert(strategy === exports.Z_FILTERED || strategy === exports.Z_HUFFMAN_ONLY || strategy === exports.Z_RLE || strategy === exports.Z_FIXED || strategy === exports.Z_DEFAULT_STRATEGY, 'invalid strategy');
  1590.  
  1591.   this._init(level, windowBits, memLevel, strategy, dictionary);
  1592.   this._setDictionary();
  1593. };
  1594.  
  1595. Zlib.prototype.params = function () {
  1596.   throw new Error('deflateParams Not supported');
  1597. };
  1598.  
  1599. Zlib.prototype.reset = function () {
  1600.   this._reset();
  1601.   this._setDictionary();
  1602. };
  1603.  
  1604. Zlib.prototype._init = function (level, windowBits, memLevel, strategy, dictionary) {
  1605.   this.level = level;
  1606.   this.windowBits = windowBits;
  1607.   this.memLevel = memLevel;
  1608.   this.strategy = strategy;
  1609.  
  1610.   this.flush = exports.Z_NO_FLUSH;
  1611.  
  1612.   this.err = exports.Z_OK;
  1613.  
  1614.   if (this.mode === exports.GZIP || this.mode === exports.GUNZIP) {
  1615.     this.windowBits += 16;
  1616.   }
  1617.  
  1618.   if (this.mode === exports.UNZIP) {
  1619.     this.windowBits += 32;
  1620.   }
  1621.  
  1622.   if (this.mode === exports.DEFLATERAW || this.mode === exports.INFLATERAW) {
  1623.     this.windowBits = -1 * this.windowBits;
  1624.   }
  1625.  
  1626.   this.strm = new Zstream();
  1627.  
  1628.   switch (this.mode) {
  1629.     case exports.DEFLATE:
  1630.     case exports.GZIP:
  1631.     case exports.DEFLATERAW:
  1632.       this.err = zlib_deflate.deflateInit2(this.strm, this.level, exports.Z_DEFLATED, this.windowBits, this.memLevel, this.strategy);
  1633.       break;
  1634.     case exports.INFLATE:
  1635.     case exports.GUNZIP:
  1636.     case exports.INFLATERAW:
  1637.     case exports.UNZIP:
  1638.       this.err = zlib_inflate.inflateInit2(this.strm, this.windowBits);
  1639.       break;
  1640.     default:
  1641.       throw new Error('Unknown mode ' + this.mode);
  1642.   }
  1643.  
  1644.   if (this.err !== exports.Z_OK) {
  1645.     this._error('Init error');
  1646.   }
  1647.  
  1648.   this.dictionary = dictionary;
  1649.  
  1650.   this.write_in_progress = false;
  1651.   this.init_done = true;
  1652. };
  1653.  
  1654. Zlib.prototype._setDictionary = function () {
  1655.   if (this.dictionary == null) {
  1656.     return;
  1657.   }
  1658.  
  1659.   this.err = exports.Z_OK;
  1660.  
  1661.   switch (this.mode) {
  1662.     case exports.DEFLATE:
  1663.     case exports.DEFLATERAW:
  1664.       this.err = zlib_deflate.deflateSetDictionary(this.strm, this.dictionary);
  1665.       break;
  1666.     default:
  1667.       break;
  1668.   }
  1669.  
  1670.   if (this.err !== exports.Z_OK) {
  1671.     this._error('Failed to set dictionary');
  1672.   }
  1673. };
  1674.  
  1675. Zlib.prototype._reset = function () {
  1676.   this.err = exports.Z_OK;
  1677.  
  1678.   switch (this.mode) {
  1679.     case exports.DEFLATE:
  1680.     case exports.DEFLATERAW:
  1681.     case exports.GZIP:
  1682.       this.err = zlib_deflate.deflateReset(this.strm);
  1683.       break;
  1684.     case exports.INFLATE:
  1685.     case exports.INFLATERAW:
  1686.     case exports.GUNZIP:
  1687.       this.err = zlib_inflate.inflateReset(this.strm);
  1688.       break;
  1689.     default:
  1690.       break;
  1691.   }
  1692.  
  1693.   if (this.err !== exports.Z_OK) {
  1694.     this._error('Failed to reset stream');
  1695.   }
  1696. };
  1697.  
  1698. exports.Zlib = Zlib;
  1699. }).call(this,require('_process'),require("buffer").Buffer)
  1700. },{"_process":29,"assert":1,"buffer":9,"pako/lib/zlib/constants":19,"pako/lib/zlib/deflate.js":21,"pako/lib/zlib/inflate.js":23,"pako/lib/zlib/zstream":27}],8:[function(require,module,exports){
  1701. (function (process){
  1702. 'use strict';
  1703.  
  1704. var Buffer = require('buffer').Buffer;
  1705. var Transform = require('stream').Transform;
  1706. var binding = require('./binding');
  1707. var util = require('util');
  1708. var assert = require('assert').ok;
  1709. var kMaxLength = require('buffer').kMaxLength;
  1710. var kRangeErrorMessage = 'Cannot create final Buffer. It would be larger ' + 'than 0x' + kMaxLength.toString(16) + ' bytes';
  1711.  
  1712. // zlib doesn't provide these, so kludge them in following the same
  1713. // const naming scheme zlib uses.
  1714. binding.Z_MIN_WINDOWBITS = 8;
  1715. binding.Z_MAX_WINDOWBITS = 15;
  1716. binding.Z_DEFAULT_WINDOWBITS = 15;
  1717.  
  1718. // fewer than 64 bytes per chunk is stupid.
  1719. // technically it could work with as few as 8, but even 64 bytes
  1720. // is absurdly low.  Usually a MB or more is best.
  1721. binding.Z_MIN_CHUNK = 64;
  1722. binding.Z_MAX_CHUNK = Infinity;
  1723. binding.Z_DEFAULT_CHUNK = 16 * 1024;
  1724.  
  1725. binding.Z_MIN_MEMLEVEL = 1;
  1726. binding.Z_MAX_MEMLEVEL = 9;
  1727. binding.Z_DEFAULT_MEMLEVEL = 8;
  1728.  
  1729. binding.Z_MIN_LEVEL = -1;
  1730. binding.Z_MAX_LEVEL = 9;
  1731. binding.Z_DEFAULT_LEVEL = binding.Z_DEFAULT_COMPRESSION;
  1732.  
  1733. // expose all the zlib constants
  1734. var bkeys = Object.keys(binding);
  1735. for (var bk = 0; bk < bkeys.length; bk++) {
  1736.   var bkey = bkeys[bk];
  1737.   if (bkey.match(/^Z/)) {
  1738.     Object.defineProperty(exports, bkey, {
  1739.       enumerable: true, value: binding[bkey], writable: false
  1740.     });
  1741.   }
  1742. }
  1743.  
  1744. // translation table for return codes.
  1745. var codes = {
  1746.   Z_OK: binding.Z_OK,
  1747.   Z_STREAM_END: binding.Z_STREAM_END,
  1748.   Z_NEED_DICT: binding.Z_NEED_DICT,
  1749.   Z_ERRNO: binding.Z_ERRNO,
  1750.   Z_STREAM_ERROR: binding.Z_STREAM_ERROR,
  1751.   Z_DATA_ERROR: binding.Z_DATA_ERROR,
  1752.   Z_MEM_ERROR: binding.Z_MEM_ERROR,
  1753.   Z_BUF_ERROR: binding.Z_BUF_ERROR,
  1754.   Z_VERSION_ERROR: binding.Z_VERSION_ERROR
  1755. };
  1756.  
  1757. var ckeys = Object.keys(codes);
  1758. for (var ck = 0; ck < ckeys.length; ck++) {
  1759.   var ckey = ckeys[ck];
  1760.   codes[codes[ckey]] = ckey;
  1761. }
  1762.  
  1763. Object.defineProperty(exports, 'codes', {
  1764.   enumerable: true, value: Object.freeze(codes), writable: false
  1765. });
  1766.  
  1767. exports.Deflate = Deflate;
  1768. exports.Inflate = Inflate;
  1769. exports.Gzip = Gzip;
  1770. exports.Gunzip = Gunzip;
  1771. exports.DeflateRaw = DeflateRaw;
  1772. exports.InflateRaw = InflateRaw;
  1773. exports.Unzip = Unzip;
  1774.  
  1775. exports.createDeflate = function (o) {
  1776.   return new Deflate(o);
  1777. };
  1778.  
  1779. exports.createInflate = function (o) {
  1780.   return new Inflate(o);
  1781. };
  1782.  
  1783. exports.createDeflateRaw = function (o) {
  1784.   return new DeflateRaw(o);
  1785. };
  1786.  
  1787. exports.createInflateRaw = function (o) {
  1788.   return new InflateRaw(o);
  1789. };
  1790.  
  1791. exports.createGzip = function (o) {
  1792.   return new Gzip(o);
  1793. };
  1794.  
  1795. exports.createGunzip = function (o) {
  1796.   return new Gunzip(o);
  1797. };
  1798.  
  1799. exports.createUnzip = function (o) {
  1800.   return new Unzip(o);
  1801. };
  1802.  
  1803. // Convenience methods.
  1804. // compress/decompress a string or buffer in one step.
  1805. exports.deflate = function (buffer, opts, callback) {
  1806.   if (typeof opts === 'function') {
  1807.     callback = opts;
  1808.     opts = {};
  1809.   }
  1810.   return zlibBuffer(new Deflate(opts), buffer, callback);
  1811. };
  1812.  
  1813. exports.deflateSync = function (buffer, opts) {
  1814.   return zlibBufferSync(new Deflate(opts), buffer);
  1815. };
  1816.  
  1817. exports.gzip = function (buffer, opts, callback) {
  1818.   if (typeof opts === 'function') {
  1819.     callback = opts;
  1820.     opts = {};
  1821.   }
  1822.   return zlibBuffer(new Gzip(opts), buffer, callback);
  1823. };
  1824.  
  1825. exports.gzipSync = function (buffer, opts) {
  1826.   return zlibBufferSync(new Gzip(opts), buffer);
  1827. };
  1828.  
  1829. exports.deflateRaw = function (buffer, opts, callback) {
  1830.   if (typeof opts === 'function') {
  1831.     callback = opts;
  1832.     opts = {};
  1833.   }
  1834.   return zlibBuffer(new DeflateRaw(opts), buffer, callback);
  1835. };
  1836.  
  1837. exports.deflateRawSync = function (buffer, opts) {
  1838.   return zlibBufferSync(new DeflateRaw(opts), buffer);
  1839. };
  1840.  
  1841. exports.unzip = function (buffer, opts, callback) {
  1842.   if (typeof opts === 'function') {
  1843.     callback = opts;
  1844.     opts = {};
  1845.   }
  1846.   return zlibBuffer(new Unzip(opts), buffer, callback);
  1847. };
  1848.  
  1849. exports.unzipSync = function (buffer, opts) {
  1850.   return zlibBufferSync(new Unzip(opts), buffer);
  1851. };
  1852.  
  1853. exports.inflate = function (buffer, opts, callback) {
  1854.   if (typeof opts === 'function') {
  1855.     callback = opts;
  1856.     opts = {};
  1857.   }
  1858.   return zlibBuffer(new Inflate(opts), buffer, callback);
  1859. };
  1860.  
  1861. exports.inflateSync = function (buffer, opts) {
  1862.   return zlibBufferSync(new Inflate(opts), buffer);
  1863. };
  1864.  
  1865. exports.gunzip = function (buffer, opts, callback) {
  1866.   if (typeof opts === 'function') {
  1867.     callback = opts;
  1868.     opts = {};
  1869.   }
  1870.   return zlibBuffer(new Gunzip(opts), buffer, callback);
  1871. };
  1872.  
  1873. exports.gunzipSync = function (buffer, opts) {
  1874.   return zlibBufferSync(new Gunzip(opts), buffer);
  1875. };
  1876.  
  1877. exports.inflateRaw = function (buffer, opts, callback) {
  1878.   if (typeof opts === 'function') {
  1879.     callback = opts;
  1880.     opts = {};
  1881.   }
  1882.   return zlibBuffer(new InflateRaw(opts), buffer, callback);
  1883. };
  1884.  
  1885. exports.inflateRawSync = function (buffer, opts) {
  1886.   return zlibBufferSync(new InflateRaw(opts), buffer);
  1887. };
  1888.  
  1889. function zlibBuffer(engine, buffer, callback) {
  1890.   var buffers = [];
  1891.   var nread = 0;
  1892.  
  1893.   engine.on('error', onError);
  1894.   engine.on('end', onEnd);
  1895.  
  1896.   engine.end(buffer);
  1897.   flow();
  1898.  
  1899.   function flow() {
  1900.     var chunk;
  1901.     while (null !== (chunk = engine.read())) {
  1902.       buffers.push(chunk);
  1903.       nread += chunk.length;
  1904.     }
  1905.     engine.once('readable', flow);
  1906.   }
  1907.  
  1908.   function onError(err) {
  1909.     engine.removeListener('end', onEnd);
  1910.     engine.removeListener('readable', flow);
  1911.     callback(err);
  1912.   }
  1913.  
  1914.   function onEnd() {
  1915.     var buf;
  1916.     var err = null;
  1917.  
  1918.     if (nread >= kMaxLength) {
  1919.       err = new RangeError(kRangeErrorMessage);
  1920.     } else {
  1921.       buf = Buffer.concat(buffers, nread);
  1922.     }
  1923.  
  1924.     buffers = [];
  1925.     engine.close();
  1926.     callback(err, buf);
  1927.   }
  1928. }
  1929.  
  1930. function zlibBufferSync(engine, buffer) {
  1931.   if (typeof buffer === 'string') buffer = Buffer.from(buffer);
  1932.  
  1933.   if (!Buffer.isBuffer(buffer)) throw new TypeError('Not a string or buffer');
  1934.  
  1935.   var flushFlag = engine._finishFlushFlag;
  1936.  
  1937.   return engine._processChunk(buffer, flushFlag);
  1938. }
  1939.  
  1940. // generic zlib
  1941. // minimal 2-byte header
  1942. function Deflate(opts) {
  1943.   if (!(this instanceof Deflate)) return new Deflate(opts);
  1944.   Zlib.call(this, opts, binding.DEFLATE);
  1945. }
  1946.  
  1947. function Inflate(opts) {
  1948.   if (!(this instanceof Inflate)) return new Inflate(opts);
  1949.   Zlib.call(this, opts, binding.INFLATE);
  1950. }
  1951.  
  1952. // gzip - bigger header, same deflate compression
  1953. function Gzip(opts) {
  1954.   if (!(this instanceof Gzip)) return new Gzip(opts);
  1955.   Zlib.call(this, opts, binding.GZIP);
  1956. }
  1957.  
  1958. function Gunzip(opts) {
  1959.   if (!(this instanceof Gunzip)) return new Gunzip(opts);
  1960.   Zlib.call(this, opts, binding.GUNZIP);
  1961. }
  1962.  
  1963. // raw - no header
  1964. function DeflateRaw(opts) {
  1965.   if (!(this instanceof DeflateRaw)) return new DeflateRaw(opts);
  1966.   Zlib.call(this, opts, binding.DEFLATERAW);
  1967. }
  1968.  
  1969. function InflateRaw(opts) {
  1970.   if (!(this instanceof InflateRaw)) return new InflateRaw(opts);
  1971.   Zlib.call(this, opts, binding.INFLATERAW);
  1972. }
  1973.  
  1974. // auto-detect header.
  1975. function Unzip(opts) {
  1976.   if (!(this instanceof Unzip)) return new Unzip(opts);
  1977.   Zlib.call(this, opts, binding.UNZIP);
  1978. }
  1979.  
  1980. function isValidFlushFlag(flag) {
  1981.   return flag === binding.Z_NO_FLUSH || flag === binding.Z_PARTIAL_FLUSH || flag === binding.Z_SYNC_FLUSH || flag === binding.Z_FULL_FLUSH || flag === binding.Z_FINISH || flag === binding.Z_BLOCK;
  1982. }
  1983.  
  1984. // the Zlib class they all inherit from
  1985. // This thing manages the queue of requests, and returns
  1986. // true or false if there is anything in the queue when
  1987. // you call the .write() method.
  1988.  
  1989. function Zlib(opts, mode) {
  1990.   var _this = this;
  1991.  
  1992.   this._opts = opts = opts || {};
  1993.   this._chunkSize = opts.chunkSize || exports.Z_DEFAULT_CHUNK;
  1994.  
  1995.   Transform.call(this, opts);
  1996.  
  1997.   if (opts.flush && !isValidFlushFlag(opts.flush)) {
  1998.     throw new Error('Invalid flush flag: ' + opts.flush);
  1999.   }
  2000.   if (opts.finishFlush && !isValidFlushFlag(opts.finishFlush)) {
  2001.     throw new Error('Invalid flush flag: ' + opts.finishFlush);
  2002.   }
  2003.  
  2004.   this._flushFlag = opts.flush || binding.Z_NO_FLUSH;
  2005.   this._finishFlushFlag = typeof opts.finishFlush !== 'undefined' ? opts.finishFlush : binding.Z_FINISH;
  2006.  
  2007.   if (opts.chunkSize) {
  2008.     if (opts.chunkSize < exports.Z_MIN_CHUNK || opts.chunkSize > exports.Z_MAX_CHUNK) {
  2009.       throw new Error('Invalid chunk size: ' + opts.chunkSize);
  2010.     }
  2011.   }
  2012.  
  2013.   if (opts.windowBits) {
  2014.     if (opts.windowBits < exports.Z_MIN_WINDOWBITS || opts.windowBits > exports.Z_MAX_WINDOWBITS) {
  2015.       throw new Error('Invalid windowBits: ' + opts.windowBits);
  2016.     }
  2017.   }
  2018.  
  2019.   if (opts.level) {
  2020.     if (opts.level < exports.Z_MIN_LEVEL || opts.level > exports.Z_MAX_LEVEL) {
  2021.       throw new Error('Invalid compression level: ' + opts.level);
  2022.     }
  2023.   }
  2024.  
  2025.   if (opts.memLevel) {
  2026.     if (opts.memLevel < exports.Z_MIN_MEMLEVEL || opts.memLevel > exports.Z_MAX_MEMLEVEL) {
  2027.       throw new Error('Invalid memLevel: ' + opts.memLevel);
  2028.     }
  2029.   }
  2030.  
  2031.   if (opts.strategy) {
  2032.     if (opts.strategy != exports.Z_FILTERED && opts.strategy != exports.Z_HUFFMAN_ONLY && opts.strategy != exports.Z_RLE && opts.strategy != exports.Z_FIXED && opts.strategy != exports.Z_DEFAULT_STRATEGY) {
  2033.       throw new Error('Invalid strategy: ' + opts.strategy);
  2034.     }
  2035.   }
  2036.  
  2037.   if (opts.dictionary) {
  2038.     if (!Buffer.isBuffer(opts.dictionary)) {
  2039.       throw new Error('Invalid dictionary: it should be a Buffer instance');
  2040.     }
  2041.   }
  2042.  
  2043.   this._handle = new binding.Zlib(mode);
  2044.  
  2045.   var self = this;
  2046.   this._hadError = false;
  2047.   this._handle.onerror = function (message, errno) {
  2048.     // there is no way to cleanly recover.
  2049.     // continuing only obscures problems.
  2050.     _close(self);
  2051.     self._hadError = true;
  2052.  
  2053.     var error = new Error(message);
  2054.     error.errno = errno;
  2055.     error.code = exports.codes[errno];
  2056.     self.emit('error', error);
  2057.   };
  2058.  
  2059.   var level = exports.Z_DEFAULT_COMPRESSION;
  2060.   if (typeof opts.level === 'number') level = opts.level;
  2061.  
  2062.   var strategy = exports.Z_DEFAULT_STRATEGY;
  2063.   if (typeof opts.strategy === 'number') strategy = opts.strategy;
  2064.  
  2065.   this._handle.init(opts.windowBits || exports.Z_DEFAULT_WINDOWBITS, level, opts.memLevel || exports.Z_DEFAULT_MEMLEVEL, strategy, opts.dictionary);
  2066.  
  2067.   this._buffer = Buffer.allocUnsafe(this._chunkSize);
  2068.   this._offset = 0;
  2069.   this._level = level;
  2070.   this._strategy = strategy;
  2071.  
  2072.   this.once('end', this.close);
  2073.  
  2074.   Object.defineProperty(this, '_closed', {
  2075.     get: function () {
  2076.       return !_this._handle;
  2077.     },
  2078.     configurable: true,
  2079.     enumerable: true
  2080.   });
  2081. }
  2082.  
  2083. util.inherits(Zlib, Transform);
  2084.  
  2085. Zlib.prototype.params = function (level, strategy, callback) {
  2086.   if (level < exports.Z_MIN_LEVEL || level > exports.Z_MAX_LEVEL) {
  2087.     throw new RangeError('Invalid compression level: ' + level);
  2088.   }
  2089.   if (strategy != exports.Z_FILTERED && strategy != exports.Z_HUFFMAN_ONLY && strategy != exports.Z_RLE && strategy != exports.Z_FIXED && strategy != exports.Z_DEFAULT_STRATEGY) {
  2090.     throw new TypeError('Invalid strategy: ' + strategy);
  2091.   }
  2092.  
  2093.   if (this._level !== level || this._strategy !== strategy) {
  2094.     var self = this;
  2095.     this.flush(binding.Z_SYNC_FLUSH, function () {
  2096.       assert(self._handle, 'zlib binding closed');
  2097.       self._handle.params(level, strategy);
  2098.       if (!self._hadError) {
  2099.         self._level = level;
  2100.         self._strategy = strategy;
  2101.         if (callback) callback();
  2102.       }
  2103.     });
  2104.   } else {
  2105.     process.nextTick(callback);
  2106.   }
  2107. };
  2108.  
  2109. Zlib.prototype.reset = function () {
  2110.   assert(this._handle, 'zlib binding closed');
  2111.   return this._handle.reset();
  2112. };
  2113.  
  2114. // This is the _flush function called by the transform class,
  2115. // internally, when the last chunk has been written.
  2116. Zlib.prototype._flush = function (callback) {
  2117.   this._transform(Buffer.alloc(0), '', callback);
  2118. };
  2119.  
  2120. Zlib.prototype.flush = function (kind, callback) {
  2121.   var _this2 = this;
  2122.  
  2123.   var ws = this._writableState;
  2124.  
  2125.   if (typeof kind === 'function' || kind === undefined && !callback) {
  2126.     callback = kind;
  2127.     kind = binding.Z_FULL_FLUSH;
  2128.   }
  2129.  
  2130.   if (ws.ended) {
  2131.     if (callback) process.nextTick(callback);
  2132.   } else if (ws.ending) {
  2133.     if (callback) this.once('end', callback);
  2134.   } else if (ws.needDrain) {
  2135.     if (callback) {
  2136.       this.once('drain', function () {
  2137.         return _this2.flush(kind, callback);
  2138.       });
  2139.     }
  2140.   } else {
  2141.     this._flushFlag = kind;
  2142.     this.write(Buffer.alloc(0), '', callback);
  2143.   }
  2144. };
  2145.  
  2146. Zlib.prototype.close = function (callback) {
  2147.   _close(this, callback);
  2148.   process.nextTick(emitCloseNT, this);
  2149. };
  2150.  
  2151. function _close(engine, callback) {
  2152.   if (callback) process.nextTick(callback);
  2153.  
  2154.   // Caller may invoke .close after a zlib error (which will null _handle).
  2155.   if (!engine._handle) return;
  2156.  
  2157.   engine._handle.close();
  2158.   engine._handle = null;
  2159. }
  2160.  
  2161. function emitCloseNT(self) {
  2162.   self.emit('close');
  2163. }
  2164.  
  2165. Zlib.prototype._transform = function (chunk, encoding, cb) {
  2166.   var flushFlag;
  2167.   var ws = this._writableState;
  2168.   var ending = ws.ending || ws.ended;
  2169.   var last = ending && (!chunk || ws.length === chunk.length);
  2170.  
  2171.   if (chunk !== null && !Buffer.isBuffer(chunk)) return cb(new Error('invalid input'));
  2172.  
  2173.   if (!this._handle) return cb(new Error('zlib binding closed'));
  2174.  
  2175.   // If it's the last chunk, or a final flush, we use the Z_FINISH flush flag
  2176.   // (or whatever flag was provided using opts.finishFlush).
  2177.   // If it's explicitly flushing at some other time, then we use
  2178.   // Z_FULL_FLUSH. Otherwise, use Z_NO_FLUSH for maximum compression
  2179.   // goodness.
  2180.   if (last) flushFlag = this._finishFlushFlag;else {
  2181.     flushFlag = this._flushFlag;
  2182.     // once we've flushed the last of the queue, stop flushing and
  2183.     // go back to the normal behavior.
  2184.     if (chunk.length >= ws.length) {
  2185.       this._flushFlag = this._opts.flush || binding.Z_NO_FLUSH;
  2186.     }
  2187.   }
  2188.  
  2189.   this._processChunk(chunk, flushFlag, cb);
  2190. };
  2191.  
  2192. Zlib.prototype._processChunk = function (chunk, flushFlag, cb) {
  2193.   var availInBefore = chunk && chunk.length;
  2194.   var availOutBefore = this._chunkSize - this._offset;
  2195.   var inOff = 0;
  2196.  
  2197.   var self = this;
  2198.  
  2199.   var async = typeof cb === 'function';
  2200.  
  2201.   if (!async) {
  2202.     var buffers = [];
  2203.     var nread = 0;
  2204.  
  2205.     var error;
  2206.     this.on('error', function (er) {
  2207.       error = er;
  2208.     });
  2209.  
  2210.     assert(this._handle, 'zlib binding closed');
  2211.     do {
  2212.       var res = this._handle.writeSync(flushFlag, chunk, // in
  2213.       inOff, // in_off
  2214.       availInBefore, // in_len
  2215.       this._buffer, // out
  2216.       this._offset, //out_off
  2217.       availOutBefore); // out_len
  2218.     } while (!this._hadError && callback(res[0], res[1]));
  2219.  
  2220.     if (this._hadError) {
  2221.       throw error;
  2222.     }
  2223.  
  2224.     if (nread >= kMaxLength) {
  2225.       _close(this);
  2226.       throw new RangeError(kRangeErrorMessage);
  2227.     }
  2228.  
  2229.     var buf = Buffer.concat(buffers, nread);
  2230.     _close(this);
  2231.  
  2232.     return buf;
  2233.   }
  2234.  
  2235.   assert(this._handle, 'zlib binding closed');
  2236.   var req = this._handle.write(flushFlag, chunk, // in
  2237.   inOff, // in_off
  2238.   availInBefore, // in_len
  2239.   this._buffer, // out
  2240.   this._offset, //out_off
  2241.   availOutBefore); // out_len
  2242.  
  2243.   req.buffer = chunk;
  2244.   req.callback = callback;
  2245.  
  2246.   function callback(availInAfter, availOutAfter) {
  2247.     // When the callback is used in an async write, the callback's
  2248.     // context is the `req` object that was created. The req object
  2249.     // is === this._handle, and that's why it's important to null
  2250.     // out the values after they are done being used. `this._handle`
  2251.     // can stay in memory longer than the callback and buffer are needed.
  2252.     if (this) {
  2253.       this.buffer = null;
  2254.       this.callback = null;
  2255.     }
  2256.  
  2257.     if (self._hadError) return;
  2258.  
  2259.     var have = availOutBefore - availOutAfter;
  2260.     assert(have >= 0, 'have should not go down');
  2261.  
  2262.     if (have > 0) {
  2263.       var out = self._buffer.slice(self._offset, self._offset + have);
  2264.       self._offset += have;
  2265.       // serve some output to the consumer.
  2266.       if (async) {
  2267.         self.push(out);
  2268.       } else {
  2269.         buffers.push(out);
  2270.         nread += out.length;
  2271.       }
  2272.     }
  2273.  
  2274.     // exhausted the output buffer, or used all the input create a new one.
  2275.     if (availOutAfter === 0 || self._offset >= self._chunkSize) {
  2276.       availOutBefore = self._chunkSize;
  2277.       self._offset = 0;
  2278.       self._buffer = Buffer.allocUnsafe(self._chunkSize);
  2279.     }
  2280.  
  2281.     if (availOutAfter === 0) {
  2282.       // Not actually done.  Need to reprocess.
  2283.       // Also, update the availInBefore to the availInAfter value,
  2284.       // so that if we have to hit it a third (fourth, etc.) time,
  2285.       // it'll have the correct byte counts.
  2286.       inOff += availInBefore - availInAfter;
  2287.       availInBefore = availInAfter;
  2288.  
  2289.       if (!async) return true;
  2290.  
  2291.       var newReq = self._handle.write(flushFlag, chunk, inOff, availInBefore, self._buffer, self._offset, self._chunkSize);
  2292.       newReq.callback = callback; // this same function
  2293.       newReq.buffer = chunk;
  2294.       return;
  2295.     }
  2296.  
  2297.     if (!async) return false;
  2298.  
  2299.     // finished with the chunk.
  2300.     cb();
  2301.   }
  2302. };
  2303.  
  2304. util.inherits(Deflate, Zlib);
  2305. util.inherits(Inflate, Zlib);
  2306. util.inherits(Gzip, Zlib);
  2307. util.inherits(Gunzip, Zlib);
  2308. util.inherits(DeflateRaw, Zlib);
  2309. util.inherits(InflateRaw, Zlib);
  2310. util.inherits(Unzip, Zlib);
  2311. }).call(this,require('_process'))
  2312. },{"./binding":7,"_process":29,"assert":1,"buffer":9,"stream":45,"util":50}],9:[function(require,module,exports){
  2313. (function (Buffer){
  2314. /*!
  2315.  * The buffer module from node.js, for the browser.
  2316.  *
  2317.  * @author   Feross Aboukhadijeh <https://feross.org>
  2318.  * @license  MIT
  2319.  */
  2320. /* eslint-disable no-proto */
  2321.  
  2322. 'use strict'
  2323.  
  2324. var base64 = require('base64-js')
  2325. var ieee754 = require('ieee754')
  2326.  
  2327. exports.Buffer = Buffer
  2328. exports.SlowBuffer = SlowBuffer
  2329. exports.INSPECT_MAX_BYTES = 50
  2330.  
  2331. var K_MAX_LENGTH = 0x7fffffff
  2332. exports.kMaxLength = K_MAX_LENGTH
  2333.  
  2334. /**
  2335.  * If `Buffer.TYPED_ARRAY_SUPPORT`:
  2336.  *   === true    Use Uint8Array implementation (fastest)
  2337.  *   === false   Print warning and recommend using `buffer` v4.x which has an Object
  2338.  *               implementation (most compatible, even IE6)
  2339.  *
  2340.  * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  2341.  * Opera 11.6+, iOS 4.2+.
  2342.  *
  2343.  * We report that the browser does not support typed arrays if the are not subclassable
  2344.  * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  2345.  * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  2346.  * for __proto__ and has a buggy typed array implementation.
  2347.  */
  2348. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
  2349.  
  2350. if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
  2351.     typeof console.error === 'function') {
  2352.   console.error(
  2353.     'This browser lacks typed array (Uint8Array) support which is required by ' +
  2354.     '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
  2355.   )
  2356. }
  2357.  
  2358. function typedArraySupport () {
  2359.   // Can typed array instances can be augmented?
  2360.   try {
  2361.     var arr = new Uint8Array(1)
  2362.     arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }
  2363.     return arr.foo() === 42
  2364.   } catch (e) {
  2365.     return false
  2366.   }
  2367. }
  2368.  
  2369. Object.defineProperty(Buffer.prototype, 'parent', {
  2370.   enumerable: true,
  2371.   get: function () {
  2372.     if (!Buffer.isBuffer(this)) return undefined
  2373.     return this.buffer
  2374.   }
  2375. })
  2376.  
  2377. Object.defineProperty(Buffer.prototype, 'offset', {
  2378.   enumerable: true,
  2379.   get: function () {
  2380.     if (!Buffer.isBuffer(this)) return undefined
  2381.     return this.byteOffset
  2382.   }
  2383. })
  2384.  
  2385. function createBuffer (length) {
  2386.   if (length > K_MAX_LENGTH) {
  2387.     throw new RangeError('The value "' + length + '" is invalid for option "size"')
  2388.   }
  2389.   // Return an augmented `Uint8Array` instance
  2390.   var buf = new Uint8Array(length)
  2391.   buf.__proto__ = Buffer.prototype
  2392.   return buf
  2393. }
  2394.  
  2395. /**
  2396.  * The Buffer constructor returns instances of `Uint8Array` that have their
  2397.  * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  2398.  * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  2399.  * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  2400.  * returns a single octet.
  2401.  *
  2402.  * The `Uint8Array` prototype remains unmodified.
  2403.  */
  2404.  
  2405. function Buffer (arg, encodingOrOffset, length) {
  2406.   // Common case.
  2407.   if (typeof arg === 'number') {
  2408.     if (typeof encodingOrOffset === 'string') {
  2409.       throw new TypeError(
  2410.         'The "string" argument must be of type string. Received type number'
  2411.       )
  2412.     }
  2413.     return allocUnsafe(arg)
  2414.   }
  2415.   return from(arg, encodingOrOffset, length)
  2416. }
  2417.  
  2418. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  2419. if (typeof Symbol !== 'undefined' && Symbol.species != null &&
  2420.     Buffer[Symbol.species] === Buffer) {
  2421.   Object.defineProperty(Buffer, Symbol.species, {
  2422.     value: null,
  2423.     configurable: true,
  2424.     enumerable: false,
  2425.     writable: false
  2426.   })
  2427. }
  2428.  
  2429. Buffer.poolSize = 8192 // not used by this implementation
  2430.  
  2431. function from (value, encodingOrOffset, length) {
  2432.   if (typeof value === 'string') {
  2433.     return fromString(value, encodingOrOffset)
  2434.   }
  2435.  
  2436.   if (ArrayBuffer.isView(value)) {
  2437.     return fromArrayLike(value)
  2438.   }
  2439.  
  2440.   if (value == null) {
  2441.     throw TypeError(
  2442.       'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
  2443.       'or Array-like Object. Received type ' + (typeof value)
  2444.     )
  2445.   }
  2446.  
  2447.   if (isInstance(value, ArrayBuffer) ||
  2448.       (value && isInstance(value.buffer, ArrayBuffer))) {
  2449.     return fromArrayBuffer(value, encodingOrOffset, length)
  2450.   }
  2451.  
  2452.   if (typeof value === 'number') {
  2453.     throw new TypeError(
  2454.       'The "value" argument must not be of type number. Received type number'
  2455.     )
  2456.   }
  2457.  
  2458.   var valueOf = value.valueOf && value.valueOf()
  2459.   if (valueOf != null && valueOf !== value) {
  2460.     return Buffer.from(valueOf, encodingOrOffset, length)
  2461.   }
  2462.  
  2463.   var b = fromObject(value)
  2464.   if (b) return b
  2465.  
  2466.   if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
  2467.       typeof value[Symbol.toPrimitive] === 'function') {
  2468.     return Buffer.from(
  2469.       value[Symbol.toPrimitive]('string'), encodingOrOffset, length
  2470.     )
  2471.   }
  2472.  
  2473.   throw new TypeError(
  2474.     'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
  2475.     'or Array-like Object. Received type ' + (typeof value)
  2476.   )
  2477. }
  2478.  
  2479. /**
  2480.  * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  2481.  * if value is a number.
  2482.  * Buffer.from(str[, encoding])
  2483.  * Buffer.from(array)
  2484.  * Buffer.from(buffer)
  2485.  * Buffer.from(arrayBuffer[, byteOffset[, length]])
  2486.  **/
  2487. Buffer.from = function (value, encodingOrOffset, length) {
  2488.   return from(value, encodingOrOffset, length)
  2489. }
  2490.  
  2491. // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  2492. // https://github.com/feross/buffer/pull/148
  2493. Buffer.prototype.__proto__ = Uint8Array.prototype
  2494. Buffer.__proto__ = Uint8Array
  2495.  
  2496. function assertSize (size) {
  2497.   if (typeof size !== 'number') {
  2498.     throw new TypeError('"size" argument must be of type number')
  2499.   } else if (size < 0) {
  2500.     throw new RangeError('The value "' + size + '" is invalid for option "size"')
  2501.   }
  2502. }
  2503.  
  2504. function alloc (size, fill, encoding) {
  2505.   assertSize(size)
  2506.   if (size <= 0) {
  2507.     return createBuffer(size)
  2508.   }
  2509.   if (fill !== undefined) {
  2510.     // Only pay attention to encoding if it's a string. This
  2511.     // prevents accidentally sending in a number that would
  2512.     // be interpretted as a start offset.
  2513.     return typeof encoding === 'string'
  2514.       ? createBuffer(size).fill(fill, encoding)
  2515.       : createBuffer(size).fill(fill)
  2516.   }
  2517.   return createBuffer(size)
  2518. }
  2519.  
  2520. /**
  2521.  * Creates a new filled Buffer instance.
  2522.  * alloc(size[, fill[, encoding]])
  2523.  **/
  2524. Buffer.alloc = function (size, fill, encoding) {
  2525.   return alloc(size, fill, encoding)
  2526. }
  2527.  
  2528. function allocUnsafe (size) {
  2529.   assertSize(size)
  2530.   return createBuffer(size < 0 ? 0 : checked(size) | 0)
  2531. }
  2532.  
  2533. /**
  2534.  * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  2535.  * */
  2536. Buffer.allocUnsafe = function (size) {
  2537.   return allocUnsafe(size)
  2538. }
  2539. /**
  2540.  * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  2541.  */
  2542. Buffer.allocUnsafeSlow = function (size) {
  2543.   return allocUnsafe(size)
  2544. }
  2545.  
  2546. function fromString (string, encoding) {
  2547.   if (typeof encoding !== 'string' || encoding === '') {
  2548.     encoding = 'utf8'
  2549.   }
  2550.  
  2551.   if (!Buffer.isEncoding(encoding)) {
  2552.     throw new TypeError('Unknown encoding: ' + encoding)
  2553.   }
  2554.  
  2555.   var length = byteLength(string, encoding) | 0
  2556.   var buf = createBuffer(length)
  2557.  
  2558.   var actual = buf.write(string, encoding)
  2559.  
  2560.   if (actual !== length) {
  2561.     // Writing a hex string, for example, that contains invalid characters will
  2562.     // cause everything after the first invalid character to be ignored. (e.g.
  2563.     // 'abxxcd' will be treated as 'ab')
  2564.     buf = buf.slice(0, actual)
  2565.   }
  2566.  
  2567.   return buf
  2568. }
  2569.  
  2570. function fromArrayLike (array) {
  2571.   var length = array.length < 0 ? 0 : checked(array.length) | 0
  2572.   var buf = createBuffer(length)
  2573.   for (var i = 0; i < length; i += 1) {
  2574.     buf[i] = array[i] & 255
  2575.   }
  2576.   return buf
  2577. }
  2578.  
  2579. function fromArrayBuffer (array, byteOffset, length) {
  2580.   if (byteOffset < 0 || array.byteLength < byteOffset) {
  2581.     throw new RangeError('"offset" is outside of buffer bounds')
  2582.   }
  2583.  
  2584.   if (array.byteLength < byteOffset + (length || 0)) {
  2585.     throw new RangeError('"length" is outside of buffer bounds')
  2586.   }
  2587.  
  2588.   var buf
  2589.   if (byteOffset === undefined && length === undefined) {
  2590.     buf = new Uint8Array(array)
  2591.   } else if (length === undefined) {
  2592.     buf = new Uint8Array(array, byteOffset)
  2593.   } else {
  2594.     buf = new Uint8Array(array, byteOffset, length)
  2595.   }
  2596.  
  2597.   // Return an augmented `Uint8Array` instance
  2598.   buf.__proto__ = Buffer.prototype
  2599.   return buf
  2600. }
  2601.  
  2602. function fromObject (obj) {
  2603.   if (Buffer.isBuffer(obj)) {
  2604.     var len = checked(obj.length) | 0
  2605.     var buf = createBuffer(len)
  2606.  
  2607.     if (buf.length === 0) {
  2608.       return buf
  2609.     }
  2610.  
  2611.     obj.copy(buf, 0, 0, len)
  2612.     return buf
  2613.   }
  2614.  
  2615.   if (obj.length !== undefined) {
  2616.     if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  2617.       return createBuffer(0)
  2618.     }
  2619.     return fromArrayLike(obj)
  2620.   }
  2621.  
  2622.   if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  2623.     return fromArrayLike(obj.data)
  2624.   }
  2625. }
  2626.  
  2627. function checked (length) {
  2628.   // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  2629.   // length is NaN (which is otherwise coerced to zero.)
  2630.   if (length >= K_MAX_LENGTH) {
  2631.     throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  2632.                          'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
  2633.   }
  2634.   return length | 0
  2635. }
  2636.  
  2637. function SlowBuffer (length) {
  2638.   if (+length != length) { // eslint-disable-line eqeqeq
  2639.     length = 0
  2640.   }
  2641.   return Buffer.alloc(+length)
  2642. }
  2643.  
  2644. Buffer.isBuffer = function isBuffer (b) {
  2645.   return b != null && b._isBuffer === true &&
  2646.     b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
  2647. }
  2648.  
  2649. Buffer.compare = function compare (a, b) {
  2650.   if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
  2651.   if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
  2652.   if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  2653.     throw new TypeError(
  2654.       'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
  2655.     )
  2656.   }
  2657.  
  2658.   if (a === b) return 0
  2659.  
  2660.   var x = a.length
  2661.   var y = b.length
  2662.  
  2663.   for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  2664.     if (a[i] !== b[i]) {
  2665.       x = a[i]
  2666.       y = b[i]
  2667.       break
  2668.     }
  2669.   }
  2670.  
  2671.   if (x < y) return -1
  2672.   if (y < x) return 1
  2673.   return 0
  2674. }
  2675.  
  2676. Buffer.isEncoding = function isEncoding (encoding) {
  2677.   switch (String(encoding).toLowerCase()) {
  2678.     case 'hex':
  2679.     case 'utf8':
  2680.     case 'utf-8':
  2681.     case 'ascii':
  2682.     case 'latin1':
  2683.     case 'binary':
  2684.     case 'base64':
  2685.     case 'ucs2':
  2686.     case 'ucs-2':
  2687.     case 'utf16le':
  2688.     case 'utf-16le':
  2689.       return true
  2690.     default:
  2691.       return false
  2692.   }
  2693. }
  2694.  
  2695. Buffer.concat = function concat (list, length) {
  2696.   if (!Array.isArray(list)) {
  2697.     throw new TypeError('"list" argument must be an Array of Buffers')
  2698.   }
  2699.  
  2700.   if (list.length === 0) {
  2701.     return Buffer.alloc(0)
  2702.   }
  2703.  
  2704.   var i
  2705.   if (length === undefined) {
  2706.     length = 0
  2707.     for (i = 0; i < list.length; ++i) {
  2708.       length += list[i].length
  2709.     }
  2710.   }
  2711.  
  2712.   var buffer = Buffer.allocUnsafe(length)
  2713.   var pos = 0
  2714.   for (i = 0; i < list.length; ++i) {
  2715.     var buf = list[i]
  2716.     if (isInstance(buf, Uint8Array)) {
  2717.       buf = Buffer.from(buf)
  2718.     }
  2719.     if (!Buffer.isBuffer(buf)) {
  2720.       throw new TypeError('"list" argument must be an Array of Buffers')
  2721.     }
  2722.     buf.copy(buffer, pos)
  2723.     pos += buf.length
  2724.   }
  2725.   return buffer
  2726. }
  2727.  
  2728. function byteLength (string, encoding) {
  2729.   if (Buffer.isBuffer(string)) {
  2730.     return string.length
  2731.   }
  2732.   if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
  2733.     return string.byteLength
  2734.   }
  2735.   if (typeof string !== 'string') {
  2736.     throw new TypeError(
  2737.       'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
  2738.       'Received type ' + typeof string
  2739.     )
  2740.   }
  2741.  
  2742.   var len = string.length
  2743.   var mustMatch = (arguments.length > 2 && arguments[2] === true)
  2744.   if (!mustMatch && len === 0) return 0
  2745.  
  2746.   // Use a for loop to avoid recursion
  2747.   var loweredCase = false
  2748.   for (;;) {
  2749.     switch (encoding) {
  2750.       case 'ascii':
  2751.       case 'latin1':
  2752.       case 'binary':
  2753.         return len
  2754.       case 'utf8':
  2755.       case 'utf-8':
  2756.         return utf8ToBytes(string).length
  2757.       case 'ucs2':
  2758.       case 'ucs-2':
  2759.       case 'utf16le':
  2760.       case 'utf-16le':
  2761.         return len * 2
  2762.       case 'hex':
  2763.         return len >>> 1
  2764.       case 'base64':
  2765.         return base64ToBytes(string).length
  2766.       default:
  2767.         if (loweredCase) {
  2768.           return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
  2769.         }
  2770.         encoding = ('' + encoding).toLowerCase()
  2771.         loweredCase = true
  2772.     }
  2773.   }
  2774. }
  2775. Buffer.byteLength = byteLength
  2776.  
  2777. function slowToString (encoding, start, end) {
  2778.   var loweredCase = false
  2779.  
  2780.   // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  2781.   // property of a typed array.
  2782.  
  2783.   // This behaves neither like String nor Uint8Array in that we set start/end
  2784.   // to their upper/lower bounds if the value passed is out of range.
  2785.   // undefined is handled specially as per ECMA-262 6th Edition,
  2786.   // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  2787.   if (start === undefined || start < 0) {
  2788.     start = 0
  2789.   }
  2790.   // Return early if start > this.length. Done here to prevent potential uint32
  2791.   // coercion fail below.
  2792.   if (start > this.length) {
  2793.     return ''
  2794.   }
  2795.  
  2796.   if (end === undefined || end > this.length) {
  2797.     end = this.length
  2798.   }
  2799.  
  2800.   if (end <= 0) {
  2801.     return ''
  2802.   }
  2803.  
  2804.   // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  2805.   end >>>= 0
  2806.   start >>>= 0
  2807.  
  2808.   if (end <= start) {
  2809.     return ''
  2810.   }
  2811.  
  2812.   if (!encoding) encoding = 'utf8'
  2813.  
  2814.   while (true) {
  2815.     switch (encoding) {
  2816.       case 'hex':
  2817.         return hexSlice(this, start, end)
  2818.  
  2819.       case 'utf8':
  2820.       case 'utf-8':
  2821.         return utf8Slice(this, start, end)
  2822.  
  2823.       case 'ascii':
  2824.         return asciiSlice(this, start, end)
  2825.  
  2826.       case 'latin1':
  2827.       case 'binary':
  2828.         return latin1Slice(this, start, end)
  2829.  
  2830.       case 'base64':
  2831.         return base64Slice(this, start, end)
  2832.  
  2833.       case 'ucs2':
  2834.       case 'ucs-2':
  2835.       case 'utf16le':
  2836.       case 'utf-16le':
  2837.         return utf16leSlice(this, start, end)
  2838.  
  2839.       default:
  2840.         if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  2841.         encoding = (encoding + '').toLowerCase()
  2842.         loweredCase = true
  2843.     }
  2844.   }
  2845. }
  2846.  
  2847. // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  2848. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  2849. // reliably in a browserify context because there could be multiple different
  2850. // copies of the 'buffer' package in use. This method works even for Buffer
  2851. // instances that were created from another copy of the `buffer` package.
  2852. // See: https://github.com/feross/buffer/issues/154
  2853. Buffer.prototype._isBuffer = true
  2854.  
  2855. function swap (b, n, m) {
  2856.   var i = b[n]
  2857.   b[n] = b[m]
  2858.   b[m] = i
  2859. }
  2860.  
  2861. Buffer.prototype.swap16 = function swap16 () {
  2862.   var len = this.length
  2863.   if (len % 2 !== 0) {
  2864.     throw new RangeError('Buffer size must be a multiple of 16-bits')
  2865.   }
  2866.   for (var i = 0; i < len; i += 2) {
  2867.     swap(this, i, i + 1)
  2868.   }
  2869.   return this
  2870. }
  2871.  
  2872. Buffer.prototype.swap32 = function swap32 () {
  2873.   var len = this.length
  2874.   if (len % 4 !== 0) {
  2875.     throw new RangeError('Buffer size must be a multiple of 32-bits')
  2876.   }
  2877.   for (var i = 0; i < len; i += 4) {
  2878.     swap(this, i, i + 3)
  2879.     swap(this, i + 1, i + 2)
  2880.   }
  2881.   return this
  2882. }
  2883.  
  2884. Buffer.prototype.swap64 = function swap64 () {
  2885.   var len = this.length
  2886.   if (len % 8 !== 0) {
  2887.     throw new RangeError('Buffer size must be a multiple of 64-bits')
  2888.   }
  2889.   for (var i = 0; i < len; i += 8) {
  2890.     swap(this, i, i + 7)
  2891.     swap(this, i + 1, i + 6)
  2892.     swap(this, i + 2, i + 5)
  2893.     swap(this, i + 3, i + 4)
  2894.   }
  2895.   return this
  2896. }
  2897.  
  2898. Buffer.prototype.toString = function toString () {
  2899.   var length = this.length
  2900.   if (length === 0) return ''
  2901.   if (arguments.length === 0) return utf8Slice(this, 0, length)
  2902.   return slowToString.apply(this, arguments)
  2903. }
  2904.  
  2905. Buffer.prototype.toLocaleString = Buffer.prototype.toString
  2906.  
  2907. Buffer.prototype.equals = function equals (b) {
  2908.   if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  2909.   if (this === b) return true
  2910.   return Buffer.compare(this, b) === 0
  2911. }
  2912.  
  2913. Buffer.prototype.inspect = function inspect () {
  2914.   var str = ''
  2915.   var max = exports.INSPECT_MAX_BYTES
  2916.   str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
  2917.   if (this.length > max) str += ' ... '
  2918.   return '<Buffer ' + str + '>'
  2919. }
  2920.  
  2921. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  2922.   if (isInstance(target, Uint8Array)) {
  2923.     target = Buffer.from(target, target.offset, target.byteLength)
  2924.   }
  2925.   if (!Buffer.isBuffer(target)) {
  2926.     throw new TypeError(
  2927.       'The "target" argument must be one of type Buffer or Uint8Array. ' +
  2928.       'Received type ' + (typeof target)
  2929.     )
  2930.   }
  2931.  
  2932.   if (start === undefined) {
  2933.     start = 0
  2934.   }
  2935.   if (end === undefined) {
  2936.     end = target ? target.length : 0
  2937.   }
  2938.   if (thisStart === undefined) {
  2939.     thisStart = 0
  2940.   }
  2941.   if (thisEnd === undefined) {
  2942.     thisEnd = this.length
  2943.   }
  2944.  
  2945.   if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  2946.     throw new RangeError('out of range index')
  2947.   }
  2948.  
  2949.   if (thisStart >= thisEnd && start >= end) {
  2950.     return 0
  2951.   }
  2952.   if (thisStart >= thisEnd) {
  2953.     return -1
  2954.   }
  2955.   if (start >= end) {
  2956.     return 1
  2957.   }
  2958.  
  2959.   start >>>= 0
  2960.   end >>>= 0
  2961.   thisStart >>>= 0
  2962.   thisEnd >>>= 0
  2963.  
  2964.   if (this === target) return 0
  2965.  
  2966.   var x = thisEnd - thisStart
  2967.   var y = end - start
  2968.   var len = Math.min(x, y)
  2969.  
  2970.   var thisCopy = this.slice(thisStart, thisEnd)
  2971.   var targetCopy = target.slice(start, end)
  2972.  
  2973.   for (var i = 0; i < len; ++i) {
  2974.     if (thisCopy[i] !== targetCopy[i]) {
  2975.       x = thisCopy[i]
  2976.       y = targetCopy[i]
  2977.       break
  2978.     }
  2979.   }
  2980.  
  2981.   if (x < y) return -1
  2982.   if (y < x) return 1
  2983.   return 0
  2984. }
  2985.  
  2986. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  2987. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  2988. //
  2989. // Arguments:
  2990. // - buffer - a Buffer to search
  2991. // - val - a string, Buffer, or number
  2992. // - byteOffset - an index into `buffer`; will be clamped to an int32
  2993. // - encoding - an optional encoding, relevant is val is a string
  2994. // - dir - true for indexOf, false for lastIndexOf
  2995. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  2996.   // Empty buffer means no match
  2997.   if (buffer.length === 0) return -1
  2998.  
  2999.   // Normalize byteOffset
  3000.   if (typeof byteOffset === 'string') {
  3001.     encoding = byteOffset
  3002.     byteOffset = 0
  3003.   } else if (byteOffset > 0x7fffffff) {
  3004.     byteOffset = 0x7fffffff
  3005.   } else if (byteOffset < -0x80000000) {
  3006.     byteOffset = -0x80000000
  3007.   }
  3008.   byteOffset = +byteOffset // Coerce to Number.
  3009.   if (numberIsNaN(byteOffset)) {
  3010.     // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  3011.     byteOffset = dir ? 0 : (buffer.length - 1)
  3012.   }
  3013.  
  3014.   // Normalize byteOffset: negative offsets start from the end of the buffer
  3015.   if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  3016.   if (byteOffset >= buffer.length) {
  3017.     if (dir) return -1
  3018.     else byteOffset = buffer.length - 1
  3019.   } else if (byteOffset < 0) {
  3020.     if (dir) byteOffset = 0
  3021.     else return -1
  3022.   }
  3023.  
  3024.   // Normalize val
  3025.   if (typeof val === 'string') {
  3026.     val = Buffer.from(val, encoding)
  3027.   }
  3028.  
  3029.   // Finally, search either indexOf (if dir is true) or lastIndexOf
  3030.   if (Buffer.isBuffer(val)) {
  3031.     // Special case: looking for empty string/buffer always fails
  3032.     if (val.length === 0) {
  3033.       return -1
  3034.     }
  3035.     return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  3036.   } else if (typeof val === 'number') {
  3037.     val = val & 0xFF // Search for a byte value [0-255]
  3038.     if (typeof Uint8Array.prototype.indexOf === 'function') {
  3039.       if (dir) {
  3040.         return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  3041.       } else {
  3042.         return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  3043.       }
  3044.     }
  3045.     return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  3046.   }
  3047.  
  3048.   throw new TypeError('val must be string, number or Buffer')
  3049. }
  3050.  
  3051. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  3052.   var indexSize = 1
  3053.   var arrLength = arr.length
  3054.   var valLength = val.length
  3055.  
  3056.   if (encoding !== undefined) {
  3057.     encoding = String(encoding).toLowerCase()
  3058.     if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  3059.         encoding === 'utf16le' || encoding === 'utf-16le') {
  3060.       if (arr.length < 2 || val.length < 2) {
  3061.         return -1
  3062.       }
  3063.       indexSize = 2
  3064.       arrLength /= 2
  3065.       valLength /= 2
  3066.       byteOffset /= 2
  3067.     }
  3068.   }
  3069.  
  3070.   function read (buf, i) {
  3071.     if (indexSize === 1) {
  3072.       return buf[i]
  3073.     } else {
  3074.       return buf.readUInt16BE(i * indexSize)
  3075.     }
  3076.   }
  3077.  
  3078.   var i
  3079.   if (dir) {
  3080.     var foundIndex = -1
  3081.     for (i = byteOffset; i < arrLength; i++) {
  3082.       if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  3083.         if (foundIndex === -1) foundIndex = i
  3084.         if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  3085.       } else {
  3086.         if (foundIndex !== -1) i -= i - foundIndex
  3087.         foundIndex = -1
  3088.       }
  3089.     }
  3090.   } else {
  3091.     if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  3092.     for (i = byteOffset; i >= 0; i--) {
  3093.       var found = true
  3094.       for (var j = 0; j < valLength; j++) {
  3095.         if (read(arr, i + j) !== read(val, j)) {
  3096.           found = false
  3097.           break
  3098.         }
  3099.       }
  3100.       if (found) return i
  3101.     }
  3102.   }
  3103.  
  3104.   return -1
  3105. }
  3106.  
  3107. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  3108.   return this.indexOf(val, byteOffset, encoding) !== -1
  3109. }
  3110.  
  3111. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  3112.   return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  3113. }
  3114.  
  3115. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  3116.   return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  3117. }
  3118.  
  3119. function hexWrite (buf, string, offset, length) {
  3120.   offset = Number(offset) || 0
  3121.   var remaining = buf.length - offset
  3122.   if (!length) {
  3123.     length = remaining
  3124.   } else {
  3125.     length = Number(length)
  3126.     if (length > remaining) {
  3127.       length = remaining
  3128.     }
  3129.   }
  3130.  
  3131.   var strLen = string.length
  3132.  
  3133.   if (length > strLen / 2) {
  3134.     length = strLen / 2
  3135.   }
  3136.   for (var i = 0; i < length; ++i) {
  3137.     var parsed = parseInt(string.substr(i * 2, 2), 16)
  3138.     if (numberIsNaN(parsed)) return i
  3139.     buf[offset + i] = parsed
  3140.   }
  3141.   return i
  3142. }
  3143.  
  3144. function utf8Write (buf, string, offset, length) {
  3145.   return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  3146. }
  3147.  
  3148. function asciiWrite (buf, string, offset, length) {
  3149.   return blitBuffer(asciiToBytes(string), buf, offset, length)
  3150. }
  3151.  
  3152. function latin1Write (buf, string, offset, length) {
  3153.   return asciiWrite(buf, string, offset, length)
  3154. }
  3155.  
  3156. function base64Write (buf, string, offset, length) {
  3157.   return blitBuffer(base64ToBytes(string), buf, offset, length)
  3158. }
  3159.  
  3160. function ucs2Write (buf, string, offset, length) {
  3161.   return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  3162. }
  3163.  
  3164. Buffer.prototype.write = function write (string, offset, length, encoding) {
  3165.   // Buffer#write(string)
  3166.   if (offset === undefined) {
  3167.     encoding = 'utf8'
  3168.     length = this.length
  3169.     offset = 0
  3170.   // Buffer#write(string, encoding)
  3171.   } else if (length === undefined && typeof offset === 'string') {
  3172.     encoding = offset
  3173.     length = this.length
  3174.     offset = 0
  3175.   // Buffer#write(string, offset[, length][, encoding])
  3176.   } else if (isFinite(offset)) {
  3177.     offset = offset >>> 0
  3178.     if (isFinite(length)) {
  3179.       length = length >>> 0
  3180.       if (encoding === undefined) encoding = 'utf8'
  3181.     } else {
  3182.       encoding = length
  3183.       length = undefined
  3184.     }
  3185.   } else {
  3186.     throw new Error(
  3187.       'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  3188.     )
  3189.   }
  3190.  
  3191.   var remaining = this.length - offset
  3192.   if (length === undefined || length > remaining) length = remaining
  3193.  
  3194.   if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  3195.     throw new RangeError('Attempt to write outside buffer bounds')
  3196.   }
  3197.  
  3198.   if (!encoding) encoding = 'utf8'
  3199.  
  3200.   var loweredCase = false
  3201.   for (;;) {
  3202.     switch (encoding) {
  3203.       case 'hex':
  3204.         return hexWrite(this, string, offset, length)
  3205.  
  3206.       case 'utf8':
  3207.       case 'utf-8':
  3208.         return utf8Write(this, string, offset, length)
  3209.  
  3210.       case 'ascii':
  3211.         return asciiWrite(this, string, offset, length)
  3212.  
  3213.       case 'latin1':
  3214.       case 'binary':
  3215.         return latin1Write(this, string, offset, length)
  3216.  
  3217.       case 'base64':
  3218.         // Warning: maxLength not taken into account in base64Write
  3219.         return base64Write(this, string, offset, length)
  3220.  
  3221.       case 'ucs2':
  3222.       case 'ucs-2':
  3223.       case 'utf16le':
  3224.       case 'utf-16le':
  3225.         return ucs2Write(this, string, offset, length)
  3226.  
  3227.       default:
  3228.         if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  3229.         encoding = ('' + encoding).toLowerCase()
  3230.         loweredCase = true
  3231.     }
  3232.   }
  3233. }
  3234.  
  3235. Buffer.prototype.toJSON = function toJSON () {
  3236.   return {
  3237.     type: 'Buffer',
  3238.     data: Array.prototype.slice.call(this._arr || this, 0)
  3239.   }
  3240. }
  3241.  
  3242. function base64Slice (buf, start, end) {
  3243.   if (start === 0 && end === buf.length) {
  3244.     return base64.fromByteArray(buf)
  3245.   } else {
  3246.     return base64.fromByteArray(buf.slice(start, end))
  3247.   }
  3248. }
  3249.  
  3250. function utf8Slice (buf, start, end) {
  3251.   end = Math.min(buf.length, end)
  3252.   var res = []
  3253.  
  3254.   var i = start
  3255.   while (i < end) {
  3256.     var firstByte = buf[i]
  3257.     var codePoint = null
  3258.     var bytesPerSequence = (firstByte > 0xEF) ? 4
  3259.       : (firstByte > 0xDF) ? 3
  3260.         : (firstByte > 0xBF) ? 2
  3261.           : 1
  3262.  
  3263.     if (i + bytesPerSequence <= end) {
  3264.       var secondByte, thirdByte, fourthByte, tempCodePoint
  3265.  
  3266.       switch (bytesPerSequence) {
  3267.         case 1:
  3268.           if (firstByte < 0x80) {
  3269.             codePoint = firstByte
  3270.           }
  3271.           break
  3272.         case 2:
  3273.           secondByte = buf[i + 1]
  3274.           if ((secondByte & 0xC0) === 0x80) {
  3275.             tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  3276.             if (tempCodePoint > 0x7F) {
  3277.               codePoint = tempCodePoint
  3278.             }
  3279.           }
  3280.           break
  3281.         case 3:
  3282.           secondByte = buf[i + 1]
  3283.           thirdByte = buf[i + 2]
  3284.           if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  3285.             tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  3286.             if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  3287.               codePoint = tempCodePoint
  3288.             }
  3289.           }
  3290.           break
  3291.         case 4:
  3292.           secondByte = buf[i + 1]
  3293.           thirdByte = buf[i + 2]
  3294.           fourthByte = buf[i + 3]
  3295.           if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  3296.             tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  3297.             if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  3298.               codePoint = tempCodePoint
  3299.             }
  3300.           }
  3301.       }
  3302.     }
  3303.  
  3304.     if (codePoint === null) {
  3305.       // we did not generate a valid codePoint so insert a
  3306.       // replacement char (U+FFFD) and advance only 1 byte
  3307.       codePoint = 0xFFFD
  3308.       bytesPerSequence = 1
  3309.     } else if (codePoint > 0xFFFF) {
  3310.       // encode to utf16 (surrogate pair dance)
  3311.       codePoint -= 0x10000
  3312.       res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  3313.       codePoint = 0xDC00 | codePoint & 0x3FF
  3314.     }
  3315.  
  3316.     res.push(codePoint)
  3317.     i += bytesPerSequence
  3318.   }
  3319.  
  3320.   return decodeCodePointsArray(res)
  3321. }
  3322.  
  3323. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  3324. // the lowest limit is Chrome, with 0x10000 args.
  3325. // We go 1 magnitude less, for safety
  3326. var MAX_ARGUMENTS_LENGTH = 0x1000
  3327.  
  3328. function decodeCodePointsArray (codePoints) {
  3329.   var len = codePoints.length
  3330.   if (len <= MAX_ARGUMENTS_LENGTH) {
  3331.     return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  3332.   }
  3333.  
  3334.   // Decode in chunks to avoid "call stack size exceeded".
  3335.   var res = ''
  3336.   var i = 0
  3337.   while (i < len) {
  3338.     res += String.fromCharCode.apply(
  3339.       String,
  3340.       codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  3341.     )
  3342.   }
  3343.   return res
  3344. }
  3345.  
  3346. function asciiSlice (buf, start, end) {
  3347.   var ret = ''
  3348.   end = Math.min(buf.length, end)
  3349.  
  3350.   for (var i = start; i < end; ++i) {
  3351.     ret += String.fromCharCode(buf[i] & 0x7F)
  3352.   }
  3353.   return ret
  3354. }
  3355.  
  3356. function latin1Slice (buf, start, end) {
  3357.   var ret = ''
  3358.   end = Math.min(buf.length, end)
  3359.  
  3360.   for (var i = start; i < end; ++i) {
  3361.     ret += String.fromCharCode(buf[i])
  3362.   }
  3363.   return ret
  3364. }
  3365.  
  3366. function hexSlice (buf, start, end) {
  3367.   var len = buf.length
  3368.  
  3369.   if (!start || start < 0) start = 0
  3370.   if (!end || end < 0 || end > len) end = len
  3371.  
  3372.   var out = ''
  3373.   for (var i = start; i < end; ++i) {
  3374.     out += toHex(buf[i])
  3375.   }
  3376.   return out
  3377. }
  3378.  
  3379. function utf16leSlice (buf, start, end) {
  3380.   var bytes = buf.slice(start, end)
  3381.   var res = ''
  3382.   for (var i = 0; i < bytes.length; i += 2) {
  3383.     res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
  3384.   }
  3385.   return res
  3386. }
  3387.  
  3388. Buffer.prototype.slice = function slice (start, end) {
  3389.   var len = this.length
  3390.   start = ~~start
  3391.   end = end === undefined ? len : ~~end
  3392.  
  3393.   if (start < 0) {
  3394.     start += len
  3395.     if (start < 0) start = 0
  3396.   } else if (start > len) {
  3397.     start = len
  3398.   }
  3399.  
  3400.   if (end < 0) {
  3401.     end += len
  3402.     if (end < 0) end = 0
  3403.   } else if (end > len) {
  3404.     end = len
  3405.   }
  3406.  
  3407.   if (end < start) end = start
  3408.  
  3409.   var newBuf = this.subarray(start, end)
  3410.   // Return an augmented `Uint8Array` instance
  3411.   newBuf.__proto__ = Buffer.prototype
  3412.   return newBuf
  3413. }
  3414.  
  3415. /*
  3416.  * Need to make sure that buffer isn't trying to write out of bounds.
  3417.  */
  3418. function checkOffset (offset, ext, length) {
  3419.   if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  3420.   if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  3421. }
  3422.  
  3423. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  3424.   offset = offset >>> 0
  3425.   byteLength = byteLength >>> 0
  3426.   if (!noAssert) checkOffset(offset, byteLength, this.length)
  3427.  
  3428.   var val = this[offset]
  3429.   var mul = 1
  3430.   var i = 0
  3431.   while (++i < byteLength && (mul *= 0x100)) {
  3432.     val += this[offset + i] * mul
  3433.   }
  3434.  
  3435.   return val
  3436. }
  3437.  
  3438. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  3439.   offset = offset >>> 0
  3440.   byteLength = byteLength >>> 0
  3441.   if (!noAssert) {
  3442.     checkOffset(offset, byteLength, this.length)
  3443.   }
  3444.  
  3445.   var val = this[offset + --byteLength]
  3446.   var mul = 1
  3447.   while (byteLength > 0 && (mul *= 0x100)) {
  3448.     val += this[offset + --byteLength] * mul
  3449.   }
  3450.  
  3451.   return val
  3452. }
  3453.  
  3454. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  3455.   offset = offset >>> 0
  3456.   if (!noAssert) checkOffset(offset, 1, this.length)
  3457.   return this[offset]
  3458. }
  3459.  
  3460. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  3461.   offset = offset >>> 0
  3462.   if (!noAssert) checkOffset(offset, 2, this.length)
  3463.   return this[offset] | (this[offset + 1] << 8)
  3464. }
  3465.  
  3466. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  3467.   offset = offset >>> 0
  3468.   if (!noAssert) checkOffset(offset, 2, this.length)
  3469.   return (this[offset] << 8) | this[offset + 1]
  3470. }
  3471.  
  3472. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  3473.   offset = offset >>> 0
  3474.   if (!noAssert) checkOffset(offset, 4, this.length)
  3475.  
  3476.   return ((this[offset]) |
  3477.       (this[offset + 1] << 8) |
  3478.       (this[offset + 2] << 16)) +
  3479.       (this[offset + 3] * 0x1000000)
  3480. }
  3481.  
  3482. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  3483.   offset = offset >>> 0
  3484.   if (!noAssert) checkOffset(offset, 4, this.length)
  3485.  
  3486.   return (this[offset] * 0x1000000) +
  3487.     ((this[offset + 1] << 16) |
  3488.     (this[offset + 2] << 8) |
  3489.     this[offset + 3])
  3490. }
  3491.  
  3492. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  3493.   offset = offset >>> 0
  3494.   byteLength = byteLength >>> 0
  3495.   if (!noAssert) checkOffset(offset, byteLength, this.length)
  3496.  
  3497.   var val = this[offset]
  3498.   var mul = 1
  3499.   var i = 0
  3500.   while (++i < byteLength && (mul *= 0x100)) {
  3501.     val += this[offset + i] * mul
  3502.   }
  3503.   mul *= 0x80
  3504.  
  3505.   if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  3506.  
  3507.   return val
  3508. }
  3509.  
  3510. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  3511.   offset = offset >>> 0
  3512.   byteLength = byteLength >>> 0
  3513.   if (!noAssert) checkOffset(offset, byteLength, this.length)
  3514.  
  3515.   var i = byteLength
  3516.   var mul = 1
  3517.   var val = this[offset + --i]
  3518.   while (i > 0 && (mul *= 0x100)) {
  3519.     val += this[offset + --i] * mul
  3520.   }
  3521.   mul *= 0x80
  3522.  
  3523.   if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  3524.  
  3525.   return val
  3526. }
  3527.  
  3528. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  3529.   offset = offset >>> 0
  3530.   if (!noAssert) checkOffset(offset, 1, this.length)
  3531.   if (!(this[offset] & 0x80)) return (this[offset])
  3532.   return ((0xff - this[offset] + 1) * -1)
  3533. }
  3534.  
  3535. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  3536.   offset = offset >>> 0
  3537.   if (!noAssert) checkOffset(offset, 2, this.length)
  3538.   var val = this[offset] | (this[offset + 1] << 8)
  3539.   return (val & 0x8000) ? val | 0xFFFF0000 : val
  3540. }
  3541.  
  3542. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  3543.   offset = offset >>> 0
  3544.   if (!noAssert) checkOffset(offset, 2, this.length)
  3545.   var val = this[offset + 1] | (this[offset] << 8)
  3546.   return (val & 0x8000) ? val | 0xFFFF0000 : val
  3547. }
  3548.  
  3549. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  3550.   offset = offset >>> 0
  3551.   if (!noAssert) checkOffset(offset, 4, this.length)
  3552.  
  3553.   return (this[offset]) |
  3554.     (this[offset + 1] << 8) |
  3555.     (this[offset + 2] << 16) |
  3556.     (this[offset + 3] << 24)
  3557. }
  3558.  
  3559. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  3560.   offset = offset >>> 0
  3561.   if (!noAssert) checkOffset(offset, 4, this.length)
  3562.  
  3563.   return (this[offset] << 24) |
  3564.     (this[offset + 1] << 16) |
  3565.     (this[offset + 2] << 8) |
  3566.     (this[offset + 3])
  3567. }
  3568.  
  3569. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  3570.   offset = offset >>> 0
  3571.   if (!noAssert) checkOffset(offset, 4, this.length)
  3572.   return ieee754.read(this, offset, true, 23, 4)
  3573. }
  3574.  
  3575. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  3576.   offset = offset >>> 0
  3577.   if (!noAssert) checkOffset(offset, 4, this.length)
  3578.   return ieee754.read(this, offset, false, 23, 4)
  3579. }
  3580.  
  3581. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  3582.   offset = offset >>> 0
  3583.   if (!noAssert) checkOffset(offset, 8, this.length)
  3584.   return ieee754.read(this, offset, true, 52, 8)
  3585. }
  3586.  
  3587. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  3588.   offset = offset >>> 0
  3589.   if (!noAssert) checkOffset(offset, 8, this.length)
  3590.   return ieee754.read(this, offset, false, 52, 8)
  3591. }
  3592.  
  3593. function checkInt (buf, value, offset, ext, max, min) {
  3594.   if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  3595.   if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  3596.   if (offset + ext > buf.length) throw new RangeError('Index out of range')
  3597. }
  3598.  
  3599. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  3600.   value = +value
  3601.   offset = offset >>> 0
  3602.   byteLength = byteLength >>> 0
  3603.   if (!noAssert) {
  3604.     var maxBytes = Math.pow(2, 8 * byteLength) - 1
  3605.     checkInt(this, value, offset, byteLength, maxBytes, 0)
  3606.   }
  3607.  
  3608.   var mul = 1
  3609.   var i = 0
  3610.   this[offset] = value & 0xFF
  3611.   while (++i < byteLength && (mul *= 0x100)) {
  3612.     this[offset + i] = (value / mul) & 0xFF
  3613.   }
  3614.  
  3615.   return offset + byteLength
  3616. }
  3617.  
  3618. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  3619.   value = +value
  3620.   offset = offset >>> 0
  3621.   byteLength = byteLength >>> 0
  3622.   if (!noAssert) {
  3623.     var maxBytes = Math.pow(2, 8 * byteLength) - 1
  3624.     checkInt(this, value, offset, byteLength, maxBytes, 0)
  3625.   }
  3626.  
  3627.   var i = byteLength - 1
  3628.   var mul = 1
  3629.   this[offset + i] = value & 0xFF
  3630.   while (--i >= 0 && (mul *= 0x100)) {
  3631.     this[offset + i] = (value / mul) & 0xFF
  3632.   }
  3633.  
  3634.   return offset + byteLength
  3635. }
  3636.  
  3637. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  3638.   value = +value
  3639.   offset = offset >>> 0
  3640.   if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  3641.   this[offset] = (value & 0xff)
  3642.   return offset + 1
  3643. }
  3644.  
  3645. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  3646.   value = +value
  3647.   offset = offset >>> 0
  3648.   if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  3649.   this[offset] = (value & 0xff)
  3650.   this[offset + 1] = (value >>> 8)
  3651.   return offset + 2
  3652. }
  3653.  
  3654. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  3655.   value = +value
  3656.   offset = offset >>> 0
  3657.   if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  3658.   this[offset] = (value >>> 8)
  3659.   this[offset + 1] = (value & 0xff)
  3660.   return offset + 2
  3661. }
  3662.  
  3663. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  3664.   value = +value
  3665.   offset = offset >>> 0
  3666.   if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  3667.   this[offset + 3] = (value >>> 24)
  3668.   this[offset + 2] = (value >>> 16)
  3669.   this[offset + 1] = (value >>> 8)
  3670.   this[offset] = (value & 0xff)
  3671.   return offset + 4
  3672. }
  3673.  
  3674. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  3675.   value = +value
  3676.   offset = offset >>> 0
  3677.   if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  3678.   this[offset] = (value >>> 24)
  3679.   this[offset + 1] = (value >>> 16)
  3680.   this[offset + 2] = (value >>> 8)
  3681.   this[offset + 3] = (value & 0xff)
  3682.   return offset + 4
  3683. }
  3684.  
  3685. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  3686.   value = +value
  3687.   offset = offset >>> 0
  3688.   if (!noAssert) {
  3689.     var limit = Math.pow(2, (8 * byteLength) - 1)
  3690.  
  3691.     checkInt(this, value, offset, byteLength, limit - 1, -limit)
  3692.   }
  3693.  
  3694.   var i = 0
  3695.   var mul = 1
  3696.   var sub = 0
  3697.   this[offset] = value & 0xFF
  3698.   while (++i < byteLength && (mul *= 0x100)) {
  3699.     if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  3700.       sub = 1
  3701.     }
  3702.     this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  3703.   }
  3704.  
  3705.   return offset + byteLength
  3706. }
  3707.  
  3708. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  3709.   value = +value
  3710.   offset = offset >>> 0
  3711.   if (!noAssert) {
  3712.     var limit = Math.pow(2, (8 * byteLength) - 1)
  3713.  
  3714.     checkInt(this, value, offset, byteLength, limit - 1, -limit)
  3715.   }
  3716.  
  3717.   var i = byteLength - 1
  3718.   var mul = 1
  3719.   var sub = 0
  3720.   this[offset + i] = value & 0xFF
  3721.   while (--i >= 0 && (mul *= 0x100)) {
  3722.     if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  3723.       sub = 1
  3724.     }
  3725.     this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  3726.   }
  3727.  
  3728.   return offset + byteLength
  3729. }
  3730.  
  3731. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  3732.   value = +value
  3733.   offset = offset >>> 0
  3734.   if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  3735.   if (value < 0) value = 0xff + value + 1
  3736.   this[offset] = (value & 0xff)
  3737.   return offset + 1
  3738. }
  3739.  
  3740. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  3741.   value = +value
  3742.   offset = offset >>> 0
  3743.   if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  3744.   this[offset] = (value & 0xff)
  3745.   this[offset + 1] = (value >>> 8)
  3746.   return offset + 2
  3747. }
  3748.  
  3749. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  3750.   value = +value
  3751.   offset = offset >>> 0
  3752.   if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  3753.   this[offset] = (value >>> 8)
  3754.   this[offset + 1] = (value & 0xff)
  3755.   return offset + 2
  3756. }
  3757.  
  3758. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  3759.   value = +value
  3760.   offset = offset >>> 0
  3761.   if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  3762.   this[offset] = (value & 0xff)
  3763.   this[offset + 1] = (value >>> 8)
  3764.   this[offset + 2] = (value >>> 16)
  3765.   this[offset + 3] = (value >>> 24)
  3766.   return offset + 4
  3767. }
  3768.  
  3769. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  3770.   value = +value
  3771.   offset = offset >>> 0
  3772.   if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  3773.   if (value < 0) value = 0xffffffff + value + 1
  3774.   this[offset] = (value >>> 24)
  3775.   this[offset + 1] = (value >>> 16)
  3776.   this[offset + 2] = (value >>> 8)
  3777.   this[offset + 3] = (value & 0xff)
  3778.   return offset + 4
  3779. }
  3780.  
  3781. function checkIEEE754 (buf, value, offset, ext, max, min) {
  3782.   if (offset + ext > buf.length) throw new RangeError('Index out of range')
  3783.   if (offset < 0) throw new RangeError('Index out of range')
  3784. }
  3785.  
  3786. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  3787.   value = +value
  3788.   offset = offset >>> 0
  3789.   if (!noAssert) {
  3790.     checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  3791.   }
  3792.   ieee754.write(buf, value, offset, littleEndian, 23, 4)
  3793.   return offset + 4
  3794. }
  3795.  
  3796. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  3797.   return writeFloat(this, value, offset, true, noAssert)
  3798. }
  3799.  
  3800. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  3801.   return writeFloat(this, value, offset, false, noAssert)
  3802. }
  3803.  
  3804. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  3805.   value = +value
  3806.   offset = offset >>> 0
  3807.   if (!noAssert) {
  3808.     checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  3809.   }
  3810.   ieee754.write(buf, value, offset, littleEndian, 52, 8)
  3811.   return offset + 8
  3812. }
  3813.  
  3814. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  3815.   return writeDouble(this, value, offset, true, noAssert)
  3816. }
  3817.  
  3818. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  3819.   return writeDouble(this, value, offset, false, noAssert)
  3820. }
  3821.  
  3822. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  3823. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  3824.   if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
  3825.   if (!start) start = 0
  3826.   if (!end && end !== 0) end = this.length
  3827.   if (targetStart >= target.length) targetStart = target.length
  3828.   if (!targetStart) targetStart = 0
  3829.   if (end > 0 && end < start) end = start
  3830.  
  3831.   // Copy 0 bytes; we're done
  3832.   if (end === start) return 0
  3833.   if (target.length === 0 || this.length === 0) return 0
  3834.  
  3835.   // Fatal error conditions
  3836.   if (targetStart < 0) {
  3837.     throw new RangeError('targetStart out of bounds')
  3838.   }
  3839.   if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
  3840.   if (end < 0) throw new RangeError('sourceEnd out of bounds')
  3841.  
  3842.   // Are we oob?
  3843.   if (end > this.length) end = this.length
  3844.   if (target.length - targetStart < end - start) {
  3845.     end = target.length - targetStart + start
  3846.   }
  3847.  
  3848.   var len = end - start
  3849.  
  3850.   if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
  3851.     // Use built-in when available, missing from IE11
  3852.     this.copyWithin(targetStart, start, end)
  3853.   } else if (this === target && start < targetStart && targetStart < end) {
  3854.     // descending copy from end
  3855.     for (var i = len - 1; i >= 0; --i) {
  3856.       target[i + targetStart] = this[i + start]
  3857.     }
  3858.   } else {
  3859.     Uint8Array.prototype.set.call(
  3860.       target,
  3861.       this.subarray(start, end),
  3862.       targetStart
  3863.     )
  3864.   }
  3865.  
  3866.   return len
  3867. }
  3868.  
  3869. // Usage:
  3870. //    buffer.fill(number[, offset[, end]])
  3871. //    buffer.fill(buffer[, offset[, end]])
  3872. //    buffer.fill(string[, offset[, end]][, encoding])
  3873. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  3874.   // Handle string cases:
  3875.   if (typeof val === 'string') {
  3876.     if (typeof start === 'string') {
  3877.       encoding = start
  3878.       start = 0
  3879.       end = this.length
  3880.     } else if (typeof end === 'string') {
  3881.       encoding = end
  3882.       end = this.length
  3883.     }
  3884.     if (encoding !== undefined && typeof encoding !== 'string') {
  3885.       throw new TypeError('encoding must be a string')
  3886.     }
  3887.     if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  3888.       throw new TypeError('Unknown encoding: ' + encoding)
  3889.     }
  3890.     if (val.length === 1) {
  3891.       var code = val.charCodeAt(0)
  3892.       if ((encoding === 'utf8' && code < 128) ||
  3893.           encoding === 'latin1') {
  3894.         // Fast path: If `val` fits into a single byte, use that numeric value.
  3895.         val = code
  3896.       }
  3897.     }
  3898.   } else if (typeof val === 'number') {
  3899.     val = val & 255
  3900.   }
  3901.  
  3902.   // Invalid ranges are not set to a default, so can range check early.
  3903.   if (start < 0 || this.length < start || this.length < end) {
  3904.     throw new RangeError('Out of range index')
  3905.   }
  3906.  
  3907.   if (end <= start) {
  3908.     return this
  3909.   }
  3910.  
  3911.   start = start >>> 0
  3912.   end = end === undefined ? this.length : end >>> 0
  3913.  
  3914.   if (!val) val = 0
  3915.  
  3916.   var i
  3917.   if (typeof val === 'number') {
  3918.     for (i = start; i < end; ++i) {
  3919.       this[i] = val
  3920.     }
  3921.   } else {
  3922.     var bytes = Buffer.isBuffer(val)
  3923.       ? val
  3924.       : Buffer.from(val, encoding)
  3925.     var len = bytes.length
  3926.     if (len === 0) {
  3927.       throw new TypeError('The value "' + val +
  3928.         '" is invalid for argument "value"')
  3929.     }
  3930.     for (i = 0; i < end - start; ++i) {
  3931.       this[i + start] = bytes[i % len]
  3932.     }
  3933.   }
  3934.  
  3935.   return this
  3936. }
  3937.  
  3938. // HELPER FUNCTIONS
  3939. // ================
  3940.  
  3941. var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
  3942.  
  3943. function base64clean (str) {
  3944.   // Node takes equal signs as end of the Base64 encoding
  3945.   str = str.split('=')[0]
  3946.   // Node strips out invalid characters like \n and \t from the string, base64-js does not
  3947.   str = str.trim().replace(INVALID_BASE64_RE, '')
  3948.   // Node converts strings with length < 2 to ''
  3949.   if (str.length < 2) return ''
  3950.   // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  3951.   while (str.length % 4 !== 0) {
  3952.     str = str + '='
  3953.   }
  3954.   return str
  3955. }
  3956.  
  3957. function toHex (n) {
  3958.   if (n < 16) return '0' + n.toString(16)
  3959.   return n.toString(16)
  3960. }
  3961.  
  3962. function utf8ToBytes (string, units) {
  3963.   units = units || Infinity
  3964.   var codePoint
  3965.   var length = string.length
  3966.   var leadSurrogate = null
  3967.   var bytes = []
  3968.  
  3969.   for (var i = 0; i < length; ++i) {
  3970.     codePoint = string.charCodeAt(i)
  3971.  
  3972.     // is surrogate component
  3973.     if (codePoint > 0xD7FF && codePoint < 0xE000) {
  3974.       // last char was a lead
  3975.       if (!leadSurrogate) {
  3976.         // no lead yet
  3977.         if (codePoint > 0xDBFF) {
  3978.           // unexpected trail
  3979.           if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  3980.           continue
  3981.         } else if (i + 1 === length) {
  3982.           // unpaired lead
  3983.           if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  3984.           continue
  3985.         }
  3986.  
  3987.         // valid lead
  3988.         leadSurrogate = codePoint
  3989.  
  3990.         continue
  3991.       }
  3992.  
  3993.       // 2 leads in a row
  3994.       if (codePoint < 0xDC00) {
  3995.         if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  3996.         leadSurrogate = codePoint
  3997.         continue
  3998.       }
  3999.  
  4000.       // valid surrogate pair
  4001.       codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  4002.     } else if (leadSurrogate) {
  4003.       // valid bmp char, but last char was a lead
  4004.       if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  4005.     }
  4006.  
  4007.     leadSurrogate = null
  4008.  
  4009.     // encode utf8
  4010.     if (codePoint < 0x80) {
  4011.       if ((units -= 1) < 0) break
  4012.       bytes.push(codePoint)
  4013.     } else if (codePoint < 0x800) {
  4014.       if ((units -= 2) < 0) break
  4015.       bytes.push(
  4016.         codePoint >> 0x6 | 0xC0,
  4017.         codePoint & 0x3F | 0x80
  4018.       )
  4019.     } else if (codePoint < 0x10000) {
  4020.       if ((units -= 3) < 0) break
  4021.       bytes.push(
  4022.         codePoint >> 0xC | 0xE0,
  4023.         codePoint >> 0x6 & 0x3F | 0x80,
  4024.         codePoint & 0x3F | 0x80
  4025.       )
  4026.     } else if (codePoint < 0x110000) {
  4027.       if ((units -= 4) < 0) break
  4028.       bytes.push(
  4029.         codePoint >> 0x12 | 0xF0,
  4030.         codePoint >> 0xC & 0x3F | 0x80,
  4031.         codePoint >> 0x6 & 0x3F | 0x80,
  4032.         codePoint & 0x3F | 0x80
  4033.       )
  4034.     } else {
  4035.       throw new Error('Invalid code point')
  4036.     }
  4037.   }
  4038.  
  4039.   return bytes
  4040. }
  4041.  
  4042. function asciiToBytes (str) {
  4043.   var byteArray = []
  4044.   for (var i = 0; i < str.length; ++i) {
  4045.     // Node's code seems to be doing this and not & 0x7F..
  4046.     byteArray.push(str.charCodeAt(i) & 0xFF)
  4047.   }
  4048.   return byteArray
  4049. }
  4050.  
  4051. function utf16leToBytes (str, units) {
  4052.   var c, hi, lo
  4053.   var byteArray = []
  4054.   for (var i = 0; i < str.length; ++i) {
  4055.     if ((units -= 2) < 0) break
  4056.  
  4057.     c = str.charCodeAt(i)
  4058.     hi = c >> 8
  4059.     lo = c % 256
  4060.     byteArray.push(lo)
  4061.     byteArray.push(hi)
  4062.   }
  4063.  
  4064.   return byteArray
  4065. }
  4066.  
  4067. function base64ToBytes (str) {
  4068.   return base64.toByteArray(base64clean(str))
  4069. }
  4070.  
  4071. function blitBuffer (src, dst, offset, length) {
  4072.   for (var i = 0; i < length; ++i) {
  4073.     if ((i + offset >= dst.length) || (i >= src.length)) break
  4074.     dst[i + offset] = src[i]
  4075.   }
  4076.   return i
  4077. }
  4078.  
  4079. // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
  4080. // the `instanceof` check but they should be treated as of that type.
  4081. // See: https://github.com/feross/buffer/issues/166
  4082. function isInstance (obj, type) {
  4083.   return obj instanceof type ||
  4084.     (obj != null && obj.constructor != null && obj.constructor.name != null &&
  4085.       obj.constructor.name === type.name)
  4086. }
  4087. function numberIsNaN (obj) {
  4088.   // For IE11 support
  4089.   return obj !== obj // eslint-disable-line no-self-compare
  4090. }
  4091.  
  4092. }).call(this,require("buffer").Buffer)
  4093. },{"base64-js":5,"buffer":9,"ieee754":12}],10:[function(require,module,exports){
  4094. (function (Buffer){
  4095. // Copyright Joyent, Inc. and other Node contributors.
  4096. //
  4097. // Permission is hereby granted, free of charge, to any person obtaining a
  4098. // copy of this software and associated documentation files (the
  4099. // "Software"), to deal in the Software without restriction, including
  4100. // without limitation the rights to use, copy, modify, merge, publish,
  4101. // distribute, sublicense, and/or sell copies of the Software, and to permit
  4102. // persons to whom the Software is furnished to do so, subject to the
  4103. // following conditions:
  4104. //
  4105. // The above copyright notice and this permission notice shall be included
  4106. // in all copies or substantial portions of the Software.
  4107. //
  4108. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  4109. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  4110. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  4111. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  4112. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  4113. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  4114. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  4115.  
  4116. // NOTE: These type checking functions intentionally don't use `instanceof`
  4117. // because it is fragile and can be easily faked with `Object.create()`.
  4118.  
  4119. function isArray(arg) {
  4120.   if (Array.isArray) {
  4121.     return Array.isArray(arg);
  4122.   }
  4123.   return objectToString(arg) === '[object Array]';
  4124. }
  4125. exports.isArray = isArray;
  4126.  
  4127. function isBoolean(arg) {
  4128.   return typeof arg === 'boolean';
  4129. }
  4130. exports.isBoolean = isBoolean;
  4131.  
  4132. function isNull(arg) {
  4133.   return arg === null;
  4134. }
  4135. exports.isNull = isNull;
  4136.  
  4137. function isNullOrUndefined(arg) {
  4138.   return arg == null;
  4139. }
  4140. exports.isNullOrUndefined = isNullOrUndefined;
  4141.  
  4142. function isNumber(arg) {
  4143.   return typeof arg === 'number';
  4144. }
  4145. exports.isNumber = isNumber;
  4146.  
  4147. function isString(arg) {
  4148.   return typeof arg === 'string';
  4149. }
  4150. exports.isString = isString;
  4151.  
  4152. function isSymbol(arg) {
  4153.   return typeof arg === 'symbol';
  4154. }
  4155. exports.isSymbol = isSymbol;
  4156.  
  4157. function isUndefined(arg) {
  4158.   return arg === void 0;
  4159. }
  4160. exports.isUndefined = isUndefined;
  4161.  
  4162. function isRegExp(re) {
  4163.   return objectToString(re) === '[object RegExp]';
  4164. }
  4165. exports.isRegExp = isRegExp;
  4166.  
  4167. function isObject(arg) {
  4168.   return typeof arg === 'object' && arg !== null;
  4169. }
  4170. exports.isObject = isObject;
  4171.  
  4172. function isDate(d) {
  4173.   return objectToString(d) === '[object Date]';
  4174. }
  4175. exports.isDate = isDate;
  4176.  
  4177. function isError(e) {
  4178.   return (objectToString(e) === '[object Error]' || e instanceof Error);
  4179. }
  4180. exports.isError = isError;
  4181.  
  4182. function isFunction(arg) {
  4183.   return typeof arg === 'function';
  4184. }
  4185. exports.isFunction = isFunction;
  4186.  
  4187. function isPrimitive(arg) {
  4188.   return arg === null ||
  4189.          typeof arg === 'boolean' ||
  4190.          typeof arg === 'number' ||
  4191.          typeof arg === 'string' ||
  4192.          typeof arg === 'symbol' ||  // ES6 symbol
  4193.          typeof arg === 'undefined';
  4194. }
  4195. exports.isPrimitive = isPrimitive;
  4196.  
  4197. exports.isBuffer = Buffer.isBuffer;
  4198.  
  4199. function objectToString(o) {
  4200.   return Object.prototype.toString.call(o);
  4201. }
  4202.  
  4203. }).call(this,{"isBuffer":require("../../is-buffer/index.js")})
  4204. },{"../../is-buffer/index.js":14}],11:[function(require,module,exports){
  4205. // Copyright Joyent, Inc. and other Node contributors.
  4206. //
  4207. // Permission is hereby granted, free of charge, to any person obtaining a
  4208. // copy of this software and associated documentation files (the
  4209. // "Software"), to deal in the Software without restriction, including
  4210. // without limitation the rights to use, copy, modify, merge, publish,
  4211. // distribute, sublicense, and/or sell copies of the Software, and to permit
  4212. // persons to whom the Software is furnished to do so, subject to the
  4213. // following conditions:
  4214. //
  4215. // The above copyright notice and this permission notice shall be included
  4216. // in all copies or substantial portions of the Software.
  4217. //
  4218. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  4219. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  4220. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  4221. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  4222. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  4223. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  4224. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  4225.  
  4226. var objectCreate = Object.create || objectCreatePolyfill
  4227. var objectKeys = Object.keys || objectKeysPolyfill
  4228. var bind = Function.prototype.bind || functionBindPolyfill
  4229.  
  4230. function EventEmitter() {
  4231.   if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
  4232.     this._events = objectCreate(null);
  4233.     this._eventsCount = 0;
  4234.   }
  4235.  
  4236.   this._maxListeners = this._maxListeners || undefined;
  4237. }
  4238. module.exports = EventEmitter;
  4239.  
  4240. // Backwards-compat with node 0.10.x
  4241. EventEmitter.EventEmitter = EventEmitter;
  4242.  
  4243. EventEmitter.prototype._events = undefined;
  4244. EventEmitter.prototype._maxListeners = undefined;
  4245.  
  4246. // By default EventEmitters will print a warning if more than 10 listeners are
  4247. // added to it. This is a useful default which helps finding memory leaks.
  4248. var defaultMaxListeners = 10;
  4249.  
  4250. var hasDefineProperty;
  4251. try {
  4252.   var o = {};
  4253.   if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 });
  4254.   hasDefineProperty = o.x === 0;
  4255. } catch (err) { hasDefineProperty = false }
  4256. if (hasDefineProperty) {
  4257.   Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
  4258.     enumerable: true,
  4259.     get: function() {
  4260.       return defaultMaxListeners;
  4261.     },
  4262.     set: function(arg) {
  4263.       // check whether the input is a positive number (whose value is zero or
  4264.       // greater and not a NaN).
  4265.       if (typeof arg !== 'number' || arg < 0 || arg !== arg)
  4266.         throw new TypeError('"defaultMaxListeners" must be a positive number');
  4267.       defaultMaxListeners = arg;
  4268.     }
  4269.   });
  4270. } else {
  4271.   EventEmitter.defaultMaxListeners = defaultMaxListeners;
  4272. }
  4273.  
  4274. // Obviously not all Emitters should be limited to 10. This function allows
  4275. // that to be increased. Set to zero for unlimited.
  4276. EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
  4277.   if (typeof n !== 'number' || n < 0 || isNaN(n))
  4278.     throw new TypeError('"n" argument must be a positive number');
  4279.   this._maxListeners = n;
  4280.   return this;
  4281. };
  4282.  
  4283. function $getMaxListeners(that) {
  4284.   if (that._maxListeners === undefined)
  4285.     return EventEmitter.defaultMaxListeners;
  4286.   return that._maxListeners;
  4287. }
  4288.  
  4289. EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
  4290.   return $getMaxListeners(this);
  4291. };
  4292.  
  4293. // These standalone emit* functions are used to optimize calling of event
  4294. // handlers for fast cases because emit() itself often has a variable number of
  4295. // arguments and can be deoptimized because of that. These functions always have
  4296. // the same number of arguments and thus do not get deoptimized, so the code
  4297. // inside them can execute faster.
  4298. function emitNone(handler, isFn, self) {
  4299.   if (isFn)
  4300.     handler.call(self);
  4301.   else {
  4302.     var len = handler.length;
  4303.     var listeners = arrayClone(handler, len);
  4304.     for (var i = 0; i < len; ++i)
  4305.       listeners[i].call(self);
  4306.   }
  4307. }
  4308. function emitOne(handler, isFn, self, arg1) {
  4309.   if (isFn)
  4310.     handler.call(self, arg1);
  4311.   else {
  4312.     var len = handler.length;
  4313.     var listeners = arrayClone(handler, len);
  4314.     for (var i = 0; i < len; ++i)
  4315.       listeners[i].call(self, arg1);
  4316.   }
  4317. }
  4318. function emitTwo(handler, isFn, self, arg1, arg2) {
  4319.   if (isFn)
  4320.     handler.call(self, arg1, arg2);
  4321.   else {
  4322.     var len = handler.length;
  4323.     var listeners = arrayClone(handler, len);
  4324.     for (var i = 0; i < len; ++i)
  4325.       listeners[i].call(self, arg1, arg2);
  4326.   }
  4327. }
  4328. function emitThree(handler, isFn, self, arg1, arg2, arg3) {
  4329.   if (isFn)
  4330.     handler.call(self, arg1, arg2, arg3);
  4331.   else {
  4332.     var len = handler.length;
  4333.     var listeners = arrayClone(handler, len);
  4334.     for (var i = 0; i < len; ++i)
  4335.       listeners[i].call(self, arg1, arg2, arg3);
  4336.   }
  4337. }
  4338.  
  4339. function emitMany(handler, isFn, self, args) {
  4340.   if (isFn)
  4341.     handler.apply(self, args);
  4342.   else {
  4343.     var len = handler.length;
  4344.     var listeners = arrayClone(handler, len);
  4345.     for (var i = 0; i < len; ++i)
  4346.       listeners[i].apply(self, args);
  4347.   }
  4348. }
  4349.  
  4350. EventEmitter.prototype.emit = function emit(type) {
  4351.   var er, handler, len, args, i, events;
  4352.   var doError = (type === 'error');
  4353.  
  4354.   events = this._events;
  4355.   if (events)
  4356.     doError = (doError && events.error == null);
  4357.   else if (!doError)
  4358.     return false;
  4359.  
  4360.   // If there is no 'error' event listener then throw.
  4361.   if (doError) {
  4362.     if (arguments.length > 1)
  4363.       er = arguments[1];
  4364.     if (er instanceof Error) {
  4365.       throw er; // Unhandled 'error' event
  4366.     } else {
  4367.       // At least give some kind of context to the user
  4368.       var err = new Error('Unhandled "error" event. (' + er + ')');
  4369.       err.context = er;
  4370.       throw err;
  4371.     }
  4372.     return false;
  4373.   }
  4374.  
  4375.   handler = events[type];
  4376.  
  4377.   if (!handler)
  4378.     return false;
  4379.  
  4380.   var isFn = typeof handler === 'function';
  4381.   len = arguments.length;
  4382.   switch (len) {
  4383.       // fast cases
  4384.     case 1:
  4385.       emitNone(handler, isFn, this);
  4386.       break;
  4387.     case 2:
  4388.       emitOne(handler, isFn, this, arguments[1]);
  4389.       break;
  4390.     case 3:
  4391.       emitTwo(handler, isFn, this, arguments[1], arguments[2]);
  4392.       break;
  4393.     case 4:
  4394.       emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
  4395.       break;
  4396.       // slower
  4397.     default:
  4398.       args = new Array(len - 1);
  4399.       for (i = 1; i < len; i++)
  4400.         args[i - 1] = arguments[i];
  4401.       emitMany(handler, isFn, this, args);
  4402.   }
  4403.  
  4404.   return true;
  4405. };
  4406.  
  4407. function _addListener(target, type, listener, prepend) {
  4408.   var m;
  4409.   var events;
  4410.   var existing;
  4411.  
  4412.   if (typeof listener !== 'function')
  4413.     throw new TypeError('"listener" argument must be a function');
  4414.  
  4415.   events = target._events;
  4416.   if (!events) {
  4417.     events = target._events = objectCreate(null);
  4418.     target._eventsCount = 0;
  4419.   } else {
  4420.     // To avoid recursion in the case that type === "newListener"! Before
  4421.     // adding it to the listeners, first emit "newListener".
  4422.     if (events.newListener) {
  4423.       target.emit('newListener', type,
  4424.           listener.listener ? listener.listener : listener);
  4425.  
  4426.       // Re-assign `events` because a newListener handler could have caused the
  4427.       // this._events to be assigned to a new object
  4428.       events = target._events;
  4429.     }
  4430.     existing = events[type];
  4431.   }
  4432.  
  4433.   if (!existing) {
  4434.     // Optimize the case of one listener. Don't need the extra array object.
  4435.     existing = events[type] = listener;
  4436.     ++target._eventsCount;
  4437.   } else {
  4438.     if (typeof existing === 'function') {
  4439.       // Adding the second element, need to change to array.
  4440.       existing = events[type] =
  4441.           prepend ? [listener, existing] : [existing, listener];
  4442.     } else {
  4443.       // If we've already got an array, just append.
  4444.       if (prepend) {
  4445.         existing.unshift(listener);
  4446.       } else {
  4447.         existing.push(listener);
  4448.       }
  4449.     }
  4450.  
  4451.     // Check for listener leak
  4452.     if (!existing.warned) {
  4453.       m = $getMaxListeners(target);
  4454.       if (m && m > 0 && existing.length > m) {
  4455.         existing.warned = true;
  4456.         var w = new Error('Possible EventEmitter memory leak detected. ' +
  4457.             existing.length + ' "' + String(type) + '" listeners ' +
  4458.             'added. Use emitter.setMaxListeners() to ' +
  4459.             'increase limit.');
  4460.         w.name = 'MaxListenersExceededWarning';
  4461.         w.emitter = target;
  4462.         w.type = type;
  4463.         w.count = existing.length;
  4464.         if (typeof console === 'object' && console.warn) {
  4465.           console.warn('%s: %s', w.name, w.message);
  4466.         }
  4467.       }
  4468.     }
  4469.   }
  4470.  
  4471.   return target;
  4472. }
  4473.  
  4474. EventEmitter.prototype.addListener = function addListener(type, listener) {
  4475.   return _addListener(this, type, listener, false);
  4476. };
  4477.  
  4478. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  4479.  
  4480. EventEmitter.prototype.prependListener =
  4481.     function prependListener(type, listener) {
  4482.       return _addListener(this, type, listener, true);
  4483.     };
  4484.  
  4485. function onceWrapper() {
  4486.   if (!this.fired) {
  4487.     this.target.removeListener(this.type, this.wrapFn);
  4488.     this.fired = true;
  4489.     switch (arguments.length) {
  4490.       case 0:
  4491.         return this.listener.call(this.target);
  4492.       case 1:
  4493.         return this.listener.call(this.target, arguments[0]);
  4494.       case 2:
  4495.         return this.listener.call(this.target, arguments[0], arguments[1]);
  4496.       case 3:
  4497.         return this.listener.call(this.target, arguments[0], arguments[1],
  4498.             arguments[2]);
  4499.       default:
  4500.         var args = new Array(arguments.length);
  4501.         for (var i = 0; i < args.length; ++i)
  4502.           args[i] = arguments[i];
  4503.         this.listener.apply(this.target, args);
  4504.     }
  4505.   }
  4506. }
  4507.  
  4508. function _onceWrap(target, type, listener) {
  4509.   var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
  4510.   var wrapped = bind.call(onceWrapper, state);
  4511.   wrapped.listener = listener;
  4512.   state.wrapFn = wrapped;
  4513.   return wrapped;
  4514. }
  4515.  
  4516. EventEmitter.prototype.once = function once(type, listener) {
  4517.   if (typeof listener !== 'function')
  4518.     throw new TypeError('"listener" argument must be a function');
  4519.   this.on(type, _onceWrap(this, type, listener));
  4520.   return this;
  4521. };
  4522.  
  4523. EventEmitter.prototype.prependOnceListener =
  4524.     function prependOnceListener(type, listener) {
  4525.       if (typeof listener !== 'function')
  4526.         throw new TypeError('"listener" argument must be a function');
  4527.       this.prependListener(type, _onceWrap(this, type, listener));
  4528.       return this;
  4529.     };
  4530.  
  4531. // Emits a 'removeListener' event if and only if the listener was removed.
  4532. EventEmitter.prototype.removeListener =
  4533.     function removeListener(type, listener) {
  4534.       var list, events, position, i, originalListener;
  4535.  
  4536.       if (typeof listener !== 'function')
  4537.         throw new TypeError('"listener" argument must be a function');
  4538.  
  4539.       events = this._events;
  4540.       if (!events)
  4541.         return this;
  4542.  
  4543.       list = events[type];
  4544.       if (!list)
  4545.         return this;
  4546.  
  4547.       if (list === listener || list.listener === listener) {
  4548.         if (--this._eventsCount === 0)
  4549.           this._events = objectCreate(null);
  4550.         else {
  4551.           delete events[type];
  4552.           if (events.removeListener)
  4553.             this.emit('removeListener', type, list.listener || listener);
  4554.         }
  4555.       } else if (typeof list !== 'function') {
  4556.         position = -1;
  4557.  
  4558.         for (i = list.length - 1; i >= 0; i--) {
  4559.           if (list[i] === listener || list[i].listener === listener) {
  4560.             originalListener = list[i].listener;
  4561.             position = i;
  4562.             break;
  4563.           }
  4564.         }
  4565.  
  4566.         if (position < 0)
  4567.           return this;
  4568.  
  4569.         if (position === 0)
  4570.           list.shift();
  4571.         else
  4572.           spliceOne(list, position);
  4573.  
  4574.         if (list.length === 1)
  4575.           events[type] = list[0];
  4576.  
  4577.         if (events.removeListener)
  4578.           this.emit('removeListener', type, originalListener || listener);
  4579.       }
  4580.  
  4581.       return this;
  4582.     };
  4583.  
  4584. EventEmitter.prototype.removeAllListeners =
  4585.     function removeAllListeners(type) {
  4586.       var listeners, events, i;
  4587.  
  4588.       events = this._events;
  4589.       if (!events)
  4590.         return this;
  4591.  
  4592.       // not listening for removeListener, no need to emit
  4593.       if (!events.removeListener) {
  4594.         if (arguments.length === 0) {
  4595.           this._events = objectCreate(null);
  4596.           this._eventsCount = 0;
  4597.         } else if (events[type]) {
  4598.           if (--this._eventsCount === 0)
  4599.             this._events = objectCreate(null);
  4600.           else
  4601.             delete events[type];
  4602.         }
  4603.         return this;
  4604.       }
  4605.  
  4606.       // emit removeListener for all listeners on all events
  4607.       if (arguments.length === 0) {
  4608.         var keys = objectKeys(events);
  4609.         var key;
  4610.         for (i = 0; i < keys.length; ++i) {
  4611.           key = keys[i];
  4612.           if (key === 'removeListener') continue;
  4613.           this.removeAllListeners(key);
  4614.         }
  4615.         this.removeAllListeners('removeListener');
  4616.         this._events = objectCreate(null);
  4617.         this._eventsCount = 0;
  4618.         return this;
  4619.       }
  4620.  
  4621.       listeners = events[type];
  4622.  
  4623.       if (typeof listeners === 'function') {
  4624.         this.removeListener(type, listeners);
  4625.       } else if (listeners) {
  4626.         // LIFO order
  4627.         for (i = listeners.length - 1; i >= 0; i--) {
  4628.           this.removeListener(type, listeners[i]);
  4629.         }
  4630.       }
  4631.  
  4632.       return this;
  4633.     };
  4634.  
  4635. function _listeners(target, type, unwrap) {
  4636.   var events = target._events;
  4637.  
  4638.   if (!events)
  4639.     return [];
  4640.  
  4641.   var evlistener = events[type];
  4642.   if (!evlistener)
  4643.     return [];
  4644.  
  4645.   if (typeof evlistener === 'function')
  4646.     return unwrap ? [evlistener.listener || evlistener] : [evlistener];
  4647.  
  4648.   return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
  4649. }
  4650.  
  4651. EventEmitter.prototype.listeners = function listeners(type) {
  4652.   return _listeners(this, type, true);
  4653. };
  4654.  
  4655. EventEmitter.prototype.rawListeners = function rawListeners(type) {
  4656.   return _listeners(this, type, false);
  4657. };
  4658.  
  4659. EventEmitter.listenerCount = function(emitter, type) {
  4660.   if (typeof emitter.listenerCount === 'function') {
  4661.     return emitter.listenerCount(type);
  4662.   } else {
  4663.     return listenerCount.call(emitter, type);
  4664.   }
  4665. };
  4666.  
  4667. EventEmitter.prototype.listenerCount = listenerCount;
  4668. function listenerCount(type) {
  4669.   var events = this._events;
  4670.  
  4671.   if (events) {
  4672.     var evlistener = events[type];
  4673.  
  4674.     if (typeof evlistener === 'function') {
  4675.       return 1;
  4676.     } else if (evlistener) {
  4677.       return evlistener.length;
  4678.     }
  4679.   }
  4680.  
  4681.   return 0;
  4682. }
  4683.  
  4684. EventEmitter.prototype.eventNames = function eventNames() {
  4685.   return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
  4686. };
  4687.  
  4688. // About 1.5x faster than the two-arg version of Array#splice().
  4689. function spliceOne(list, index) {
  4690.   for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
  4691.     list[i] = list[k];
  4692.   list.pop();
  4693. }
  4694.  
  4695. function arrayClone(arr, n) {
  4696.   var copy = new Array(n);
  4697.   for (var i = 0; i < n; ++i)
  4698.     copy[i] = arr[i];
  4699.   return copy;
  4700. }
  4701.  
  4702. function unwrapListeners(arr) {
  4703.   var ret = new Array(arr.length);
  4704.   for (var i = 0; i < ret.length; ++i) {
  4705.     ret[i] = arr[i].listener || arr[i];
  4706.   }
  4707.   return ret;
  4708. }
  4709.  
  4710. function objectCreatePolyfill(proto) {
  4711.   var F = function() {};
  4712.   F.prototype = proto;
  4713.   return new F;
  4714. }
  4715. function objectKeysPolyfill(obj) {
  4716.   var keys = [];
  4717.   for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {
  4718.     keys.push(k);
  4719.   }
  4720.   return k;
  4721. }
  4722. function functionBindPolyfill(context) {
  4723.   var fn = this;
  4724.   return function () {
  4725.     return fn.apply(context, arguments);
  4726.   };
  4727. }
  4728.  
  4729. },{}],12:[function(require,module,exports){
  4730. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  4731.   var e, m
  4732.   var eLen = (nBytes * 8) - mLen - 1
  4733.   var eMax = (1 << eLen) - 1
  4734.   var eBias = eMax >> 1
  4735.   var nBits = -7
  4736.   var i = isLE ? (nBytes - 1) : 0
  4737.   var d = isLE ? -1 : 1
  4738.   var s = buffer[offset + i]
  4739.  
  4740.   i += d
  4741.  
  4742.   e = s & ((1 << (-nBits)) - 1)
  4743.   s >>= (-nBits)
  4744.   nBits += eLen
  4745.   for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  4746.  
  4747.   m = e & ((1 << (-nBits)) - 1)
  4748.   e >>= (-nBits)
  4749.   nBits += mLen
  4750.   for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  4751.  
  4752.   if (e === 0) {
  4753.     e = 1 - eBias
  4754.   } else if (e === eMax) {
  4755.     return m ? NaN : ((s ? -1 : 1) * Infinity)
  4756.   } else {
  4757.     m = m + Math.pow(2, mLen)
  4758.     e = e - eBias
  4759.   }
  4760.   return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  4761. }
  4762.  
  4763. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  4764.   var e, m, c
  4765.   var eLen = (nBytes * 8) - mLen - 1
  4766.   var eMax = (1 << eLen) - 1
  4767.   var eBias = eMax >> 1
  4768.   var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  4769.   var i = isLE ? 0 : (nBytes - 1)
  4770.   var d = isLE ? 1 : -1
  4771.   var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  4772.  
  4773.   value = Math.abs(value)
  4774.  
  4775.   if (isNaN(value) || value === Infinity) {
  4776.     m = isNaN(value) ? 1 : 0
  4777.     e = eMax
  4778.   } else {
  4779.     e = Math.floor(Math.log(value) / Math.LN2)
  4780.     if (value * (c = Math.pow(2, -e)) < 1) {
  4781.       e--
  4782.       c *= 2
  4783.     }
  4784.     if (e + eBias >= 1) {
  4785.       value += rt / c
  4786.     } else {
  4787.       value += rt * Math.pow(2, 1 - eBias)
  4788.     }
  4789.     if (value * c >= 2) {
  4790.       e++
  4791.       c /= 2
  4792.     }
  4793.  
  4794.     if (e + eBias >= eMax) {
  4795.       m = 0
  4796.       e = eMax
  4797.     } else if (e + eBias >= 1) {
  4798.       m = ((value * c) - 1) * Math.pow(2, mLen)
  4799.       e = e + eBias
  4800.     } else {
  4801.       m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  4802.       e = 0
  4803.     }
  4804.   }
  4805.  
  4806.   for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  4807.  
  4808.   e = (e << mLen) | m
  4809.   eLen += mLen
  4810.   for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  4811.  
  4812.   buffer[offset + i - d] |= s * 128
  4813. }
  4814.  
  4815. },{}],13:[function(require,module,exports){
  4816. if (typeof Object.create === 'function') {
  4817.   // implementation from standard node.js 'util' module
  4818.   module.exports = function inherits(ctor, superCtor) {
  4819.     if (superCtor) {
  4820.       ctor.super_ = superCtor
  4821.       ctor.prototype = Object.create(superCtor.prototype, {
  4822.         constructor: {
  4823.           value: ctor,
  4824.           enumerable: false,
  4825.           writable: true,
  4826.           configurable: true
  4827.         }
  4828.       })
  4829.     }
  4830.   };
  4831. } else {
  4832.   // old school shim for old browsers
  4833.   module.exports = function inherits(ctor, superCtor) {
  4834.     if (superCtor) {
  4835.       ctor.super_ = superCtor
  4836.       var TempCtor = function () {}
  4837.       TempCtor.prototype = superCtor.prototype
  4838.       ctor.prototype = new TempCtor()
  4839.       ctor.prototype.constructor = ctor
  4840.     }
  4841.   }
  4842. }
  4843.  
  4844. },{}],14:[function(require,module,exports){
  4845. /*!
  4846.  * Determine if an object is a Buffer
  4847.  *
  4848.  * @author   Feross Aboukhadijeh <https://feross.org>
  4849.  * @license  MIT
  4850.  */
  4851.  
  4852. // The _isBuffer check is for Safari 5-7 support, because it's missing
  4853. // Object.prototype.constructor. Remove this eventually
  4854. module.exports = function (obj) {
  4855.   return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
  4856. }
  4857.  
  4858. function isBuffer (obj) {
  4859.   return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  4860. }
  4861.  
  4862. // For Node v0.10 support. Remove this eventually.
  4863. function isSlowBuffer (obj) {
  4864.   return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
  4865. }
  4866.  
  4867. },{}],15:[function(require,module,exports){
  4868. var toString = {}.toString;
  4869.  
  4870. module.exports = Array.isArray || function (arr) {
  4871.   return toString.call(arr) == '[object Array]';
  4872. };
  4873.  
  4874. },{}],16:[function(require,module,exports){
  4875. /*
  4876. object-assign
  4877. (c) Sindre Sorhus
  4878. @license MIT
  4879. */
  4880.  
  4881. 'use strict';
  4882. /* eslint-disable no-unused-vars */
  4883. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  4884. var hasOwnProperty = Object.prototype.hasOwnProperty;
  4885. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  4886.  
  4887. function toObject(val) {
  4888.     if (val === null || val === undefined) {
  4889.         throw new TypeError('Object.assign cannot be called with null or undefined');
  4890.     }
  4891.  
  4892.     return Object(val);
  4893. }
  4894.  
  4895. function shouldUseNative() {
  4896.     try {
  4897.         if (!Object.assign) {
  4898.             return false;
  4899.         }
  4900.  
  4901.         // Detect buggy property enumeration order in older V8 versions.
  4902.  
  4903.         // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  4904.         var test1 = new String('abc');  // eslint-disable-line no-new-wrappers
  4905.         test1[5] = 'de';
  4906.         if (Object.getOwnPropertyNames(test1)[0] === '5') {
  4907.             return false;
  4908.         }
  4909.  
  4910.         // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  4911.         var test2 = {};
  4912.         for (var i = 0; i < 10; i++) {
  4913.             test2['_' + String.fromCharCode(i)] = i;
  4914.         }
  4915.         var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  4916.             return test2[n];
  4917.         });
  4918.         if (order2.join('') !== '0123456789') {
  4919.             return false;
  4920.         }
  4921.  
  4922.         // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  4923.         var test3 = {};
  4924.         'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  4925.             test3[letter] = letter;
  4926.         });
  4927.         if (Object.keys(Object.assign({}, test3)).join('') !==
  4928.                 'abcdefghijklmnopqrst') {
  4929.             return false;
  4930.         }
  4931.  
  4932.         return true;
  4933.     } catch (err) {
  4934.         // We don't expect any of the above to throw, but better to be safe.
  4935.         return false;
  4936.     }
  4937. }
  4938.  
  4939. module.exports = shouldUseNative() ? Object.assign : function (target, source) {
  4940.     var from;
  4941.     var to = toObject(target);
  4942.     var symbols;
  4943.  
  4944.     for (var s = 1; s < arguments.length; s++) {
  4945.         from = Object(arguments[s]);
  4946.  
  4947.         for (var key in from) {
  4948.             if (hasOwnProperty.call(from, key)) {
  4949.                 to[key] = from[key];
  4950.             }
  4951.         }
  4952.  
  4953.         if (getOwnPropertySymbols) {
  4954.             symbols = getOwnPropertySymbols(from);
  4955.             for (var i = 0; i < symbols.length; i++) {
  4956.                 if (propIsEnumerable.call(from, symbols[i])) {
  4957.                     to[symbols[i]] = from[symbols[i]];
  4958.                 }
  4959.             }
  4960.         }
  4961.     }
  4962.  
  4963.     return to;
  4964. };
  4965.  
  4966. },{}],17:[function(require,module,exports){
  4967. 'use strict';
  4968.  
  4969.  
  4970. var TYPED_OK =  (typeof Uint8Array !== 'undefined') &&
  4971.                 (typeof Uint16Array !== 'undefined') &&
  4972.                 (typeof Int32Array !== 'undefined');
  4973.  
  4974. function _has(obj, key) {
  4975.   return Object.prototype.hasOwnProperty.call(obj, key);
  4976. }
  4977.  
  4978. exports.assign = function (obj /*from1, from2, from3, ...*/) {
  4979.   var sources = Array.prototype.slice.call(arguments, 1);
  4980.   while (sources.length) {
  4981.     var source = sources.shift();
  4982.     if (!source) { continue; }
  4983.  
  4984.     if (typeof source !== 'object') {
  4985.       throw new TypeError(source + 'must be non-object');
  4986.     }
  4987.  
  4988.     for (var p in source) {
  4989.       if (_has(source, p)) {
  4990.         obj[p] = source[p];
  4991.       }
  4992.     }
  4993.   }
  4994.  
  4995.   return obj;
  4996. };
  4997.  
  4998.  
  4999. // reduce buffer size, avoiding mem copy
  5000. exports.shrinkBuf = function (buf, size) {
  5001.   if (buf.length === size) { return buf; }
  5002.   if (buf.subarray) { return buf.subarray(0, size); }
  5003.   buf.length = size;
  5004.   return buf;
  5005. };
  5006.  
  5007.  
  5008. var fnTyped = {
  5009.   arraySet: function (dest, src, src_offs, len, dest_offs) {
  5010.     if (src.subarray && dest.subarray) {
  5011.       dest.set(src.subarray(src_offs, src_offs + len), dest_offs);
  5012.       return;
  5013.     }
  5014.     // Fallback to ordinary array
  5015.     for (var i = 0; i < len; i++) {
  5016.       dest[dest_offs + i] = src[src_offs + i];
  5017.     }
  5018.   },
  5019.   // Join array of chunks to single array.
  5020.   flattenChunks: function (chunks) {
  5021.     var i, l, len, pos, chunk, result;
  5022.  
  5023.     // calculate data length
  5024.     len = 0;
  5025.     for (i = 0, l = chunks.length; i < l; i++) {
  5026.       len += chunks[i].length;
  5027.     }
  5028.  
  5029.     // join chunks
  5030.     result = new Uint8Array(len);
  5031.     pos = 0;
  5032.     for (i = 0, l = chunks.length; i < l; i++) {
  5033.       chunk = chunks[i];
  5034.       result.set(chunk, pos);
  5035.       pos += chunk.length;
  5036.     }
  5037.  
  5038.     return result;
  5039.   }
  5040. };
  5041.  
  5042. var fnUntyped = {
  5043.   arraySet: function (dest, src, src_offs, len, dest_offs) {
  5044.     for (var i = 0; i < len; i++) {
  5045.       dest[dest_offs + i] = src[src_offs + i];
  5046.     }
  5047.   },
  5048.   // Join array of chunks to single array.
  5049.   flattenChunks: function (chunks) {
  5050.     return [].concat.apply([], chunks);
  5051.   }
  5052. };
  5053.  
  5054.  
  5055. // Enable/Disable typed arrays use, for testing
  5056. //
  5057. exports.setTyped = function (on) {
  5058.   if (on) {
  5059.     exports.Buf8  = Uint8Array;
  5060.     exports.Buf16 = Uint16Array;
  5061.     exports.Buf32 = Int32Array;
  5062.     exports.assign(exports, fnTyped);
  5063.   } else {
  5064.     exports.Buf8  = Array;
  5065.     exports.Buf16 = Array;
  5066.     exports.Buf32 = Array;
  5067.     exports.assign(exports, fnUntyped);
  5068.   }
  5069. };
  5070.  
  5071. exports.setTyped(TYPED_OK);
  5072.  
  5073. },{}],18:[function(require,module,exports){
  5074. 'use strict';
  5075.  
  5076. // Note: adler32 takes 12% for level 0 and 2% for level 6.
  5077. // It isn't worth it to make additional optimizations as in original.
  5078. // Small size is preferable.
  5079.  
  5080. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  5081. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  5082. //
  5083. // This software is provided 'as-is', without any express or implied
  5084. // warranty. In no event will the authors be held liable for any damages
  5085. // arising from the use of this software.
  5086. //
  5087. // Permission is granted to anyone to use this software for any purpose,
  5088. // including commercial applications, and to alter it and redistribute it
  5089. // freely, subject to the following restrictions:
  5090. //
  5091. // 1. The origin of this software must not be misrepresented; you must not
  5092. //   claim that you wrote the original software. If you use this software
  5093. //   in a product, an acknowledgment in the product documentation would be
  5094. //   appreciated but is not required.
  5095. // 2. Altered source versions must be plainly marked as such, and must not be
  5096. //   misrepresented as being the original software.
  5097. // 3. This notice may not be removed or altered from any source distribution.
  5098.  
  5099. function adler32(adler, buf, len, pos) {
  5100.   var s1 = (adler & 0xffff) |0,
  5101.       s2 = ((adler >>> 16) & 0xffff) |0,
  5102.       n = 0;
  5103.  
  5104.   while (len !== 0) {
  5105.     // Set limit ~ twice less than 5552, to keep
  5106.     // s2 in 31-bits, because we force signed ints.
  5107.     // in other case %= will fail.
  5108.     n = len > 2000 ? 2000 : len;
  5109.     len -= n;
  5110.  
  5111.     do {
  5112.       s1 = (s1 + buf[pos++]) |0;
  5113.       s2 = (s2 + s1) |0;
  5114.     } while (--n);
  5115.  
  5116.     s1 %= 65521;
  5117.     s2 %= 65521;
  5118.   }
  5119.  
  5120.   return (s1 | (s2 << 16)) |0;
  5121. }
  5122.  
  5123.  
  5124. module.exports = adler32;
  5125.  
  5126. },{}],19:[function(require,module,exports){
  5127. 'use strict';
  5128.  
  5129. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  5130. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  5131. //
  5132. // This software is provided 'as-is', without any express or implied
  5133. // warranty. In no event will the authors be held liable for any damages
  5134. // arising from the use of this software.
  5135. //
  5136. // Permission is granted to anyone to use this software for any purpose,
  5137. // including commercial applications, and to alter it and redistribute it
  5138. // freely, subject to the following restrictions:
  5139. //
  5140. // 1. The origin of this software must not be misrepresented; you must not
  5141. //   claim that you wrote the original software. If you use this software
  5142. //   in a product, an acknowledgment in the product documentation would be
  5143. //   appreciated but is not required.
  5144. // 2. Altered source versions must be plainly marked as such, and must not be
  5145. //   misrepresented as being the original software.
  5146. // 3. This notice may not be removed or altered from any source distribution.
  5147.  
  5148. module.exports = {
  5149.  
  5150.   /* Allowed flush values; see deflate() and inflate() below for details */
  5151.   Z_NO_FLUSH:         0,
  5152.   Z_PARTIAL_FLUSH:    1,
  5153.   Z_SYNC_FLUSH:       2,
  5154.   Z_FULL_FLUSH:       3,
  5155.   Z_FINISH:           4,
  5156.   Z_BLOCK:            5,
  5157.   Z_TREES:            6,
  5158.  
  5159.   /* Return codes for the compression/decompression functions. Negative values
  5160.   * are errors, positive values are used for special but normal events.
  5161.   */
  5162.   Z_OK:               0,
  5163.   Z_STREAM_END:       1,
  5164.   Z_NEED_DICT:        2,
  5165.   Z_ERRNO:           -1,
  5166.   Z_STREAM_ERROR:    -2,
  5167.   Z_DATA_ERROR:      -3,
  5168.   //Z_MEM_ERROR:     -4,
  5169.   Z_BUF_ERROR:       -5,
  5170.   //Z_VERSION_ERROR: -6,
  5171.  
  5172.   /* compression levels */
  5173.   Z_NO_COMPRESSION:         0,
  5174.   Z_BEST_SPEED:             1,
  5175.   Z_BEST_COMPRESSION:       9,
  5176.   Z_DEFAULT_COMPRESSION:   -1,
  5177.  
  5178.  
  5179.   Z_FILTERED:               1,
  5180.   Z_HUFFMAN_ONLY:           2,
  5181.   Z_RLE:                    3,
  5182.   Z_FIXED:                  4,
  5183.   Z_DEFAULT_STRATEGY:       0,
  5184.  
  5185.   /* Possible values of the data_type field (though see inflate()) */
  5186.   Z_BINARY:                 0,
  5187.   Z_TEXT:                   1,
  5188.   //Z_ASCII:                1, // = Z_TEXT (deprecated)
  5189.   Z_UNKNOWN:                2,
  5190.  
  5191.   /* The deflate compression method */
  5192.   Z_DEFLATED:               8
  5193.   //Z_NULL:                 null // Use -1 or null inline, depending on var type
  5194. };
  5195.  
  5196. },{}],20:[function(require,module,exports){
  5197. 'use strict';
  5198.  
  5199. // Note: we can't get significant speed boost here.
  5200. // So write code to minimize size - no pregenerated tables
  5201. // and array tools dependencies.
  5202.  
  5203. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  5204. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  5205. //
  5206. // This software is provided 'as-is', without any express or implied
  5207. // warranty. In no event will the authors be held liable for any damages
  5208. // arising from the use of this software.
  5209. //
  5210. // Permission is granted to anyone to use this software for any purpose,
  5211. // including commercial applications, and to alter it and redistribute it
  5212. // freely, subject to the following restrictions:
  5213. //
  5214. // 1. The origin of this software must not be misrepresented; you must not
  5215. //   claim that you wrote the original software. If you use this software
  5216. //   in a product, an acknowledgment in the product documentation would be
  5217. //   appreciated but is not required.
  5218. // 2. Altered source versions must be plainly marked as such, and must not be
  5219. //   misrepresented as being the original software.
  5220. // 3. This notice may not be removed or altered from any source distribution.
  5221.  
  5222. // Use ordinary array, since untyped makes no boost here
  5223. function makeTable() {
  5224.   var c, table = [];
  5225.  
  5226.   for (var n = 0; n < 256; n++) {
  5227.     c = n;
  5228.     for (var k = 0; k < 8; k++) {
  5229.       c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
  5230.     }
  5231.     table[n] = c;
  5232.   }
  5233.  
  5234.   return table;
  5235. }
  5236.  
  5237. // Create table on load. Just 255 signed longs. Not a problem.
  5238. var crcTable = makeTable();
  5239.  
  5240.  
  5241. function crc32(crc, buf, len, pos) {
  5242.   var t = crcTable,
  5243.       end = pos + len;
  5244.  
  5245.   crc ^= -1;
  5246.  
  5247.   for (var i = pos; i < end; i++) {
  5248.     crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];
  5249.   }
  5250.  
  5251.   return (crc ^ (-1)); // >>> 0;
  5252. }
  5253.  
  5254.  
  5255. module.exports = crc32;
  5256.  
  5257. },{}],21:[function(require,module,exports){
  5258. 'use strict';
  5259.  
  5260. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  5261. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  5262. //
  5263. // This software is provided 'as-is', without any express or implied
  5264. // warranty. In no event will the authors be held liable for any damages
  5265. // arising from the use of this software.
  5266. //
  5267. // Permission is granted to anyone to use this software for any purpose,
  5268. // including commercial applications, and to alter it and redistribute it
  5269. // freely, subject to the following restrictions:
  5270. //
  5271. // 1. The origin of this software must not be misrepresented; you must not
  5272. //   claim that you wrote the original software. If you use this software
  5273. //   in a product, an acknowledgment in the product documentation would be
  5274. //   appreciated but is not required.
  5275. // 2. Altered source versions must be plainly marked as such, and must not be
  5276. //   misrepresented as being the original software.
  5277. // 3. This notice may not be removed or altered from any source distribution.
  5278.  
  5279. var utils   = require('../utils/common');
  5280. var trees   = require('./trees');
  5281. var adler32 = require('./adler32');
  5282. var crc32   = require('./crc32');
  5283. var msg     = require('./messages');
  5284.  
  5285. /* Public constants ==========================================================*/
  5286. /* ===========================================================================*/
  5287.  
  5288.  
  5289. /* Allowed flush values; see deflate() and inflate() below for details */
  5290. var Z_NO_FLUSH      = 0;
  5291. var Z_PARTIAL_FLUSH = 1;
  5292. //var Z_SYNC_FLUSH    = 2;
  5293. var Z_FULL_FLUSH    = 3;
  5294. var Z_FINISH        = 4;
  5295. var Z_BLOCK         = 5;
  5296. //var Z_TREES         = 6;
  5297.  
  5298.  
  5299. /* Return codes for the compression/decompression functions. Negative values
  5300.  * are errors, positive values are used for special but normal events.
  5301.  */
  5302. var Z_OK            = 0;
  5303. var Z_STREAM_END    = 1;
  5304. //var Z_NEED_DICT     = 2;
  5305. //var Z_ERRNO         = -1;
  5306. var Z_STREAM_ERROR  = -2;
  5307. var Z_DATA_ERROR    = -3;
  5308. //var Z_MEM_ERROR     = -4;
  5309. var Z_BUF_ERROR     = -5;
  5310. //var Z_VERSION_ERROR = -6;
  5311.  
  5312.  
  5313. /* compression levels */
  5314. //var Z_NO_COMPRESSION      = 0;
  5315. //var Z_BEST_SPEED          = 1;
  5316. //var Z_BEST_COMPRESSION    = 9;
  5317. var Z_DEFAULT_COMPRESSION = -1;
  5318.  
  5319.  
  5320. var Z_FILTERED            = 1;
  5321. var Z_HUFFMAN_ONLY        = 2;
  5322. var Z_RLE                 = 3;
  5323. var Z_FIXED               = 4;
  5324. var Z_DEFAULT_STRATEGY    = 0;
  5325.  
  5326. /* Possible values of the data_type field (though see inflate()) */
  5327. //var Z_BINARY              = 0;
  5328. //var Z_TEXT                = 1;
  5329. //var Z_ASCII               = 1; // = Z_TEXT
  5330. var Z_UNKNOWN             = 2;
  5331.  
  5332.  
  5333. /* The deflate compression method */
  5334. var Z_DEFLATED  = 8;
  5335.  
  5336. /*============================================================================*/
  5337.  
  5338.  
  5339. var MAX_MEM_LEVEL = 9;
  5340. /* Maximum value for memLevel in deflateInit2 */
  5341. var MAX_WBITS = 15;
  5342. /* 32K LZ77 window */
  5343. var DEF_MEM_LEVEL = 8;
  5344.  
  5345.  
  5346. var LENGTH_CODES  = 29;
  5347. /* number of length codes, not counting the special END_BLOCK code */
  5348. var LITERALS      = 256;
  5349. /* number of literal bytes 0..255 */
  5350. var L_CODES       = LITERALS + 1 + LENGTH_CODES;
  5351. /* number of Literal or Length codes, including the END_BLOCK code */
  5352. var D_CODES       = 30;
  5353. /* number of distance codes */
  5354. var BL_CODES      = 19;
  5355. /* number of codes used to transfer the bit lengths */
  5356. var HEAP_SIZE     = 2 * L_CODES + 1;
  5357. /* maximum heap size */
  5358. var MAX_BITS  = 15;
  5359. /* All codes must not exceed MAX_BITS bits */
  5360.  
  5361. var MIN_MATCH = 3;
  5362. var MAX_MATCH = 258;
  5363. var MIN_LOOKAHEAD = (MAX_MATCH + MIN_MATCH + 1);
  5364.  
  5365. var PRESET_DICT = 0x20;
  5366.  
  5367. var INIT_STATE = 42;
  5368. var EXTRA_STATE = 69;
  5369. var NAME_STATE = 73;
  5370. var COMMENT_STATE = 91;
  5371. var HCRC_STATE = 103;
  5372. var BUSY_STATE = 113;
  5373. var FINISH_STATE = 666;
  5374.  
  5375. var BS_NEED_MORE      = 1; /* block not completed, need more input or more output */
  5376. var BS_BLOCK_DONE     = 2; /* block flush performed */
  5377. var BS_FINISH_STARTED = 3; /* finish started, need only more output at next deflate */
  5378. var BS_FINISH_DONE    = 4; /* finish done, accept no more input or output */
  5379.  
  5380. var OS_CODE = 0x03; // Unix :) . Don't detect, use this default.
  5381.  
  5382. function err(strm, errorCode) {
  5383.   strm.msg = msg[errorCode];
  5384.   return errorCode;
  5385. }
  5386.  
  5387. function rank(f) {
  5388.   return ((f) << 1) - ((f) > 4 ? 9 : 0);
  5389. }
  5390.  
  5391. function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
  5392.  
  5393.  
  5394. /* =========================================================================
  5395.  * Flush as much pending output as possible. All deflate() output goes
  5396.  * through this function so some applications may wish to modify it
  5397.  * to avoid allocating a large strm->output buffer and copying into it.
  5398.  * (See also read_buf()).
  5399.  */
  5400. function flush_pending(strm) {
  5401.   var s = strm.state;
  5402.  
  5403.   //_tr_flush_bits(s);
  5404.   var len = s.pending;
  5405.   if (len > strm.avail_out) {
  5406.     len = strm.avail_out;
  5407.   }
  5408.   if (len === 0) { return; }
  5409.  
  5410.   utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out);
  5411.   strm.next_out += len;
  5412.   s.pending_out += len;
  5413.   strm.total_out += len;
  5414.   strm.avail_out -= len;
  5415.   s.pending -= len;
  5416.   if (s.pending === 0) {
  5417.     s.pending_out = 0;
  5418.   }
  5419. }
  5420.  
  5421.  
  5422. function flush_block_only(s, last) {
  5423.   trees._tr_flush_block(s, (s.block_start >= 0 ? s.block_start : -1), s.strstart - s.block_start, last);
  5424.   s.block_start = s.strstart;
  5425.   flush_pending(s.strm);
  5426. }
  5427.  
  5428.  
  5429. function put_byte(s, b) {
  5430.   s.pending_buf[s.pending++] = b;
  5431. }
  5432.  
  5433.  
  5434. /* =========================================================================
  5435.  * Put a short in the pending buffer. The 16-bit value is put in MSB order.
  5436.  * IN assertion: the stream state is correct and there is enough room in
  5437.  * pending_buf.
  5438.  */
  5439. function putShortMSB(s, b) {
  5440. //  put_byte(s, (Byte)(b >> 8));
  5441. //  put_byte(s, (Byte)(b & 0xff));
  5442.   s.pending_buf[s.pending++] = (b >>> 8) & 0xff;
  5443.   s.pending_buf[s.pending++] = b & 0xff;
  5444. }
  5445.  
  5446.  
  5447. /* ===========================================================================
  5448.  * Read a new buffer from the current input stream, update the adler32
  5449.  * and total number of bytes read.  All deflate() input goes through
  5450.  * this function so some applications may wish to modify it to avoid
  5451.  * allocating a large strm->input buffer and copying from it.
  5452.  * (See also flush_pending()).
  5453.  */
  5454. function read_buf(strm, buf, start, size) {
  5455.   var len = strm.avail_in;
  5456.  
  5457.   if (len > size) { len = size; }
  5458.   if (len === 0) { return 0; }
  5459.  
  5460.   strm.avail_in -= len;
  5461.  
  5462.   // zmemcpy(buf, strm->next_in, len);
  5463.   utils.arraySet(buf, strm.input, strm.next_in, len, start);
  5464.   if (strm.state.wrap === 1) {
  5465.     strm.adler = adler32(strm.adler, buf, len, start);
  5466.   }
  5467.  
  5468.   else if (strm.state.wrap === 2) {
  5469.     strm.adler = crc32(strm.adler, buf, len, start);
  5470.   }
  5471.  
  5472.   strm.next_in += len;
  5473.   strm.total_in += len;
  5474.  
  5475.   return len;
  5476. }
  5477.  
  5478.  
  5479. /* ===========================================================================
  5480.  * Set match_start to the longest match starting at the given string and
  5481.  * return its length. Matches shorter or equal to prev_length are discarded,
  5482.  * in which case the result is equal to prev_length and match_start is
  5483.  * garbage.
  5484.  * IN assertions: cur_match is the head of the hash chain for the current
  5485.  *   string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
  5486.  * OUT assertion: the match length is not greater than s->lookahead.
  5487.  */
  5488. function longest_match(s, cur_match) {
  5489.   var chain_length = s.max_chain_length;      /* max hash chain length */
  5490.   var scan = s.strstart; /* current string */
  5491.   var match;                       /* matched string */
  5492.   var len;                           /* length of current match */
  5493.   var best_len = s.prev_length;              /* best match length so far */
  5494.   var nice_match = s.nice_match;             /* stop if match long enough */
  5495.   var limit = (s.strstart > (s.w_size - MIN_LOOKAHEAD)) ?
  5496.       s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0/*NIL*/;
  5497.  
  5498.   var _win = s.window; // shortcut
  5499.  
  5500.   var wmask = s.w_mask;
  5501.   var prev  = s.prev;
  5502.  
  5503.   /* Stop when cur_match becomes <= limit. To simplify the code,
  5504.    * we prevent matches with the string of window index 0.
  5505.    */
  5506.  
  5507.   var strend = s.strstart + MAX_MATCH;
  5508.   var scan_end1  = _win[scan + best_len - 1];
  5509.   var scan_end   = _win[scan + best_len];
  5510.  
  5511.   /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
  5512.    * It is easy to get rid of this optimization if necessary.
  5513.    */
  5514.   // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  5515.  
  5516.   /* Do not waste too much time if we already have a good match: */
  5517.   if (s.prev_length >= s.good_match) {
  5518.     chain_length >>= 2;
  5519.   }
  5520.   /* Do not look for matches beyond the end of the input. This is necessary
  5521.    * to make deflate deterministic.
  5522.    */
  5523.   if (nice_match > s.lookahead) { nice_match = s.lookahead; }
  5524.  
  5525.   // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  5526.  
  5527.   do {
  5528.     // Assert(cur_match < s->strstart, "no future");
  5529.     match = cur_match;
  5530.  
  5531.     /* Skip to next match if the match length cannot increase
  5532.      * or if the match length is less than 2.  Note that the checks below
  5533.      * for insufficient lookahead only occur occasionally for performance
  5534.      * reasons.  Therefore uninitialized memory will be accessed, and
  5535.      * conditional jumps will be made that depend on those values.
  5536.      * However the length of the match is limited to the lookahead, so
  5537.      * the output of deflate is not affected by the uninitialized values.
  5538.      */
  5539.  
  5540.     if (_win[match + best_len]     !== scan_end  ||
  5541.         _win[match + best_len - 1] !== scan_end1 ||
  5542.         _win[match]                !== _win[scan] ||
  5543.         _win[++match]              !== _win[scan + 1]) {
  5544.       continue;
  5545.     }
  5546.  
  5547.     /* The check at best_len-1 can be removed because it will be made
  5548.      * again later. (This heuristic is not always a win.)
  5549.      * It is not necessary to compare scan[2] and match[2] since they
  5550.      * are always equal when the other bytes match, given that
  5551.      * the hash keys are equal and that HASH_BITS >= 8.
  5552.      */
  5553.     scan += 2;
  5554.     match++;
  5555.     // Assert(*scan == *match, "match[2]?");
  5556.  
  5557.     /* We check for insufficient lookahead only every 8th comparison;
  5558.      * the 256th check will be made at strstart+258.
  5559.      */
  5560.     do {
  5561.       /*jshint noempty:false*/
  5562.     } while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
  5563.              _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
  5564.              _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
  5565.              _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
  5566.              scan < strend);
  5567.  
  5568.     // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  5569.  
  5570.     len = MAX_MATCH - (strend - scan);
  5571.     scan = strend - MAX_MATCH;
  5572.  
  5573.     if (len > best_len) {
  5574.       s.match_start = cur_match;
  5575.       best_len = len;
  5576.       if (len >= nice_match) {
  5577.         break;
  5578.       }
  5579.       scan_end1  = _win[scan + best_len - 1];
  5580.       scan_end   = _win[scan + best_len];
  5581.     }
  5582.   } while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0);
  5583.  
  5584.   if (best_len <= s.lookahead) {
  5585.     return best_len;
  5586.   }
  5587.   return s.lookahead;
  5588. }
  5589.  
  5590.  
  5591. /* ===========================================================================
  5592.  * Fill the window when the lookahead becomes insufficient.
  5593.  * Updates strstart and lookahead.
  5594.  *
  5595.  * IN assertion: lookahead < MIN_LOOKAHEAD
  5596.  * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
  5597.  *    At least one byte has been read, or avail_in == 0; reads are
  5598.  *    performed for at least two bytes (required for the zip translate_eol
  5599.  *    option -- not supported here).
  5600.  */
  5601. function fill_window(s) {
  5602.   var _w_size = s.w_size;
  5603.   var p, n, m, more, str;
  5604.  
  5605.   //Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
  5606.  
  5607.   do {
  5608.     more = s.window_size - s.lookahead - s.strstart;
  5609.  
  5610.     // JS ints have 32 bit, block below not needed
  5611.     /* Deal with !@#$% 64K limit: */
  5612.     //if (sizeof(int) <= 2) {
  5613.     //    if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  5614.     //        more = wsize;
  5615.     //
  5616.     //  } else if (more == (unsigned)(-1)) {
  5617.     //        /* Very unlikely, but possible on 16 bit machine if
  5618.     //         * strstart == 0 && lookahead == 1 (input done a byte at time)
  5619.     //         */
  5620.     //        more--;
  5621.     //    }
  5622.     //}
  5623.  
  5624.  
  5625.     /* If the window is almost full and there is insufficient lookahead,
  5626.      * move the upper half to the lower one to make room in the upper half.
  5627.      */
  5628.     if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {
  5629.  
  5630.       utils.arraySet(s.window, s.window, _w_size, _w_size, 0);
  5631.       s.match_start -= _w_size;
  5632.       s.strstart -= _w_size;
  5633.       /* we now have strstart >= MAX_DIST */
  5634.       s.block_start -= _w_size;
  5635.  
  5636.       /* Slide the hash table (could be avoided with 32 bit values
  5637.        at the expense of memory usage). We slide even when level == 0
  5638.        to keep the hash table consistent if we switch back to level > 0
  5639.        later. (Using level 0 permanently is not an optimal usage of
  5640.        zlib, so we don't care about this pathological case.)
  5641.        */
  5642.  
  5643.       n = s.hash_size;
  5644.       p = n;
  5645.       do {
  5646.         m = s.head[--p];
  5647.         s.head[p] = (m >= _w_size ? m - _w_size : 0);
  5648.       } while (--n);
  5649.  
  5650.       n = _w_size;
  5651.       p = n;
  5652.       do {
  5653.         m = s.prev[--p];
  5654.         s.prev[p] = (m >= _w_size ? m - _w_size : 0);
  5655.         /* If n is not on any hash chain, prev[n] is garbage but
  5656.          * its value will never be used.
  5657.          */
  5658.       } while (--n);
  5659.  
  5660.       more += _w_size;
  5661.     }
  5662.     if (s.strm.avail_in === 0) {
  5663.       break;
  5664.     }
  5665.  
  5666.     /* If there was no sliding:
  5667.      *    strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
  5668.      *    more == window_size - lookahead - strstart
  5669.      * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
  5670.      * => more >= window_size - 2*WSIZE + 2
  5671.      * In the BIG_MEM or MMAP case (not yet supported),
  5672.      *   window_size == input_size + MIN_LOOKAHEAD  &&
  5673.      *   strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
  5674.      * Otherwise, window_size == 2*WSIZE so more >= 2.
  5675.      * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
  5676.      */
  5677.     //Assert(more >= 2, "more < 2");
  5678.     n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more);
  5679.     s.lookahead += n;
  5680.  
  5681.     /* Initialize the hash value now that we have some input: */
  5682.     if (s.lookahead + s.insert >= MIN_MATCH) {
  5683.       str = s.strstart - s.insert;
  5684.       s.ins_h = s.window[str];
  5685.  
  5686.       /* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */
  5687.       s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + 1]) & s.hash_mask;
  5688. //#if MIN_MATCH != 3
  5689. //        Call update_hash() MIN_MATCH-3 more times
  5690. //#endif
  5691.       while (s.insert) {
  5692.         /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
  5693.         s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
  5694.  
  5695.         s.prev[str & s.w_mask] = s.head[s.ins_h];
  5696.         s.head[s.ins_h] = str;
  5697.         str++;
  5698.         s.insert--;
  5699.         if (s.lookahead + s.insert < MIN_MATCH) {
  5700.           break;
  5701.         }
  5702.       }
  5703.     }
  5704.     /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
  5705.      * but this is not important since only literal bytes will be emitted.
  5706.      */
  5707.  
  5708.   } while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0);
  5709.  
  5710.   /* If the WIN_INIT bytes after the end of the current data have never been
  5711.    * written, then zero those bytes in order to avoid memory check reports of
  5712.    * the use of uninitialized (or uninitialised as Julian writes) bytes by
  5713.    * the longest match routines.  Update the high water mark for the next
  5714.    * time through here.  WIN_INIT is set to MAX_MATCH since the longest match
  5715.    * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
  5716.    */
  5717. //  if (s.high_water < s.window_size) {
  5718. //    var curr = s.strstart + s.lookahead;
  5719. //    var init = 0;
  5720. //
  5721. //    if (s.high_water < curr) {
  5722. //      /* Previous high water mark below current data -- zero WIN_INIT
  5723. //       * bytes or up to end of window, whichever is less.
  5724. //       */
  5725. //      init = s.window_size - curr;
  5726. //      if (init > WIN_INIT)
  5727. //        init = WIN_INIT;
  5728. //      zmemzero(s->window + curr, (unsigned)init);
  5729. //      s->high_water = curr + init;
  5730. //    }
  5731. //    else if (s->high_water < (ulg)curr + WIN_INIT) {
  5732. //      /* High water mark at or above current data, but below current data
  5733. //       * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
  5734. //       * to end of window, whichever is less.
  5735. //       */
  5736. //      init = (ulg)curr + WIN_INIT - s->high_water;
  5737. //      if (init > s->window_size - s->high_water)
  5738. //        init = s->window_size - s->high_water;
  5739. //      zmemzero(s->window + s->high_water, (unsigned)init);
  5740. //      s->high_water += init;
  5741. //    }
  5742. //  }
  5743. //
  5744. //  Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
  5745. //    "not enough room for search");
  5746. }
  5747.  
  5748. /* ===========================================================================
  5749.  * Copy without compression as much as possible from the input stream, return
  5750.  * the current block state.
  5751.  * This function does not insert new strings in the dictionary since
  5752.  * uncompressible data is probably not useful. This function is used
  5753.  * only for the level=0 compression option.
  5754.  * NOTE: this function should be optimized to avoid extra copying from
  5755.  * window to pending_buf.
  5756.  */
  5757. function deflate_stored(s, flush) {
  5758.   /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
  5759.    * to pending_buf_size, and each stored block has a 5 byte header:
  5760.    */
  5761.   var max_block_size = 0xffff;
  5762.  
  5763.   if (max_block_size > s.pending_buf_size - 5) {
  5764.     max_block_size = s.pending_buf_size - 5;
  5765.   }
  5766.  
  5767.   /* Copy as much as possible from input to output: */
  5768.   for (;;) {
  5769.     /* Fill the window as much as possible: */
  5770.     if (s.lookahead <= 1) {
  5771.  
  5772.       //Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  5773.       //  s->block_start >= (long)s->w_size, "slide too late");
  5774. //      if (!(s.strstart < s.w_size + (s.w_size - MIN_LOOKAHEAD) ||
  5775. //        s.block_start >= s.w_size)) {
  5776. //        throw  new Error("slide too late");
  5777. //      }
  5778.  
  5779.       fill_window(s);
  5780.       if (s.lookahead === 0 && flush === Z_NO_FLUSH) {
  5781.         return BS_NEED_MORE;
  5782.       }
  5783.  
  5784.       if (s.lookahead === 0) {
  5785.         break;
  5786.       }
  5787.       /* flush the current block */
  5788.     }
  5789.     //Assert(s->block_start >= 0L, "block gone");
  5790. //    if (s.block_start < 0) throw new Error("block gone");
  5791.  
  5792.     s.strstart += s.lookahead;
  5793.     s.lookahead = 0;
  5794.  
  5795.     /* Emit a stored block if pending_buf will be full: */
  5796.     var max_start = s.block_start + max_block_size;
  5797.  
  5798.     if (s.strstart === 0 || s.strstart >= max_start) {
  5799.       /* strstart == 0 is possible when wraparound on 16-bit machine */
  5800.       s.lookahead = s.strstart - max_start;
  5801.       s.strstart = max_start;
  5802.       /*** FLUSH_BLOCK(s, 0); ***/
  5803.       flush_block_only(s, false);
  5804.       if (s.strm.avail_out === 0) {
  5805.         return BS_NEED_MORE;
  5806.       }
  5807.       /***/
  5808.  
  5809.  
  5810.     }
  5811.     /* Flush if we may have to slide, otherwise block_start may become
  5812.      * negative and the data will be gone:
  5813.      */
  5814.     if (s.strstart - s.block_start >= (s.w_size - MIN_LOOKAHEAD)) {
  5815.       /*** FLUSH_BLOCK(s, 0); ***/
  5816.       flush_block_only(s, false);
  5817.       if (s.strm.avail_out === 0) {
  5818.         return BS_NEED_MORE;
  5819.       }
  5820.       /***/
  5821.     }
  5822.   }
  5823.  
  5824.   s.insert = 0;
  5825.  
  5826.   if (flush === Z_FINISH) {
  5827.     /*** FLUSH_BLOCK(s, 1); ***/
  5828.     flush_block_only(s, true);
  5829.     if (s.strm.avail_out === 0) {
  5830.       return BS_FINISH_STARTED;
  5831.     }
  5832.     /***/
  5833.     return BS_FINISH_DONE;
  5834.   }
  5835.  
  5836.   if (s.strstart > s.block_start) {
  5837.     /*** FLUSH_BLOCK(s, 0); ***/
  5838.     flush_block_only(s, false);
  5839.     if (s.strm.avail_out === 0) {
  5840.       return BS_NEED_MORE;
  5841.     }
  5842.     /***/
  5843.   }
  5844.  
  5845.   return BS_NEED_MORE;
  5846. }
  5847.  
  5848. /* ===========================================================================
  5849.  * Compress as much as possible from the input stream, return the current
  5850.  * block state.
  5851.  * This function does not perform lazy evaluation of matches and inserts
  5852.  * new strings in the dictionary only for unmatched strings or for short
  5853.  * matches. It is used only for the fast compression options.
  5854.  */
  5855. function deflate_fast(s, flush) {
  5856.   var hash_head;        /* head of the hash chain */
  5857.   var bflush;           /* set if current block must be flushed */
  5858.  
  5859.   for (;;) {
  5860.     /* Make sure that we always have enough lookahead, except
  5861.      * at the end of the input file. We need MAX_MATCH bytes
  5862.      * for the next match, plus MIN_MATCH bytes to insert the
  5863.      * string following the next match.
  5864.      */
  5865.     if (s.lookahead < MIN_LOOKAHEAD) {
  5866.       fill_window(s);
  5867.       if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
  5868.         return BS_NEED_MORE;
  5869.       }
  5870.       if (s.lookahead === 0) {
  5871.         break; /* flush the current block */
  5872.       }
  5873.     }
  5874.  
  5875.     /* Insert the string window[strstart .. strstart+2] in the
  5876.      * dictionary, and set hash_head to the head of the hash chain:
  5877.      */
  5878.     hash_head = 0/*NIL*/;
  5879.     if (s.lookahead >= MIN_MATCH) {
  5880.       /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  5881.       s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  5882.       hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  5883.       s.head[s.ins_h] = s.strstart;
  5884.       /***/
  5885.     }
  5886.  
  5887.     /* Find the longest match, discarding those <= prev_length.
  5888.      * At this point we have always match_length < MIN_MATCH
  5889.      */
  5890.     if (hash_head !== 0/*NIL*/ && ((s.strstart - hash_head) <= (s.w_size - MIN_LOOKAHEAD))) {
  5891.       /* To simplify the code, we prevent matches with the string
  5892.        * of window index 0 (in particular we have to avoid a match
  5893.        * of the string with itself at the start of the input file).
  5894.        */
  5895.       s.match_length = longest_match(s, hash_head);
  5896.       /* longest_match() sets match_start */
  5897.     }
  5898.     if (s.match_length >= MIN_MATCH) {
  5899.       // check_match(s, s.strstart, s.match_start, s.match_length); // for debug only
  5900.  
  5901.       /*** _tr_tally_dist(s, s.strstart - s.match_start,
  5902.                      s.match_length - MIN_MATCH, bflush); ***/
  5903.       bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);
  5904.  
  5905.       s.lookahead -= s.match_length;
  5906.  
  5907.       /* Insert new strings in the hash table only if the match length
  5908.        * is not too large. This saves time but degrades compression.
  5909.        */
  5910.       if (s.match_length <= s.max_lazy_match/*max_insert_length*/ && s.lookahead >= MIN_MATCH) {
  5911.         s.match_length--; /* string at strstart already in table */
  5912.         do {
  5913.           s.strstart++;
  5914.           /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  5915.           s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  5916.           hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  5917.           s.head[s.ins_h] = s.strstart;
  5918.           /***/
  5919.           /* strstart never exceeds WSIZE-MAX_MATCH, so there are
  5920.            * always MIN_MATCH bytes ahead.
  5921.            */
  5922.         } while (--s.match_length !== 0);
  5923.         s.strstart++;
  5924.       } else
  5925.       {
  5926.         s.strstart += s.match_length;
  5927.         s.match_length = 0;
  5928.         s.ins_h = s.window[s.strstart];
  5929.         /* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */
  5930.         s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + 1]) & s.hash_mask;
  5931.  
  5932. //#if MIN_MATCH != 3
  5933. //                Call UPDATE_HASH() MIN_MATCH-3 more times
  5934. //#endif
  5935.         /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
  5936.          * matter since it will be recomputed at next deflate call.
  5937.          */
  5938.       }
  5939.     } else {
  5940.       /* No match, output a literal byte */
  5941.       //Tracevv((stderr,"%c", s.window[s.strstart]));
  5942.       /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
  5943.       bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
  5944.  
  5945.       s.lookahead--;
  5946.       s.strstart++;
  5947.     }
  5948.     if (bflush) {
  5949.       /*** FLUSH_BLOCK(s, 0); ***/
  5950.       flush_block_only(s, false);
  5951.       if (s.strm.avail_out === 0) {
  5952.         return BS_NEED_MORE;
  5953.       }
  5954.       /***/
  5955.     }
  5956.   }
  5957.   s.insert = ((s.strstart < (MIN_MATCH - 1)) ? s.strstart : MIN_MATCH - 1);
  5958.   if (flush === Z_FINISH) {
  5959.     /*** FLUSH_BLOCK(s, 1); ***/
  5960.     flush_block_only(s, true);
  5961.     if (s.strm.avail_out === 0) {
  5962.       return BS_FINISH_STARTED;
  5963.     }
  5964.     /***/
  5965.     return BS_FINISH_DONE;
  5966.   }
  5967.   if (s.last_lit) {
  5968.     /*** FLUSH_BLOCK(s, 0); ***/
  5969.     flush_block_only(s, false);
  5970.     if (s.strm.avail_out === 0) {
  5971.       return BS_NEED_MORE;
  5972.     }
  5973.     /***/
  5974.   }
  5975.   return BS_BLOCK_DONE;
  5976. }
  5977.  
  5978. /* ===========================================================================
  5979.  * Same as above, but achieves better compression. We use a lazy
  5980.  * evaluation for matches: a match is finally adopted only if there is
  5981.  * no better match at the next window position.
  5982.  */
  5983. function deflate_slow(s, flush) {
  5984.   var hash_head;          /* head of hash chain */
  5985.   var bflush;              /* set if current block must be flushed */
  5986.  
  5987.   var max_insert;
  5988.  
  5989.   /* Process the input block. */
  5990.   for (;;) {
  5991.     /* Make sure that we always have enough lookahead, except
  5992.      * at the end of the input file. We need MAX_MATCH bytes
  5993.      * for the next match, plus MIN_MATCH bytes to insert the
  5994.      * string following the next match.
  5995.      */
  5996.     if (s.lookahead < MIN_LOOKAHEAD) {
  5997.       fill_window(s);
  5998.       if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
  5999.         return BS_NEED_MORE;
  6000.       }
  6001.       if (s.lookahead === 0) { break; } /* flush the current block */
  6002.     }
  6003.  
  6004.     /* Insert the string window[strstart .. strstart+2] in the
  6005.      * dictionary, and set hash_head to the head of the hash chain:
  6006.      */
  6007.     hash_head = 0/*NIL*/;
  6008.     if (s.lookahead >= MIN_MATCH) {
  6009.       /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  6010.       s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  6011.       hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  6012.       s.head[s.ins_h] = s.strstart;
  6013.       /***/
  6014.     }
  6015.  
  6016.     /* Find the longest match, discarding those <= prev_length.
  6017.      */
  6018.     s.prev_length = s.match_length;
  6019.     s.prev_match = s.match_start;
  6020.     s.match_length = MIN_MATCH - 1;
  6021.  
  6022.     if (hash_head !== 0/*NIL*/ && s.prev_length < s.max_lazy_match &&
  6023.         s.strstart - hash_head <= (s.w_size - MIN_LOOKAHEAD)/*MAX_DIST(s)*/) {
  6024.       /* To simplify the code, we prevent matches with the string
  6025.        * of window index 0 (in particular we have to avoid a match
  6026.        * of the string with itself at the start of the input file).
  6027.        */
  6028.       s.match_length = longest_match(s, hash_head);
  6029.       /* longest_match() sets match_start */
  6030.  
  6031.       if (s.match_length <= 5 &&
  6032.          (s.strategy === Z_FILTERED || (s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096/*TOO_FAR*/))) {
  6033.  
  6034.         /* If prev_match is also MIN_MATCH, match_start is garbage
  6035.          * but we will ignore the current match anyway.
  6036.          */
  6037.         s.match_length = MIN_MATCH - 1;
  6038.       }
  6039.     }
  6040.     /* If there was a match at the previous step and the current
  6041.      * match is not better, output the previous match:
  6042.      */
  6043.     if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) {
  6044.       max_insert = s.strstart + s.lookahead - MIN_MATCH;
  6045.       /* Do not insert strings in hash table beyond this. */
  6046.  
  6047.       //check_match(s, s.strstart-1, s.prev_match, s.prev_length);
  6048.  
  6049.       /***_tr_tally_dist(s, s.strstart - 1 - s.prev_match,
  6050.                      s.prev_length - MIN_MATCH, bflush);***/
  6051.       bflush = trees._tr_tally(s, s.strstart - 1 - s.prev_match, s.prev_length - MIN_MATCH);
  6052.       /* Insert in hash table all strings up to the end of the match.
  6053.        * strstart-1 and strstart are already inserted. If there is not
  6054.        * enough lookahead, the last two strings are not inserted in
  6055.        * the hash table.
  6056.        */
  6057.       s.lookahead -= s.prev_length - 1;
  6058.       s.prev_length -= 2;
  6059.       do {
  6060.         if (++s.strstart <= max_insert) {
  6061.           /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  6062.           s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  6063.           hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  6064.           s.head[s.ins_h] = s.strstart;
  6065.           /***/
  6066.         }
  6067.       } while (--s.prev_length !== 0);
  6068.       s.match_available = 0;
  6069.       s.match_length = MIN_MATCH - 1;
  6070.       s.strstart++;
  6071.  
  6072.       if (bflush) {
  6073.         /*** FLUSH_BLOCK(s, 0); ***/
  6074.         flush_block_only(s, false);
  6075.         if (s.strm.avail_out === 0) {
  6076.           return BS_NEED_MORE;
  6077.         }
  6078.         /***/
  6079.       }
  6080.  
  6081.     } else if (s.match_available) {
  6082.       /* If there was no match at the previous position, output a
  6083.        * single literal. If there was a match but the current match
  6084.        * is longer, truncate the previous match to a single literal.
  6085.        */
  6086.       //Tracevv((stderr,"%c", s->window[s->strstart-1]));
  6087.       /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
  6088.       bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
  6089.  
  6090.       if (bflush) {
  6091.         /*** FLUSH_BLOCK_ONLY(s, 0) ***/
  6092.         flush_block_only(s, false);
  6093.         /***/
  6094.       }
  6095.       s.strstart++;
  6096.       s.lookahead--;
  6097.       if (s.strm.avail_out === 0) {
  6098.         return BS_NEED_MORE;
  6099.       }
  6100.     } else {
  6101.       /* There is no previous match to compare with, wait for
  6102.        * the next step to decide.
  6103.        */
  6104.       s.match_available = 1;
  6105.       s.strstart++;
  6106.       s.lookahead--;
  6107.     }
  6108.   }
  6109.   //Assert (flush != Z_NO_FLUSH, "no flush?");
  6110.   if (s.match_available) {
  6111.     //Tracevv((stderr,"%c", s->window[s->strstart-1]));
  6112.     /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
  6113.     bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
  6114.  
  6115.     s.match_available = 0;
  6116.   }
  6117.   s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;
  6118.   if (flush === Z_FINISH) {
  6119.     /*** FLUSH_BLOCK(s, 1); ***/
  6120.     flush_block_only(s, true);
  6121.     if (s.strm.avail_out === 0) {
  6122.       return BS_FINISH_STARTED;
  6123.     }
  6124.     /***/
  6125.     return BS_FINISH_DONE;
  6126.   }
  6127.   if (s.last_lit) {
  6128.     /*** FLUSH_BLOCK(s, 0); ***/
  6129.     flush_block_only(s, false);
  6130.     if (s.strm.avail_out === 0) {
  6131.       return BS_NEED_MORE;
  6132.     }
  6133.     /***/
  6134.   }
  6135.  
  6136.   return BS_BLOCK_DONE;
  6137. }
  6138.  
  6139.  
  6140. /* ===========================================================================
  6141.  * For Z_RLE, simply look for runs of bytes, generate matches only of distance
  6142.  * one.  Do not maintain a hash table.  (It will be regenerated if this run of
  6143.  * deflate switches away from Z_RLE.)
  6144.  */
  6145. function deflate_rle(s, flush) {
  6146.   var bflush;            /* set if current block must be flushed */
  6147.   var prev;              /* byte at distance one to match */
  6148.   var scan, strend;      /* scan goes up to strend for length of run */
  6149.  
  6150.   var _win = s.window;
  6151.  
  6152.   for (;;) {
  6153.     /* Make sure that we always have enough lookahead, except
  6154.      * at the end of the input file. We need MAX_MATCH bytes
  6155.      * for the longest run, plus one for the unrolled loop.
  6156.      */
  6157.     if (s.lookahead <= MAX_MATCH) {
  6158.       fill_window(s);
  6159.       if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) {
  6160.         return BS_NEED_MORE;
  6161.       }
  6162.       if (s.lookahead === 0) { break; } /* flush the current block */
  6163.     }
  6164.  
  6165.     /* See how many times the previous byte repeats */
  6166.     s.match_length = 0;
  6167.     if (s.lookahead >= MIN_MATCH && s.strstart > 0) {
  6168.       scan = s.strstart - 1;
  6169.       prev = _win[scan];
  6170.       if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) {
  6171.         strend = s.strstart + MAX_MATCH;
  6172.         do {
  6173.           /*jshint noempty:false*/
  6174.         } while (prev === _win[++scan] && prev === _win[++scan] &&
  6175.                  prev === _win[++scan] && prev === _win[++scan] &&
  6176.                  prev === _win[++scan] && prev === _win[++scan] &&
  6177.                  prev === _win[++scan] && prev === _win[++scan] &&
  6178.                  scan < strend);
  6179.         s.match_length = MAX_MATCH - (strend - scan);
  6180.         if (s.match_length > s.lookahead) {
  6181.           s.match_length = s.lookahead;
  6182.         }
  6183.       }
  6184.       //Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
  6185.     }
  6186.  
  6187.     /* Emit match if have run of MIN_MATCH or longer, else emit literal */
  6188.     if (s.match_length >= MIN_MATCH) {
  6189.       //check_match(s, s.strstart, s.strstart - 1, s.match_length);
  6190.  
  6191.       /*** _tr_tally_dist(s, 1, s.match_length - MIN_MATCH, bflush); ***/
  6192.       bflush = trees._tr_tally(s, 1, s.match_length - MIN_MATCH);
  6193.  
  6194.       s.lookahead -= s.match_length;
  6195.       s.strstart += s.match_length;
  6196.       s.match_length = 0;
  6197.     } else {
  6198.       /* No match, output a literal byte */
  6199.       //Tracevv((stderr,"%c", s->window[s->strstart]));
  6200.       /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
  6201.       bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
  6202.  
  6203.       s.lookahead--;
  6204.       s.strstart++;
  6205.     }
  6206.     if (bflush) {
  6207.       /*** FLUSH_BLOCK(s, 0); ***/
  6208.       flush_block_only(s, false);
  6209.       if (s.strm.avail_out === 0) {
  6210.         return BS_NEED_MORE;
  6211.       }
  6212.       /***/
  6213.     }
  6214.   }
  6215.   s.insert = 0;
  6216.   if (flush === Z_FINISH) {
  6217.     /*** FLUSH_BLOCK(s, 1); ***/
  6218.     flush_block_only(s, true);
  6219.     if (s.strm.avail_out === 0) {
  6220.       return BS_FINISH_STARTED;
  6221.     }
  6222.     /***/
  6223.     return BS_FINISH_DONE;
  6224.   }
  6225.   if (s.last_lit) {
  6226.     /*** FLUSH_BLOCK(s, 0); ***/
  6227.     flush_block_only(s, false);
  6228.     if (s.strm.avail_out === 0) {
  6229.       return BS_NEED_MORE;
  6230.     }
  6231.     /***/
  6232.   }
  6233.   return BS_BLOCK_DONE;
  6234. }
  6235.  
  6236. /* ===========================================================================
  6237.  * For Z_HUFFMAN_ONLY, do not look for matches.  Do not maintain a hash table.
  6238.  * (It will be regenerated if this run of deflate switches away from Huffman.)
  6239.  */
  6240. function deflate_huff(s, flush) {
  6241.   var bflush;             /* set if current block must be flushed */
  6242.  
  6243.   for (;;) {
  6244.     /* Make sure that we have a literal to write. */
  6245.     if (s.lookahead === 0) {
  6246.       fill_window(s);
  6247.       if (s.lookahead === 0) {
  6248.         if (flush === Z_NO_FLUSH) {
  6249.           return BS_NEED_MORE;
  6250.         }
  6251.         break;      /* flush the current block */
  6252.       }
  6253.     }
  6254.  
  6255.     /* Output a literal byte */
  6256.     s.match_length = 0;
  6257.     //Tracevv((stderr,"%c", s->window[s->strstart]));
  6258.     /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
  6259.     bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
  6260.     s.lookahead--;
  6261.     s.strstart++;
  6262.     if (bflush) {
  6263.       /*** FLUSH_BLOCK(s, 0); ***/
  6264.       flush_block_only(s, false);
  6265.       if (s.strm.avail_out === 0) {
  6266.         return BS_NEED_MORE;
  6267.       }
  6268.       /***/
  6269.     }
  6270.   }
  6271.   s.insert = 0;
  6272.   if (flush === Z_FINISH) {
  6273.     /*** FLUSH_BLOCK(s, 1); ***/
  6274.     flush_block_only(s, true);
  6275.     if (s.strm.avail_out === 0) {
  6276.       return BS_FINISH_STARTED;
  6277.     }
  6278.     /***/
  6279.     return BS_FINISH_DONE;
  6280.   }
  6281.   if (s.last_lit) {
  6282.     /*** FLUSH_BLOCK(s, 0); ***/
  6283.     flush_block_only(s, false);
  6284.     if (s.strm.avail_out === 0) {
  6285.       return BS_NEED_MORE;
  6286.     }
  6287.     /***/
  6288.   }
  6289.   return BS_BLOCK_DONE;
  6290. }
  6291.  
  6292. /* Values for max_lazy_match, good_match and max_chain_length, depending on
  6293.  * the desired pack level (0..9). The values given below have been tuned to
  6294.  * exclude worst case performance for pathological files. Better values may be
  6295.  * found for specific files.
  6296.  */
  6297. function Config(good_length, max_lazy, nice_length, max_chain, func) {
  6298.   this.good_length = good_length;
  6299.   this.max_lazy = max_lazy;
  6300.   this.nice_length = nice_length;
  6301.   this.max_chain = max_chain;
  6302.   this.func = func;
  6303. }
  6304.  
  6305. var configuration_table;
  6306.  
  6307. configuration_table = [
  6308.   /*      good lazy nice chain */
  6309.   new Config(0, 0, 0, 0, deflate_stored),          /* 0 store only */
  6310.   new Config(4, 4, 8, 4, deflate_fast),            /* 1 max speed, no lazy matches */
  6311.   new Config(4, 5, 16, 8, deflate_fast),           /* 2 */
  6312.   new Config(4, 6, 32, 32, deflate_fast),          /* 3 */
  6313.  
  6314.   new Config(4, 4, 16, 16, deflate_slow),          /* 4 lazy matches */
  6315.   new Config(8, 16, 32, 32, deflate_slow),         /* 5 */
  6316.   new Config(8, 16, 128, 128, deflate_slow),       /* 6 */
  6317.   new Config(8, 32, 128, 256, deflate_slow),       /* 7 */
  6318.   new Config(32, 128, 258, 1024, deflate_slow),    /* 8 */
  6319.   new Config(32, 258, 258, 4096, deflate_slow)     /* 9 max compression */
  6320. ];
  6321.  
  6322.  
  6323. /* ===========================================================================
  6324.  * Initialize the "longest match" routines for a new zlib stream
  6325.  */
  6326. function lm_init(s) {
  6327.   s.window_size = 2 * s.w_size;
  6328.  
  6329.   /*** CLEAR_HASH(s); ***/
  6330.   zero(s.head); // Fill with NIL (= 0);
  6331.  
  6332.   /* Set the default configuration parameters:
  6333.    */
  6334.   s.max_lazy_match = configuration_table[s.level].max_lazy;
  6335.   s.good_match = configuration_table[s.level].good_length;
  6336.   s.nice_match = configuration_table[s.level].nice_length;
  6337.   s.max_chain_length = configuration_table[s.level].max_chain;
  6338.  
  6339.   s.strstart = 0;
  6340.   s.block_start = 0;
  6341.   s.lookahead = 0;
  6342.   s.insert = 0;
  6343.   s.match_length = s.prev_length = MIN_MATCH - 1;
  6344.   s.match_available = 0;
  6345.   s.ins_h = 0;
  6346. }
  6347.  
  6348.  
  6349. function DeflateState() {
  6350.   this.strm = null;            /* pointer back to this zlib stream */
  6351.   this.status = 0;            /* as the name implies */
  6352.   this.pending_buf = null;      /* output still pending */
  6353.   this.pending_buf_size = 0;  /* size of pending_buf */
  6354.   this.pending_out = 0;       /* next pending byte to output to the stream */
  6355.   this.pending = 0;           /* nb of bytes in the pending buffer */
  6356.   this.wrap = 0;              /* bit 0 true for zlib, bit 1 true for gzip */
  6357.   this.gzhead = null;         /* gzip header information to write */
  6358.   this.gzindex = 0;           /* where in extra, name, or comment */
  6359.   this.method = Z_DEFLATED; /* can only be DEFLATED */
  6360.   this.last_flush = -1;   /* value of flush param for previous deflate call */
  6361.  
  6362.   this.w_size = 0;  /* LZ77 window size (32K by default) */
  6363.   this.w_bits = 0;  /* log2(w_size)  (8..16) */
  6364.   this.w_mask = 0;  /* w_size - 1 */
  6365.  
  6366.   this.window = null;
  6367.   /* Sliding window. Input bytes are read into the second half of the window,
  6368.    * and move to the first half later to keep a dictionary of at least wSize
  6369.    * bytes. With this organization, matches are limited to a distance of
  6370.    * wSize-MAX_MATCH bytes, but this ensures that IO is always
  6371.    * performed with a length multiple of the block size.
  6372.    */
  6373.  
  6374.   this.window_size = 0;
  6375.   /* Actual size of window: 2*wSize, except when the user input buffer
  6376.    * is directly used as sliding window.
  6377.    */
  6378.  
  6379.   this.prev = null;
  6380.   /* Link to older string with same hash index. To limit the size of this
  6381.    * array to 64K, this link is maintained only for the last 32K strings.
  6382.    * An index in this array is thus a window index modulo 32K.
  6383.    */
  6384.  
  6385.   this.head = null;   /* Heads of the hash chains or NIL. */
  6386.  
  6387.   this.ins_h = 0;       /* hash index of string to be inserted */
  6388.   this.hash_size = 0;   /* number of elements in hash table */
  6389.   this.hash_bits = 0;   /* log2(hash_size) */
  6390.   this.hash_mask = 0;   /* hash_size-1 */
  6391.  
  6392.   this.hash_shift = 0;
  6393.   /* Number of bits by which ins_h must be shifted at each input
  6394.    * step. It must be such that after MIN_MATCH steps, the oldest
  6395.    * byte no longer takes part in the hash key, that is:
  6396.    *   hash_shift * MIN_MATCH >= hash_bits
  6397.    */
  6398.  
  6399.   this.block_start = 0;
  6400.   /* Window position at the beginning of the current output block. Gets
  6401.    * negative when the window is moved backwards.
  6402.    */
  6403.  
  6404.   this.match_length = 0;      /* length of best match */
  6405.   this.prev_match = 0;        /* previous match */
  6406.   this.match_available = 0;   /* set if previous match exists */
  6407.   this.strstart = 0;          /* start of string to insert */
  6408.   this.match_start = 0;       /* start of matching string */
  6409.   this.lookahead = 0;         /* number of valid bytes ahead in window */
  6410.  
  6411.   this.prev_length = 0;
  6412.   /* Length of the best match at previous step. Matches not greater than this
  6413.    * are discarded. This is used in the lazy match evaluation.
  6414.    */
  6415.  
  6416.   this.max_chain_length = 0;
  6417.   /* To speed up deflation, hash chains are never searched beyond this
  6418.    * length.  A higher limit improves compression ratio but degrades the
  6419.    * speed.
  6420.    */
  6421.  
  6422.   this.max_lazy_match = 0;
  6423.   /* Attempt to find a better match only when the current match is strictly
  6424.    * smaller than this value. This mechanism is used only for compression
  6425.    * levels >= 4.
  6426.    */
  6427.   // That's alias to max_lazy_match, don't use directly
  6428.   //this.max_insert_length = 0;
  6429.   /* Insert new strings in the hash table only if the match length is not
  6430.    * greater than this length. This saves time but degrades compression.
  6431.    * max_insert_length is used only for compression levels <= 3.
  6432.    */
  6433.  
  6434.   this.level = 0;     /* compression level (1..9) */
  6435.   this.strategy = 0;  /* favor or force Huffman coding*/
  6436.  
  6437.   this.good_match = 0;
  6438.   /* Use a faster search when the previous match is longer than this */
  6439.  
  6440.   this.nice_match = 0; /* Stop searching when current match exceeds this */
  6441.  
  6442.               /* used by trees.c: */
  6443.  
  6444.   /* Didn't use ct_data typedef below to suppress compiler warning */
  6445.  
  6446.   // struct ct_data_s dyn_ltree[HEAP_SIZE];   /* literal and length tree */
  6447.   // struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  6448.   // struct ct_data_s bl_tree[2*BL_CODES+1];  /* Huffman tree for bit lengths */
  6449.  
  6450.   // Use flat array of DOUBLE size, with interleaved fata,
  6451.   // because JS does not support effective
  6452.   this.dyn_ltree  = new utils.Buf16(HEAP_SIZE * 2);
  6453.   this.dyn_dtree  = new utils.Buf16((2 * D_CODES + 1) * 2);
  6454.   this.bl_tree    = new utils.Buf16((2 * BL_CODES + 1) * 2);
  6455.   zero(this.dyn_ltree);
  6456.   zero(this.dyn_dtree);
  6457.   zero(this.bl_tree);
  6458.  
  6459.   this.l_desc   = null;         /* desc. for literal tree */
  6460.   this.d_desc   = null;         /* desc. for distance tree */
  6461.   this.bl_desc  = null;         /* desc. for bit length tree */
  6462.  
  6463.   //ush bl_count[MAX_BITS+1];
  6464.   this.bl_count = new utils.Buf16(MAX_BITS + 1);
  6465.   /* number of codes at each bit length for an optimal tree */
  6466.  
  6467.   //int heap[2*L_CODES+1];      /* heap used to build the Huffman trees */
  6468.   this.heap = new utils.Buf16(2 * L_CODES + 1);  /* heap used to build the Huffman trees */
  6469.   zero(this.heap);
  6470.  
  6471.   this.heap_len = 0;               /* number of elements in the heap */
  6472.   this.heap_max = 0;               /* element of largest frequency */
  6473.   /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
  6474.    * The same heap array is used to build all trees.
  6475.    */
  6476.  
  6477.   this.depth = new utils.Buf16(2 * L_CODES + 1); //uch depth[2*L_CODES+1];
  6478.   zero(this.depth);
  6479.   /* Depth of each subtree used as tie breaker for trees of equal frequency
  6480.    */
  6481.  
  6482.   this.l_buf = 0;          /* buffer index for literals or lengths */
  6483.  
  6484.   this.lit_bufsize = 0;
  6485.   /* Size of match buffer for literals/lengths.  There are 4 reasons for
  6486.    * limiting lit_bufsize to 64K:
  6487.    *   - frequencies can be kept in 16 bit counters
  6488.    *   - if compression is not successful for the first block, all input
  6489.    *     data is still in the window so we can still emit a stored block even
  6490.    *     when input comes from standard input.  (This can also be done for
  6491.    *     all blocks if lit_bufsize is not greater than 32K.)
  6492.    *   - if compression is not successful for a file smaller than 64K, we can
  6493.    *     even emit a stored file instead of a stored block (saving 5 bytes).
  6494.    *     This is applicable only for zip (not gzip or zlib).
  6495.    *   - creating new Huffman trees less frequently may not provide fast
  6496.    *     adaptation to changes in the input data statistics. (Take for
  6497.    *     example a binary file with poorly compressible code followed by
  6498.    *     a highly compressible string table.) Smaller buffer sizes give
  6499.    *     fast adaptation but have of course the overhead of transmitting
  6500.    *     trees more frequently.
  6501.    *   - I can't count above 4
  6502.    */
  6503.  
  6504.   this.last_lit = 0;      /* running index in l_buf */
  6505.  
  6506.   this.d_buf = 0;
  6507.   /* Buffer index for distances. To simplify the code, d_buf and l_buf have
  6508.    * the same number of elements. To use different lengths, an extra flag
  6509.    * array would be necessary.
  6510.    */
  6511.  
  6512.   this.opt_len = 0;       /* bit length of current block with optimal trees */
  6513.   this.static_len = 0;    /* bit length of current block with static trees */
  6514.   this.matches = 0;       /* number of string matches in current block */
  6515.   this.insert = 0;        /* bytes at end of window left to insert */
  6516.  
  6517.  
  6518.   this.bi_buf = 0;
  6519.   /* Output buffer. bits are inserted starting at the bottom (least
  6520.    * significant bits).
  6521.    */
  6522.   this.bi_valid = 0;
  6523.   /* Number of valid bits in bi_buf.  All bits above the last valid bit
  6524.    * are always zero.
  6525.    */
  6526.  
  6527.   // Used for window memory init. We safely ignore it for JS. That makes
  6528.   // sense only for pointers and memory check tools.
  6529.   //this.high_water = 0;
  6530.   /* High water mark offset in window for initialized bytes -- bytes above
  6531.    * this are set to zero in order to avoid memory check warnings when
  6532.    * longest match routines access bytes past the input.  This is then
  6533.    * updated to the new high water mark.
  6534.    */
  6535. }
  6536.  
  6537.  
  6538. function deflateResetKeep(strm) {
  6539.   var s;
  6540.  
  6541.   if (!strm || !strm.state) {
  6542.     return err(strm, Z_STREAM_ERROR);
  6543.   }
  6544.  
  6545.   strm.total_in = strm.total_out = 0;
  6546.   strm.data_type = Z_UNKNOWN;
  6547.  
  6548.   s = strm.state;
  6549.   s.pending = 0;
  6550.   s.pending_out = 0;
  6551.  
  6552.   if (s.wrap < 0) {
  6553.     s.wrap = -s.wrap;
  6554.     /* was made negative by deflate(..., Z_FINISH); */
  6555.   }
  6556.   s.status = (s.wrap ? INIT_STATE : BUSY_STATE);
  6557.   strm.adler = (s.wrap === 2) ?
  6558.     0  // crc32(0, Z_NULL, 0)
  6559.   :
  6560.     1; // adler32(0, Z_NULL, 0)
  6561.   s.last_flush = Z_NO_FLUSH;
  6562.   trees._tr_init(s);
  6563.   return Z_OK;
  6564. }
  6565.  
  6566.  
  6567. function deflateReset(strm) {
  6568.   var ret = deflateResetKeep(strm);
  6569.   if (ret === Z_OK) {
  6570.     lm_init(strm.state);
  6571.   }
  6572.   return ret;
  6573. }
  6574.  
  6575.  
  6576. function deflateSetHeader(strm, head) {
  6577.   if (!strm || !strm.state) { return Z_STREAM_ERROR; }
  6578.   if (strm.state.wrap !== 2) { return Z_STREAM_ERROR; }
  6579.   strm.state.gzhead = head;
  6580.   return Z_OK;
  6581. }
  6582.  
  6583.  
  6584. function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
  6585.   if (!strm) { // === Z_NULL
  6586.     return Z_STREAM_ERROR;
  6587.   }
  6588.   var wrap = 1;
  6589.  
  6590.   if (level === Z_DEFAULT_COMPRESSION) {
  6591.     level = 6;
  6592.   }
  6593.  
  6594.   if (windowBits < 0) { /* suppress zlib wrapper */
  6595.     wrap = 0;
  6596.     windowBits = -windowBits;
  6597.   }
  6598.  
  6599.   else if (windowBits > 15) {
  6600.     wrap = 2;           /* write gzip wrapper instead */
  6601.     windowBits -= 16;
  6602.   }
  6603.  
  6604.  
  6605.   if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED ||
  6606.     windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  6607.     strategy < 0 || strategy > Z_FIXED) {
  6608.     return err(strm, Z_STREAM_ERROR);
  6609.   }
  6610.  
  6611.  
  6612.   if (windowBits === 8) {
  6613.     windowBits = 9;
  6614.   }
  6615.   /* until 256-byte window bug fixed */
  6616.  
  6617.   var s = new DeflateState();
  6618.  
  6619.   strm.state = s;
  6620.   s.strm = strm;
  6621.  
  6622.   s.wrap = wrap;
  6623.   s.gzhead = null;
  6624.   s.w_bits = windowBits;
  6625.   s.w_size = 1 << s.w_bits;
  6626.   s.w_mask = s.w_size - 1;
  6627.  
  6628.   s.hash_bits = memLevel + 7;
  6629.   s.hash_size = 1 << s.hash_bits;
  6630.   s.hash_mask = s.hash_size - 1;
  6631.   s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH);
  6632.  
  6633.   s.window = new utils.Buf8(s.w_size * 2);
  6634.   s.head = new utils.Buf16(s.hash_size);
  6635.   s.prev = new utils.Buf16(s.w_size);
  6636.  
  6637.   // Don't need mem init magic for JS.
  6638.   //s.high_water = 0;  /* nothing written to s->window yet */
  6639.  
  6640.   s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  6641.  
  6642.   s.pending_buf_size = s.lit_bufsize * 4;
  6643.  
  6644.   //overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  6645.   //s->pending_buf = (uchf *) overlay;
  6646.   s.pending_buf = new utils.Buf8(s.pending_buf_size);
  6647.  
  6648.   // It is offset from `s.pending_buf` (size is `s.lit_bufsize * 2`)
  6649.   //s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  6650.   s.d_buf = 1 * s.lit_bufsize;
  6651.  
  6652.   //s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  6653.   s.l_buf = (1 + 2) * s.lit_bufsize;
  6654.  
  6655.   s.level = level;
  6656.   s.strategy = strategy;
  6657.   s.method = method;
  6658.  
  6659.   return deflateReset(strm);
  6660. }
  6661.  
  6662. function deflateInit(strm, level) {
  6663.   return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
  6664. }
  6665.  
  6666.  
  6667. function deflate(strm, flush) {
  6668.   var old_flush, s;
  6669.   var beg, val; // for gzip header write only
  6670.  
  6671.   if (!strm || !strm.state ||
  6672.     flush > Z_BLOCK || flush < 0) {
  6673.     return strm ? err(strm, Z_STREAM_ERROR) : Z_STREAM_ERROR;
  6674.   }
  6675.  
  6676.   s = strm.state;
  6677.  
  6678.   if (!strm.output ||
  6679.       (!strm.input && strm.avail_in !== 0) ||
  6680.       (s.status === FINISH_STATE && flush !== Z_FINISH)) {
  6681.     return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR);
  6682.   }
  6683.  
  6684.   s.strm = strm; /* just in case */
  6685.   old_flush = s.last_flush;
  6686.   s.last_flush = flush;
  6687.  
  6688.   /* Write the header */
  6689.   if (s.status === INIT_STATE) {
  6690.  
  6691.     if (s.wrap === 2) { // GZIP header
  6692.       strm.adler = 0;  //crc32(0L, Z_NULL, 0);
  6693.       put_byte(s, 31);
  6694.       put_byte(s, 139);
  6695.       put_byte(s, 8);
  6696.       if (!s.gzhead) { // s->gzhead == Z_NULL
  6697.         put_byte(s, 0);
  6698.         put_byte(s, 0);
  6699.         put_byte(s, 0);
  6700.         put_byte(s, 0);
  6701.         put_byte(s, 0);
  6702.         put_byte(s, s.level === 9 ? 2 :
  6703.                     (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?
  6704.                      4 : 0));
  6705.         put_byte(s, OS_CODE);
  6706.         s.status = BUSY_STATE;
  6707.       }
  6708.       else {
  6709.         put_byte(s, (s.gzhead.text ? 1 : 0) +
  6710.                     (s.gzhead.hcrc ? 2 : 0) +
  6711.                     (!s.gzhead.extra ? 0 : 4) +
  6712.                     (!s.gzhead.name ? 0 : 8) +
  6713.                     (!s.gzhead.comment ? 0 : 16)
  6714.         );
  6715.         put_byte(s, s.gzhead.time & 0xff);
  6716.         put_byte(s, (s.gzhead.time >> 8) & 0xff);
  6717.         put_byte(s, (s.gzhead.time >> 16) & 0xff);
  6718.         put_byte(s, (s.gzhead.time >> 24) & 0xff);
  6719.         put_byte(s, s.level === 9 ? 2 :
  6720.                     (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?
  6721.                      4 : 0));
  6722.         put_byte(s, s.gzhead.os & 0xff);
  6723.         if (s.gzhead.extra && s.gzhead.extra.length) {
  6724.           put_byte(s, s.gzhead.extra.length & 0xff);
  6725.           put_byte(s, (s.gzhead.extra.length >> 8) & 0xff);
  6726.         }
  6727.         if (s.gzhead.hcrc) {
  6728.           strm.adler = crc32(strm.adler, s.pending_buf, s.pending, 0);
  6729.         }
  6730.         s.gzindex = 0;
  6731.         s.status = EXTRA_STATE;
  6732.       }
  6733.     }
  6734.     else // DEFLATE header
  6735.     {
  6736.       var header = (Z_DEFLATED + ((s.w_bits - 8) << 4)) << 8;
  6737.       var level_flags = -1;
  6738.  
  6739.       if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) {
  6740.         level_flags = 0;
  6741.       } else if (s.level < 6) {
  6742.         level_flags = 1;
  6743.       } else if (s.level === 6) {
  6744.         level_flags = 2;
  6745.       } else {
  6746.         level_flags = 3;
  6747.       }
  6748.       header |= (level_flags << 6);
  6749.       if (s.strstart !== 0) { header |= PRESET_DICT; }
  6750.       header += 31 - (header % 31);
  6751.  
  6752.       s.status = BUSY_STATE;
  6753.       putShortMSB(s, header);
  6754.  
  6755.       /* Save the adler32 of the preset dictionary: */
  6756.       if (s.strstart !== 0) {
  6757.         putShortMSB(s, strm.adler >>> 16);
  6758.         putShortMSB(s, strm.adler & 0xffff);
  6759.       }
  6760.       strm.adler = 1; // adler32(0L, Z_NULL, 0);
  6761.     }
  6762.   }
  6763.  
  6764. //#ifdef GZIP
  6765.   if (s.status === EXTRA_STATE) {
  6766.     if (s.gzhead.extra/* != Z_NULL*/) {
  6767.       beg = s.pending;  /* start of bytes to update crc */
  6768.  
  6769.       while (s.gzindex < (s.gzhead.extra.length & 0xffff)) {
  6770.         if (s.pending === s.pending_buf_size) {
  6771.           if (s.gzhead.hcrc && s.pending > beg) {
  6772.             strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  6773.           }
  6774.           flush_pending(strm);
  6775.           beg = s.pending;
  6776.           if (s.pending === s.pending_buf_size) {
  6777.             break;
  6778.           }
  6779.         }
  6780.         put_byte(s, s.gzhead.extra[s.gzindex] & 0xff);
  6781.         s.gzindex++;
  6782.       }
  6783.       if (s.gzhead.hcrc && s.pending > beg) {
  6784.         strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  6785.       }
  6786.       if (s.gzindex === s.gzhead.extra.length) {
  6787.         s.gzindex = 0;
  6788.         s.status = NAME_STATE;
  6789.       }
  6790.     }
  6791.     else {
  6792.       s.status = NAME_STATE;
  6793.     }
  6794.   }
  6795.   if (s.status === NAME_STATE) {
  6796.     if (s.gzhead.name/* != Z_NULL*/) {
  6797.       beg = s.pending;  /* start of bytes to update crc */
  6798.       //int val;
  6799.  
  6800.       do {
  6801.         if (s.pending === s.pending_buf_size) {
  6802.           if (s.gzhead.hcrc && s.pending > beg) {
  6803.             strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  6804.           }
  6805.           flush_pending(strm);
  6806.           beg = s.pending;
  6807.           if (s.pending === s.pending_buf_size) {
  6808.             val = 1;
  6809.             break;
  6810.           }
  6811.         }
  6812.         // JS specific: little magic to add zero terminator to end of string
  6813.         if (s.gzindex < s.gzhead.name.length) {
  6814.           val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff;
  6815.         } else {
  6816.           val = 0;
  6817.         }
  6818.         put_byte(s, val);
  6819.       } while (val !== 0);
  6820.  
  6821.       if (s.gzhead.hcrc && s.pending > beg) {
  6822.         strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  6823.       }
  6824.       if (val === 0) {
  6825.         s.gzindex = 0;
  6826.         s.status = COMMENT_STATE;
  6827.       }
  6828.     }
  6829.     else {
  6830.       s.status = COMMENT_STATE;
  6831.     }
  6832.   }
  6833.   if (s.status === COMMENT_STATE) {
  6834.     if (s.gzhead.comment/* != Z_NULL*/) {
  6835.       beg = s.pending;  /* start of bytes to update crc */
  6836.       //int val;
  6837.  
  6838.       do {
  6839.         if (s.pending === s.pending_buf_size) {
  6840.           if (s.gzhead.hcrc && s.pending > beg) {
  6841.             strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  6842.           }
  6843.           flush_pending(strm);
  6844.           beg = s.pending;
  6845.           if (s.pending === s.pending_buf_size) {
  6846.             val = 1;
  6847.             break;
  6848.           }
  6849.         }
  6850.         // JS specific: little magic to add zero terminator to end of string
  6851.         if (s.gzindex < s.gzhead.comment.length) {
  6852.           val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff;
  6853.         } else {
  6854.           val = 0;
  6855.         }
  6856.         put_byte(s, val);
  6857.       } while (val !== 0);
  6858.  
  6859.       if (s.gzhead.hcrc && s.pending > beg) {
  6860.         strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  6861.       }
  6862.       if (val === 0) {
  6863.         s.status = HCRC_STATE;
  6864.       }
  6865.     }
  6866.     else {
  6867.       s.status = HCRC_STATE;
  6868.     }
  6869.   }
  6870.   if (s.status === HCRC_STATE) {
  6871.     if (s.gzhead.hcrc) {
  6872.       if (s.pending + 2 > s.pending_buf_size) {
  6873.         flush_pending(strm);
  6874.       }
  6875.       if (s.pending + 2 <= s.pending_buf_size) {
  6876.         put_byte(s, strm.adler & 0xff);
  6877.         put_byte(s, (strm.adler >> 8) & 0xff);
  6878.         strm.adler = 0; //crc32(0L, Z_NULL, 0);
  6879.         s.status = BUSY_STATE;
  6880.       }
  6881.     }
  6882.     else {
  6883.       s.status = BUSY_STATE;
  6884.     }
  6885.   }
  6886. //#endif
  6887.  
  6888.   /* Flush as much pending output as possible */
  6889.   if (s.pending !== 0) {
  6890.     flush_pending(strm);
  6891.     if (strm.avail_out === 0) {
  6892.       /* Since avail_out is 0, deflate will be called again with
  6893.        * more output space, but possibly with both pending and
  6894.        * avail_in equal to zero. There won't be anything to do,
  6895.        * but this is not an error situation so make sure we
  6896.        * return OK instead of BUF_ERROR at next call of deflate:
  6897.        */
  6898.       s.last_flush = -1;
  6899.       return Z_OK;
  6900.     }
  6901.  
  6902.     /* Make sure there is something to do and avoid duplicate consecutive
  6903.      * flushes. For repeated and useless calls with Z_FINISH, we keep
  6904.      * returning Z_STREAM_END instead of Z_BUF_ERROR.
  6905.      */
  6906.   } else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) &&
  6907.     flush !== Z_FINISH) {
  6908.     return err(strm, Z_BUF_ERROR);
  6909.   }
  6910.  
  6911.   /* User must not provide more input after the first FINISH: */
  6912.   if (s.status === FINISH_STATE && strm.avail_in !== 0) {
  6913.     return err(strm, Z_BUF_ERROR);
  6914.   }
  6915.  
  6916.   /* Start a new block or continue the current one.
  6917.    */
  6918.   if (strm.avail_in !== 0 || s.lookahead !== 0 ||
  6919.     (flush !== Z_NO_FLUSH && s.status !== FINISH_STATE)) {
  6920.     var bstate = (s.strategy === Z_HUFFMAN_ONLY) ? deflate_huff(s, flush) :
  6921.       (s.strategy === Z_RLE ? deflate_rle(s, flush) :
  6922.         configuration_table[s.level].func(s, flush));
  6923.  
  6924.     if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) {
  6925.       s.status = FINISH_STATE;
  6926.     }
  6927.     if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) {
  6928.       if (strm.avail_out === 0) {
  6929.         s.last_flush = -1;
  6930.         /* avoid BUF_ERROR next call, see above */
  6931.       }
  6932.       return Z_OK;
  6933.       /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
  6934.        * of deflate should use the same flush parameter to make sure
  6935.        * that the flush is complete. So we don't have to output an
  6936.        * empty block here, this will be done at next call. This also
  6937.        * ensures that for a very small output buffer, we emit at most
  6938.        * one empty block.
  6939.        */
  6940.     }
  6941.     if (bstate === BS_BLOCK_DONE) {
  6942.       if (flush === Z_PARTIAL_FLUSH) {
  6943.         trees._tr_align(s);
  6944.       }
  6945.       else if (flush !== Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
  6946.  
  6947.         trees._tr_stored_block(s, 0, 0, false);
  6948.         /* For a full flush, this empty block will be recognized
  6949.          * as a special marker by inflate_sync().
  6950.          */
  6951.         if (flush === Z_FULL_FLUSH) {
  6952.           /*** CLEAR_HASH(s); ***/             /* forget history */
  6953.           zero(s.head); // Fill with NIL (= 0);
  6954.  
  6955.           if (s.lookahead === 0) {
  6956.             s.strstart = 0;
  6957.             s.block_start = 0;
  6958.             s.insert = 0;
  6959.           }
  6960.         }
  6961.       }
  6962.       flush_pending(strm);
  6963.       if (strm.avail_out === 0) {
  6964.         s.last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  6965.         return Z_OK;
  6966.       }
  6967.     }
  6968.   }
  6969.   //Assert(strm->avail_out > 0, "bug2");
  6970.   //if (strm.avail_out <= 0) { throw new Error("bug2");}
  6971.  
  6972.   if (flush !== Z_FINISH) { return Z_OK; }
  6973.   if (s.wrap <= 0) { return Z_STREAM_END; }
  6974.  
  6975.   /* Write the trailer */
  6976.   if (s.wrap === 2) {
  6977.     put_byte(s, strm.adler & 0xff);
  6978.     put_byte(s, (strm.adler >> 8) & 0xff);
  6979.     put_byte(s, (strm.adler >> 16) & 0xff);
  6980.     put_byte(s, (strm.adler >> 24) & 0xff);
  6981.     put_byte(s, strm.total_in & 0xff);
  6982.     put_byte(s, (strm.total_in >> 8) & 0xff);
  6983.     put_byte(s, (strm.total_in >> 16) & 0xff);
  6984.     put_byte(s, (strm.total_in >> 24) & 0xff);
  6985.   }
  6986.   else
  6987.   {
  6988.     putShortMSB(s, strm.adler >>> 16);
  6989.     putShortMSB(s, strm.adler & 0xffff);
  6990.   }
  6991.  
  6992.   flush_pending(strm);
  6993.   /* If avail_out is zero, the application will call deflate again
  6994.    * to flush the rest.
  6995.    */
  6996.   if (s.wrap > 0) { s.wrap = -s.wrap; }
  6997.   /* write the trailer only once! */
  6998.   return s.pending !== 0 ? Z_OK : Z_STREAM_END;
  6999. }
  7000.  
  7001. function deflateEnd(strm) {
  7002.   var status;
  7003.  
  7004.   if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {
  7005.     return Z_STREAM_ERROR;
  7006.   }
  7007.  
  7008.   status = strm.state.status;
  7009.   if (status !== INIT_STATE &&
  7010.     status !== EXTRA_STATE &&
  7011.     status !== NAME_STATE &&
  7012.     status !== COMMENT_STATE &&
  7013.     status !== HCRC_STATE &&
  7014.     status !== BUSY_STATE &&
  7015.     status !== FINISH_STATE
  7016.   ) {
  7017.     return err(strm, Z_STREAM_ERROR);
  7018.   }
  7019.  
  7020.   strm.state = null;
  7021.  
  7022.   return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK;
  7023. }
  7024.  
  7025.  
  7026. /* =========================================================================
  7027.  * Initializes the compression dictionary from the given byte
  7028.  * sequence without producing any compressed output.
  7029.  */
  7030. function deflateSetDictionary(strm, dictionary) {
  7031.   var dictLength = dictionary.length;
  7032.  
  7033.   var s;
  7034.   var str, n;
  7035.   var wrap;
  7036.   var avail;
  7037.   var next;
  7038.   var input;
  7039.   var tmpDict;
  7040.  
  7041.   if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {
  7042.     return Z_STREAM_ERROR;
  7043.   }
  7044.  
  7045.   s = strm.state;
  7046.   wrap = s.wrap;
  7047.  
  7048.   if (wrap === 2 || (wrap === 1 && s.status !== INIT_STATE) || s.lookahead) {
  7049.     return Z_STREAM_ERROR;
  7050.   }
  7051.  
  7052.   /* when using zlib wrappers, compute Adler-32 for provided dictionary */
  7053.   if (wrap === 1) {
  7054.     /* adler32(strm->adler, dictionary, dictLength); */
  7055.     strm.adler = adler32(strm.adler, dictionary, dictLength, 0);
  7056.   }
  7057.  
  7058.   s.wrap = 0;   /* avoid computing Adler-32 in read_buf */
  7059.  
  7060.   /* if dictionary would fill window, just replace the history */
  7061.   if (dictLength >= s.w_size) {
  7062.     if (wrap === 0) {            /* already empty otherwise */
  7063.       /*** CLEAR_HASH(s); ***/
  7064.       zero(s.head); // Fill with NIL (= 0);
  7065.       s.strstart = 0;
  7066.       s.block_start = 0;
  7067.       s.insert = 0;
  7068.     }
  7069.     /* use the tail */
  7070.     // dictionary = dictionary.slice(dictLength - s.w_size);
  7071.     tmpDict = new utils.Buf8(s.w_size);
  7072.     utils.arraySet(tmpDict, dictionary, dictLength - s.w_size, s.w_size, 0);
  7073.     dictionary = tmpDict;
  7074.     dictLength = s.w_size;
  7075.   }
  7076.   /* insert dictionary into window and hash */
  7077.   avail = strm.avail_in;
  7078.   next = strm.next_in;
  7079.   input = strm.input;
  7080.   strm.avail_in = dictLength;
  7081.   strm.next_in = 0;
  7082.   strm.input = dictionary;
  7083.   fill_window(s);
  7084.   while (s.lookahead >= MIN_MATCH) {
  7085.     str = s.strstart;
  7086.     n = s.lookahead - (MIN_MATCH - 1);
  7087.     do {
  7088.       /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
  7089.       s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
  7090.  
  7091.       s.prev[str & s.w_mask] = s.head[s.ins_h];
  7092.  
  7093.       s.head[s.ins_h] = str;
  7094.       str++;
  7095.     } while (--n);
  7096.     s.strstart = str;
  7097.     s.lookahead = MIN_MATCH - 1;
  7098.     fill_window(s);
  7099.   }
  7100.   s.strstart += s.lookahead;
  7101.   s.block_start = s.strstart;
  7102.   s.insert = s.lookahead;
  7103.   s.lookahead = 0;
  7104.   s.match_length = s.prev_length = MIN_MATCH - 1;
  7105.   s.match_available = 0;
  7106.   strm.next_in = next;
  7107.   strm.input = input;
  7108.   strm.avail_in = avail;
  7109.   s.wrap = wrap;
  7110.   return Z_OK;
  7111. }
  7112.  
  7113.  
  7114. exports.deflateInit = deflateInit;
  7115. exports.deflateInit2 = deflateInit2;
  7116. exports.deflateReset = deflateReset;
  7117. exports.deflateResetKeep = deflateResetKeep;
  7118. exports.deflateSetHeader = deflateSetHeader;
  7119. exports.deflate = deflate;
  7120. exports.deflateEnd = deflateEnd;
  7121. exports.deflateSetDictionary = deflateSetDictionary;
  7122. exports.deflateInfo = 'pako deflate (from Nodeca project)';
  7123.  
  7124. /* Not implemented
  7125. exports.deflateBound = deflateBound;
  7126. exports.deflateCopy = deflateCopy;
  7127. exports.deflateParams = deflateParams;
  7128. exports.deflatePending = deflatePending;
  7129. exports.deflatePrime = deflatePrime;
  7130. exports.deflateTune = deflateTune;
  7131. */
  7132.  
  7133. },{"../utils/common":17,"./adler32":18,"./crc32":20,"./messages":25,"./trees":26}],22:[function(require,module,exports){
  7134. 'use strict';
  7135.  
  7136. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  7137. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  7138. //
  7139. // This software is provided 'as-is', without any express or implied
  7140. // warranty. In no event will the authors be held liable for any damages
  7141. // arising from the use of this software.
  7142. //
  7143. // Permission is granted to anyone to use this software for any purpose,
  7144. // including commercial applications, and to alter it and redistribute it
  7145. // freely, subject to the following restrictions:
  7146. //
  7147. // 1. The origin of this software must not be misrepresented; you must not
  7148. //   claim that you wrote the original software. If you use this software
  7149. //   in a product, an acknowledgment in the product documentation would be
  7150. //   appreciated but is not required.
  7151. // 2. Altered source versions must be plainly marked as such, and must not be
  7152. //   misrepresented as being the original software.
  7153. // 3. This notice may not be removed or altered from any source distribution.
  7154.  
  7155. // See state defs from inflate.js
  7156. var BAD = 30;       /* got a data error -- remain here until reset */
  7157. var TYPE = 12;      /* i: waiting for type bits, including last-flag bit */
  7158.  
  7159. /*
  7160.    Decode literal, length, and distance codes and write out the resulting
  7161.    literal and match bytes until either not enough input or output is
  7162.    available, an end-of-block is encountered, or a data error is encountered.
  7163.    When large enough input and output buffers are supplied to inflate(), for
  7164.    example, a 16K input buffer and a 64K output buffer, more than 95% of the
  7165.    inflate execution time is spent in this routine.
  7166.  
  7167.    Entry assumptions:
  7168.  
  7169.         state.mode === LEN
  7170.         strm.avail_in >= 6
  7171.         strm.avail_out >= 258
  7172.         start >= strm.avail_out
  7173.         state.bits < 8
  7174.  
  7175.    On return, state.mode is one of:
  7176.  
  7177.         LEN -- ran out of enough output space or enough available input
  7178.         TYPE -- reached end of block code, inflate() to interpret next block
  7179.         BAD -- error in block data
  7180.  
  7181.    Notes:
  7182.  
  7183.     - The maximum input bits used by a length/distance pair is 15 bits for the
  7184.       length code, 5 bits for the length extra, 15 bits for the distance code,
  7185.       and 13 bits for the distance extra.  This totals 48 bits, or six bytes.
  7186.       Therefore if strm.avail_in >= 6, then there is enough input to avoid
  7187.       checking for available input while decoding.
  7188.  
  7189.     - The maximum bytes that a single length/distance pair can output is 258
  7190.       bytes, which is the maximum length that can be coded.  inflate_fast()
  7191.       requires strm.avail_out >= 258 for each loop to avoid checking for
  7192.       output space.
  7193.  */
  7194. module.exports = function inflate_fast(strm, start) {
  7195.   var state;
  7196.   var _in;                    /* local strm.input */
  7197.   var last;                   /* have enough input while in < last */
  7198.   var _out;                   /* local strm.output */
  7199.   var beg;                    /* inflate()'s initial strm.output */
  7200.   var end;                    /* while out < end, enough space available */
  7201. //#ifdef INFLATE_STRICT
  7202.   var dmax;                   /* maximum distance from zlib header */
  7203. //#endif
  7204.   var wsize;                  /* window size or zero if not using window */
  7205.   var whave;                  /* valid bytes in the window */
  7206.   var wnext;                  /* window write index */
  7207.   // Use `s_window` instead `window`, avoid conflict with instrumentation tools
  7208.   var s_window;               /* allocated sliding window, if wsize != 0 */
  7209.   var hold;                   /* local strm.hold */
  7210.   var bits;                   /* local strm.bits */
  7211.   var lcode;                  /* local strm.lencode */
  7212.   var dcode;                  /* local strm.distcode */
  7213.   var lmask;                  /* mask for first level of length codes */
  7214.   var dmask;                  /* mask for first level of distance codes */
  7215.   var here;                   /* retrieved table entry */
  7216.   var op;                     /* code bits, operation, extra bits, or */
  7217.                               /*  window position, window bytes to copy */
  7218.   var len;                    /* match length, unused bytes */
  7219.   var dist;                   /* match distance */
  7220.   var from;                   /* where to copy match from */
  7221.   var from_source;
  7222.  
  7223.  
  7224.   var input, output; // JS specific, because we have no pointers
  7225.  
  7226.   /* copy state to local variables */
  7227.   state = strm.state;
  7228.   //here = state.here;
  7229.   _in = strm.next_in;
  7230.   input = strm.input;
  7231.   last = _in + (strm.avail_in - 5);
  7232.   _out = strm.next_out;
  7233.   output = strm.output;
  7234.   beg = _out - (start - strm.avail_out);
  7235.   end = _out + (strm.avail_out - 257);
  7236. //#ifdef INFLATE_STRICT
  7237.   dmax = state.dmax;
  7238. //#endif
  7239.   wsize = state.wsize;
  7240.   whave = state.whave;
  7241.   wnext = state.wnext;
  7242.   s_window = state.window;
  7243.   hold = state.hold;
  7244.   bits = state.bits;
  7245.   lcode = state.lencode;
  7246.   dcode = state.distcode;
  7247.   lmask = (1 << state.lenbits) - 1;
  7248.   dmask = (1 << state.distbits) - 1;
  7249.  
  7250.  
  7251.   /* decode literals and length/distances until end-of-block or not enough
  7252.      input data or output space */
  7253.  
  7254.   top:
  7255.   do {
  7256.     if (bits < 15) {
  7257.       hold += input[_in++] << bits;
  7258.       bits += 8;
  7259.       hold += input[_in++] << bits;
  7260.       bits += 8;
  7261.     }
  7262.  
  7263.     here = lcode[hold & lmask];
  7264.  
  7265.     dolen:
  7266.     for (;;) { // Goto emulation
  7267.       op = here >>> 24/*here.bits*/;
  7268.       hold >>>= op;
  7269.       bits -= op;
  7270.       op = (here >>> 16) & 0xff/*here.op*/;
  7271.       if (op === 0) {                          /* literal */
  7272.         //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
  7273.         //        "inflate:         literal '%c'\n" :
  7274.         //        "inflate:         literal 0x%02x\n", here.val));
  7275.         output[_out++] = here & 0xffff/*here.val*/;
  7276.       }
  7277.       else if (op & 16) {                     /* length base */
  7278.         len = here & 0xffff/*here.val*/;
  7279.         op &= 15;                           /* number of extra bits */
  7280.         if (op) {
  7281.           if (bits < op) {
  7282.             hold += input[_in++] << bits;
  7283.             bits += 8;
  7284.           }
  7285.           len += hold & ((1 << op) - 1);
  7286.           hold >>>= op;
  7287.           bits -= op;
  7288.         }
  7289.         //Tracevv((stderr, "inflate:         length %u\n", len));
  7290.         if (bits < 15) {
  7291.           hold += input[_in++] << bits;
  7292.           bits += 8;
  7293.           hold += input[_in++] << bits;
  7294.           bits += 8;
  7295.         }
  7296.         here = dcode[hold & dmask];
  7297.  
  7298.         dodist:
  7299.         for (;;) { // goto emulation
  7300.           op = here >>> 24/*here.bits*/;
  7301.           hold >>>= op;
  7302.           bits -= op;
  7303.           op = (here >>> 16) & 0xff/*here.op*/;
  7304.  
  7305.           if (op & 16) {                      /* distance base */
  7306.             dist = here & 0xffff/*here.val*/;
  7307.             op &= 15;                       /* number of extra bits */
  7308.             if (bits < op) {
  7309.               hold += input[_in++] << bits;
  7310.               bits += 8;
  7311.               if (bits < op) {
  7312.                 hold += input[_in++] << bits;
  7313.                 bits += 8;
  7314.               }
  7315.             }
  7316.             dist += hold & ((1 << op) - 1);
  7317. //#ifdef INFLATE_STRICT
  7318.             if (dist > dmax) {
  7319.               strm.msg = 'invalid distance too far back';
  7320.               state.mode = BAD;
  7321.               break top;
  7322.             }
  7323. //#endif
  7324.             hold >>>= op;
  7325.             bits -= op;
  7326.             //Tracevv((stderr, "inflate:         distance %u\n", dist));
  7327.             op = _out - beg;                /* max distance in output */
  7328.             if (dist > op) {                /* see if copy from window */
  7329.               op = dist - op;               /* distance back in window */
  7330.               if (op > whave) {
  7331.                 if (state.sane) {
  7332.                   strm.msg = 'invalid distance too far back';
  7333.                   state.mode = BAD;
  7334.                   break top;
  7335.                 }
  7336.  
  7337. // (!) This block is disabled in zlib defaults,
  7338. // don't enable it for binary compatibility
  7339. //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
  7340. //                if (len <= op - whave) {
  7341. //                  do {
  7342. //                    output[_out++] = 0;
  7343. //                  } while (--len);
  7344. //                  continue top;
  7345. //                }
  7346. //                len -= op - whave;
  7347. //                do {
  7348. //                  output[_out++] = 0;
  7349. //                } while (--op > whave);
  7350. //                if (op === 0) {
  7351. //                  from = _out - dist;
  7352. //                  do {
  7353. //                    output[_out++] = output[from++];
  7354. //                  } while (--len);
  7355. //                  continue top;
  7356. //                }
  7357. //#endif
  7358.               }
  7359.               from = 0; // window index
  7360.               from_source = s_window;
  7361.               if (wnext === 0) {           /* very common case */
  7362.                 from += wsize - op;
  7363.                 if (op < len) {         /* some from window */
  7364.                   len -= op;
  7365.                   do {
  7366.                     output[_out++] = s_window[from++];
  7367.                   } while (--op);
  7368.                   from = _out - dist;  /* rest from output */
  7369.                   from_source = output;
  7370.                 }
  7371.               }
  7372.               else if (wnext < op) {      /* wrap around window */
  7373.                 from += wsize + wnext - op;
  7374.                 op -= wnext;
  7375.                 if (op < len) {         /* some from end of window */
  7376.                   len -= op;
  7377.                   do {
  7378.                     output[_out++] = s_window[from++];
  7379.                   } while (--op);
  7380.                   from = 0;
  7381.                   if (wnext < len) {  /* some from start of window */
  7382.                     op = wnext;
  7383.                     len -= op;
  7384.                     do {
  7385.                       output[_out++] = s_window[from++];
  7386.                     } while (--op);
  7387.                     from = _out - dist;      /* rest from output */
  7388.                     from_source = output;
  7389.                   }
  7390.                 }
  7391.               }
  7392.               else {                      /* contiguous in window */
  7393.                 from += wnext - op;
  7394.                 if (op < len) {         /* some from window */
  7395.                   len -= op;
  7396.                   do {
  7397.                     output[_out++] = s_window[from++];
  7398.                   } while (--op);
  7399.                   from = _out - dist;  /* rest from output */
  7400.                   from_source = output;
  7401.                 }
  7402.               }
  7403.               while (len > 2) {
  7404.                 output[_out++] = from_source[from++];
  7405.                 output[_out++] = from_source[from++];
  7406.                 output[_out++] = from_source[from++];
  7407.                 len -= 3;
  7408.               }
  7409.               if (len) {
  7410.                 output[_out++] = from_source[from++];
  7411.                 if (len > 1) {
  7412.                   output[_out++] = from_source[from++];
  7413.                 }
  7414.               }
  7415.             }
  7416.             else {
  7417.               from = _out - dist;          /* copy direct from output */
  7418.               do {                        /* minimum length is three */
  7419.                 output[_out++] = output[from++];
  7420.                 output[_out++] = output[from++];
  7421.                 output[_out++] = output[from++];
  7422.                 len -= 3;
  7423.               } while (len > 2);
  7424.               if (len) {
  7425.                 output[_out++] = output[from++];
  7426.                 if (len > 1) {
  7427.                   output[_out++] = output[from++];
  7428.                 }
  7429.               }
  7430.             }
  7431.           }
  7432.           else if ((op & 64) === 0) {          /* 2nd level distance code */
  7433.             here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
  7434.             continue dodist;
  7435.           }
  7436.           else {
  7437.             strm.msg = 'invalid distance code';
  7438.             state.mode = BAD;
  7439.             break top;
  7440.           }
  7441.  
  7442.           break; // need to emulate goto via "continue"
  7443.         }
  7444.       }
  7445.       else if ((op & 64) === 0) {              /* 2nd level length code */
  7446.         here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
  7447.         continue dolen;
  7448.       }
  7449.       else if (op & 32) {                     /* end-of-block */
  7450.         //Tracevv((stderr, "inflate:         end of block\n"));
  7451.         state.mode = TYPE;
  7452.         break top;
  7453.       }
  7454.       else {
  7455.         strm.msg = 'invalid literal/length code';
  7456.         state.mode = BAD;
  7457.         break top;
  7458.       }
  7459.  
  7460.       break; // need to emulate goto via "continue"
  7461.     }
  7462.   } while (_in < last && _out < end);
  7463.  
  7464.   /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
  7465.   len = bits >> 3;
  7466.   _in -= len;
  7467.   bits -= len << 3;
  7468.   hold &= (1 << bits) - 1;
  7469.  
  7470.   /* update state and return */
  7471.   strm.next_in = _in;
  7472.   strm.next_out = _out;
  7473.   strm.avail_in = (_in < last ? 5 + (last - _in) : 5 - (_in - last));
  7474.   strm.avail_out = (_out < end ? 257 + (end - _out) : 257 - (_out - end));
  7475.   state.hold = hold;
  7476.   state.bits = bits;
  7477.   return;
  7478. };
  7479.  
  7480. },{}],23:[function(require,module,exports){
  7481. 'use strict';
  7482.  
  7483. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  7484. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  7485. //
  7486. // This software is provided 'as-is', without any express or implied
  7487. // warranty. In no event will the authors be held liable for any damages
  7488. // arising from the use of this software.
  7489. //
  7490. // Permission is granted to anyone to use this software for any purpose,
  7491. // including commercial applications, and to alter it and redistribute it
  7492. // freely, subject to the following restrictions:
  7493. //
  7494. // 1. The origin of this software must not be misrepresented; you must not
  7495. //   claim that you wrote the original software. If you use this software
  7496. //   in a product, an acknowledgment in the product documentation would be
  7497. //   appreciated but is not required.
  7498. // 2. Altered source versions must be plainly marked as such, and must not be
  7499. //   misrepresented as being the original software.
  7500. // 3. This notice may not be removed or altered from any source distribution.
  7501.  
  7502. var utils         = require('../utils/common');
  7503. var adler32       = require('./adler32');
  7504. var crc32         = require('./crc32');
  7505. var inflate_fast  = require('./inffast');
  7506. var inflate_table = require('./inftrees');
  7507.  
  7508. var CODES = 0;
  7509. var LENS = 1;
  7510. var DISTS = 2;
  7511.  
  7512. /* Public constants ==========================================================*/
  7513. /* ===========================================================================*/
  7514.  
  7515.  
  7516. /* Allowed flush values; see deflate() and inflate() below for details */
  7517. //var Z_NO_FLUSH      = 0;
  7518. //var Z_PARTIAL_FLUSH = 1;
  7519. //var Z_SYNC_FLUSH    = 2;
  7520. //var Z_FULL_FLUSH    = 3;
  7521. var Z_FINISH        = 4;
  7522. var Z_BLOCK         = 5;
  7523. var Z_TREES         = 6;
  7524.  
  7525.  
  7526. /* Return codes for the compression/decompression functions. Negative values
  7527.  * are errors, positive values are used for special but normal events.
  7528.  */
  7529. var Z_OK            = 0;
  7530. var Z_STREAM_END    = 1;
  7531. var Z_NEED_DICT     = 2;
  7532. //var Z_ERRNO         = -1;
  7533. var Z_STREAM_ERROR  = -2;
  7534. var Z_DATA_ERROR    = -3;
  7535. var Z_MEM_ERROR     = -4;
  7536. var Z_BUF_ERROR     = -5;
  7537. //var Z_VERSION_ERROR = -6;
  7538.  
  7539. /* The deflate compression method */
  7540. var Z_DEFLATED  = 8;
  7541.  
  7542.  
  7543. /* STATES ====================================================================*/
  7544. /* ===========================================================================*/
  7545.  
  7546.  
  7547. var    HEAD = 1;       /* i: waiting for magic header */
  7548. var    FLAGS = 2;      /* i: waiting for method and flags (gzip) */
  7549. var    TIME = 3;       /* i: waiting for modification time (gzip) */
  7550. var    OS = 4;         /* i: waiting for extra flags and operating system (gzip) */
  7551. var    EXLEN = 5;      /* i: waiting for extra length (gzip) */
  7552. var    EXTRA = 6;      /* i: waiting for extra bytes (gzip) */
  7553. var    NAME = 7;       /* i: waiting for end of file name (gzip) */
  7554. var    COMMENT = 8;    /* i: waiting for end of comment (gzip) */
  7555. var    HCRC = 9;       /* i: waiting for header crc (gzip) */
  7556. var    DICTID = 10;    /* i: waiting for dictionary check value */
  7557. var    DICT = 11;      /* waiting for inflateSetDictionary() call */
  7558. var        TYPE = 12;      /* i: waiting for type bits, including last-flag bit */
  7559. var        TYPEDO = 13;    /* i: same, but skip check to exit inflate on new block */
  7560. var        STORED = 14;    /* i: waiting for stored size (length and complement) */
  7561. var        COPY_ = 15;     /* i/o: same as COPY below, but only first time in */
  7562. var        COPY = 16;      /* i/o: waiting for input or output to copy stored block */
  7563. var        TABLE = 17;     /* i: waiting for dynamic block table lengths */
  7564. var        LENLENS = 18;   /* i: waiting for code length code lengths */
  7565. var        CODELENS = 19;  /* i: waiting for length/lit and distance code lengths */
  7566. var            LEN_ = 20;      /* i: same as LEN below, but only first time in */
  7567. var            LEN = 21;       /* i: waiting for length/lit/eob code */
  7568. var            LENEXT = 22;    /* i: waiting for length extra bits */
  7569. var            DIST = 23;      /* i: waiting for distance code */
  7570. var            DISTEXT = 24;   /* i: waiting for distance extra bits */
  7571. var            MATCH = 25;     /* o: waiting for output space to copy string */
  7572. var            LIT = 26;       /* o: waiting for output space to write literal */
  7573. var    CHECK = 27;     /* i: waiting for 32-bit check value */
  7574. var    LENGTH = 28;    /* i: waiting for 32-bit length (gzip) */
  7575. var    DONE = 29;      /* finished check, done -- remain here until reset */
  7576. var    BAD = 30;       /* got a data error -- remain here until reset */
  7577. var    MEM = 31;       /* got an inflate() memory error -- remain here until reset */
  7578. var    SYNC = 32;      /* looking for synchronization bytes to restart inflate() */
  7579.  
  7580. /* ===========================================================================*/
  7581.  
  7582.  
  7583.  
  7584. var ENOUGH_LENS = 852;
  7585. var ENOUGH_DISTS = 592;
  7586. //var ENOUGH =  (ENOUGH_LENS+ENOUGH_DISTS);
  7587.  
  7588. var MAX_WBITS = 15;
  7589. /* 32K LZ77 window */
  7590. var DEF_WBITS = MAX_WBITS;
  7591.  
  7592.  
  7593. function zswap32(q) {
  7594.   return  (((q >>> 24) & 0xff) +
  7595.           ((q >>> 8) & 0xff00) +
  7596.           ((q & 0xff00) << 8) +
  7597.           ((q & 0xff) << 24));
  7598. }
  7599.  
  7600.  
  7601. function InflateState() {
  7602.   this.mode = 0;             /* current inflate mode */
  7603.   this.last = false;          /* true if processing last block */
  7604.   this.wrap = 0;              /* bit 0 true for zlib, bit 1 true for gzip */
  7605.   this.havedict = false;      /* true if dictionary provided */
  7606.   this.flags = 0;             /* gzip header method and flags (0 if zlib) */
  7607.   this.dmax = 0;              /* zlib header max distance (INFLATE_STRICT) */
  7608.   this.check = 0;             /* protected copy of check value */
  7609.   this.total = 0;             /* protected copy of output count */
  7610.   // TODO: may be {}
  7611.   this.head = null;           /* where to save gzip header information */
  7612.  
  7613.   /* sliding window */
  7614.   this.wbits = 0;             /* log base 2 of requested window size */
  7615.   this.wsize = 0;             /* window size or zero if not using window */
  7616.   this.whave = 0;             /* valid bytes in the window */
  7617.   this.wnext = 0;             /* window write index */
  7618.   this.window = null;         /* allocated sliding window, if needed */
  7619.  
  7620.   /* bit accumulator */
  7621.   this.hold = 0;              /* input bit accumulator */
  7622.   this.bits = 0;              /* number of bits in "in" */
  7623.  
  7624.   /* for string and stored block copying */
  7625.   this.length = 0;            /* literal or length of data to copy */
  7626.   this.offset = 0;            /* distance back to copy string from */
  7627.  
  7628.   /* for table and code decoding */
  7629.   this.extra = 0;             /* extra bits needed */
  7630.  
  7631.   /* fixed and dynamic code tables */
  7632.   this.lencode = null;          /* starting table for length/literal codes */
  7633.   this.distcode = null;         /* starting table for distance codes */
  7634.   this.lenbits = 0;           /* index bits for lencode */
  7635.   this.distbits = 0;          /* index bits for distcode */
  7636.  
  7637.   /* dynamic table building */
  7638.   this.ncode = 0;             /* number of code length code lengths */
  7639.   this.nlen = 0;              /* number of length code lengths */
  7640.   this.ndist = 0;             /* number of distance code lengths */
  7641.   this.have = 0;              /* number of code lengths in lens[] */
  7642.   this.next = null;              /* next available space in codes[] */
  7643.  
  7644.   this.lens = new utils.Buf16(320); /* temporary storage for code lengths */
  7645.   this.work = new utils.Buf16(288); /* work area for code table building */
  7646.  
  7647.   /*
  7648.    because we don't have pointers in js, we use lencode and distcode directly
  7649.    as buffers so we don't need codes
  7650.   */
  7651.   //this.codes = new utils.Buf32(ENOUGH);       /* space for code tables */
  7652.   this.lendyn = null;              /* dynamic table for length/literal codes (JS specific) */
  7653.   this.distdyn = null;             /* dynamic table for distance codes (JS specific) */
  7654.   this.sane = 0;                   /* if false, allow invalid distance too far */
  7655.   this.back = 0;                   /* bits back of last unprocessed length/lit */
  7656.   this.was = 0;                    /* initial length of match */
  7657. }
  7658.  
  7659. function inflateResetKeep(strm) {
  7660.   var state;
  7661.  
  7662.   if (!strm || !strm.state) { return Z_STREAM_ERROR; }
  7663.   state = strm.state;
  7664.   strm.total_in = strm.total_out = state.total = 0;
  7665.   strm.msg = ''; /*Z_NULL*/
  7666.   if (state.wrap) {       /* to support ill-conceived Java test suite */
  7667.     strm.adler = state.wrap & 1;
  7668.   }
  7669.   state.mode = HEAD;
  7670.   state.last = 0;
  7671.   state.havedict = 0;
  7672.   state.dmax = 32768;
  7673.   state.head = null/*Z_NULL*/;
  7674.   state.hold = 0;
  7675.   state.bits = 0;
  7676.   //state.lencode = state.distcode = state.next = state.codes;
  7677.   state.lencode = state.lendyn = new utils.Buf32(ENOUGH_LENS);
  7678.   state.distcode = state.distdyn = new utils.Buf32(ENOUGH_DISTS);
  7679.  
  7680.   state.sane = 1;
  7681.   state.back = -1;
  7682.   //Tracev((stderr, "inflate: reset\n"));
  7683.   return Z_OK;
  7684. }
  7685.  
  7686. function inflateReset(strm) {
  7687.   var state;
  7688.  
  7689.   if (!strm || !strm.state) { return Z_STREAM_ERROR; }
  7690.   state = strm.state;
  7691.   state.wsize = 0;
  7692.   state.whave = 0;
  7693.   state.wnext = 0;
  7694.   return inflateResetKeep(strm);
  7695.  
  7696. }
  7697.  
  7698. function inflateReset2(strm, windowBits) {
  7699.   var wrap;
  7700.   var state;
  7701.  
  7702.   /* get the state */
  7703.   if (!strm || !strm.state) { return Z_STREAM_ERROR; }
  7704.   state = strm.state;
  7705.  
  7706.   /* extract wrap request from windowBits parameter */
  7707.   if (windowBits < 0) {
  7708.     wrap = 0;
  7709.     windowBits = -windowBits;
  7710.   }
  7711.   else {
  7712.     wrap = (windowBits >> 4) + 1;
  7713.     if (windowBits < 48) {
  7714.       windowBits &= 15;
  7715.     }
  7716.   }
  7717.  
  7718.   /* set number of window bits, free window if different */
  7719.   if (windowBits && (windowBits < 8 || windowBits > 15)) {
  7720.     return Z_STREAM_ERROR;
  7721.   }
  7722.   if (state.window !== null && state.wbits !== windowBits) {
  7723.     state.window = null;
  7724.   }
  7725.  
  7726.   /* update state and reset the rest of it */
  7727.   state.wrap = wrap;
  7728.   state.wbits = windowBits;
  7729.   return inflateReset(strm);
  7730. }
  7731.  
  7732. function inflateInit2(strm, windowBits) {
  7733.   var ret;
  7734.   var state;
  7735.  
  7736.   if (!strm) { return Z_STREAM_ERROR; }
  7737.   //strm.msg = Z_NULL;                 /* in case we return an error */
  7738.  
  7739.   state = new InflateState();
  7740.  
  7741.   //if (state === Z_NULL) return Z_MEM_ERROR;
  7742.   //Tracev((stderr, "inflate: allocated\n"));
  7743.   strm.state = state;
  7744.   state.window = null/*Z_NULL*/;
  7745.   ret = inflateReset2(strm, windowBits);
  7746.   if (ret !== Z_OK) {
  7747.     strm.state = null/*Z_NULL*/;
  7748.   }
  7749.   return ret;
  7750. }
  7751.  
  7752. function inflateInit(strm) {
  7753.   return inflateInit2(strm, DEF_WBITS);
  7754. }
  7755.  
  7756.  
  7757. /*
  7758.  Return state with length and distance decoding tables and index sizes set to
  7759.  fixed code decoding.  Normally this returns fixed tables from inffixed.h.
  7760.  If BUILDFIXED is defined, then instead this routine builds the tables the
  7761.  first time it's called, and returns those tables the first time and
  7762.  thereafter.  This reduces the size of the code by about 2K bytes, in
  7763.  exchange for a little execution time.  However, BUILDFIXED should not be
  7764.  used for threaded applications, since the rewriting of the tables and virgin
  7765.  may not be thread-safe.
  7766.  */
  7767. var virgin = true;
  7768.  
  7769. var lenfix, distfix; // We have no pointers in JS, so keep tables separate
  7770.  
  7771. function fixedtables(state) {
  7772.   /* build fixed huffman tables if first call (may not be thread safe) */
  7773.   if (virgin) {
  7774.     var sym;
  7775.  
  7776.     lenfix = new utils.Buf32(512);
  7777.     distfix = new utils.Buf32(32);
  7778.  
  7779.     /* literal/length table */
  7780.     sym = 0;
  7781.     while (sym < 144) { state.lens[sym++] = 8; }
  7782.     while (sym < 256) { state.lens[sym++] = 9; }
  7783.     while (sym < 280) { state.lens[sym++] = 7; }
  7784.     while (sym < 288) { state.lens[sym++] = 8; }
  7785.  
  7786.     inflate_table(LENS,  state.lens, 0, 288, lenfix,   0, state.work, { bits: 9 });
  7787.  
  7788.     /* distance table */
  7789.     sym = 0;
  7790.     while (sym < 32) { state.lens[sym++] = 5; }
  7791.  
  7792.     inflate_table(DISTS, state.lens, 0, 32,   distfix, 0, state.work, { bits: 5 });
  7793.  
  7794.     /* do this just once */
  7795.     virgin = false;
  7796.   }
  7797.  
  7798.   state.lencode = lenfix;
  7799.   state.lenbits = 9;
  7800.   state.distcode = distfix;
  7801.   state.distbits = 5;
  7802. }
  7803.  
  7804.  
  7805. /*
  7806.  Update the window with the last wsize (normally 32K) bytes written before
  7807.  returning.  If window does not exist yet, create it.  This is only called
  7808.  when a window is already in use, or when output has been written during this
  7809.  inflate call, but the end of the deflate stream has not been reached yet.
  7810.  It is also called to create a window for dictionary data when a dictionary
  7811.  is loaded.
  7812.  
  7813.  Providing output buffers larger than 32K to inflate() should provide a speed
  7814.  advantage, since only the last 32K of output is copied to the sliding window
  7815.  upon return from inflate(), and since all distances after the first 32K of
  7816.  output will fall in the output data, making match copies simpler and faster.
  7817.  The advantage may be dependent on the size of the processor's data caches.
  7818.  */
  7819. function updatewindow(strm, src, end, copy) {
  7820.   var dist;
  7821.   var state = strm.state;
  7822.  
  7823.   /* if it hasn't been done already, allocate space for the window */
  7824.   if (state.window === null) {
  7825.     state.wsize = 1 << state.wbits;
  7826.     state.wnext = 0;
  7827.     state.whave = 0;
  7828.  
  7829.     state.window = new utils.Buf8(state.wsize);
  7830.   }
  7831.  
  7832.   /* copy state->wsize or less output bytes into the circular window */
  7833.   if (copy >= state.wsize) {
  7834.     utils.arraySet(state.window, src, end - state.wsize, state.wsize, 0);
  7835.     state.wnext = 0;
  7836.     state.whave = state.wsize;
  7837.   }
  7838.   else {
  7839.     dist = state.wsize - state.wnext;
  7840.     if (dist > copy) {
  7841.       dist = copy;
  7842.     }
  7843.     //zmemcpy(state->window + state->wnext, end - copy, dist);
  7844.     utils.arraySet(state.window, src, end - copy, dist, state.wnext);
  7845.     copy -= dist;
  7846.     if (copy) {
  7847.       //zmemcpy(state->window, end - copy, copy);
  7848.       utils.arraySet(state.window, src, end - copy, copy, 0);
  7849.       state.wnext = copy;
  7850.       state.whave = state.wsize;
  7851.     }
  7852.     else {
  7853.       state.wnext += dist;
  7854.       if (state.wnext === state.wsize) { state.wnext = 0; }
  7855.       if (state.whave < state.wsize) { state.whave += dist; }
  7856.     }
  7857.   }
  7858.   return 0;
  7859. }
  7860.  
  7861. function inflate(strm, flush) {
  7862.   var state;
  7863.   var input, output;          // input/output buffers
  7864.   var next;                   /* next input INDEX */
  7865.   var put;                    /* next output INDEX */
  7866.   var have, left;             /* available input and output */
  7867.   var hold;                   /* bit buffer */
  7868.   var bits;                   /* bits in bit buffer */
  7869.   var _in, _out;              /* save starting available input and output */
  7870.   var copy;                   /* number of stored or match bytes to copy */
  7871.   var from;                   /* where to copy match bytes from */
  7872.   var from_source;
  7873.   var here = 0;               /* current decoding table entry */
  7874.   var here_bits, here_op, here_val; // paked "here" denormalized (JS specific)
  7875.   //var last;                   /* parent table entry */
  7876.   var last_bits, last_op, last_val; // paked "last" denormalized (JS specific)
  7877.   var len;                    /* length to copy for repeats, bits to drop */
  7878.   var ret;                    /* return code */
  7879.   var hbuf = new utils.Buf8(4);    /* buffer for gzip header crc calculation */
  7880.   var opts;
  7881.  
  7882.   var n; // temporary var for NEED_BITS
  7883.  
  7884.   var order = /* permutation of code lengths */
  7885.     [ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 ];
  7886.  
  7887.  
  7888.   if (!strm || !strm.state || !strm.output ||
  7889.       (!strm.input && strm.avail_in !== 0)) {
  7890.     return Z_STREAM_ERROR;
  7891.   }
  7892.  
  7893.   state = strm.state;
  7894.   if (state.mode === TYPE) { state.mode = TYPEDO; }    /* skip check */
  7895.  
  7896.  
  7897.   //--- LOAD() ---
  7898.   put = strm.next_out;
  7899.   output = strm.output;
  7900.   left = strm.avail_out;
  7901.   next = strm.next_in;
  7902.   input = strm.input;
  7903.   have = strm.avail_in;
  7904.   hold = state.hold;
  7905.   bits = state.bits;
  7906.   //---
  7907.  
  7908.   _in = have;
  7909.   _out = left;
  7910.   ret = Z_OK;
  7911.  
  7912.   inf_leave: // goto emulation
  7913.   for (;;) {
  7914.     switch (state.mode) {
  7915.       case HEAD:
  7916.         if (state.wrap === 0) {
  7917.           state.mode = TYPEDO;
  7918.           break;
  7919.         }
  7920.         //=== NEEDBITS(16);
  7921.         while (bits < 16) {
  7922.           if (have === 0) { break inf_leave; }
  7923.           have--;
  7924.           hold += input[next++] << bits;
  7925.           bits += 8;
  7926.         }
  7927.         //===//
  7928.         if ((state.wrap & 2) && hold === 0x8b1f) {  /* gzip header */
  7929.           state.check = 0/*crc32(0L, Z_NULL, 0)*/;
  7930.           //=== CRC2(state.check, hold);
  7931.           hbuf[0] = hold & 0xff;
  7932.           hbuf[1] = (hold >>> 8) & 0xff;
  7933.           state.check = crc32(state.check, hbuf, 2, 0);
  7934.           //===//
  7935.  
  7936.           //=== INITBITS();
  7937.           hold = 0;
  7938.           bits = 0;
  7939.           //===//
  7940.           state.mode = FLAGS;
  7941.           break;
  7942.         }
  7943.         state.flags = 0;           /* expect zlib header */
  7944.         if (state.head) {
  7945.           state.head.done = false;
  7946.         }
  7947.         if (!(state.wrap & 1) ||   /* check if zlib header allowed */
  7948.           (((hold & 0xff)/*BITS(8)*/ << 8) + (hold >> 8)) % 31) {
  7949.           strm.msg = 'incorrect header check';
  7950.           state.mode = BAD;
  7951.           break;
  7952.         }
  7953.         if ((hold & 0x0f)/*BITS(4)*/ !== Z_DEFLATED) {
  7954.           strm.msg = 'unknown compression method';
  7955.           state.mode = BAD;
  7956.           break;
  7957.         }
  7958.         //--- DROPBITS(4) ---//
  7959.         hold >>>= 4;
  7960.         bits -= 4;
  7961.         //---//
  7962.         len = (hold & 0x0f)/*BITS(4)*/ + 8;
  7963.         if (state.wbits === 0) {
  7964.           state.wbits = len;
  7965.         }
  7966.         else if (len > state.wbits) {
  7967.           strm.msg = 'invalid window size';
  7968.           state.mode = BAD;
  7969.           break;
  7970.         }
  7971.         state.dmax = 1 << len;
  7972.         //Tracev((stderr, "inflate:   zlib header ok\n"));
  7973.         strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
  7974.         state.mode = hold & 0x200 ? DICTID : TYPE;
  7975.         //=== INITBITS();
  7976.         hold = 0;
  7977.         bits = 0;
  7978.         //===//
  7979.         break;
  7980.       case FLAGS:
  7981.         //=== NEEDBITS(16); */
  7982.         while (bits < 16) {
  7983.           if (have === 0) { break inf_leave; }
  7984.           have--;
  7985.           hold += input[next++] << bits;
  7986.           bits += 8;
  7987.         }
  7988.         //===//
  7989.         state.flags = hold;
  7990.         if ((state.flags & 0xff) !== Z_DEFLATED) {
  7991.           strm.msg = 'unknown compression method';
  7992.           state.mode = BAD;
  7993.           break;
  7994.         }
  7995.         if (state.flags & 0xe000) {
  7996.           strm.msg = 'unknown header flags set';
  7997.           state.mode = BAD;
  7998.           break;
  7999.         }
  8000.         if (state.head) {
  8001.           state.head.text = ((hold >> 8) & 1);
  8002.         }
  8003.         if (state.flags & 0x0200) {
  8004.           //=== CRC2(state.check, hold);
  8005.           hbuf[0] = hold & 0xff;
  8006.           hbuf[1] = (hold >>> 8) & 0xff;
  8007.           state.check = crc32(state.check, hbuf, 2, 0);
  8008.           //===//
  8009.         }
  8010.         //=== INITBITS();
  8011.         hold = 0;
  8012.         bits = 0;
  8013.         //===//
  8014.         state.mode = TIME;
  8015.         /* falls through */
  8016.       case TIME:
  8017.         //=== NEEDBITS(32); */
  8018.         while (bits < 32) {
  8019.           if (have === 0) { break inf_leave; }
  8020.           have--;
  8021.           hold += input[next++] << bits;
  8022.           bits += 8;
  8023.         }
  8024.         //===//
  8025.         if (state.head) {
  8026.           state.head.time = hold;
  8027.         }
  8028.         if (state.flags & 0x0200) {
  8029.           //=== CRC4(state.check, hold)
  8030.           hbuf[0] = hold & 0xff;
  8031.           hbuf[1] = (hold >>> 8) & 0xff;
  8032.           hbuf[2] = (hold >>> 16) & 0xff;
  8033.           hbuf[3] = (hold >>> 24) & 0xff;
  8034.           state.check = crc32(state.check, hbuf, 4, 0);
  8035.           //===
  8036.         }
  8037.         //=== INITBITS();
  8038.         hold = 0;
  8039.         bits = 0;
  8040.         //===//
  8041.         state.mode = OS;
  8042.         /* falls through */
  8043.       case OS:
  8044.         //=== NEEDBITS(16); */
  8045.         while (bits < 16) {
  8046.           if (have === 0) { break inf_leave; }
  8047.           have--;
  8048.           hold += input[next++] << bits;
  8049.           bits += 8;
  8050.         }
  8051.         //===//
  8052.         if (state.head) {
  8053.           state.head.xflags = (hold & 0xff);
  8054.           state.head.os = (hold >> 8);
  8055.         }
  8056.         if (state.flags & 0x0200) {
  8057.           //=== CRC2(state.check, hold);
  8058.           hbuf[0] = hold & 0xff;
  8059.           hbuf[1] = (hold >>> 8) & 0xff;
  8060.           state.check = crc32(state.check, hbuf, 2, 0);
  8061.           //===//
  8062.         }
  8063.         //=== INITBITS();
  8064.         hold = 0;
  8065.         bits = 0;
  8066.         //===//
  8067.         state.mode = EXLEN;
  8068.         /* falls through */
  8069.       case EXLEN:
  8070.         if (state.flags & 0x0400) {
  8071.           //=== NEEDBITS(16); */
  8072.           while (bits < 16) {
  8073.             if (have === 0) { break inf_leave; }
  8074.             have--;
  8075.             hold += input[next++] << bits;
  8076.             bits += 8;
  8077.           }
  8078.           //===//
  8079.           state.length = hold;
  8080.           if (state.head) {
  8081.             state.head.extra_len = hold;
  8082.           }
  8083.           if (state.flags & 0x0200) {
  8084.             //=== CRC2(state.check, hold);
  8085.             hbuf[0] = hold & 0xff;
  8086.             hbuf[1] = (hold >>> 8) & 0xff;
  8087.             state.check = crc32(state.check, hbuf, 2, 0);
  8088.             //===//
  8089.           }
  8090.           //=== INITBITS();
  8091.           hold = 0;
  8092.           bits = 0;
  8093.           //===//
  8094.         }
  8095.         else if (state.head) {
  8096.           state.head.extra = null/*Z_NULL*/;
  8097.         }
  8098.         state.mode = EXTRA;
  8099.         /* falls through */
  8100.       case EXTRA:
  8101.         if (state.flags & 0x0400) {
  8102.           copy = state.length;
  8103.           if (copy > have) { copy = have; }
  8104.           if (copy) {
  8105.             if (state.head) {
  8106.               len = state.head.extra_len - state.length;
  8107.               if (!state.head.extra) {
  8108.                 // Use untyped array for more convenient processing later
  8109.                 state.head.extra = new Array(state.head.extra_len);
  8110.               }
  8111.               utils.arraySet(
  8112.                 state.head.extra,
  8113.                 input,
  8114.                 next,
  8115.                 // extra field is limited to 65536 bytes
  8116.                 // - no need for additional size check
  8117.                 copy,
  8118.                 /*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
  8119.                 len
  8120.               );
  8121.               //zmemcpy(state.head.extra + len, next,
  8122.               //        len + copy > state.head.extra_max ?
  8123.               //        state.head.extra_max - len : copy);
  8124.             }
  8125.             if (state.flags & 0x0200) {
  8126.               state.check = crc32(state.check, input, copy, next);
  8127.             }
  8128.             have -= copy;
  8129.             next += copy;
  8130.             state.length -= copy;
  8131.           }
  8132.           if (state.length) { break inf_leave; }
  8133.         }
  8134.         state.length = 0;
  8135.         state.mode = NAME;
  8136.         /* falls through */
  8137.       case NAME:
  8138.         if (state.flags & 0x0800) {
  8139.           if (have === 0) { break inf_leave; }
  8140.           copy = 0;
  8141.           do {
  8142.             // TODO: 2 or 1 bytes?
  8143.             len = input[next + copy++];
  8144.             /* use constant limit because in js we should not preallocate memory */
  8145.             if (state.head && len &&
  8146.                 (state.length < 65536 /*state.head.name_max*/)) {
  8147.               state.head.name += String.fromCharCode(len);
  8148.             }
  8149.           } while (len && copy < have);
  8150.  
  8151.           if (state.flags & 0x0200) {
  8152.             state.check = crc32(state.check, input, copy, next);
  8153.           }
  8154.           have -= copy;
  8155.           next += copy;
  8156.           if (len) { break inf_leave; }
  8157.         }
  8158.         else if (state.head) {
  8159.           state.head.name = null;
  8160.         }
  8161.         state.length = 0;
  8162.         state.mode = COMMENT;
  8163.         /* falls through */
  8164.       case COMMENT:
  8165.         if (state.flags & 0x1000) {
  8166.           if (have === 0) { break inf_leave; }
  8167.           copy = 0;
  8168.           do {
  8169.             len = input[next + copy++];
  8170.             /* use constant limit because in js we should not preallocate memory */
  8171.             if (state.head && len &&
  8172.                 (state.length < 65536 /*state.head.comm_max*/)) {
  8173.               state.head.comment += String.fromCharCode(len);
  8174.             }
  8175.           } while (len && copy < have);
  8176.           if (state.flags & 0x0200) {
  8177.             state.check = crc32(state.check, input, copy, next);
  8178.           }
  8179.           have -= copy;
  8180.           next += copy;
  8181.           if (len) { break inf_leave; }
  8182.         }
  8183.         else if (state.head) {
  8184.           state.head.comment = null;
  8185.         }
  8186.         state.mode = HCRC;
  8187.         /* falls through */
  8188.       case HCRC:
  8189.         if (state.flags & 0x0200) {
  8190.           //=== NEEDBITS(16); */
  8191.           while (bits < 16) {
  8192.             if (have === 0) { break inf_leave; }
  8193.             have--;
  8194.             hold += input[next++] << bits;
  8195.             bits += 8;
  8196.           }
  8197.           //===//
  8198.           if (hold !== (state.check & 0xffff)) {
  8199.             strm.msg = 'header crc mismatch';
  8200.             state.mode = BAD;
  8201.             break;
  8202.           }
  8203.           //=== INITBITS();
  8204.           hold = 0;
  8205.           bits = 0;
  8206.           //===//
  8207.         }
  8208.         if (state.head) {
  8209.           state.head.hcrc = ((state.flags >> 9) & 1);
  8210.           state.head.done = true;
  8211.         }
  8212.         strm.adler = state.check = 0;
  8213.         state.mode = TYPE;
  8214.         break;
  8215.       case DICTID:
  8216.         //=== NEEDBITS(32); */
  8217.         while (bits < 32) {
  8218.           if (have === 0) { break inf_leave; }
  8219.           have--;
  8220.           hold += input[next++] << bits;
  8221.           bits += 8;
  8222.         }
  8223.         //===//
  8224.         strm.adler = state.check = zswap32(hold);
  8225.         //=== INITBITS();
  8226.         hold = 0;
  8227.         bits = 0;
  8228.         //===//
  8229.         state.mode = DICT;
  8230.         /* falls through */
  8231.       case DICT:
  8232.         if (state.havedict === 0) {
  8233.           //--- RESTORE() ---
  8234.           strm.next_out = put;
  8235.           strm.avail_out = left;
  8236.           strm.next_in = next;
  8237.           strm.avail_in = have;
  8238.           state.hold = hold;
  8239.           state.bits = bits;
  8240.           //---
  8241.           return Z_NEED_DICT;
  8242.         }
  8243.         strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
  8244.         state.mode = TYPE;
  8245.         /* falls through */
  8246.       case TYPE:
  8247.         if (flush === Z_BLOCK || flush === Z_TREES) { break inf_leave; }
  8248.         /* falls through */
  8249.       case TYPEDO:
  8250.         if (state.last) {
  8251.           //--- BYTEBITS() ---//
  8252.           hold >>>= bits & 7;
  8253.           bits -= bits & 7;
  8254.           //---//
  8255.           state.mode = CHECK;
  8256.           break;
  8257.         }
  8258.         //=== NEEDBITS(3); */
  8259.         while (bits < 3) {
  8260.           if (have === 0) { break inf_leave; }
  8261.           have--;
  8262.           hold += input[next++] << bits;
  8263.           bits += 8;
  8264.         }
  8265.         //===//
  8266.         state.last = (hold & 0x01)/*BITS(1)*/;
  8267.         //--- DROPBITS(1) ---//
  8268.         hold >>>= 1;
  8269.         bits -= 1;
  8270.         //---//
  8271.  
  8272.         switch ((hold & 0x03)/*BITS(2)*/) {
  8273.           case 0:                             /* stored block */
  8274.             //Tracev((stderr, "inflate:     stored block%s\n",
  8275.             //        state.last ? " (last)" : ""));
  8276.             state.mode = STORED;
  8277.             break;
  8278.           case 1:                             /* fixed block */
  8279.             fixedtables(state);
  8280.             //Tracev((stderr, "inflate:     fixed codes block%s\n",
  8281.             //        state.last ? " (last)" : ""));
  8282.             state.mode = LEN_;             /* decode codes */
  8283.             if (flush === Z_TREES) {
  8284.               //--- DROPBITS(2) ---//
  8285.               hold >>>= 2;
  8286.               bits -= 2;
  8287.               //---//
  8288.               break inf_leave;
  8289.             }
  8290.             break;
  8291.           case 2:                             /* dynamic block */
  8292.             //Tracev((stderr, "inflate:     dynamic codes block%s\n",
  8293.             //        state.last ? " (last)" : ""));
  8294.             state.mode = TABLE;
  8295.             break;
  8296.           case 3:
  8297.             strm.msg = 'invalid block type';
  8298.             state.mode = BAD;
  8299.         }
  8300.         //--- DROPBITS(2) ---//
  8301.         hold >>>= 2;
  8302.         bits -= 2;
  8303.         //---//
  8304.         break;
  8305.       case STORED:
  8306.         //--- BYTEBITS() ---// /* go to byte boundary */
  8307.         hold >>>= bits & 7;
  8308.         bits -= bits & 7;
  8309.         //---//
  8310.         //=== NEEDBITS(32); */
  8311.         while (bits < 32) {
  8312.           if (have === 0) { break inf_leave; }
  8313.           have--;
  8314.           hold += input[next++] << bits;
  8315.           bits += 8;
  8316.         }
  8317.         //===//
  8318.         if ((hold & 0xffff) !== ((hold >>> 16) ^ 0xffff)) {
  8319.           strm.msg = 'invalid stored block lengths';
  8320.           state.mode = BAD;
  8321.           break;
  8322.         }
  8323.         state.length = hold & 0xffff;
  8324.         //Tracev((stderr, "inflate:       stored length %u\n",
  8325.         //        state.length));
  8326.         //=== INITBITS();
  8327.         hold = 0;
  8328.         bits = 0;
  8329.         //===//
  8330.         state.mode = COPY_;
  8331.         if (flush === Z_TREES) { break inf_leave; }
  8332.         /* falls through */
  8333.       case COPY_:
  8334.         state.mode = COPY;
  8335.         /* falls through */
  8336.       case COPY:
  8337.         copy = state.length;
  8338.         if (copy) {
  8339.           if (copy > have) { copy = have; }
  8340.           if (copy > left) { copy = left; }
  8341.           if (copy === 0) { break inf_leave; }
  8342.           //--- zmemcpy(put, next, copy); ---
  8343.           utils.arraySet(output, input, next, copy, put);
  8344.           //---//
  8345.           have -= copy;
  8346.           next += copy;
  8347.           left -= copy;
  8348.           put += copy;
  8349.           state.length -= copy;
  8350.           break;
  8351.         }
  8352.         //Tracev((stderr, "inflate:       stored end\n"));
  8353.         state.mode = TYPE;
  8354.         break;
  8355.       case TABLE:
  8356.         //=== NEEDBITS(14); */
  8357.         while (bits < 14) {
  8358.           if (have === 0) { break inf_leave; }
  8359.           have--;
  8360.           hold += input[next++] << bits;
  8361.           bits += 8;
  8362.         }
  8363.         //===//
  8364.         state.nlen = (hold & 0x1f)/*BITS(5)*/ + 257;
  8365.         //--- DROPBITS(5) ---//
  8366.         hold >>>= 5;
  8367.         bits -= 5;
  8368.         //---//
  8369.         state.ndist = (hold & 0x1f)/*BITS(5)*/ + 1;
  8370.         //--- DROPBITS(5) ---//
  8371.         hold >>>= 5;
  8372.         bits -= 5;
  8373.         //---//
  8374.         state.ncode = (hold & 0x0f)/*BITS(4)*/ + 4;
  8375.         //--- DROPBITS(4) ---//
  8376.         hold >>>= 4;
  8377.         bits -= 4;
  8378.         //---//
  8379. //#ifndef PKZIP_BUG_WORKAROUND
  8380.         if (state.nlen > 286 || state.ndist > 30) {
  8381.           strm.msg = 'too many length or distance symbols';
  8382.           state.mode = BAD;
  8383.           break;
  8384.         }
  8385. //#endif
  8386.         //Tracev((stderr, "inflate:       table sizes ok\n"));
  8387.         state.have = 0;
  8388.         state.mode = LENLENS;
  8389.         /* falls through */
  8390.       case LENLENS:
  8391.         while (state.have < state.ncode) {
  8392.           //=== NEEDBITS(3);
  8393.           while (bits < 3) {
  8394.             if (have === 0) { break inf_leave; }
  8395.             have--;
  8396.             hold += input[next++] << bits;
  8397.             bits += 8;
  8398.           }
  8399.           //===//
  8400.           state.lens[order[state.have++]] = (hold & 0x07);//BITS(3);
  8401.           //--- DROPBITS(3) ---//
  8402.           hold >>>= 3;
  8403.           bits -= 3;
  8404.           //---//
  8405.         }
  8406.         while (state.have < 19) {
  8407.           state.lens[order[state.have++]] = 0;
  8408.         }
  8409.         // We have separate tables & no pointers. 2 commented lines below not needed.
  8410.         //state.next = state.codes;
  8411.         //state.lencode = state.next;
  8412.         // Switch to use dynamic table
  8413.         state.lencode = state.lendyn;
  8414.         state.lenbits = 7;
  8415.  
  8416.         opts = { bits: state.lenbits };
  8417.         ret = inflate_table(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts);
  8418.         state.lenbits = opts.bits;
  8419.  
  8420.         if (ret) {
  8421.           strm.msg = 'invalid code lengths set';
  8422.           state.mode = BAD;
  8423.           break;
  8424.         }
  8425.         //Tracev((stderr, "inflate:       code lengths ok\n"));
  8426.         state.have = 0;
  8427.         state.mode = CODELENS;
  8428.         /* falls through */
  8429.       case CODELENS:
  8430.         while (state.have < state.nlen + state.ndist) {
  8431.           for (;;) {
  8432.             here = state.lencode[hold & ((1 << state.lenbits) - 1)];/*BITS(state.lenbits)*/
  8433.             here_bits = here >>> 24;
  8434.             here_op = (here >>> 16) & 0xff;
  8435.             here_val = here & 0xffff;
  8436.  
  8437.             if ((here_bits) <= bits) { break; }
  8438.             //--- PULLBYTE() ---//
  8439.             if (have === 0) { break inf_leave; }
  8440.             have--;
  8441.             hold += input[next++] << bits;
  8442.             bits += 8;
  8443.             //---//
  8444.           }
  8445.           if (here_val < 16) {
  8446.             //--- DROPBITS(here.bits) ---//
  8447.             hold >>>= here_bits;
  8448.             bits -= here_bits;
  8449.             //---//
  8450.             state.lens[state.have++] = here_val;
  8451.           }
  8452.           else {
  8453.             if (here_val === 16) {
  8454.               //=== NEEDBITS(here.bits + 2);
  8455.               n = here_bits + 2;
  8456.               while (bits < n) {
  8457.                 if (have === 0) { break inf_leave; }
  8458.                 have--;
  8459.                 hold += input[next++] << bits;
  8460.                 bits += 8;
  8461.               }
  8462.               //===//
  8463.               //--- DROPBITS(here.bits) ---//
  8464.               hold >>>= here_bits;
  8465.               bits -= here_bits;
  8466.               //---//
  8467.               if (state.have === 0) {
  8468.                 strm.msg = 'invalid bit length repeat';
  8469.                 state.mode = BAD;
  8470.                 break;
  8471.               }
  8472.               len = state.lens[state.have - 1];
  8473.               copy = 3 + (hold & 0x03);//BITS(2);
  8474.               //--- DROPBITS(2) ---//
  8475.               hold >>>= 2;
  8476.               bits -= 2;
  8477.               //---//
  8478.             }
  8479.             else if (here_val === 17) {
  8480.               //=== NEEDBITS(here.bits + 3);
  8481.               n = here_bits + 3;
  8482.               while (bits < n) {
  8483.                 if (have === 0) { break inf_leave; }
  8484.                 have--;
  8485.                 hold += input[next++] << bits;
  8486.                 bits += 8;
  8487.               }
  8488.               //===//
  8489.               //--- DROPBITS(here.bits) ---//
  8490.               hold >>>= here_bits;
  8491.               bits -= here_bits;
  8492.               //---//
  8493.               len = 0;
  8494.               copy = 3 + (hold & 0x07);//BITS(3);
  8495.               //--- DROPBITS(3) ---//
  8496.               hold >>>= 3;
  8497.               bits -= 3;
  8498.               //---//
  8499.             }
  8500.             else {
  8501.               //=== NEEDBITS(here.bits + 7);
  8502.               n = here_bits + 7;
  8503.               while (bits < n) {
  8504.                 if (have === 0) { break inf_leave; }
  8505.                 have--;
  8506.                 hold += input[next++] << bits;
  8507.                 bits += 8;
  8508.               }
  8509.               //===//
  8510.               //--- DROPBITS(here.bits) ---//
  8511.               hold >>>= here_bits;
  8512.               bits -= here_bits;
  8513.               //---//
  8514.               len = 0;
  8515.               copy = 11 + (hold & 0x7f);//BITS(7);
  8516.               //--- DROPBITS(7) ---//
  8517.               hold >>>= 7;
  8518.               bits -= 7;
  8519.               //---//
  8520.             }
  8521.             if (state.have + copy > state.nlen + state.ndist) {
  8522.               strm.msg = 'invalid bit length repeat';
  8523.               state.mode = BAD;
  8524.               break;
  8525.             }
  8526.             while (copy--) {
  8527.               state.lens[state.have++] = len;
  8528.             }
  8529.           }
  8530.         }
  8531.  
  8532.         /* handle error breaks in while */
  8533.         if (state.mode === BAD) { break; }
  8534.  
  8535.         /* check for end-of-block code (better have one) */
  8536.         if (state.lens[256] === 0) {
  8537.           strm.msg = 'invalid code -- missing end-of-block';
  8538.           state.mode = BAD;
  8539.           break;
  8540.         }
  8541.  
  8542.         /* build code tables -- note: do not change the lenbits or distbits
  8543.            values here (9 and 6) without reading the comments in inftrees.h
  8544.            concerning the ENOUGH constants, which depend on those values */
  8545.         state.lenbits = 9;
  8546.  
  8547.         opts = { bits: state.lenbits };
  8548.         ret = inflate_table(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts);
  8549.         // We have separate tables & no pointers. 2 commented lines below not needed.
  8550.         // state.next_index = opts.table_index;
  8551.         state.lenbits = opts.bits;
  8552.         // state.lencode = state.next;
  8553.  
  8554.         if (ret) {
  8555.           strm.msg = 'invalid literal/lengths set';
  8556.           state.mode = BAD;
  8557.           break;
  8558.         }
  8559.  
  8560.         state.distbits = 6;
  8561.         //state.distcode.copy(state.codes);
  8562.         // Switch to use dynamic table
  8563.         state.distcode = state.distdyn;
  8564.         opts = { bits: state.distbits };
  8565.         ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts);
  8566.         // We have separate tables & no pointers. 2 commented lines below not needed.
  8567.         // state.next_index = opts.table_index;
  8568.         state.distbits = opts.bits;
  8569.         // state.distcode = state.next;
  8570.  
  8571.         if (ret) {
  8572.           strm.msg = 'invalid distances set';
  8573.           state.mode = BAD;
  8574.           break;
  8575.         }
  8576.         //Tracev((stderr, 'inflate:       codes ok\n'));
  8577.         state.mode = LEN_;
  8578.         if (flush === Z_TREES) { break inf_leave; }
  8579.         /* falls through */
  8580.       case LEN_:
  8581.         state.mode = LEN;
  8582.         /* falls through */
  8583.       case LEN:
  8584.         if (have >= 6 && left >= 258) {
  8585.           //--- RESTORE() ---
  8586.           strm.next_out = put;
  8587.           strm.avail_out = left;
  8588.           strm.next_in = next;
  8589.           strm.avail_in = have;
  8590.           state.hold = hold;
  8591.           state.bits = bits;
  8592.           //---
  8593.           inflate_fast(strm, _out);
  8594.           //--- LOAD() ---
  8595.           put = strm.next_out;
  8596.           output = strm.output;
  8597.           left = strm.avail_out;
  8598.           next = strm.next_in;
  8599.           input = strm.input;
  8600.           have = strm.avail_in;
  8601.           hold = state.hold;
  8602.           bits = state.bits;
  8603.           //---
  8604.  
  8605.           if (state.mode === TYPE) {
  8606.             state.back = -1;
  8607.           }
  8608.           break;
  8609.         }
  8610.         state.back = 0;
  8611.         for (;;) {
  8612.           here = state.lencode[hold & ((1 << state.lenbits) - 1)];  /*BITS(state.lenbits)*/
  8613.           here_bits = here >>> 24;
  8614.           here_op = (here >>> 16) & 0xff;
  8615.           here_val = here & 0xffff;
  8616.  
  8617.           if (here_bits <= bits) { break; }
  8618.           //--- PULLBYTE() ---//
  8619.           if (have === 0) { break inf_leave; }
  8620.           have--;
  8621.           hold += input[next++] << bits;
  8622.           bits += 8;
  8623.           //---//
  8624.         }
  8625.         if (here_op && (here_op & 0xf0) === 0) {
  8626.           last_bits = here_bits;
  8627.           last_op = here_op;
  8628.           last_val = here_val;
  8629.           for (;;) {
  8630.             here = state.lencode[last_val +
  8631.                     ((hold & ((1 << (last_bits + last_op)) - 1))/*BITS(last.bits + last.op)*/ >> last_bits)];
  8632.             here_bits = here >>> 24;
  8633.             here_op = (here >>> 16) & 0xff;
  8634.             here_val = here & 0xffff;
  8635.  
  8636.             if ((last_bits + here_bits) <= bits) { break; }
  8637.             //--- PULLBYTE() ---//
  8638.             if (have === 0) { break inf_leave; }
  8639.             have--;
  8640.             hold += input[next++] << bits;
  8641.             bits += 8;
  8642.             //---//
  8643.           }
  8644.           //--- DROPBITS(last.bits) ---//
  8645.           hold >>>= last_bits;
  8646.           bits -= last_bits;
  8647.           //---//
  8648.           state.back += last_bits;
  8649.         }
  8650.         //--- DROPBITS(here.bits) ---//
  8651.         hold >>>= here_bits;
  8652.         bits -= here_bits;
  8653.         //---//
  8654.         state.back += here_bits;
  8655.         state.length = here_val;
  8656.         if (here_op === 0) {
  8657.           //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
  8658.           //        "inflate:         literal '%c'\n" :
  8659.           //        "inflate:         literal 0x%02x\n", here.val));
  8660.           state.mode = LIT;
  8661.           break;
  8662.         }
  8663.         if (here_op & 32) {
  8664.           //Tracevv((stderr, "inflate:         end of block\n"));
  8665.           state.back = -1;
  8666.           state.mode = TYPE;
  8667.           break;
  8668.         }
  8669.         if (here_op & 64) {
  8670.           strm.msg = 'invalid literal/length code';
  8671.           state.mode = BAD;
  8672.           break;
  8673.         }
  8674.         state.extra = here_op & 15;
  8675.         state.mode = LENEXT;
  8676.         /* falls through */
  8677.       case LENEXT:
  8678.         if (state.extra) {
  8679.           //=== NEEDBITS(state.extra);
  8680.           n = state.extra;
  8681.           while (bits < n) {
  8682.             if (have === 0) { break inf_leave; }
  8683.             have--;
  8684.             hold += input[next++] << bits;
  8685.             bits += 8;
  8686.           }
  8687.           //===//
  8688.           state.length += hold & ((1 << state.extra) - 1)/*BITS(state.extra)*/;
  8689.           //--- DROPBITS(state.extra) ---//
  8690.           hold >>>= state.extra;
  8691.           bits -= state.extra;
  8692.           //---//
  8693.           state.back += state.extra;
  8694.         }
  8695.         //Tracevv((stderr, "inflate:         length %u\n", state.length));
  8696.         state.was = state.length;
  8697.         state.mode = DIST;
  8698.         /* falls through */
  8699.       case DIST:
  8700.         for (;;) {
  8701.           here = state.distcode[hold & ((1 << state.distbits) - 1)];/*BITS(state.distbits)*/
  8702.           here_bits = here >>> 24;
  8703.           here_op = (here >>> 16) & 0xff;
  8704.           here_val = here & 0xffff;
  8705.  
  8706.           if ((here_bits) <= bits) { break; }
  8707.           //--- PULLBYTE() ---//
  8708.           if (have === 0) { break inf_leave; }
  8709.           have--;
  8710.           hold += input[next++] << bits;
  8711.           bits += 8;
  8712.           //---//
  8713.         }
  8714.         if ((here_op & 0xf0) === 0) {
  8715.           last_bits = here_bits;
  8716.           last_op = here_op;
  8717.           last_val = here_val;
  8718.           for (;;) {
  8719.             here = state.distcode[last_val +
  8720.                     ((hold & ((1 << (last_bits + last_op)) - 1))/*BITS(last.bits + last.op)*/ >> last_bits)];
  8721.             here_bits = here >>> 24;
  8722.             here_op = (here >>> 16) & 0xff;
  8723.             here_val = here & 0xffff;
  8724.  
  8725.             if ((last_bits + here_bits) <= bits) { break; }
  8726.             //--- PULLBYTE() ---//
  8727.             if (have === 0) { break inf_leave; }
  8728.             have--;
  8729.             hold += input[next++] << bits;
  8730.             bits += 8;
  8731.             //---//
  8732.           }
  8733.           //--- DROPBITS(last.bits) ---//
  8734.           hold >>>= last_bits;
  8735.           bits -= last_bits;
  8736.           //---//
  8737.           state.back += last_bits;
  8738.         }
  8739.         //--- DROPBITS(here.bits) ---//
  8740.         hold >>>= here_bits;
  8741.         bits -= here_bits;
  8742.         //---//
  8743.         state.back += here_bits;
  8744.         if (here_op & 64) {
  8745.           strm.msg = 'invalid distance code';
  8746.           state.mode = BAD;
  8747.           break;
  8748.         }
  8749.         state.offset = here_val;
  8750.         state.extra = (here_op) & 15;
  8751.         state.mode = DISTEXT;
  8752.         /* falls through */
  8753.       case DISTEXT:
  8754.         if (state.extra) {
  8755.           //=== NEEDBITS(state.extra);
  8756.           n = state.extra;
  8757.           while (bits < n) {
  8758.             if (have === 0) { break inf_leave; }
  8759.             have--;
  8760.             hold += input[next++] << bits;
  8761.             bits += 8;
  8762.           }
  8763.           //===//
  8764.           state.offset += hold & ((1 << state.extra) - 1)/*BITS(state.extra)*/;
  8765.           //--- DROPBITS(state.extra) ---//
  8766.           hold >>>= state.extra;
  8767.           bits -= state.extra;
  8768.           //---//
  8769.           state.back += state.extra;
  8770.         }
  8771. //#ifdef INFLATE_STRICT
  8772.         if (state.offset > state.dmax) {
  8773.           strm.msg = 'invalid distance too far back';
  8774.           state.mode = BAD;
  8775.           break;
  8776.         }
  8777. //#endif
  8778.         //Tracevv((stderr, "inflate:         distance %u\n", state.offset));
  8779.         state.mode = MATCH;
  8780.         /* falls through */
  8781.       case MATCH:
  8782.         if (left === 0) { break inf_leave; }
  8783.         copy = _out - left;
  8784.         if (state.offset > copy) {         /* copy from window */
  8785.           copy = state.offset - copy;
  8786.           if (copy > state.whave) {
  8787.             if (state.sane) {
  8788.               strm.msg = 'invalid distance too far back';
  8789.               state.mode = BAD;
  8790.               break;
  8791.             }
  8792. // (!) This block is disabled in zlib defaults,
  8793. // don't enable it for binary compatibility
  8794. //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
  8795. //          Trace((stderr, "inflate.c too far\n"));
  8796. //          copy -= state.whave;
  8797. //          if (copy > state.length) { copy = state.length; }
  8798. //          if (copy > left) { copy = left; }
  8799. //          left -= copy;
  8800. //          state.length -= copy;
  8801. //          do {
  8802. //            output[put++] = 0;
  8803. //          } while (--copy);
  8804. //          if (state.length === 0) { state.mode = LEN; }
  8805. //          break;
  8806. //#endif
  8807.           }
  8808.           if (copy > state.wnext) {
  8809.             copy -= state.wnext;
  8810.             from = state.wsize - copy;
  8811.           }
  8812.           else {
  8813.             from = state.wnext - copy;
  8814.           }
  8815.           if (copy > state.length) { copy = state.length; }
  8816.           from_source = state.window;
  8817.         }
  8818.         else {                              /* copy from output */
  8819.           from_source = output;
  8820.           from = put - state.offset;
  8821.           copy = state.length;
  8822.         }
  8823.         if (copy > left) { copy = left; }
  8824.         left -= copy;
  8825.         state.length -= copy;
  8826.         do {
  8827.           output[put++] = from_source[from++];
  8828.         } while (--copy);
  8829.         if (state.length === 0) { state.mode = LEN; }
  8830.         break;
  8831.       case LIT:
  8832.         if (left === 0) { break inf_leave; }
  8833.         output[put++] = state.length;
  8834.         left--;
  8835.         state.mode = LEN;
  8836.         break;
  8837.       case CHECK:
  8838.         if (state.wrap) {
  8839.           //=== NEEDBITS(32);
  8840.           while (bits < 32) {
  8841.             if (have === 0) { break inf_leave; }
  8842.             have--;
  8843.             // Use '|' instead of '+' to make sure that result is signed
  8844.             hold |= input[next++] << bits;
  8845.             bits += 8;
  8846.           }
  8847.           //===//
  8848.           _out -= left;
  8849.           strm.total_out += _out;
  8850.           state.total += _out;
  8851.           if (_out) {
  8852.             strm.adler = state.check =
  8853.                 /*UPDATE(state.check, put - _out, _out);*/
  8854.                 (state.flags ? crc32(state.check, output, _out, put - _out) : adler32(state.check, output, _out, put - _out));
  8855.  
  8856.           }
  8857.           _out = left;
  8858.           // NB: crc32 stored as signed 32-bit int, zswap32 returns signed too
  8859.           if ((state.flags ? hold : zswap32(hold)) !== state.check) {
  8860.             strm.msg = 'incorrect data check';
  8861.             state.mode = BAD;
  8862.             break;
  8863.           }
  8864.           //=== INITBITS();
  8865.           hold = 0;
  8866.           bits = 0;
  8867.           //===//
  8868.           //Tracev((stderr, "inflate:   check matches trailer\n"));
  8869.         }
  8870.         state.mode = LENGTH;
  8871.         /* falls through */
  8872.       case LENGTH:
  8873.         if (state.wrap && state.flags) {
  8874.           //=== NEEDBITS(32);
  8875.           while (bits < 32) {
  8876.             if (have === 0) { break inf_leave; }
  8877.             have--;
  8878.             hold += input[next++] << bits;
  8879.             bits += 8;
  8880.           }
  8881.           //===//
  8882.           if (hold !== (state.total & 0xffffffff)) {
  8883.             strm.msg = 'incorrect length check';
  8884.             state.mode = BAD;
  8885.             break;
  8886.           }
  8887.           //=== INITBITS();
  8888.           hold = 0;
  8889.           bits = 0;
  8890.           //===//
  8891.           //Tracev((stderr, "inflate:   length matches trailer\n"));
  8892.         }
  8893.         state.mode = DONE;
  8894.         /* falls through */
  8895.       case DONE:
  8896.         ret = Z_STREAM_END;
  8897.         break inf_leave;
  8898.       case BAD:
  8899.         ret = Z_DATA_ERROR;
  8900.         break inf_leave;
  8901.       case MEM:
  8902.         return Z_MEM_ERROR;
  8903.       case SYNC:
  8904.         /* falls through */
  8905.       default:
  8906.         return Z_STREAM_ERROR;
  8907.     }
  8908.   }
  8909.  
  8910.   // inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave"
  8911.  
  8912.   /*
  8913.      Return from inflate(), updating the total counts and the check value.
  8914.      If there was no progress during the inflate() call, return a buffer
  8915.      error.  Call updatewindow() to create and/or update the window state.
  8916.      Note: a memory error from inflate() is non-recoverable.
  8917.    */
  8918.  
  8919.   //--- RESTORE() ---
  8920.   strm.next_out = put;
  8921.   strm.avail_out = left;
  8922.   strm.next_in = next;
  8923.   strm.avail_in = have;
  8924.   state.hold = hold;
  8925.   state.bits = bits;
  8926.   //---
  8927.  
  8928.   if (state.wsize || (_out !== strm.avail_out && state.mode < BAD &&
  8929.                       (state.mode < CHECK || flush !== Z_FINISH))) {
  8930.     if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) {
  8931.       state.mode = MEM;
  8932.       return Z_MEM_ERROR;
  8933.     }
  8934.   }
  8935.   _in -= strm.avail_in;
  8936.   _out -= strm.avail_out;
  8937.   strm.total_in += _in;
  8938.   strm.total_out += _out;
  8939.   state.total += _out;
  8940.   if (state.wrap && _out) {
  8941.     strm.adler = state.check = /*UPDATE(state.check, strm.next_out - _out, _out);*/
  8942.       (state.flags ? crc32(state.check, output, _out, strm.next_out - _out) : adler32(state.check, output, _out, strm.next_out - _out));
  8943.   }
  8944.   strm.data_type = state.bits + (state.last ? 64 : 0) +
  8945.                     (state.mode === TYPE ? 128 : 0) +
  8946.                     (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);
  8947.   if (((_in === 0 && _out === 0) || flush === Z_FINISH) && ret === Z_OK) {
  8948.     ret = Z_BUF_ERROR;
  8949.   }
  8950.   return ret;
  8951. }
  8952.  
  8953. function inflateEnd(strm) {
  8954.  
  8955.   if (!strm || !strm.state /*|| strm->zfree == (free_func)0*/) {
  8956.     return Z_STREAM_ERROR;
  8957.   }
  8958.  
  8959.   var state = strm.state;
  8960.   if (state.window) {
  8961.     state.window = null;
  8962.   }
  8963.   strm.state = null;
  8964.   return Z_OK;
  8965. }
  8966.  
  8967. function inflateGetHeader(strm, head) {
  8968.   var state;
  8969.  
  8970.   /* check state */
  8971.   if (!strm || !strm.state) { return Z_STREAM_ERROR; }
  8972.   state = strm.state;
  8973.   if ((state.wrap & 2) === 0) { return Z_STREAM_ERROR; }
  8974.  
  8975.   /* save header structure */
  8976.   state.head = head;
  8977.   head.done = false;
  8978.   return Z_OK;
  8979. }
  8980.  
  8981. function inflateSetDictionary(strm, dictionary) {
  8982.   var dictLength = dictionary.length;
  8983.  
  8984.   var state;
  8985.   var dictid;
  8986.   var ret;
  8987.  
  8988.   /* check state */
  8989.   if (!strm /* == Z_NULL */ || !strm.state /* == Z_NULL */) { return Z_STREAM_ERROR; }
  8990.   state = strm.state;
  8991.  
  8992.   if (state.wrap !== 0 && state.mode !== DICT) {
  8993.     return Z_STREAM_ERROR;
  8994.   }
  8995.  
  8996.   /* check for correct dictionary identifier */
  8997.   if (state.mode === DICT) {
  8998.     dictid = 1; /* adler32(0, null, 0)*/
  8999.     /* dictid = adler32(dictid, dictionary, dictLength); */
  9000.     dictid = adler32(dictid, dictionary, dictLength, 0);
  9001.     if (dictid !== state.check) {
  9002.       return Z_DATA_ERROR;
  9003.     }
  9004.   }
  9005.   /* copy dictionary to window using updatewindow(), which will amend the
  9006.    existing dictionary if appropriate */
  9007.   ret = updatewindow(strm, dictionary, dictLength, dictLength);
  9008.   if (ret) {
  9009.     state.mode = MEM;
  9010.     return Z_MEM_ERROR;
  9011.   }
  9012.   state.havedict = 1;
  9013.   // Tracev((stderr, "inflate:   dictionary set\n"));
  9014.   return Z_OK;
  9015. }
  9016.  
  9017. exports.inflateReset = inflateReset;
  9018. exports.inflateReset2 = inflateReset2;
  9019. exports.inflateResetKeep = inflateResetKeep;
  9020. exports.inflateInit = inflateInit;
  9021. exports.inflateInit2 = inflateInit2;
  9022. exports.inflate = inflate;
  9023. exports.inflateEnd = inflateEnd;
  9024. exports.inflateGetHeader = inflateGetHeader;
  9025. exports.inflateSetDictionary = inflateSetDictionary;
  9026. exports.inflateInfo = 'pako inflate (from Nodeca project)';
  9027.  
  9028. /* Not implemented
  9029. exports.inflateCopy = inflateCopy;
  9030. exports.inflateGetDictionary = inflateGetDictionary;
  9031. exports.inflateMark = inflateMark;
  9032. exports.inflatePrime = inflatePrime;
  9033. exports.inflateSync = inflateSync;
  9034. exports.inflateSyncPoint = inflateSyncPoint;
  9035. exports.inflateUndermine = inflateUndermine;
  9036. */
  9037.  
  9038. },{"../utils/common":17,"./adler32":18,"./crc32":20,"./inffast":22,"./inftrees":24}],24:[function(require,module,exports){
  9039. 'use strict';
  9040.  
  9041. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  9042. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  9043. //
  9044. // This software is provided 'as-is', without any express or implied
  9045. // warranty. In no event will the authors be held liable for any damages
  9046. // arising from the use of this software.
  9047. //
  9048. // Permission is granted to anyone to use this software for any purpose,
  9049. // including commercial applications, and to alter it and redistribute it
  9050. // freely, subject to the following restrictions:
  9051. //
  9052. // 1. The origin of this software must not be misrepresented; you must not
  9053. //   claim that you wrote the original software. If you use this software
  9054. //   in a product, an acknowledgment in the product documentation would be
  9055. //   appreciated but is not required.
  9056. // 2. Altered source versions must be plainly marked as such, and must not be
  9057. //   misrepresented as being the original software.
  9058. // 3. This notice may not be removed or altered from any source distribution.
  9059.  
  9060. var utils = require('../utils/common');
  9061.  
  9062. var MAXBITS = 15;
  9063. var ENOUGH_LENS = 852;
  9064. var ENOUGH_DISTS = 592;
  9065. //var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
  9066.  
  9067. var CODES = 0;
  9068. var LENS = 1;
  9069. var DISTS = 2;
  9070.  
  9071. var lbase = [ /* Length codes 257..285 base */
  9072.   3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  9073.   35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
  9074. ];
  9075.  
  9076. var lext = [ /* Length codes 257..285 extra */
  9077.   16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  9078.   19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78
  9079. ];
  9080.  
  9081. var dbase = [ /* Distance codes 0..29 base */
  9082.   1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  9083.   257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  9084.   8193, 12289, 16385, 24577, 0, 0
  9085. ];
  9086.  
  9087. var dext = [ /* Distance codes 0..29 extra */
  9088.   16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  9089.   23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  9090.   28, 28, 29, 29, 64, 64
  9091. ];
  9092.  
  9093. module.exports = function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts)
  9094. {
  9095.   var bits = opts.bits;
  9096.       //here = opts.here; /* table entry for duplication */
  9097.  
  9098.   var len = 0;               /* a code's length in bits */
  9099.   var sym = 0;               /* index of code symbols */
  9100.   var min = 0, max = 0;          /* minimum and maximum code lengths */
  9101.   var root = 0;              /* number of index bits for root table */
  9102.   var curr = 0;              /* number of index bits for current table */
  9103.   var drop = 0;              /* code bits to drop for sub-table */
  9104.   var left = 0;                   /* number of prefix codes available */
  9105.   var used = 0;              /* code entries in table used */
  9106.   var huff = 0;              /* Huffman code */
  9107.   var incr;              /* for incrementing code, index */
  9108.   var fill;              /* index for replicating entries */
  9109.   var low;               /* low bits for current root entry */
  9110.   var mask;              /* mask for low root bits */
  9111.   var next;             /* next available space in table */
  9112.   var base = null;     /* base value table to use */
  9113.   var base_index = 0;
  9114. //  var shoextra;    /* extra bits table to use */
  9115.   var end;                    /* use base and extra for symbol > end */
  9116.   var count = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1];    /* number of codes of each length */
  9117.   var offs = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1];     /* offsets in table for each length */
  9118.   var extra = null;
  9119.   var extra_index = 0;
  9120.  
  9121.   var here_bits, here_op, here_val;
  9122.  
  9123.   /*
  9124.    Process a set of code lengths to create a canonical Huffman code.  The
  9125.    code lengths are lens[0..codes-1].  Each length corresponds to the
  9126.    symbols 0..codes-1.  The Huffman code is generated by first sorting the
  9127.    symbols by length from short to long, and retaining the symbol order
  9128.    for codes with equal lengths.  Then the code starts with all zero bits
  9129.    for the first code of the shortest length, and the codes are integer
  9130.    increments for the same length, and zeros are appended as the length
  9131.    increases.  For the deflate format, these bits are stored backwards
  9132.    from their more natural integer increment ordering, and so when the
  9133.    decoding tables are built in the large loop below, the integer codes
  9134.    are incremented backwards.
  9135.  
  9136.    This routine assumes, but does not check, that all of the entries in
  9137.    lens[] are in the range 0..MAXBITS.  The caller must assure this.
  9138.    1..MAXBITS is interpreted as that code length.  zero means that that
  9139.    symbol does not occur in this code.
  9140.  
  9141.    The codes are sorted by computing a count of codes for each length,
  9142.    creating from that a table of starting indices for each length in the
  9143.    sorted table, and then entering the symbols in order in the sorted
  9144.    table.  The sorted table is work[], with that space being provided by
  9145.    the caller.
  9146.  
  9147.    The length counts are used for other purposes as well, i.e. finding
  9148.    the minimum and maximum length codes, determining if there are any
  9149.    codes at all, checking for a valid set of lengths, and looking ahead
  9150.    at length counts to determine sub-table sizes when building the
  9151.    decoding tables.
  9152.    */
  9153.  
  9154.   /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
  9155.   for (len = 0; len <= MAXBITS; len++) {
  9156.     count[len] = 0;
  9157.   }
  9158.   for (sym = 0; sym < codes; sym++) {
  9159.     count[lens[lens_index + sym]]++;
  9160.   }
  9161.  
  9162.   /* bound code lengths, force root to be within code lengths */
  9163.   root = bits;
  9164.   for (max = MAXBITS; max >= 1; max--) {
  9165.     if (count[max] !== 0) { break; }
  9166.   }
  9167.   if (root > max) {
  9168.     root = max;
  9169.   }
  9170.   if (max === 0) {                     /* no symbols to code at all */
  9171.     //table.op[opts.table_index] = 64;  //here.op = (var char)64;    /* invalid code marker */
  9172.     //table.bits[opts.table_index] = 1;   //here.bits = (var char)1;
  9173.     //table.val[opts.table_index++] = 0;   //here.val = (var short)0;
  9174.     table[table_index++] = (1 << 24) | (64 << 16) | 0;
  9175.  
  9176.  
  9177.     //table.op[opts.table_index] = 64;
  9178.     //table.bits[opts.table_index] = 1;
  9179.     //table.val[opts.table_index++] = 0;
  9180.     table[table_index++] = (1 << 24) | (64 << 16) | 0;
  9181.  
  9182.     opts.bits = 1;
  9183.     return 0;     /* no symbols, but wait for decoding to report error */
  9184.   }
  9185.   for (min = 1; min < max; min++) {
  9186.     if (count[min] !== 0) { break; }
  9187.   }
  9188.   if (root < min) {
  9189.     root = min;
  9190.   }
  9191.  
  9192.   /* check for an over-subscribed or incomplete set of lengths */
  9193.   left = 1;
  9194.   for (len = 1; len <= MAXBITS; len++) {
  9195.     left <<= 1;
  9196.     left -= count[len];
  9197.     if (left < 0) {
  9198.       return -1;
  9199.     }        /* over-subscribed */
  9200.   }
  9201.   if (left > 0 && (type === CODES || max !== 1)) {
  9202.     return -1;                      /* incomplete set */
  9203.   }
  9204.  
  9205.   /* generate offsets into symbol table for each length for sorting */
  9206.   offs[1] = 0;
  9207.   for (len = 1; len < MAXBITS; len++) {
  9208.     offs[len + 1] = offs[len] + count[len];
  9209.   }
  9210.  
  9211.   /* sort symbols by length, by symbol order within each length */
  9212.   for (sym = 0; sym < codes; sym++) {
  9213.     if (lens[lens_index + sym] !== 0) {
  9214.       work[offs[lens[lens_index + sym]]++] = sym;
  9215.     }
  9216.   }
  9217.  
  9218.   /*
  9219.    Create and fill in decoding tables.  In this loop, the table being
  9220.    filled is at next and has curr index bits.  The code being used is huff
  9221.    with length len.  That code is converted to an index by dropping drop
  9222.    bits off of the bottom.  For codes where len is less than drop + curr,
  9223.    those top drop + curr - len bits are incremented through all values to
  9224.    fill the table with replicated entries.
  9225.  
  9226.    root is the number of index bits for the root table.  When len exceeds
  9227.    root, sub-tables are created pointed to by the root entry with an index
  9228.    of the low root bits of huff.  This is saved in low to check for when a
  9229.    new sub-table should be started.  drop is zero when the root table is
  9230.    being filled, and drop is root when sub-tables are being filled.
  9231.  
  9232.    When a new sub-table is needed, it is necessary to look ahead in the
  9233.    code lengths to determine what size sub-table is needed.  The length
  9234.    counts are used for this, and so count[] is decremented as codes are
  9235.    entered in the tables.
  9236.  
  9237.    used keeps track of how many table entries have been allocated from the
  9238.    provided *table space.  It is checked for LENS and DIST tables against
  9239.    the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
  9240.    the initial root table size constants.  See the comments in inftrees.h
  9241.    for more information.
  9242.  
  9243.    sym increments through all symbols, and the loop terminates when
  9244.    all codes of length max, i.e. all codes, have been processed.  This
  9245.    routine permits incomplete codes, so another loop after this one fills
  9246.    in the rest of the decoding tables with invalid code markers.
  9247.    */
  9248.  
  9249.   /* set up for code type */
  9250.   // poor man optimization - use if-else instead of switch,
  9251.   // to avoid deopts in old v8
  9252.   if (type === CODES) {
  9253.     base = extra = work;    /* dummy value--not used */
  9254.     end = 19;
  9255.  
  9256.   } else if (type === LENS) {
  9257.     base = lbase;
  9258.     base_index -= 257;
  9259.     extra = lext;
  9260.     extra_index -= 257;
  9261.     end = 256;
  9262.  
  9263.   } else {                    /* DISTS */
  9264.     base = dbase;
  9265.     extra = dext;
  9266.     end = -1;
  9267.   }
  9268.  
  9269.   /* initialize opts for loop */
  9270.   huff = 0;                   /* starting code */
  9271.   sym = 0;                    /* starting code symbol */
  9272.   len = min;                  /* starting code length */
  9273.   next = table_index;              /* current table to fill in */
  9274.   curr = root;                /* current table index bits */
  9275.   drop = 0;                   /* current bits to drop from code for index */
  9276.   low = -1;                   /* trigger new sub-table when len > root */
  9277.   used = 1 << root;          /* use root table entries */
  9278.   mask = used - 1;            /* mask for comparing low */
  9279.  
  9280.   /* check available table space */
  9281.   if ((type === LENS && used > ENOUGH_LENS) ||
  9282.     (type === DISTS && used > ENOUGH_DISTS)) {
  9283.     return 1;
  9284.   }
  9285.  
  9286.   /* process all codes and make table entries */
  9287.   for (;;) {
  9288.     /* create table entry */
  9289.     here_bits = len - drop;
  9290.     if (work[sym] < end) {
  9291.       here_op = 0;
  9292.       here_val = work[sym];
  9293.     }
  9294.     else if (work[sym] > end) {
  9295.       here_op = extra[extra_index + work[sym]];
  9296.       here_val = base[base_index + work[sym]];
  9297.     }
  9298.     else {
  9299.       here_op = 32 + 64;         /* end of block */
  9300.       here_val = 0;
  9301.     }
  9302.  
  9303.     /* replicate for those indices with low len bits equal to huff */
  9304.     incr = 1 << (len - drop);
  9305.     fill = 1 << curr;
  9306.     min = fill;                 /* save offset to next table */
  9307.     do {
  9308.       fill -= incr;
  9309.       table[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val |0;
  9310.     } while (fill !== 0);
  9311.  
  9312.     /* backwards increment the len-bit code huff */
  9313.     incr = 1 << (len - 1);
  9314.     while (huff & incr) {
  9315.       incr >>= 1;
  9316.     }
  9317.     if (incr !== 0) {
  9318.       huff &= incr - 1;
  9319.       huff += incr;
  9320.     } else {
  9321.       huff = 0;
  9322.     }
  9323.  
  9324.     /* go to next symbol, update count, len */
  9325.     sym++;
  9326.     if (--count[len] === 0) {
  9327.       if (len === max) { break; }
  9328.       len = lens[lens_index + work[sym]];
  9329.     }
  9330.  
  9331.     /* create new sub-table if needed */
  9332.     if (len > root && (huff & mask) !== low) {
  9333.       /* if first time, transition to sub-tables */
  9334.       if (drop === 0) {
  9335.         drop = root;
  9336.       }
  9337.  
  9338.       /* increment past last table */
  9339.       next += min;            /* here min is 1 << curr */
  9340.  
  9341.       /* determine length of next table */
  9342.       curr = len - drop;
  9343.       left = 1 << curr;
  9344.       while (curr + drop < max) {
  9345.         left -= count[curr + drop];
  9346.         if (left <= 0) { break; }
  9347.         curr++;
  9348.         left <<= 1;
  9349.       }
  9350.  
  9351.       /* check for enough space */
  9352.       used += 1 << curr;
  9353.       if ((type === LENS && used > ENOUGH_LENS) ||
  9354.         (type === DISTS && used > ENOUGH_DISTS)) {
  9355.         return 1;
  9356.       }
  9357.  
  9358.       /* point entry in root table to sub-table */
  9359.       low = huff & mask;
  9360.       /*table.op[low] = curr;
  9361.       table.bits[low] = root;
  9362.       table.val[low] = next - opts.table_index;*/
  9363.       table[low] = (root << 24) | (curr << 16) | (next - table_index) |0;
  9364.     }
  9365.   }
  9366.  
  9367.   /* fill in remaining table entry if code is incomplete (guaranteed to have
  9368.    at most one remaining entry, since if the code is incomplete, the
  9369.    maximum code length that was allowed to get this far is one bit) */
  9370.   if (huff !== 0) {
  9371.     //table.op[next + huff] = 64;            /* invalid code marker */
  9372.     //table.bits[next + huff] = len - drop;
  9373.     //table.val[next + huff] = 0;
  9374.     table[next + huff] = ((len - drop) << 24) | (64 << 16) |0;
  9375.   }
  9376.  
  9377.   /* set return parameters */
  9378.   //opts.table_index += used;
  9379.   opts.bits = root;
  9380.   return 0;
  9381. };
  9382.  
  9383. },{"../utils/common":17}],25:[function(require,module,exports){
  9384. 'use strict';
  9385.  
  9386. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  9387. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  9388. //
  9389. // This software is provided 'as-is', without any express or implied
  9390. // warranty. In no event will the authors be held liable for any damages
  9391. // arising from the use of this software.
  9392. //
  9393. // Permission is granted to anyone to use this software for any purpose,
  9394. // including commercial applications, and to alter it and redistribute it
  9395. // freely, subject to the following restrictions:
  9396. //
  9397. // 1. The origin of this software must not be misrepresented; you must not
  9398. //   claim that you wrote the original software. If you use this software
  9399. //   in a product, an acknowledgment in the product documentation would be
  9400. //   appreciated but is not required.
  9401. // 2. Altered source versions must be plainly marked as such, and must not be
  9402. //   misrepresented as being the original software.
  9403. // 3. This notice may not be removed or altered from any source distribution.
  9404.  
  9405. module.exports = {
  9406.   2:      'need dictionary',     /* Z_NEED_DICT       2  */
  9407.   1:      'stream end',          /* Z_STREAM_END      1  */
  9408.   0:      '',                    /* Z_OK              0  */
  9409.   '-1':   'file error',          /* Z_ERRNO         (-1) */
  9410.   '-2':   'stream error',        /* Z_STREAM_ERROR  (-2) */
  9411.   '-3':   'data error',          /* Z_DATA_ERROR    (-3) */
  9412.   '-4':   'insufficient memory', /* Z_MEM_ERROR     (-4) */
  9413.   '-5':   'buffer error',        /* Z_BUF_ERROR     (-5) */
  9414.   '-6':   'incompatible version' /* Z_VERSION_ERROR (-6) */
  9415. };
  9416.  
  9417. },{}],26:[function(require,module,exports){
  9418. 'use strict';
  9419.  
  9420. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  9421. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  9422. //
  9423. // This software is provided 'as-is', without any express or implied
  9424. // warranty. In no event will the authors be held liable for any damages
  9425. // arising from the use of this software.
  9426. //
  9427. // Permission is granted to anyone to use this software for any purpose,
  9428. // including commercial applications, and to alter it and redistribute it
  9429. // freely, subject to the following restrictions:
  9430. //
  9431. // 1. The origin of this software must not be misrepresented; you must not
  9432. //   claim that you wrote the original software. If you use this software
  9433. //   in a product, an acknowledgment in the product documentation would be
  9434. //   appreciated but is not required.
  9435. // 2. Altered source versions must be plainly marked as such, and must not be
  9436. //   misrepresented as being the original software.
  9437. // 3. This notice may not be removed or altered from any source distribution.
  9438.  
  9439. /* eslint-disable space-unary-ops */
  9440.  
  9441. var utils = require('../utils/common');
  9442.  
  9443. /* Public constants ==========================================================*/
  9444. /* ===========================================================================*/
  9445.  
  9446.  
  9447. //var Z_FILTERED          = 1;
  9448. //var Z_HUFFMAN_ONLY      = 2;
  9449. //var Z_RLE               = 3;
  9450. var Z_FIXED               = 4;
  9451. //var Z_DEFAULT_STRATEGY  = 0;
  9452.  
  9453. /* Possible values of the data_type field (though see inflate()) */
  9454. var Z_BINARY              = 0;
  9455. var Z_TEXT                = 1;
  9456. //var Z_ASCII             = 1; // = Z_TEXT
  9457. var Z_UNKNOWN             = 2;
  9458.  
  9459. /*============================================================================*/
  9460.  
  9461.  
  9462. function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
  9463.  
  9464. // From zutil.h
  9465.  
  9466. var STORED_BLOCK = 0;
  9467. var STATIC_TREES = 1;
  9468. var DYN_TREES    = 2;
  9469. /* The three kinds of block type */
  9470.  
  9471. var MIN_MATCH    = 3;
  9472. var MAX_MATCH    = 258;
  9473. /* The minimum and maximum match lengths */
  9474.  
  9475. // From deflate.h
  9476. /* ===========================================================================
  9477.  * Internal compression state.
  9478.  */
  9479.  
  9480. var LENGTH_CODES  = 29;
  9481. /* number of length codes, not counting the special END_BLOCK code */
  9482.  
  9483. var LITERALS      = 256;
  9484. /* number of literal bytes 0..255 */
  9485.  
  9486. var L_CODES       = LITERALS + 1 + LENGTH_CODES;
  9487. /* number of Literal or Length codes, including the END_BLOCK code */
  9488.  
  9489. var D_CODES       = 30;
  9490. /* number of distance codes */
  9491.  
  9492. var BL_CODES      = 19;
  9493. /* number of codes used to transfer the bit lengths */
  9494.  
  9495. var HEAP_SIZE     = 2 * L_CODES + 1;
  9496. /* maximum heap size */
  9497.  
  9498. var MAX_BITS      = 15;
  9499. /* All codes must not exceed MAX_BITS bits */
  9500.  
  9501. var Buf_size      = 16;
  9502. /* size of bit buffer in bi_buf */
  9503.  
  9504.  
  9505. /* ===========================================================================
  9506.  * Constants
  9507.  */
  9508.  
  9509. var MAX_BL_BITS = 7;
  9510. /* Bit length codes must not exceed MAX_BL_BITS bits */
  9511.  
  9512. var END_BLOCK   = 256;
  9513. /* end of block literal code */
  9514.  
  9515. var REP_3_6     = 16;
  9516. /* repeat previous bit length 3-6 times (2 bits of repeat count) */
  9517.  
  9518. var REPZ_3_10   = 17;
  9519. /* repeat a zero length 3-10 times  (3 bits of repeat count) */
  9520.  
  9521. var REPZ_11_138 = 18;
  9522. /* repeat a zero length 11-138 times  (7 bits of repeat count) */
  9523.  
  9524. /* eslint-disable comma-spacing,array-bracket-spacing */
  9525. var extra_lbits =   /* extra bits for each length code */
  9526.   [0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0];
  9527.  
  9528. var extra_dbits =   /* extra bits for each distance code */
  9529.   [0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];
  9530.  
  9531. var extra_blbits =  /* extra bits for each bit length code */
  9532.   [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7];
  9533.  
  9534. var bl_order =
  9535.   [16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];
  9536. /* eslint-enable comma-spacing,array-bracket-spacing */
  9537.  
  9538. /* The lengths of the bit length codes are sent in order of decreasing
  9539.  * probability, to avoid transmitting the lengths for unused bit length codes.
  9540.  */
  9541.  
  9542. /* ===========================================================================
  9543.  * Local data. These are initialized only once.
  9544.  */
  9545.  
  9546. // We pre-fill arrays with 0 to avoid uninitialized gaps
  9547.  
  9548. var DIST_CODE_LEN = 512; /* see definition of array dist_code below */
  9549.  
  9550. // !!!! Use flat array instead of structure, Freq = i*2, Len = i*2+1
  9551. var static_ltree  = new Array((L_CODES + 2) * 2);
  9552. zero(static_ltree);
  9553. /* The static literal tree. Since the bit lengths are imposed, there is no
  9554.  * need for the L_CODES extra codes used during heap construction. However
  9555.  * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
  9556.  * below).
  9557.  */
  9558.  
  9559. var static_dtree  = new Array(D_CODES * 2);
  9560. zero(static_dtree);
  9561. /* The static distance tree. (Actually a trivial tree since all codes use
  9562.  * 5 bits.)
  9563.  */
  9564.  
  9565. var _dist_code    = new Array(DIST_CODE_LEN);
  9566. zero(_dist_code);
  9567. /* Distance codes. The first 256 values correspond to the distances
  9568.  * 3 .. 258, the last 256 values correspond to the top 8 bits of
  9569.  * the 15 bit distances.
  9570.  */
  9571.  
  9572. var _length_code  = new Array(MAX_MATCH - MIN_MATCH + 1);
  9573. zero(_length_code);
  9574. /* length code for each normalized match length (0 == MIN_MATCH) */
  9575.  
  9576. var base_length   = new Array(LENGTH_CODES);
  9577. zero(base_length);
  9578. /* First normalized length for each code (0 = MIN_MATCH) */
  9579.  
  9580. var base_dist     = new Array(D_CODES);
  9581. zero(base_dist);
  9582. /* First normalized distance for each code (0 = distance of 1) */
  9583.  
  9584.  
  9585. function StaticTreeDesc(static_tree, extra_bits, extra_base, elems, max_length) {
  9586.  
  9587.   this.static_tree  = static_tree;  /* static tree or NULL */
  9588.   this.extra_bits   = extra_bits;   /* extra bits for each code or NULL */
  9589.   this.extra_base   = extra_base;   /* base index for extra_bits */
  9590.   this.elems        = elems;        /* max number of elements in the tree */
  9591.   this.max_length   = max_length;   /* max bit length for the codes */
  9592.  
  9593.   // show if `static_tree` has data or dummy - needed for monomorphic objects
  9594.   this.has_stree    = static_tree && static_tree.length;
  9595. }
  9596.  
  9597.  
  9598. var static_l_desc;
  9599. var static_d_desc;
  9600. var static_bl_desc;
  9601.  
  9602.  
  9603. function TreeDesc(dyn_tree, stat_desc) {
  9604.   this.dyn_tree = dyn_tree;     /* the dynamic tree */
  9605.   this.max_code = 0;            /* largest code with non zero frequency */
  9606.   this.stat_desc = stat_desc;   /* the corresponding static tree */
  9607. }
  9608.  
  9609.  
  9610.  
  9611. function d_code(dist) {
  9612.   return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];
  9613. }
  9614.  
  9615.  
  9616. /* ===========================================================================
  9617.  * Output a short LSB first on the stream.
  9618.  * IN assertion: there is enough room in pendingBuf.
  9619.  */
  9620. function put_short(s, w) {
  9621. //    put_byte(s, (uch)((w) & 0xff));
  9622. //    put_byte(s, (uch)((ush)(w) >> 8));
  9623.   s.pending_buf[s.pending++] = (w) & 0xff;
  9624.   s.pending_buf[s.pending++] = (w >>> 8) & 0xff;
  9625. }
  9626.  
  9627.  
  9628. /* ===========================================================================
  9629.  * Send a value on a given number of bits.
  9630.  * IN assertion: length <= 16 and value fits in length bits.
  9631.  */
  9632. function send_bits(s, value, length) {
  9633.   if (s.bi_valid > (Buf_size - length)) {
  9634.     s.bi_buf |= (value << s.bi_valid) & 0xffff;
  9635.     put_short(s, s.bi_buf);
  9636.     s.bi_buf = value >> (Buf_size - s.bi_valid);
  9637.     s.bi_valid += length - Buf_size;
  9638.   } else {
  9639.     s.bi_buf |= (value << s.bi_valid) & 0xffff;
  9640.     s.bi_valid += length;
  9641.   }
  9642. }
  9643.  
  9644.  
  9645. function send_code(s, c, tree) {
  9646.   send_bits(s, tree[c * 2]/*.Code*/, tree[c * 2 + 1]/*.Len*/);
  9647. }
  9648.  
  9649.  
  9650. /* ===========================================================================
  9651.  * Reverse the first len bits of a code, using straightforward code (a faster
  9652.  * method would use a table)
  9653.  * IN assertion: 1 <= len <= 15
  9654.  */
  9655. function bi_reverse(code, len) {
  9656.   var res = 0;
  9657.   do {
  9658.     res |= code & 1;
  9659.     code >>>= 1;
  9660.     res <<= 1;
  9661.   } while (--len > 0);
  9662.   return res >>> 1;
  9663. }
  9664.  
  9665.  
  9666. /* ===========================================================================
  9667.  * Flush the bit buffer, keeping at most 7 bits in it.
  9668.  */
  9669. function bi_flush(s) {
  9670.   if (s.bi_valid === 16) {
  9671.     put_short(s, s.bi_buf);
  9672.     s.bi_buf = 0;
  9673.     s.bi_valid = 0;
  9674.  
  9675.   } else if (s.bi_valid >= 8) {
  9676.     s.pending_buf[s.pending++] = s.bi_buf & 0xff;
  9677.     s.bi_buf >>= 8;
  9678.     s.bi_valid -= 8;
  9679.   }
  9680. }
  9681.  
  9682.  
  9683. /* ===========================================================================
  9684.  * Compute the optimal bit lengths for a tree and update the total bit length
  9685.  * for the current block.
  9686.  * IN assertion: the fields freq and dad are set, heap[heap_max] and
  9687.  *    above are the tree nodes sorted by increasing frequency.
  9688.  * OUT assertions: the field len is set to the optimal bit length, the
  9689.  *     array bl_count contains the frequencies for each bit length.
  9690.  *     The length opt_len is updated; static_len is also updated if stree is
  9691.  *     not null.
  9692.  */
  9693. function gen_bitlen(s, desc)
  9694. //    deflate_state *s;
  9695. //    tree_desc *desc;    /* the tree descriptor */
  9696. {
  9697.   var tree            = desc.dyn_tree;
  9698.   var max_code        = desc.max_code;
  9699.   var stree           = desc.stat_desc.static_tree;
  9700.   var has_stree       = desc.stat_desc.has_stree;
  9701.   var extra           = desc.stat_desc.extra_bits;
  9702.   var base            = desc.stat_desc.extra_base;
  9703.   var max_length      = desc.stat_desc.max_length;
  9704.   var h;              /* heap index */
  9705.   var n, m;           /* iterate over the tree elements */
  9706.   var bits;           /* bit length */
  9707.   var xbits;          /* extra bits */
  9708.   var f;              /* frequency */
  9709.   var overflow = 0;   /* number of elements with bit length too large */
  9710.  
  9711.   for (bits = 0; bits <= MAX_BITS; bits++) {
  9712.     s.bl_count[bits] = 0;
  9713.   }
  9714.  
  9715.   /* In a first pass, compute the optimal bit lengths (which may
  9716.    * overflow in the case of the bit length tree).
  9717.    */
  9718.   tree[s.heap[s.heap_max] * 2 + 1]/*.Len*/ = 0; /* root of the heap */
  9719.  
  9720.   for (h = s.heap_max + 1; h < HEAP_SIZE; h++) {
  9721.     n = s.heap[h];
  9722.     bits = tree[tree[n * 2 + 1]/*.Dad*/ * 2 + 1]/*.Len*/ + 1;
  9723.     if (bits > max_length) {
  9724.       bits = max_length;
  9725.       overflow++;
  9726.     }
  9727.     tree[n * 2 + 1]/*.Len*/ = bits;
  9728.     /* We overwrite tree[n].Dad which is no longer needed */
  9729.  
  9730.     if (n > max_code) { continue; } /* not a leaf node */
  9731.  
  9732.     s.bl_count[bits]++;
  9733.     xbits = 0;
  9734.     if (n >= base) {
  9735.       xbits = extra[n - base];
  9736.     }
  9737.     f = tree[n * 2]/*.Freq*/;
  9738.     s.opt_len += f * (bits + xbits);
  9739.     if (has_stree) {
  9740.       s.static_len += f * (stree[n * 2 + 1]/*.Len*/ + xbits);
  9741.     }
  9742.   }
  9743.   if (overflow === 0) { return; }
  9744.  
  9745.   // Trace((stderr,"\nbit length overflow\n"));
  9746.   /* This happens for example on obj2 and pic of the Calgary corpus */
  9747.  
  9748.   /* Find the first bit length which could increase: */
  9749.   do {
  9750.     bits = max_length - 1;
  9751.     while (s.bl_count[bits] === 0) { bits--; }
  9752.     s.bl_count[bits]--;      /* move one leaf down the tree */
  9753.     s.bl_count[bits + 1] += 2; /* move one overflow item as its brother */
  9754.     s.bl_count[max_length]--;
  9755.     /* The brother of the overflow item also moves one step up,
  9756.      * but this does not affect bl_count[max_length]
  9757.      */
  9758.     overflow -= 2;
  9759.   } while (overflow > 0);
  9760.  
  9761.   /* Now recompute all bit lengths, scanning in increasing frequency.
  9762.    * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
  9763.    * lengths instead of fixing only the wrong ones. This idea is taken
  9764.    * from 'ar' written by Haruhiko Okumura.)
  9765.    */
  9766.   for (bits = max_length; bits !== 0; bits--) {
  9767.     n = s.bl_count[bits];
  9768.     while (n !== 0) {
  9769.       m = s.heap[--h];
  9770.       if (m > max_code) { continue; }
  9771.       if (tree[m * 2 + 1]/*.Len*/ !== bits) {
  9772.         // Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  9773.         s.opt_len += (bits - tree[m * 2 + 1]/*.Len*/) * tree[m * 2]/*.Freq*/;
  9774.         tree[m * 2 + 1]/*.Len*/ = bits;
  9775.       }
  9776.       n--;
  9777.     }
  9778.   }
  9779. }
  9780.  
  9781.  
  9782. /* ===========================================================================
  9783.  * Generate the codes for a given tree and bit counts (which need not be
  9784.  * optimal).
  9785.  * IN assertion: the array bl_count contains the bit length statistics for
  9786.  * the given tree and the field len is set for all tree elements.
  9787.  * OUT assertion: the field code is set for all tree elements of non
  9788.  *     zero code length.
  9789.  */
  9790. function gen_codes(tree, max_code, bl_count)
  9791. //    ct_data *tree;             /* the tree to decorate */
  9792. //    int max_code;              /* largest code with non zero frequency */
  9793. //    ushf *bl_count;            /* number of codes at each bit length */
  9794. {
  9795.   var next_code = new Array(MAX_BITS + 1); /* next code value for each bit length */
  9796.   var code = 0;              /* running code value */
  9797.   var bits;                  /* bit index */
  9798.   var n;                     /* code index */
  9799.  
  9800.   /* The distribution counts are first used to generate the code values
  9801.    * without bit reversal.
  9802.    */
  9803.   for (bits = 1; bits <= MAX_BITS; bits++) {
  9804.     next_code[bits] = code = (code + bl_count[bits - 1]) << 1;
  9805.   }
  9806.   /* Check that the bit counts in bl_count are consistent. The last code
  9807.    * must be all ones.
  9808.    */
  9809.   //Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  9810.   //        "inconsistent bit counts");
  9811.   //Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  9812.  
  9813.   for (n = 0;  n <= max_code; n++) {
  9814.     var len = tree[n * 2 + 1]/*.Len*/;
  9815.     if (len === 0) { continue; }
  9816.     /* Now reverse the bits */
  9817.     tree[n * 2]/*.Code*/ = bi_reverse(next_code[len]++, len);
  9818.  
  9819.     //Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  9820.     //     n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  9821.   }
  9822. }
  9823.  
  9824.  
  9825. /* ===========================================================================
  9826.  * Initialize the various 'constant' tables.
  9827.  */
  9828. function tr_static_init() {
  9829.   var n;        /* iterates over tree elements */
  9830.   var bits;     /* bit counter */
  9831.   var length;   /* length value */
  9832.   var code;     /* code value */
  9833.   var dist;     /* distance index */
  9834.   var bl_count = new Array(MAX_BITS + 1);
  9835.   /* number of codes at each bit length for an optimal tree */
  9836.  
  9837.   // do check in _tr_init()
  9838.   //if (static_init_done) return;
  9839.  
  9840.   /* For some embedded targets, global variables are not initialized: */
  9841. /*#ifdef NO_INIT_GLOBAL_POINTERS
  9842.   static_l_desc.static_tree = static_ltree;
  9843.   static_l_desc.extra_bits = extra_lbits;
  9844.   static_d_desc.static_tree = static_dtree;
  9845.   static_d_desc.extra_bits = extra_dbits;
  9846.   static_bl_desc.extra_bits = extra_blbits;
  9847. #endif*/
  9848.  
  9849.   /* Initialize the mapping length (0..255) -> length code (0..28) */
  9850.   length = 0;
  9851.   for (code = 0; code < LENGTH_CODES - 1; code++) {
  9852.     base_length[code] = length;
  9853.     for (n = 0; n < (1 << extra_lbits[code]); n++) {
  9854.       _length_code[length++] = code;
  9855.     }
  9856.   }
  9857.   //Assert (length == 256, "tr_static_init: length != 256");
  9858.   /* Note that the length 255 (match length 258) can be represented
  9859.    * in two different ways: code 284 + 5 bits or code 285, so we
  9860.    * overwrite length_code[255] to use the best encoding:
  9861.    */
  9862.   _length_code[length - 1] = code;
  9863.  
  9864.   /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
  9865.   dist = 0;
  9866.   for (code = 0; code < 16; code++) {
  9867.     base_dist[code] = dist;
  9868.     for (n = 0; n < (1 << extra_dbits[code]); n++) {
  9869.       _dist_code[dist++] = code;
  9870.     }
  9871.   }
  9872.   //Assert (dist == 256, "tr_static_init: dist != 256");
  9873.   dist >>= 7; /* from now on, all distances are divided by 128 */
  9874.   for (; code < D_CODES; code++) {
  9875.     base_dist[code] = dist << 7;
  9876.     for (n = 0; n < (1 << (extra_dbits[code] - 7)); n++) {
  9877.       _dist_code[256 + dist++] = code;
  9878.     }
  9879.   }
  9880.   //Assert (dist == 256, "tr_static_init: 256+dist != 512");
  9881.  
  9882.   /* Construct the codes of the static literal tree */
  9883.   for (bits = 0; bits <= MAX_BITS; bits++) {
  9884.     bl_count[bits] = 0;
  9885.   }
  9886.  
  9887.   n = 0;
  9888.   while (n <= 143) {
  9889.     static_ltree[n * 2 + 1]/*.Len*/ = 8;
  9890.     n++;
  9891.     bl_count[8]++;
  9892.   }
  9893.   while (n <= 255) {
  9894.     static_ltree[n * 2 + 1]/*.Len*/ = 9;
  9895.     n++;
  9896.     bl_count[9]++;
  9897.   }
  9898.   while (n <= 279) {
  9899.     static_ltree[n * 2 + 1]/*.Len*/ = 7;
  9900.     n++;
  9901.     bl_count[7]++;
  9902.   }
  9903.   while (n <= 287) {
  9904.     static_ltree[n * 2 + 1]/*.Len*/ = 8;
  9905.     n++;
  9906.     bl_count[8]++;
  9907.   }
  9908.   /* Codes 286 and 287 do not exist, but we must include them in the
  9909.    * tree construction to get a canonical Huffman tree (longest code
  9910.    * all ones)
  9911.    */
  9912.   gen_codes(static_ltree, L_CODES + 1, bl_count);
  9913.  
  9914.   /* The static distance tree is trivial: */
  9915.   for (n = 0; n < D_CODES; n++) {
  9916.     static_dtree[n * 2 + 1]/*.Len*/ = 5;
  9917.     static_dtree[n * 2]/*.Code*/ = bi_reverse(n, 5);
  9918.   }
  9919.  
  9920.   // Now data ready and we can init static trees
  9921.   static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS + 1, L_CODES, MAX_BITS);
  9922.   static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0,          D_CODES, MAX_BITS);
  9923.   static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0,         BL_CODES, MAX_BL_BITS);
  9924.  
  9925.   //static_init_done = true;
  9926. }
  9927.  
  9928.  
  9929. /* ===========================================================================
  9930.  * Initialize a new block.
  9931.  */
  9932. function init_block(s) {
  9933.   var n; /* iterates over tree elements */
  9934.  
  9935.   /* Initialize the trees. */
  9936.   for (n = 0; n < L_CODES;  n++) { s.dyn_ltree[n * 2]/*.Freq*/ = 0; }
  9937.   for (n = 0; n < D_CODES;  n++) { s.dyn_dtree[n * 2]/*.Freq*/ = 0; }
  9938.   for (n = 0; n < BL_CODES; n++) { s.bl_tree[n * 2]/*.Freq*/ = 0; }
  9939.  
  9940.   s.dyn_ltree[END_BLOCK * 2]/*.Freq*/ = 1;
  9941.   s.opt_len = s.static_len = 0;
  9942.   s.last_lit = s.matches = 0;
  9943. }
  9944.  
  9945.  
  9946. /* ===========================================================================
  9947.  * Flush the bit buffer and align the output on a byte boundary
  9948.  */
  9949. function bi_windup(s)
  9950. {
  9951.   if (s.bi_valid > 8) {
  9952.     put_short(s, s.bi_buf);
  9953.   } else if (s.bi_valid > 0) {
  9954.     //put_byte(s, (Byte)s->bi_buf);
  9955.     s.pending_buf[s.pending++] = s.bi_buf;
  9956.   }
  9957.   s.bi_buf = 0;
  9958.   s.bi_valid = 0;
  9959. }
  9960.  
  9961. /* ===========================================================================
  9962.  * Copy a stored block, storing first the length and its
  9963.  * one's complement if requested.
  9964.  */
  9965. function copy_block(s, buf, len, header)
  9966. //DeflateState *s;
  9967. //charf    *buf;    /* the input data */
  9968. //unsigned len;     /* its length */
  9969. //int      header;  /* true if block header must be written */
  9970. {
  9971.   bi_windup(s);        /* align on byte boundary */
  9972.  
  9973.   if (header) {
  9974.     put_short(s, len);
  9975.     put_short(s, ~len);
  9976.   }
  9977. //  while (len--) {
  9978. //    put_byte(s, *buf++);
  9979. //  }
  9980.   utils.arraySet(s.pending_buf, s.window, buf, len, s.pending);
  9981.   s.pending += len;
  9982. }
  9983.  
  9984. /* ===========================================================================
  9985.  * Compares to subtrees, using the tree depth as tie breaker when
  9986.  * the subtrees have equal frequency. This minimizes the worst case length.
  9987.  */
  9988. function smaller(tree, n, m, depth) {
  9989.   var _n2 = n * 2;
  9990.   var _m2 = m * 2;
  9991.   return (tree[_n2]/*.Freq*/ < tree[_m2]/*.Freq*/ ||
  9992.          (tree[_n2]/*.Freq*/ === tree[_m2]/*.Freq*/ && depth[n] <= depth[m]));
  9993. }
  9994.  
  9995. /* ===========================================================================
  9996.  * Restore the heap property by moving down the tree starting at node k,
  9997.  * exchanging a node with the smallest of its two sons if necessary, stopping
  9998.  * when the heap property is re-established (each father smaller than its
  9999.  * two sons).
  10000.  */
  10001. function pqdownheap(s, tree, k)
  10002. //    deflate_state *s;
  10003. //    ct_data *tree;  /* the tree to restore */
  10004. //    int k;               /* node to move down */
  10005. {
  10006.   var v = s.heap[k];
  10007.   var j = k << 1;  /* left son of k */
  10008.   while (j <= s.heap_len) {
  10009.     /* Set j to the smallest of the two sons: */
  10010.     if (j < s.heap_len &&
  10011.       smaller(tree, s.heap[j + 1], s.heap[j], s.depth)) {
  10012.       j++;
  10013.     }
  10014.     /* Exit if v is smaller than both sons */
  10015.     if (smaller(tree, v, s.heap[j], s.depth)) { break; }
  10016.  
  10017.     /* Exchange v with the smallest son */
  10018.     s.heap[k] = s.heap[j];
  10019.     k = j;
  10020.  
  10021.     /* And continue down the tree, setting j to the left son of k */
  10022.     j <<= 1;
  10023.   }
  10024.   s.heap[k] = v;
  10025. }
  10026.  
  10027.  
  10028. // inlined manually
  10029. // var SMALLEST = 1;
  10030.  
  10031. /* ===========================================================================
  10032.  * Send the block data compressed using the given Huffman trees
  10033.  */
  10034. function compress_block(s, ltree, dtree)
  10035. //    deflate_state *s;
  10036. //    const ct_data *ltree; /* literal tree */
  10037. //    const ct_data *dtree; /* distance tree */
  10038. {
  10039.   var dist;           /* distance of matched string */
  10040.   var lc;             /* match length or unmatched char (if dist == 0) */
  10041.   var lx = 0;         /* running index in l_buf */
  10042.   var code;           /* the code to send */
  10043.   var extra;          /* number of extra bits to send */
  10044.  
  10045.   if (s.last_lit !== 0) {
  10046.     do {
  10047.       dist = (s.pending_buf[s.d_buf + lx * 2] << 8) | (s.pending_buf[s.d_buf + lx * 2 + 1]);
  10048.       lc = s.pending_buf[s.l_buf + lx];
  10049.       lx++;
  10050.  
  10051.       if (dist === 0) {
  10052.         send_code(s, lc, ltree); /* send a literal byte */
  10053.         //Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  10054.       } else {
  10055.         /* Here, lc is the match length - MIN_MATCH */
  10056.         code = _length_code[lc];
  10057.         send_code(s, code + LITERALS + 1, ltree); /* send the length code */
  10058.         extra = extra_lbits[code];
  10059.         if (extra !== 0) {
  10060.           lc -= base_length[code];
  10061.           send_bits(s, lc, extra);       /* send the extra length bits */
  10062.         }
  10063.         dist--; /* dist is now the match distance - 1 */
  10064.         code = d_code(dist);
  10065.         //Assert (code < D_CODES, "bad d_code");
  10066.  
  10067.         send_code(s, code, dtree);       /* send the distance code */
  10068.         extra = extra_dbits[code];
  10069.         if (extra !== 0) {
  10070.           dist -= base_dist[code];
  10071.           send_bits(s, dist, extra);   /* send the extra distance bits */
  10072.         }
  10073.       } /* literal or match pair ? */
  10074.  
  10075.       /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
  10076.       //Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  10077.       //       "pendingBuf overflow");
  10078.  
  10079.     } while (lx < s.last_lit);
  10080.   }
  10081.  
  10082.   send_code(s, END_BLOCK, ltree);
  10083. }
  10084.  
  10085.  
  10086. /* ===========================================================================
  10087.  * Construct one Huffman tree and assigns the code bit strings and lengths.
  10088.  * Update the total bit length for the current block.
  10089.  * IN assertion: the field freq is set for all tree elements.
  10090.  * OUT assertions: the fields len and code are set to the optimal bit length
  10091.  *     and corresponding code. The length opt_len is updated; static_len is
  10092.  *     also updated if stree is not null. The field max_code is set.
  10093.  */
  10094. function build_tree(s, desc)
  10095. //    deflate_state *s;
  10096. //    tree_desc *desc; /* the tree descriptor */
  10097. {
  10098.   var tree     = desc.dyn_tree;
  10099.   var stree    = desc.stat_desc.static_tree;
  10100.   var has_stree = desc.stat_desc.has_stree;
  10101.   var elems    = desc.stat_desc.elems;
  10102.   var n, m;          /* iterate over heap elements */
  10103.   var max_code = -1; /* largest code with non zero frequency */
  10104.   var node;          /* new node being created */
  10105.  
  10106.   /* Construct the initial heap, with least frequent element in
  10107.    * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
  10108.    * heap[0] is not used.
  10109.    */
  10110.   s.heap_len = 0;
  10111.   s.heap_max = HEAP_SIZE;
  10112.  
  10113.   for (n = 0; n < elems; n++) {
  10114.     if (tree[n * 2]/*.Freq*/ !== 0) {
  10115.       s.heap[++s.heap_len] = max_code = n;
  10116.       s.depth[n] = 0;
  10117.  
  10118.     } else {
  10119.       tree[n * 2 + 1]/*.Len*/ = 0;
  10120.     }
  10121.   }
  10122.  
  10123.   /* The pkzip format requires that at least one distance code exists,
  10124.    * and that at least one bit should be sent even if there is only one
  10125.    * possible code. So to avoid special checks later on we force at least
  10126.    * two codes of non zero frequency.
  10127.    */
  10128.   while (s.heap_len < 2) {
  10129.     node = s.heap[++s.heap_len] = (max_code < 2 ? ++max_code : 0);
  10130.     tree[node * 2]/*.Freq*/ = 1;
  10131.     s.depth[node] = 0;
  10132.     s.opt_len--;
  10133.  
  10134.     if (has_stree) {
  10135.       s.static_len -= stree[node * 2 + 1]/*.Len*/;
  10136.     }
  10137.     /* node is 0 or 1 so it does not have extra bits */
  10138.   }
  10139.   desc.max_code = max_code;
  10140.  
  10141.   /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
  10142.    * establish sub-heaps of increasing lengths:
  10143.    */
  10144.   for (n = (s.heap_len >> 1/*int /2*/); n >= 1; n--) { pqdownheap(s, tree, n); }
  10145.  
  10146.   /* Construct the Huffman tree by repeatedly combining the least two
  10147.    * frequent nodes.
  10148.    */
  10149.   node = elems;              /* next internal node of the tree */
  10150.   do {
  10151.     //pqremove(s, tree, n);  /* n = node of least frequency */
  10152.     /*** pqremove ***/
  10153.     n = s.heap[1/*SMALLEST*/];
  10154.     s.heap[1/*SMALLEST*/] = s.heap[s.heap_len--];
  10155.     pqdownheap(s, tree, 1/*SMALLEST*/);
  10156.     /***/
  10157.  
  10158.     m = s.heap[1/*SMALLEST*/]; /* m = node of next least frequency */
  10159.  
  10160.     s.heap[--s.heap_max] = n; /* keep the nodes sorted by frequency */
  10161.     s.heap[--s.heap_max] = m;
  10162.  
  10163.     /* Create a new node father of n and m */
  10164.     tree[node * 2]/*.Freq*/ = tree[n * 2]/*.Freq*/ + tree[m * 2]/*.Freq*/;
  10165.     s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;
  10166.     tree[n * 2 + 1]/*.Dad*/ = tree[m * 2 + 1]/*.Dad*/ = node;
  10167.  
  10168.     /* and insert the new node in the heap */
  10169.     s.heap[1/*SMALLEST*/] = node++;
  10170.     pqdownheap(s, tree, 1/*SMALLEST*/);
  10171.  
  10172.   } while (s.heap_len >= 2);
  10173.  
  10174.   s.heap[--s.heap_max] = s.heap[1/*SMALLEST*/];
  10175.  
  10176.   /* At this point, the fields freq and dad are set. We can now
  10177.    * generate the bit lengths.
  10178.    */
  10179.   gen_bitlen(s, desc);
  10180.  
  10181.   /* The field len is now set, we can generate the bit codes */
  10182.   gen_codes(tree, max_code, s.bl_count);
  10183. }
  10184.  
  10185.  
  10186. /* ===========================================================================
  10187.  * Scan a literal or distance tree to determine the frequencies of the codes
  10188.  * in the bit length tree.
  10189.  */
  10190. function scan_tree(s, tree, max_code)
  10191. //    deflate_state *s;
  10192. //    ct_data *tree;   /* the tree to be scanned */
  10193. //    int max_code;    /* and its largest code of non zero frequency */
  10194. {
  10195.   var n;                     /* iterates over all tree elements */
  10196.   var prevlen = -1;          /* last emitted length */
  10197.   var curlen;                /* length of current code */
  10198.  
  10199.   var nextlen = tree[0 * 2 + 1]/*.Len*/; /* length of next code */
  10200.  
  10201.   var count = 0;             /* repeat count of the current code */
  10202.   var max_count = 7;         /* max repeat count */
  10203.   var min_count = 4;         /* min repeat count */
  10204.  
  10205.   if (nextlen === 0) {
  10206.     max_count = 138;
  10207.     min_count = 3;
  10208.   }
  10209.   tree[(max_code + 1) * 2 + 1]/*.Len*/ = 0xffff; /* guard */
  10210.  
  10211.   for (n = 0; n <= max_code; n++) {
  10212.     curlen = nextlen;
  10213.     nextlen = tree[(n + 1) * 2 + 1]/*.Len*/;
  10214.  
  10215.     if (++count < max_count && curlen === nextlen) {
  10216.       continue;
  10217.  
  10218.     } else if (count < min_count) {
  10219.       s.bl_tree[curlen * 2]/*.Freq*/ += count;
  10220.  
  10221.     } else if (curlen !== 0) {
  10222.  
  10223.       if (curlen !== prevlen) { s.bl_tree[curlen * 2]/*.Freq*/++; }
  10224.       s.bl_tree[REP_3_6 * 2]/*.Freq*/++;
  10225.  
  10226.     } else if (count <= 10) {
  10227.       s.bl_tree[REPZ_3_10 * 2]/*.Freq*/++;
  10228.  
  10229.     } else {
  10230.       s.bl_tree[REPZ_11_138 * 2]/*.Freq*/++;
  10231.     }
  10232.  
  10233.     count = 0;
  10234.     prevlen = curlen;
  10235.  
  10236.     if (nextlen === 0) {
  10237.       max_count = 138;
  10238.       min_count = 3;
  10239.  
  10240.     } else if (curlen === nextlen) {
  10241.       max_count = 6;
  10242.       min_count = 3;
  10243.  
  10244.     } else {
  10245.       max_count = 7;
  10246.       min_count = 4;
  10247.     }
  10248.   }
  10249. }
  10250.  
  10251.  
  10252. /* ===========================================================================
  10253.  * Send a literal or distance tree in compressed form, using the codes in
  10254.  * bl_tree.
  10255.  */
  10256. function send_tree(s, tree, max_code)
  10257. //    deflate_state *s;
  10258. //    ct_data *tree; /* the tree to be scanned */
  10259. //    int max_code;       /* and its largest code of non zero frequency */
  10260. {
  10261.   var n;                     /* iterates over all tree elements */
  10262.   var prevlen = -1;          /* last emitted length */
  10263.   var curlen;                /* length of current code */
  10264.  
  10265.   var nextlen = tree[0 * 2 + 1]/*.Len*/; /* length of next code */
  10266.  
  10267.   var count = 0;             /* repeat count of the current code */
  10268.   var max_count = 7;         /* max repeat count */
  10269.   var min_count = 4;         /* min repeat count */
  10270.  
  10271.   /* tree[max_code+1].Len = -1; */  /* guard already set */
  10272.   if (nextlen === 0) {
  10273.     max_count = 138;
  10274.     min_count = 3;
  10275.   }
  10276.  
  10277.   for (n = 0; n <= max_code; n++) {
  10278.     curlen = nextlen;
  10279.     nextlen = tree[(n + 1) * 2 + 1]/*.Len*/;
  10280.  
  10281.     if (++count < max_count && curlen === nextlen) {
  10282.       continue;
  10283.  
  10284.     } else if (count < min_count) {
  10285.       do { send_code(s, curlen, s.bl_tree); } while (--count !== 0);
  10286.  
  10287.     } else if (curlen !== 0) {
  10288.       if (curlen !== prevlen) {
  10289.         send_code(s, curlen, s.bl_tree);
  10290.         count--;
  10291.       }
  10292.       //Assert(count >= 3 && count <= 6, " 3_6?");
  10293.       send_code(s, REP_3_6, s.bl_tree);
  10294.       send_bits(s, count - 3, 2);
  10295.  
  10296.     } else if (count <= 10) {
  10297.       send_code(s, REPZ_3_10, s.bl_tree);
  10298.       send_bits(s, count - 3, 3);
  10299.  
  10300.     } else {
  10301.       send_code(s, REPZ_11_138, s.bl_tree);
  10302.       send_bits(s, count - 11, 7);
  10303.     }
  10304.  
  10305.     count = 0;
  10306.     prevlen = curlen;
  10307.     if (nextlen === 0) {
  10308.       max_count = 138;
  10309.       min_count = 3;
  10310.  
  10311.     } else if (curlen === nextlen) {
  10312.       max_count = 6;
  10313.       min_count = 3;
  10314.  
  10315.     } else {
  10316.       max_count = 7;
  10317.       min_count = 4;
  10318.     }
  10319.   }
  10320. }
  10321.  
  10322.  
  10323. /* ===========================================================================
  10324.  * Construct the Huffman tree for the bit lengths and return the index in
  10325.  * bl_order of the last bit length code to send.
  10326.  */
  10327. function build_bl_tree(s) {
  10328.   var max_blindex;  /* index of last bit length code of non zero freq */
  10329.  
  10330.   /* Determine the bit length frequencies for literal and distance trees */
  10331.   scan_tree(s, s.dyn_ltree, s.l_desc.max_code);
  10332.   scan_tree(s, s.dyn_dtree, s.d_desc.max_code);
  10333.  
  10334.   /* Build the bit length tree: */
  10335.   build_tree(s, s.bl_desc);
  10336.   /* opt_len now includes the length of the tree representations, except
  10337.    * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
  10338.    */
  10339.  
  10340.   /* Determine the number of bit length codes to send. The pkzip format
  10341.    * requires that at least 4 bit length codes be sent. (appnote.txt says
  10342.    * 3 but the actual value used is 4.)
  10343.    */
  10344.   for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) {
  10345.     if (s.bl_tree[bl_order[max_blindex] * 2 + 1]/*.Len*/ !== 0) {
  10346.       break;
  10347.     }
  10348.   }
  10349.   /* Update opt_len to include the bit length tree and counts */
  10350.   s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
  10351.   //Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  10352.   //        s->opt_len, s->static_len));
  10353.  
  10354.   return max_blindex;
  10355. }
  10356.  
  10357.  
  10358. /* ===========================================================================
  10359.  * Send the header for a block using dynamic Huffman trees: the counts, the
  10360.  * lengths of the bit length codes, the literal tree and the distance tree.
  10361.  * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
  10362.  */
  10363. function send_all_trees(s, lcodes, dcodes, blcodes)
  10364. //    deflate_state *s;
  10365. //    int lcodes, dcodes, blcodes; /* number of codes for each tree */
  10366. {
  10367.   var rank;                    /* index in bl_order */
  10368.  
  10369.   //Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  10370.   //Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  10371.   //        "too many codes");
  10372.   //Tracev((stderr, "\nbl counts: "));
  10373.   send_bits(s, lcodes - 257, 5); /* not +255 as stated in appnote.txt */
  10374.   send_bits(s, dcodes - 1,   5);
  10375.   send_bits(s, blcodes - 4,  4); /* not -3 as stated in appnote.txt */
  10376.   for (rank = 0; rank < blcodes; rank++) {
  10377.     //Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  10378.     send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1]/*.Len*/, 3);
  10379.   }
  10380.   //Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  10381.  
  10382.   send_tree(s, s.dyn_ltree, lcodes - 1); /* literal tree */
  10383.   //Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  10384.  
  10385.   send_tree(s, s.dyn_dtree, dcodes - 1); /* distance tree */
  10386.   //Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  10387. }
  10388.  
  10389.  
  10390. /* ===========================================================================
  10391.  * Check if the data type is TEXT or BINARY, using the following algorithm:
  10392.  * - TEXT if the two conditions below are satisfied:
  10393.  *    a) There are no non-portable control characters belonging to the
  10394.  *       "black list" (0..6, 14..25, 28..31).
  10395.  *    b) There is at least one printable character belonging to the
  10396.  *       "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
  10397.  * - BINARY otherwise.
  10398.  * - The following partially-portable control characters form a
  10399.  *   "gray list" that is ignored in this detection algorithm:
  10400.  *   (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
  10401.  * IN assertion: the fields Freq of dyn_ltree are set.
  10402.  */
  10403. function detect_data_type(s) {
  10404.   /* black_mask is the bit mask of black-listed bytes
  10405.    * set bits 0..6, 14..25, and 28..31
  10406.    * 0xf3ffc07f = binary 11110011111111111100000001111111
  10407.    */
  10408.   var black_mask = 0xf3ffc07f;
  10409.   var n;
  10410.  
  10411.   /* Check for non-textual ("black-listed") bytes. */
  10412.   for (n = 0; n <= 31; n++, black_mask >>>= 1) {
  10413.     if ((black_mask & 1) && (s.dyn_ltree[n * 2]/*.Freq*/ !== 0)) {
  10414.       return Z_BINARY;
  10415.     }
  10416.   }
  10417.  
  10418.   /* Check for textual ("white-listed") bytes. */
  10419.   if (s.dyn_ltree[9 * 2]/*.Freq*/ !== 0 || s.dyn_ltree[10 * 2]/*.Freq*/ !== 0 ||
  10420.       s.dyn_ltree[13 * 2]/*.Freq*/ !== 0) {
  10421.     return Z_TEXT;
  10422.   }
  10423.   for (n = 32; n < LITERALS; n++) {
  10424.     if (s.dyn_ltree[n * 2]/*.Freq*/ !== 0) {
  10425.       return Z_TEXT;
  10426.     }
  10427.   }
  10428.  
  10429.   /* There are no "black-listed" or "white-listed" bytes:
  10430.    * this stream either is empty or has tolerated ("gray-listed") bytes only.
  10431.    */
  10432.   return Z_BINARY;
  10433. }
  10434.  
  10435.  
  10436. var static_init_done = false;
  10437.  
  10438. /* ===========================================================================
  10439.  * Initialize the tree data structures for a new zlib stream.
  10440.  */
  10441. function _tr_init(s)
  10442. {
  10443.  
  10444.   if (!static_init_done) {
  10445.     tr_static_init();
  10446.     static_init_done = true;
  10447.   }
  10448.  
  10449.   s.l_desc  = new TreeDesc(s.dyn_ltree, static_l_desc);
  10450.   s.d_desc  = new TreeDesc(s.dyn_dtree, static_d_desc);
  10451.   s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc);
  10452.  
  10453.   s.bi_buf = 0;
  10454.   s.bi_valid = 0;
  10455.  
  10456.   /* Initialize the first block of the first file: */
  10457.   init_block(s);
  10458. }
  10459.  
  10460.  
  10461. /* ===========================================================================
  10462.  * Send a stored block
  10463.  */
  10464. function _tr_stored_block(s, buf, stored_len, last)
  10465. //DeflateState *s;
  10466. //charf *buf;       /* input block */
  10467. //ulg stored_len;   /* length of input block */
  10468. //int last;         /* one if this is the last block for a file */
  10469. {
  10470.   send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3);    /* send block type */
  10471.   copy_block(s, buf, stored_len, true); /* with header */
  10472. }
  10473.  
  10474.  
  10475. /* ===========================================================================
  10476.  * Send one empty static block to give enough lookahead for inflate.
  10477.  * This takes 10 bits, of which 7 may remain in the bit buffer.
  10478.  */
  10479. function _tr_align(s) {
  10480.   send_bits(s, STATIC_TREES << 1, 3);
  10481.   send_code(s, END_BLOCK, static_ltree);
  10482.   bi_flush(s);
  10483. }
  10484.  
  10485.  
  10486. /* ===========================================================================
  10487.  * Determine the best encoding for the current block: dynamic trees, static
  10488.  * trees or store, and output the encoded block to the zip file.
  10489.  */
  10490. function _tr_flush_block(s, buf, stored_len, last)
  10491. //DeflateState *s;
  10492. //charf *buf;       /* input block, or NULL if too old */
  10493. //ulg stored_len;   /* length of input block */
  10494. //int last;         /* one if this is the last block for a file */
  10495. {
  10496.   var opt_lenb, static_lenb;  /* opt_len and static_len in bytes */
  10497.   var max_blindex = 0;        /* index of last bit length code of non zero freq */
  10498.  
  10499.   /* Build the Huffman trees unless a stored block is forced */
  10500.   if (s.level > 0) {
  10501.  
  10502.     /* Check if the file is binary or text */
  10503.     if (s.strm.data_type === Z_UNKNOWN) {
  10504.       s.strm.data_type = detect_data_type(s);
  10505.     }
  10506.  
  10507.     /* Construct the literal and distance trees */
  10508.     build_tree(s, s.l_desc);
  10509.     // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  10510.     //        s->static_len));
  10511.  
  10512.     build_tree(s, s.d_desc);
  10513.     // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  10514.     //        s->static_len));
  10515.     /* At this point, opt_len and static_len are the total bit lengths of
  10516.      * the compressed block data, excluding the tree representations.
  10517.      */
  10518.  
  10519.     /* Build the bit length tree for the above two trees, and get the index
  10520.      * in bl_order of the last bit length code to send.
  10521.      */
  10522.     max_blindex = build_bl_tree(s);
  10523.  
  10524.     /* Determine the best encoding. Compute the block lengths in bytes. */
  10525.     opt_lenb = (s.opt_len + 3 + 7) >>> 3;
  10526.     static_lenb = (s.static_len + 3 + 7) >>> 3;
  10527.  
  10528.     // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  10529.     //        opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  10530.     //        s->last_lit));
  10531.  
  10532.     if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }
  10533.  
  10534.   } else {
  10535.     // Assert(buf != (char*)0, "lost buf");
  10536.     opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  10537.   }
  10538.  
  10539.   if ((stored_len + 4 <= opt_lenb) && (buf !== -1)) {
  10540.     /* 4: two words for the lengths */
  10541.  
  10542.     /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
  10543.      * Otherwise we can't have processed more than WSIZE input bytes since
  10544.      * the last block flush, because compression would have been
  10545.      * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
  10546.      * transform a block into a stored block.
  10547.      */
  10548.     _tr_stored_block(s, buf, stored_len, last);
  10549.  
  10550.   } else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) {
  10551.  
  10552.     send_bits(s, (STATIC_TREES << 1) + (last ? 1 : 0), 3);
  10553.     compress_block(s, static_ltree, static_dtree);
  10554.  
  10555.   } else {
  10556.     send_bits(s, (DYN_TREES << 1) + (last ? 1 : 0), 3);
  10557.     send_all_trees(s, s.l_desc.max_code + 1, s.d_desc.max_code + 1, max_blindex + 1);
  10558.     compress_block(s, s.dyn_ltree, s.dyn_dtree);
  10559.   }
  10560.   // Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  10561.   /* The above check is made mod 2^32, for files larger than 512 MB
  10562.    * and uLong implemented on 32 bits.
  10563.    */
  10564.   init_block(s);
  10565.  
  10566.   if (last) {
  10567.     bi_windup(s);
  10568.   }
  10569.   // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  10570.   //       s->compressed_len-7*last));
  10571. }
  10572.  
  10573. /* ===========================================================================
  10574.  * Save the match info and tally the frequency counts. Return true if
  10575.  * the current block must be flushed.
  10576.  */
  10577. function _tr_tally(s, dist, lc)
  10578. //    deflate_state *s;
  10579. //    unsigned dist;  /* distance of matched string */
  10580. //    unsigned lc;    /* match length-MIN_MATCH or unmatched char (if dist==0) */
  10581. {
  10582.   //var out_length, in_length, dcode;
  10583.  
  10584.   s.pending_buf[s.d_buf + s.last_lit * 2]     = (dist >>> 8) & 0xff;
  10585.   s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff;
  10586.  
  10587.   s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff;
  10588.   s.last_lit++;
  10589.  
  10590.   if (dist === 0) {
  10591.     /* lc is the unmatched char */
  10592.     s.dyn_ltree[lc * 2]/*.Freq*/++;
  10593.   } else {
  10594.     s.matches++;
  10595.     /* Here, lc is the match length - MIN_MATCH */
  10596.     dist--;             /* dist = match distance - 1 */
  10597.     //Assert((ush)dist < (ush)MAX_DIST(s) &&
  10598.     //       (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  10599.     //       (ush)d_code(dist) < (ush)D_CODES,  "_tr_tally: bad match");
  10600.  
  10601.     s.dyn_ltree[(_length_code[lc] + LITERALS + 1) * 2]/*.Freq*/++;
  10602.     s.dyn_dtree[d_code(dist) * 2]/*.Freq*/++;
  10603.   }
  10604.  
  10605. // (!) This block is disabled in zlib defaults,
  10606. // don't enable it for binary compatibility
  10607.  
  10608. //#ifdef TRUNCATE_BLOCK
  10609. //  /* Try to guess if it is profitable to stop the current block here */
  10610. //  if ((s.last_lit & 0x1fff) === 0 && s.level > 2) {
  10611. //    /* Compute an upper bound for the compressed length */
  10612. //    out_length = s.last_lit*8;
  10613. //    in_length = s.strstart - s.block_start;
  10614. //
  10615. //    for (dcode = 0; dcode < D_CODES; dcode++) {
  10616. //      out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]);
  10617. //    }
  10618. //    out_length >>>= 3;
  10619. //    //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  10620. //    //       s->last_lit, in_length, out_length,
  10621. //    //       100L - out_length*100L/in_length));
  10622. //    if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) {
  10623. //      return true;
  10624. //    }
  10625. //  }
  10626. //#endif
  10627.  
  10628.   return (s.last_lit === s.lit_bufsize - 1);
  10629.   /* We avoid equality with lit_bufsize because of wraparound at 64K
  10630.    * on 16 bit machines and because stored blocks are restricted to
  10631.    * 64K-1 bytes.
  10632.    */
  10633. }
  10634.  
  10635. exports._tr_init  = _tr_init;
  10636. exports._tr_stored_block = _tr_stored_block;
  10637. exports._tr_flush_block  = _tr_flush_block;
  10638. exports._tr_tally = _tr_tally;
  10639. exports._tr_align = _tr_align;
  10640.  
  10641. },{"../utils/common":17}],27:[function(require,module,exports){
  10642. 'use strict';
  10643.  
  10644. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  10645. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  10646. //
  10647. // This software is provided 'as-is', without any express or implied
  10648. // warranty. In no event will the authors be held liable for any damages
  10649. // arising from the use of this software.
  10650. //
  10651. // Permission is granted to anyone to use this software for any purpose,
  10652. // including commercial applications, and to alter it and redistribute it
  10653. // freely, subject to the following restrictions:
  10654. //
  10655. // 1. The origin of this software must not be misrepresented; you must not
  10656. //   claim that you wrote the original software. If you use this software
  10657. //   in a product, an acknowledgment in the product documentation would be
  10658. //   appreciated but is not required.
  10659. // 2. Altered source versions must be plainly marked as such, and must not be
  10660. //   misrepresented as being the original software.
  10661. // 3. This notice may not be removed or altered from any source distribution.
  10662.  
  10663. function ZStream() {
  10664.   /* next input byte */
  10665.   this.input = null; // JS specific, because we have no pointers
  10666.   this.next_in = 0;
  10667.   /* number of bytes available at input */
  10668.   this.avail_in = 0;
  10669.   /* total number of input bytes read so far */
  10670.   this.total_in = 0;
  10671.   /* next output byte should be put there */
  10672.   this.output = null; // JS specific, because we have no pointers
  10673.   this.next_out = 0;
  10674.   /* remaining free space at output */
  10675.   this.avail_out = 0;
  10676.   /* total number of bytes output so far */
  10677.   this.total_out = 0;
  10678.   /* last error message, NULL if no error */
  10679.   this.msg = ''/*Z_NULL*/;
  10680.   /* not visible by applications */
  10681.   this.state = null;
  10682.   /* best guess about the data type: binary or text */
  10683.   this.data_type = 2/*Z_UNKNOWN*/;
  10684.   /* adler32 value of the uncompressed data */
  10685.   this.adler = 0;
  10686. }
  10687.  
  10688. module.exports = ZStream;
  10689.  
  10690. },{}],28:[function(require,module,exports){
  10691. (function (process){
  10692. 'use strict';
  10693.  
  10694. if (typeof process === 'undefined' ||
  10695.     !process.version ||
  10696.     process.version.indexOf('v0.') === 0 ||
  10697.     process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
  10698.   module.exports = { nextTick: nextTick };
  10699. } else {
  10700.   module.exports = process
  10701. }
  10702.  
  10703. function nextTick(fn, arg1, arg2, arg3) {
  10704.   if (typeof fn !== 'function') {
  10705.     throw new TypeError('"callback" argument must be a function');
  10706.   }
  10707.   var len = arguments.length;
  10708.   var args, i;
  10709.   switch (len) {
  10710.   case 0:
  10711.   case 1:
  10712.     return process.nextTick(fn);
  10713.   case 2:
  10714.     return process.nextTick(function afterTickOne() {
  10715.       fn.call(null, arg1);
  10716.     });
  10717.   case 3:
  10718.     return process.nextTick(function afterTickTwo() {
  10719.       fn.call(null, arg1, arg2);
  10720.     });
  10721.   case 4:
  10722.     return process.nextTick(function afterTickThree() {
  10723.       fn.call(null, arg1, arg2, arg3);
  10724.     });
  10725.   default:
  10726.     args = new Array(len - 1);
  10727.     i = 0;
  10728.     while (i < args.length) {
  10729.       args[i++] = arguments[i];
  10730.     }
  10731.     return process.nextTick(function afterTick() {
  10732.       fn.apply(null, args);
  10733.     });
  10734.   }
  10735. }
  10736.  
  10737.  
  10738. }).call(this,require('_process'))
  10739. },{"_process":29}],29:[function(require,module,exports){
  10740. // shim for using process in browser
  10741. var process = module.exports = {};
  10742.  
  10743. // cached from whatever global is present so that test runners that stub it
  10744. // don't break things.  But we need to wrap it in a try catch in case it is
  10745. // wrapped in strict mode code which doesn't define any globals.  It's inside a
  10746. // function because try/catches deoptimize in certain engines.
  10747.  
  10748. var cachedSetTimeout;
  10749. var cachedClearTimeout;
  10750.  
  10751. function defaultSetTimout() {
  10752.     throw new Error('setTimeout has not been defined');
  10753. }
  10754. function defaultClearTimeout () {
  10755.     throw new Error('clearTimeout has not been defined');
  10756. }
  10757. (function () {
  10758.     try {
  10759.         if (typeof setTimeout === 'function') {
  10760.             cachedSetTimeout = setTimeout;
  10761.         } else {
  10762.             cachedSetTimeout = defaultSetTimout;
  10763.         }
  10764.     } catch (e) {
  10765.         cachedSetTimeout = defaultSetTimout;
  10766.     }
  10767.     try {
  10768.         if (typeof clearTimeout === 'function') {
  10769.             cachedClearTimeout = clearTimeout;
  10770.         } else {
  10771.             cachedClearTimeout = defaultClearTimeout;
  10772.         }
  10773.     } catch (e) {
  10774.         cachedClearTimeout = defaultClearTimeout;
  10775.     }
  10776. } ())
  10777. function runTimeout(fun) {
  10778.     if (cachedSetTimeout === setTimeout) {
  10779.         //normal enviroments in sane situations
  10780.         return setTimeout(fun, 0);
  10781.     }
  10782.     // if setTimeout wasn't available but was latter defined
  10783.     if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  10784.         cachedSetTimeout = setTimeout;
  10785.         return setTimeout(fun, 0);
  10786.     }
  10787.     try {
  10788.         // when when somebody has screwed with setTimeout but no I.E. maddness
  10789.         return cachedSetTimeout(fun, 0);
  10790.     } catch(e){
  10791.         try {
  10792.             // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  10793.             return cachedSetTimeout.call(null, fun, 0);
  10794.         } catch(e){
  10795.             // 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
  10796.             return cachedSetTimeout.call(this, fun, 0);
  10797.         }
  10798.     }
  10799.  
  10800.  
  10801. }
  10802. function runClearTimeout(marker) {
  10803.     if (cachedClearTimeout === clearTimeout) {
  10804.         //normal enviroments in sane situations
  10805.         return clearTimeout(marker);
  10806.     }
  10807.     // if clearTimeout wasn't available but was latter defined
  10808.     if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  10809.         cachedClearTimeout = clearTimeout;
  10810.         return clearTimeout(marker);
  10811.     }
  10812.     try {
  10813.         // when when somebody has screwed with setTimeout but no I.E. maddness
  10814.         return cachedClearTimeout(marker);
  10815.     } catch (e){
  10816.         try {
  10817.             // When we are in I.E. but the script has been evaled so I.E. doesn't  trust the global object when called normally
  10818.             return cachedClearTimeout.call(null, marker);
  10819.         } catch (e){
  10820.             // 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.
  10821.             // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  10822.             return cachedClearTimeout.call(this, marker);
  10823.         }
  10824.     }
  10825.  
  10826.  
  10827.  
  10828. }
  10829. var queue = [];
  10830. var draining = false;
  10831. var currentQueue;
  10832. var queueIndex = -1;
  10833.  
  10834. function cleanUpNextTick() {
  10835.     if (!draining || !currentQueue) {
  10836.         return;
  10837.     }
  10838.     draining = false;
  10839.     if (currentQueue.length) {
  10840.         queue = currentQueue.concat(queue);
  10841.     } else {
  10842.         queueIndex = -1;
  10843.     }
  10844.     if (queue.length) {
  10845.         drainQueue();
  10846.     }
  10847. }
  10848.  
  10849. function drainQueue() {
  10850.     if (draining) {
  10851.         return;
  10852.     }
  10853.     var timeout = runTimeout(cleanUpNextTick);
  10854.     draining = true;
  10855.  
  10856.     var len = queue.length;
  10857.     while(len) {
  10858.         currentQueue = queue;
  10859.         queue = [];
  10860.         while (++queueIndex < len) {
  10861.             if (currentQueue) {
  10862.                 currentQueue[queueIndex].run();
  10863.             }
  10864.         }
  10865.         queueIndex = -1;
  10866.         len = queue.length;
  10867.     }
  10868.     currentQueue = null;
  10869.     draining = false;
  10870.     runClearTimeout(timeout);
  10871. }
  10872.  
  10873. process.nextTick = function (fun) {
  10874.     var args = new Array(arguments.length - 1);
  10875.     if (arguments.length > 1) {
  10876.         for (var i = 1; i < arguments.length; i++) {
  10877.             args[i - 1] = arguments[i];
  10878.         }
  10879.     }
  10880.     queue.push(new Item(fun, args));
  10881.     if (queue.length === 1 && !draining) {
  10882.         runTimeout(drainQueue);
  10883.     }
  10884. };
  10885.  
  10886. // v8 likes predictible objects
  10887. function Item(fun, array) {
  10888.     this.fun = fun;
  10889.     this.array = array;
  10890. }
  10891. Item.prototype.run = function () {
  10892.     this.fun.apply(null, this.array);
  10893. };
  10894. process.title = 'browser';
  10895. process.browser = true;
  10896. process.env = {};
  10897. process.argv = [];
  10898. process.version = ''; // empty string to avoid regexp issues
  10899. process.versions = {};
  10900.  
  10901. function noop() {}
  10902.  
  10903. process.on = noop;
  10904. process.addListener = noop;
  10905. process.once = noop;
  10906. process.off = noop;
  10907. process.removeListener = noop;
  10908. process.removeAllListeners = noop;
  10909. process.emit = noop;
  10910. process.prependListener = noop;
  10911. process.prependOnceListener = noop;
  10912.  
  10913. process.listeners = function (name) { return [] }
  10914.  
  10915. process.binding = function (name) {
  10916.     throw new Error('process.binding is not supported');
  10917. };
  10918.  
  10919. process.cwd = function () { return '/' };
  10920. process.chdir = function (dir) {
  10921.     throw new Error('process.chdir is not supported');
  10922. };
  10923. process.umask = function() { return 0; };
  10924.  
  10925. },{}],30:[function(require,module,exports){
  10926. module.exports = require('./lib/_stream_duplex.js');
  10927.  
  10928. },{"./lib/_stream_duplex.js":31}],31:[function(require,module,exports){
  10929. // Copyright Joyent, Inc. and other Node contributors.
  10930. //
  10931. // Permission is hereby granted, free of charge, to any person obtaining a
  10932. // copy of this software and associated documentation files (the
  10933. // "Software"), to deal in the Software without restriction, including
  10934. // without limitation the rights to use, copy, modify, merge, publish,
  10935. // distribute, sublicense, and/or sell copies of the Software, and to permit
  10936. // persons to whom the Software is furnished to do so, subject to the
  10937. // following conditions:
  10938. //
  10939. // The above copyright notice and this permission notice shall be included
  10940. // in all copies or substantial portions of the Software.
  10941. //
  10942. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  10943. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10944. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  10945. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  10946. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  10947. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  10948. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  10949.  
  10950. // a duplex stream is just a stream that is both readable and writable.
  10951. // Since JS doesn't have multiple prototypal inheritance, this class
  10952. // prototypally inherits from Readable, and then parasitically from
  10953. // Writable.
  10954.  
  10955. 'use strict';
  10956.  
  10957. /*<replacement>*/
  10958.  
  10959. var pna = require('process-nextick-args');
  10960. /*</replacement>*/
  10961.  
  10962. /*<replacement>*/
  10963. var objectKeys = Object.keys || function (obj) {
  10964.   var keys = [];
  10965.   for (var key in obj) {
  10966.     keys.push(key);
  10967.   }return keys;
  10968. };
  10969. /*</replacement>*/
  10970.  
  10971. module.exports = Duplex;
  10972.  
  10973. /*<replacement>*/
  10974. var util = require('core-util-is');
  10975. util.inherits = require('inherits');
  10976. /*</replacement>*/
  10977.  
  10978. var Readable = require('./_stream_readable');
  10979. var Writable = require('./_stream_writable');
  10980.  
  10981. util.inherits(Duplex, Readable);
  10982.  
  10983. {
  10984.   // avoid scope creep, the keys array can then be collected
  10985.   var keys = objectKeys(Writable.prototype);
  10986.   for (var v = 0; v < keys.length; v++) {
  10987.     var method = keys[v];
  10988.     if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  10989.   }
  10990. }
  10991.  
  10992. function Duplex(options) {
  10993.   if (!(this instanceof Duplex)) return new Duplex(options);
  10994.  
  10995.   Readable.call(this, options);
  10996.   Writable.call(this, options);
  10997.  
  10998.   if (options && options.readable === false) this.readable = false;
  10999.  
  11000.   if (options && options.writable === false) this.writable = false;
  11001.  
  11002.   this.allowHalfOpen = true;
  11003.   if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
  11004.  
  11005.   this.once('end', onend);
  11006. }
  11007.  
  11008. Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
  11009.   // making it explicit this property is not enumerable
  11010.   // because otherwise some prototype manipulation in
  11011.   // userland will fail
  11012.   enumerable: false,
  11013.   get: function () {
  11014.     return this._writableState.highWaterMark;
  11015.   }
  11016. });
  11017.  
  11018. // the no-half-open enforcer
  11019. function onend() {
  11020.   // if we allow half-open state, or if the writable side ended,
  11021.   // then we're ok.
  11022.   if (this.allowHalfOpen || this._writableState.ended) return;
  11023.  
  11024.   // no more data can be written.
  11025.   // But allow more writes to happen in this tick.
  11026.   pna.nextTick(onEndNT, this);
  11027. }
  11028.  
  11029. function onEndNT(self) {
  11030.   self.end();
  11031. }
  11032.  
  11033. Object.defineProperty(Duplex.prototype, 'destroyed', {
  11034.   get: function () {
  11035.     if (this._readableState === undefined || this._writableState === undefined) {
  11036.       return false;
  11037.     }
  11038.     return this._readableState.destroyed && this._writableState.destroyed;
  11039.   },
  11040.   set: function (value) {
  11041.     // we ignore the value if the stream
  11042.     // has not been initialized yet
  11043.     if (this._readableState === undefined || this._writableState === undefined) {
  11044.       return;
  11045.     }
  11046.  
  11047.     // backward compatibility, the user is explicitly
  11048.     // managing destroyed
  11049.     this._readableState.destroyed = value;
  11050.     this._writableState.destroyed = value;
  11051.   }
  11052. });
  11053.  
  11054. Duplex.prototype._destroy = function (err, cb) {
  11055.   this.push(null);
  11056.   this.end();
  11057.  
  11058.   pna.nextTick(cb, err);
  11059. };
  11060. },{"./_stream_readable":33,"./_stream_writable":35,"core-util-is":10,"inherits":13,"process-nextick-args":28}],32:[function(require,module,exports){
  11061. // Copyright Joyent, Inc. and other Node contributors.
  11062. //
  11063. // Permission is hereby granted, free of charge, to any person obtaining a
  11064. // copy of this software and associated documentation files (the
  11065. // "Software"), to deal in the Software without restriction, including
  11066. // without limitation the rights to use, copy, modify, merge, publish,
  11067. // distribute, sublicense, and/or sell copies of the Software, and to permit
  11068. // persons to whom the Software is furnished to do so, subject to the
  11069. // following conditions:
  11070. //
  11071. // The above copyright notice and this permission notice shall be included
  11072. // in all copies or substantial portions of the Software.
  11073. //
  11074. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11075. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11076. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  11077. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  11078. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  11079. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  11080. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  11081.  
  11082. // a passthrough stream.
  11083. // basically just the most minimal sort of Transform stream.
  11084. // Every written chunk gets output as-is.
  11085.  
  11086. 'use strict';
  11087.  
  11088. module.exports = PassThrough;
  11089.  
  11090. var Transform = require('./_stream_transform');
  11091.  
  11092. /*<replacement>*/
  11093. var util = require('core-util-is');
  11094. util.inherits = require('inherits');
  11095. /*</replacement>*/
  11096.  
  11097. util.inherits(PassThrough, Transform);
  11098.  
  11099. function PassThrough(options) {
  11100.   if (!(this instanceof PassThrough)) return new PassThrough(options);
  11101.  
  11102.   Transform.call(this, options);
  11103. }
  11104.  
  11105. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  11106.   cb(null, chunk);
  11107. };
  11108. },{"./_stream_transform":34,"core-util-is":10,"inherits":13}],33:[function(require,module,exports){
  11109. (function (process,global){
  11110. // Copyright Joyent, Inc. and other Node contributors.
  11111. //
  11112. // Permission is hereby granted, free of charge, to any person obtaining a
  11113. // copy of this software and associated documentation files (the
  11114. // "Software"), to deal in the Software without restriction, including
  11115. // without limitation the rights to use, copy, modify, merge, publish,
  11116. // distribute, sublicense, and/or sell copies of the Software, and to permit
  11117. // persons to whom the Software is furnished to do so, subject to the
  11118. // following conditions:
  11119. //
  11120. // The above copyright notice and this permission notice shall be included
  11121. // in all copies or substantial portions of the Software.
  11122. //
  11123. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11124. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11125. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  11126. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  11127. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  11128. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  11129. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  11130.  
  11131. 'use strict';
  11132.  
  11133. /*<replacement>*/
  11134.  
  11135. var pna = require('process-nextick-args');
  11136. /*</replacement>*/
  11137.  
  11138. module.exports = Readable;
  11139.  
  11140. /*<replacement>*/
  11141. var isArray = require('isarray');
  11142. /*</replacement>*/
  11143.  
  11144. /*<replacement>*/
  11145. var Duplex;
  11146. /*</replacement>*/
  11147.  
  11148. Readable.ReadableState = ReadableState;
  11149.  
  11150. /*<replacement>*/
  11151. var EE = require('events').EventEmitter;
  11152.  
  11153. var EElistenerCount = function (emitter, type) {
  11154.   return emitter.listeners(type).length;
  11155. };
  11156. /*</replacement>*/
  11157.  
  11158. /*<replacement>*/
  11159. var Stream = require('./internal/streams/stream');
  11160. /*</replacement>*/
  11161.  
  11162. /*<replacement>*/
  11163.  
  11164. var Buffer = require('safe-buffer').Buffer;
  11165. var OurUint8Array = global.Uint8Array || function () {};
  11166. function _uint8ArrayToBuffer(chunk) {
  11167.   return Buffer.from(chunk);
  11168. }
  11169. function _isUint8Array(obj) {
  11170.   return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  11171. }
  11172.  
  11173. /*</replacement>*/
  11174.  
  11175. /*<replacement>*/
  11176. var util = require('core-util-is');
  11177. util.inherits = require('inherits');
  11178. /*</replacement>*/
  11179.  
  11180. /*<replacement>*/
  11181. var debugUtil = require('util');
  11182. var debug = void 0;
  11183. if (debugUtil && debugUtil.debuglog) {
  11184.   debug = debugUtil.debuglog('stream');
  11185. } else {
  11186.   debug = function () {};
  11187. }
  11188. /*</replacement>*/
  11189.  
  11190. var BufferList = require('./internal/streams/BufferList');
  11191. var destroyImpl = require('./internal/streams/destroy');
  11192. var StringDecoder;
  11193.  
  11194. util.inherits(Readable, Stream);
  11195.  
  11196. var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
  11197.  
  11198. function prependListener(emitter, event, fn) {
  11199.   // Sadly this is not cacheable as some libraries bundle their own
  11200.   // event emitter implementation with them.
  11201.   if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
  11202.  
  11203.   // This is a hack to make sure that our error handler is attached before any
  11204.   // userland ones.  NEVER DO THIS. This is here only because this code needs
  11205.   // to continue to work with older versions of Node.js that do not include
  11206.   // the prependListener() method. The goal is to eventually remove this hack.
  11207.   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]];
  11208. }
  11209.  
  11210. function ReadableState(options, stream) {
  11211.   Duplex = Duplex || require('./_stream_duplex');
  11212.  
  11213.   options = options || {};
  11214.  
  11215.   // Duplex streams are both readable and writable, but share
  11216.   // the same options object.
  11217.   // However, some cases require setting options to different
  11218.   // values for the readable and the writable sides of the duplex stream.
  11219.   // These options can be provided separately as readableXXX and writableXXX.
  11220.   var isDuplex = stream instanceof Duplex;
  11221.  
  11222.   // object stream flag. Used to make read(n) ignore n and to
  11223.   // make all the buffer merging and length checks go away
  11224.   this.objectMode = !!options.objectMode;
  11225.  
  11226.   if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
  11227.  
  11228.   // the point at which it stops calling _read() to fill the buffer
  11229.   // Note: 0 is a valid value, means "don't call _read preemptively ever"
  11230.   var hwm = options.highWaterMark;
  11231.   var readableHwm = options.readableHighWaterMark;
  11232.   var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  11233.  
  11234.   if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm;
  11235.  
  11236.   // cast to ints.
  11237.   this.highWaterMark = Math.floor(this.highWaterMark);
  11238.  
  11239.   // A linked list is used to store data chunks instead of an array because the
  11240.   // linked list can remove elements from the beginning faster than
  11241.   // array.shift()
  11242.   this.buffer = new BufferList();
  11243.   this.length = 0;
  11244.   this.pipes = null;
  11245.   this.pipesCount = 0;
  11246.   this.flowing = null;
  11247.   this.ended = false;
  11248.   this.endEmitted = false;
  11249.   this.reading = false;
  11250.  
  11251.   // a flag to be able to tell if the event 'readable'/'data' is emitted
  11252.   // immediately, or on a later tick.  We set this to true at first, because
  11253.   // any actions that shouldn't happen until "later" should generally also
  11254.   // not happen before the first read call.
  11255.   this.sync = true;
  11256.  
  11257.   // whenever we return null, then we set a flag to say
  11258.   // that we're awaiting a 'readable' event emission.
  11259.   this.needReadable = false;
  11260.   this.emittedReadable = false;
  11261.   this.readableListening = false;
  11262.   this.resumeScheduled = false;
  11263.  
  11264.   // has it been destroyed
  11265.   this.destroyed = false;
  11266.  
  11267.   // Crypto is kind of old and crusty.  Historically, its default string
  11268.   // encoding is 'binary' so we have to make this configurable.
  11269.   // Everything else in the universe uses 'utf8', though.
  11270.   this.defaultEncoding = options.defaultEncoding || 'utf8';
  11271.  
  11272.   // the number of writers that are awaiting a drain event in .pipe()s
  11273.   this.awaitDrain = 0;
  11274.  
  11275.   // if true, a maybeReadMore has been scheduled
  11276.   this.readingMore = false;
  11277.  
  11278.   this.decoder = null;
  11279.   this.encoding = null;
  11280.   if (options.encoding) {
  11281.     if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  11282.     this.decoder = new StringDecoder(options.encoding);
  11283.     this.encoding = options.encoding;
  11284.   }
  11285. }
  11286.  
  11287. function Readable(options) {
  11288.   Duplex = Duplex || require('./_stream_duplex');
  11289.  
  11290.   if (!(this instanceof Readable)) return new Readable(options);
  11291.  
  11292.   this._readableState = new ReadableState(options, this);
  11293.  
  11294.   // legacy
  11295.   this.readable = true;
  11296.  
  11297.   if (options) {
  11298.     if (typeof options.read === 'function') this._read = options.read;
  11299.  
  11300.     if (typeof options.destroy === 'function') this._destroy = options.destroy;
  11301.   }
  11302.  
  11303.   Stream.call(this);
  11304. }
  11305.  
  11306. Object.defineProperty(Readable.prototype, 'destroyed', {
  11307.   get: function () {
  11308.     if (this._readableState === undefined) {
  11309.       return false;
  11310.     }
  11311.     return this._readableState.destroyed;
  11312.   },
  11313.   set: function (value) {
  11314.     // we ignore the value if the stream
  11315.     // has not been initialized yet
  11316.     if (!this._readableState) {
  11317.       return;
  11318.     }
  11319.  
  11320.     // backward compatibility, the user is explicitly
  11321.     // managing destroyed
  11322.     this._readableState.destroyed = value;
  11323.   }
  11324. });
  11325.  
  11326. Readable.prototype.destroy = destroyImpl.destroy;
  11327. Readable.prototype._undestroy = destroyImpl.undestroy;
  11328. Readable.prototype._destroy = function (err, cb) {
  11329.   this.push(null);
  11330.   cb(err);
  11331. };
  11332.  
  11333. // Manually shove something into the read() buffer.
  11334. // This returns true if the highWaterMark has not been hit yet,
  11335. // similar to how Writable.write() returns true if you should
  11336. // write() some more.
  11337. Readable.prototype.push = function (chunk, encoding) {
  11338.   var state = this._readableState;
  11339.   var skipChunkCheck;
  11340.  
  11341.   if (!state.objectMode) {
  11342.     if (typeof chunk === 'string') {
  11343.       encoding = encoding || state.defaultEncoding;
  11344.       if (encoding !== state.encoding) {
  11345.         chunk = Buffer.from(chunk, encoding);
  11346.         encoding = '';
  11347.       }
  11348.       skipChunkCheck = true;
  11349.     }
  11350.   } else {
  11351.     skipChunkCheck = true;
  11352.   }
  11353.  
  11354.   return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
  11355. };
  11356.  
  11357. // Unshift should *always* be something directly out of read()
  11358. Readable.prototype.unshift = function (chunk) {
  11359.   return readableAddChunk(this, chunk, null, true, false);
  11360. };
  11361.  
  11362. function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
  11363.   var state = stream._readableState;
  11364.   if (chunk === null) {
  11365.     state.reading = false;
  11366.     onEofChunk(stream, state);
  11367.   } else {
  11368.     var er;
  11369.     if (!skipChunkCheck) er = chunkInvalid(state, chunk);
  11370.     if (er) {
  11371.       stream.emit('error', er);
  11372.     } else if (state.objectMode || chunk && chunk.length > 0) {
  11373.       if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
  11374.         chunk = _uint8ArrayToBuffer(chunk);
  11375.       }
  11376.  
  11377.       if (addToFront) {
  11378.         if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
  11379.       } else if (state.ended) {
  11380.         stream.emit('error', new Error('stream.push() after EOF'));
  11381.       } else {
  11382.         state.reading = false;
  11383.         if (state.decoder && !encoding) {
  11384.           chunk = state.decoder.write(chunk);
  11385.           if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
  11386.         } else {
  11387.           addChunk(stream, state, chunk, false);
  11388.         }
  11389.       }
  11390.     } else if (!addToFront) {
  11391.       state.reading = false;
  11392.     }
  11393.   }
  11394.  
  11395.   return needMoreData(state);
  11396. }
  11397.  
  11398. function addChunk(stream, state, chunk, addToFront) {
  11399.   if (state.flowing && state.length === 0 && !state.sync) {
  11400.     stream.emit('data', chunk);
  11401.     stream.read(0);
  11402.   } else {
  11403.     // update the buffer info.
  11404.     state.length += state.objectMode ? 1 : chunk.length;
  11405.     if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  11406.  
  11407.     if (state.needReadable) emitReadable(stream);
  11408.   }
  11409.   maybeReadMore(stream, state);
  11410. }
  11411.  
  11412. function chunkInvalid(state, chunk) {
  11413.   var er;
  11414.   if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  11415.     er = new TypeError('Invalid non-string/buffer chunk');
  11416.   }
  11417.   return er;
  11418. }
  11419.  
  11420. // if it's past the high water mark, we can push in some more.
  11421. // Also, if we have no data yet, we can stand some
  11422. // more bytes.  This is to work around cases where hwm=0,
  11423. // such as the repl.  Also, if the push() triggered a
  11424. // readable event, and the user called read(largeNumber) such that
  11425. // needReadable was set, then we ought to push more, so that another
  11426. // 'readable' event will be triggered.
  11427. function needMoreData(state) {
  11428.   return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
  11429. }
  11430.  
  11431. Readable.prototype.isPaused = function () {
  11432.   return this._readableState.flowing === false;
  11433. };
  11434.  
  11435. // backwards compatibility.
  11436. Readable.prototype.setEncoding = function (enc) {
  11437.   if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  11438.   this._readableState.decoder = new StringDecoder(enc);
  11439.   this._readableState.encoding = enc;
  11440.   return this;
  11441. };
  11442.  
  11443. // Don't raise the hwm > 8MB
  11444. var MAX_HWM = 0x800000;
  11445. function computeNewHighWaterMark(n) {
  11446.   if (n >= MAX_HWM) {
  11447.     n = MAX_HWM;
  11448.   } else {
  11449.     // Get the next highest power of 2 to prevent increasing hwm excessively in
  11450.     // tiny amounts
  11451.     n--;
  11452.     n |= n >>> 1;
  11453.     n |= n >>> 2;
  11454.     n |= n >>> 4;
  11455.     n |= n >>> 8;
  11456.     n |= n >>> 16;
  11457.     n++;
  11458.   }
  11459.   return n;
  11460. }
  11461.  
  11462. // This function is designed to be inlinable, so please take care when making
  11463. // changes to the function body.
  11464. function howMuchToRead(n, state) {
  11465.   if (n <= 0 || state.length === 0 && state.ended) return 0;
  11466.   if (state.objectMode) return 1;
  11467.   if (n !== n) {
  11468.     // Only flow one buffer at a time
  11469.     if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  11470.   }
  11471.   // If we're asking for more than the current hwm, then raise the hwm.
  11472.   if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  11473.   if (n <= state.length) return n;
  11474.   // Don't have enough
  11475.   if (!state.ended) {
  11476.     state.needReadable = true;
  11477.     return 0;
  11478.   }
  11479.   return state.length;
  11480. }
  11481.  
  11482. // you can override either this method, or the async _read(n) below.
  11483. Readable.prototype.read = function (n) {
  11484.   debug('read', n);
  11485.   n = parseInt(n, 10);
  11486.   var state = this._readableState;
  11487.   var nOrig = n;
  11488.  
  11489.   if (n !== 0) state.emittedReadable = false;
  11490.  
  11491.   // if we're doing read(0) to trigger a readable event, but we
  11492.   // already have a bunch of data in the buffer, then just trigger
  11493.   // the 'readable' event and move on.
  11494.   if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
  11495.     debug('read: emitReadable', state.length, state.ended);
  11496.     if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  11497.     return null;
  11498.   }
  11499.  
  11500.   n = howMuchToRead(n, state);
  11501.  
  11502.   // if we've ended, and we're now clear, then finish it up.
  11503.   if (n === 0 && state.ended) {
  11504.     if (state.length === 0) endReadable(this);
  11505.     return null;
  11506.   }
  11507.  
  11508.   // All the actual chunk generation logic needs to be
  11509.   // *below* the call to _read.  The reason is that in certain
  11510.   // synthetic stream cases, such as passthrough streams, _read
  11511.   // may be a completely synchronous operation which may change
  11512.   // the state of the read buffer, providing enough data when
  11513.   // before there was *not* enough.
  11514.   //
  11515.   // So, the steps are:
  11516.   // 1. Figure out what the state of things will be after we do
  11517.   // a read from the buffer.
  11518.   //
  11519.   // 2. If that resulting state will trigger a _read, then call _read.
  11520.   // Note that this may be asynchronous, or synchronous.  Yes, it is
  11521.   // deeply ugly to write APIs this way, but that still doesn't mean
  11522.   // that the Readable class should behave improperly, as streams are
  11523.   // designed to be sync/async agnostic.
  11524.   // Take note if the _read call is sync or async (ie, if the read call
  11525.   // has returned yet), so that we know whether or not it's safe to emit
  11526.   // 'readable' etc.
  11527.   //
  11528.   // 3. Actually pull the requested chunks out of the buffer and return.
  11529.  
  11530.   // if we need a readable event, then we need to do some reading.
  11531.   var doRead = state.needReadable;
  11532.   debug('need readable', doRead);
  11533.  
  11534.   // if we currently have less than the highWaterMark, then also read some
  11535.   if (state.length === 0 || state.length - n < state.highWaterMark) {
  11536.     doRead = true;
  11537.     debug('length less than watermark', doRead);
  11538.   }
  11539.  
  11540.   // however, if we've ended, then there's no point, and if we're already
  11541.   // reading, then it's unnecessary.
  11542.   if (state.ended || state.reading) {
  11543.     doRead = false;
  11544.     debug('reading or ended', doRead);
  11545.   } else if (doRead) {
  11546.     debug('do read');
  11547.     state.reading = true;
  11548.     state.sync = true;
  11549.     // if the length is currently zero, then we *need* a readable event.
  11550.     if (state.length === 0) state.needReadable = true;
  11551.     // call internal read method
  11552.     this._read(state.highWaterMark);
  11553.     state.sync = false;
  11554.     // If _read pushed data synchronously, then `reading` will be false,
  11555.     // and we need to re-evaluate how much data we can return to the user.
  11556.     if (!state.reading) n = howMuchToRead(nOrig, state);
  11557.   }
  11558.  
  11559.   var ret;
  11560.   if (n > 0) ret = fromList(n, state);else ret = null;
  11561.  
  11562.   if (ret === null) {
  11563.     state.needReadable = true;
  11564.     n = 0;
  11565.   } else {
  11566.     state.length -= n;
  11567.   }
  11568.  
  11569.   if (state.length === 0) {
  11570.     // If we have nothing in the buffer, then we want to know
  11571.     // as soon as we *do* get something into the buffer.
  11572.     if (!state.ended) state.needReadable = true;
  11573.  
  11574.     // If we tried to read() past the EOF, then emit end on the next tick.
  11575.     if (nOrig !== n && state.ended) endReadable(this);
  11576.   }
  11577.  
  11578.   if (ret !== null) this.emit('data', ret);
  11579.  
  11580.   return ret;
  11581. };
  11582.  
  11583. function onEofChunk(stream, state) {
  11584.   if (state.ended) return;
  11585.   if (state.decoder) {
  11586.     var chunk = state.decoder.end();
  11587.     if (chunk && chunk.length) {
  11588.       state.buffer.push(chunk);
  11589.       state.length += state.objectMode ? 1 : chunk.length;
  11590.     }
  11591.   }
  11592.   state.ended = true;
  11593.  
  11594.   // emit 'readable' now to make sure it gets picked up.
  11595.   emitReadable(stream);
  11596. }
  11597.  
  11598. // Don't emit readable right away in sync mode, because this can trigger
  11599. // another read() call => stack overflow.  This way, it might trigger
  11600. // a nextTick recursion warning, but that's not so bad.
  11601. function emitReadable(stream) {
  11602.   var state = stream._readableState;
  11603.   state.needReadable = false;
  11604.   if (!state.emittedReadable) {
  11605.     debug('emitReadable', state.flowing);
  11606.     state.emittedReadable = true;
  11607.     if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream);
  11608.   }
  11609. }
  11610.  
  11611. function emitReadable_(stream) {
  11612.   debug('emit readable');
  11613.   stream.emit('readable');
  11614.   flow(stream);
  11615. }
  11616.  
  11617. // at this point, the user has presumably seen the 'readable' event,
  11618. // and called read() to consume some data.  that may have triggered
  11619. // in turn another _read(n) call, in which case reading = true if
  11620. // it's in progress.
  11621. // However, if we're not ended, or reading, and the length < hwm,
  11622. // then go ahead and try to read some more preemptively.
  11623. function maybeReadMore(stream, state) {
  11624.   if (!state.readingMore) {
  11625.     state.readingMore = true;
  11626.     pna.nextTick(maybeReadMore_, stream, state);
  11627.   }
  11628. }
  11629.  
  11630. function maybeReadMore_(stream, state) {
  11631.   var len = state.length;
  11632.   while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
  11633.     debug('maybeReadMore read 0');
  11634.     stream.read(0);
  11635.     if (len === state.length)
  11636.       // didn't get any data, stop spinning.
  11637.       break;else len = state.length;
  11638.   }
  11639.   state.readingMore = false;
  11640. }
  11641.  
  11642. // abstract method.  to be overridden in specific implementation classes.
  11643. // call cb(er, data) where data is <= n in length.
  11644. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  11645. // arbitrary, and perhaps not very meaningful.
  11646. Readable.prototype._read = function (n) {
  11647.   this.emit('error', new Error('_read() is not implemented'));
  11648. };
  11649.  
  11650. Readable.prototype.pipe = function (dest, pipeOpts) {
  11651.   var src = this;
  11652.   var state = this._readableState;
  11653.  
  11654.   switch (state.pipesCount) {
  11655.     case 0:
  11656.       state.pipes = dest;
  11657.       break;
  11658.     case 1:
  11659.       state.pipes = [state.pipes, dest];
  11660.       break;
  11661.     default:
  11662.       state.pipes.push(dest);
  11663.       break;
  11664.   }
  11665.   state.pipesCount += 1;
  11666.   debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  11667.  
  11668.   var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  11669.  
  11670.   var endFn = doEnd ? onend : unpipe;
  11671.   if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
  11672.  
  11673.   dest.on('unpipe', onunpipe);
  11674.   function onunpipe(readable, unpipeInfo) {
  11675.     debug('onunpipe');
  11676.     if (readable === src) {
  11677.       if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
  11678.         unpipeInfo.hasUnpiped = true;
  11679.         cleanup();
  11680.       }
  11681.     }
  11682.   }
  11683.  
  11684.   function onend() {
  11685.     debug('onend');
  11686.     dest.end();
  11687.   }
  11688.  
  11689.   // when the dest drains, it reduces the awaitDrain counter
  11690.   // on the source.  This would be more elegant with a .once()
  11691.   // handler in flow(), but adding and removing repeatedly is
  11692.   // too slow.
  11693.   var ondrain = pipeOnDrain(src);
  11694.   dest.on('drain', ondrain);
  11695.  
  11696.   var cleanedUp = false;
  11697.   function cleanup() {
  11698.     debug('cleanup');
  11699.     // cleanup event handlers once the pipe is broken
  11700.     dest.removeListener('close', onclose);
  11701.     dest.removeListener('finish', onfinish);
  11702.     dest.removeListener('drain', ondrain);
  11703.     dest.removeListener('error', onerror);
  11704.     dest.removeListener('unpipe', onunpipe);
  11705.     src.removeListener('end', onend);
  11706.     src.removeListener('end', unpipe);
  11707.     src.removeListener('data', ondata);
  11708.  
  11709.     cleanedUp = true;
  11710.  
  11711.     // if the reader is waiting for a drain event from this
  11712.     // specific writer, then it would cause it to never start
  11713.     // flowing again.
  11714.     // So, if this is awaiting a drain, then we just call it now.
  11715.     // If we don't know, then assume that we are waiting for one.
  11716.     if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  11717.   }
  11718.  
  11719.   // If the user pushes more data while we're writing to dest then we'll end up
  11720.   // in ondata again. However, we only want to increase awaitDrain once because
  11721.   // dest will only emit one 'drain' event for the multiple writes.
  11722.   // => Introduce a guard on increasing awaitDrain.
  11723.   var increasedAwaitDrain = false;
  11724.   src.on('data', ondata);
  11725.   function ondata(chunk) {
  11726.     debug('ondata');
  11727.     increasedAwaitDrain = false;
  11728.     var ret = dest.write(chunk);
  11729.     if (false === ret && !increasedAwaitDrain) {
  11730.       // If the user unpiped during `dest.write()`, it is possible
  11731.       // to get stuck in a permanently paused state if that write
  11732.       // also returned false.
  11733.       // => Check whether `dest` is still a piping destination.
  11734.       if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  11735.         debug('false write response, pause', src._readableState.awaitDrain);
  11736.         src._readableState.awaitDrain++;
  11737.         increasedAwaitDrain = true;
  11738.       }
  11739.       src.pause();
  11740.     }
  11741.   }
  11742.  
  11743.   // if the dest has an error, then stop piping into it.
  11744.   // however, don't suppress the throwing behavior for this.
  11745.   function onerror(er) {
  11746.     debug('onerror', er);
  11747.     unpipe();
  11748.     dest.removeListener('error', onerror);
  11749.     if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
  11750.   }
  11751.  
  11752.   // Make sure our error handler is attached before userland ones.
  11753.   prependListener(dest, 'error', onerror);
  11754.  
  11755.   // Both close and finish should trigger unpipe, but only once.
  11756.   function onclose() {
  11757.     dest.removeListener('finish', onfinish);
  11758.     unpipe();
  11759.   }
  11760.   dest.once('close', onclose);
  11761.   function onfinish() {
  11762.     debug('onfinish');
  11763.     dest.removeListener('close', onclose);
  11764.     unpipe();
  11765.   }
  11766.   dest.once('finish', onfinish);
  11767.  
  11768.   function unpipe() {
  11769.     debug('unpipe');
  11770.     src.unpipe(dest);
  11771.   }
  11772.  
  11773.   // tell the dest that it's being piped to
  11774.   dest.emit('pipe', src);
  11775.  
  11776.   // start the flow if it hasn't been started already.
  11777.   if (!state.flowing) {
  11778.     debug('pipe resume');
  11779.     src.resume();
  11780.   }
  11781.  
  11782.   return dest;
  11783. };
  11784.  
  11785. function pipeOnDrain(src) {
  11786.   return function () {
  11787.     var state = src._readableState;
  11788.     debug('pipeOnDrain', state.awaitDrain);
  11789.     if (state.awaitDrain) state.awaitDrain--;
  11790.     if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  11791.       state.flowing = true;
  11792.       flow(src);
  11793.     }
  11794.   };
  11795. }
  11796.  
  11797. Readable.prototype.unpipe = function (dest) {
  11798.   var state = this._readableState;
  11799.   var unpipeInfo = { hasUnpiped: false };
  11800.  
  11801.   // if we're not piping anywhere, then do nothing.
  11802.   if (state.pipesCount === 0) return this;
  11803.  
  11804.   // just one destination.  most common case.
  11805.   if (state.pipesCount === 1) {
  11806.     // passed in one, but it's not the right one.
  11807.     if (dest && dest !== state.pipes) return this;
  11808.  
  11809.     if (!dest) dest = state.pipes;
  11810.  
  11811.     // got a match.
  11812.     state.pipes = null;
  11813.     state.pipesCount = 0;
  11814.     state.flowing = false;
  11815.     if (dest) dest.emit('unpipe', this, unpipeInfo);
  11816.     return this;
  11817.   }
  11818.  
  11819.   // slow case. multiple pipe destinations.
  11820.  
  11821.   if (!dest) {
  11822.     // remove all.
  11823.     var dests = state.pipes;
  11824.     var len = state.pipesCount;
  11825.     state.pipes = null;
  11826.     state.pipesCount = 0;
  11827.     state.flowing = false;
  11828.  
  11829.     for (var i = 0; i < len; i++) {
  11830.       dests[i].emit('unpipe', this, unpipeInfo);
  11831.     }return this;
  11832.   }
  11833.  
  11834.   // try to find the right one.
  11835.   var index = indexOf(state.pipes, dest);
  11836.   if (index === -1) return this;
  11837.  
  11838.   state.pipes.splice(index, 1);
  11839.   state.pipesCount -= 1;
  11840.   if (state.pipesCount === 1) state.pipes = state.pipes[0];
  11841.  
  11842.   dest.emit('unpipe', this, unpipeInfo);
  11843.  
  11844.   return this;
  11845. };
  11846.  
  11847. // set up data events if they are asked for
  11848. // Ensure readable listeners eventually get something
  11849. Readable.prototype.on = function (ev, fn) {
  11850.   var res = Stream.prototype.on.call(this, ev, fn);
  11851.  
  11852.   if (ev === 'data') {
  11853.     // Start flowing on next tick if stream isn't explicitly paused
  11854.     if (this._readableState.flowing !== false) this.resume();
  11855.   } else if (ev === 'readable') {
  11856.     var state = this._readableState;
  11857.     if (!state.endEmitted && !state.readableListening) {
  11858.       state.readableListening = state.needReadable = true;
  11859.       state.emittedReadable = false;
  11860.       if (!state.reading) {
  11861.         pna.nextTick(nReadingNextTick, this);
  11862.       } else if (state.length) {
  11863.         emitReadable(this);
  11864.       }
  11865.     }
  11866.   }
  11867.  
  11868.   return res;
  11869. };
  11870. Readable.prototype.addListener = Readable.prototype.on;
  11871.  
  11872. function nReadingNextTick(self) {
  11873.   debug('readable nexttick read 0');
  11874.   self.read(0);
  11875. }
  11876.  
  11877. // pause() and resume() are remnants of the legacy readable stream API
  11878. // If the user uses them, then switch into old mode.
  11879. Readable.prototype.resume = function () {
  11880.   var state = this._readableState;
  11881.   if (!state.flowing) {
  11882.     debug('resume');
  11883.     state.flowing = true;
  11884.     resume(this, state);
  11885.   }
  11886.   return this;
  11887. };
  11888.  
  11889. function resume(stream, state) {
  11890.   if (!state.resumeScheduled) {
  11891.     state.resumeScheduled = true;
  11892.     pna.nextTick(resume_, stream, state);
  11893.   }
  11894. }
  11895.  
  11896. function resume_(stream, state) {
  11897.   if (!state.reading) {
  11898.     debug('resume read 0');
  11899.     stream.read(0);
  11900.   }
  11901.  
  11902.   state.resumeScheduled = false;
  11903.   state.awaitDrain = 0;
  11904.   stream.emit('resume');
  11905.   flow(stream);
  11906.   if (state.flowing && !state.reading) stream.read(0);
  11907. }
  11908.  
  11909. Readable.prototype.pause = function () {
  11910.   debug('call pause flowing=%j', this._readableState.flowing);
  11911.   if (false !== this._readableState.flowing) {
  11912.     debug('pause');
  11913.     this._readableState.flowing = false;
  11914.     this.emit('pause');
  11915.   }
  11916.   return this;
  11917. };
  11918.  
  11919. function flow(stream) {
  11920.   var state = stream._readableState;
  11921.   debug('flow', state.flowing);
  11922.   while (state.flowing && stream.read() !== null) {}
  11923. }
  11924.  
  11925. // wrap an old-style stream as the async data source.
  11926. // This is *not* part of the readable stream interface.
  11927. // It is an ugly unfortunate mess of history.
  11928. Readable.prototype.wrap = function (stream) {
  11929.   var _this = this;
  11930.  
  11931.   var state = this._readableState;
  11932.   var paused = false;
  11933.  
  11934.   stream.on('end', function () {
  11935.     debug('wrapped end');
  11936.     if (state.decoder && !state.ended) {
  11937.       var chunk = state.decoder.end();
  11938.       if (chunk && chunk.length) _this.push(chunk);
  11939.     }
  11940.  
  11941.     _this.push(null);
  11942.   });
  11943.  
  11944.   stream.on('data', function (chunk) {
  11945.     debug('wrapped data');
  11946.     if (state.decoder) chunk = state.decoder.write(chunk);
  11947.  
  11948.     // don't skip over falsy values in objectMode
  11949.     if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  11950.  
  11951.     var ret = _this.push(chunk);
  11952.     if (!ret) {
  11953.       paused = true;
  11954.       stream.pause();
  11955.     }
  11956.   });
  11957.  
  11958.   // proxy all the other methods.
  11959.   // important when wrapping filters and duplexes.
  11960.   for (var i in stream) {
  11961.     if (this[i] === undefined && typeof stream[i] === 'function') {
  11962.       this[i] = function (method) {
  11963.         return function () {
  11964.           return stream[method].apply(stream, arguments);
  11965.         };
  11966.       }(i);
  11967.     }
  11968.   }
  11969.  
  11970.   // proxy certain important events.
  11971.   for (var n = 0; n < kProxyEvents.length; n++) {
  11972.     stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
  11973.   }
  11974.  
  11975.   // when we try to consume some more bytes, simply unpause the
  11976.   // underlying stream.
  11977.   this._read = function (n) {
  11978.     debug('wrapped _read', n);
  11979.     if (paused) {
  11980.       paused = false;
  11981.       stream.resume();
  11982.     }
  11983.   };
  11984.  
  11985.   return this;
  11986. };
  11987.  
  11988. Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
  11989.   // making it explicit this property is not enumerable
  11990.   // because otherwise some prototype manipulation in
  11991.   // userland will fail
  11992.   enumerable: false,
  11993.   get: function () {
  11994.     return this._readableState.highWaterMark;
  11995.   }
  11996. });
  11997.  
  11998. // exposed for testing purposes only.
  11999. Readable._fromList = fromList;
  12000.  
  12001. // Pluck off n bytes from an array of buffers.
  12002. // Length is the combined lengths of all the buffers in the list.
  12003. // This function is designed to be inlinable, so please take care when making
  12004. // changes to the function body.
  12005. function fromList(n, state) {
  12006.   // nothing buffered
  12007.   if (state.length === 0) return null;
  12008.  
  12009.   var ret;
  12010.   if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
  12011.     // read it all, truncate the list
  12012.     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);
  12013.     state.buffer.clear();
  12014.   } else {
  12015.     // read part of list
  12016.     ret = fromListPartial(n, state.buffer, state.decoder);
  12017.   }
  12018.  
  12019.   return ret;
  12020. }
  12021.  
  12022. // Extracts only enough buffered data to satisfy the amount requested.
  12023. // This function is designed to be inlinable, so please take care when making
  12024. // changes to the function body.
  12025. function fromListPartial(n, list, hasStrings) {
  12026.   var ret;
  12027.   if (n < list.head.data.length) {
  12028.     // slice is the same for buffers and strings
  12029.     ret = list.head.data.slice(0, n);
  12030.     list.head.data = list.head.data.slice(n);
  12031.   } else if (n === list.head.data.length) {
  12032.     // first chunk is a perfect match
  12033.     ret = list.shift();
  12034.   } else {
  12035.     // result spans more than one buffer
  12036.     ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
  12037.   }
  12038.   return ret;
  12039. }
  12040.  
  12041. // Copies a specified amount of characters from the list of buffered data
  12042. // chunks.
  12043. // This function is designed to be inlinable, so please take care when making
  12044. // changes to the function body.
  12045. function copyFromBufferString(n, list) {
  12046.   var p = list.head;
  12047.   var c = 1;
  12048.   var ret = p.data;
  12049.   n -= ret.length;
  12050.   while (p = p.next) {
  12051.     var str = p.data;
  12052.     var nb = n > str.length ? str.length : n;
  12053.     if (nb === str.length) ret += str;else ret += str.slice(0, n);
  12054.     n -= nb;
  12055.     if (n === 0) {
  12056.       if (nb === str.length) {
  12057.         ++c;
  12058.         if (p.next) list.head = p.next;else list.head = list.tail = null;
  12059.       } else {
  12060.         list.head = p;
  12061.         p.data = str.slice(nb);
  12062.       }
  12063.       break;
  12064.     }
  12065.     ++c;
  12066.   }
  12067.   list.length -= c;
  12068.   return ret;
  12069. }
  12070.  
  12071. // Copies a specified amount of bytes from the list of buffered data chunks.
  12072. // This function is designed to be inlinable, so please take care when making
  12073. // changes to the function body.
  12074. function copyFromBuffer(n, list) {
  12075.   var ret = Buffer.allocUnsafe(n);
  12076.   var p = list.head;
  12077.   var c = 1;
  12078.   p.data.copy(ret);
  12079.   n -= p.data.length;
  12080.   while (p = p.next) {
  12081.     var buf = p.data;
  12082.     var nb = n > buf.length ? buf.length : n;
  12083.     buf.copy(ret, ret.length - n, 0, nb);
  12084.     n -= nb;
  12085.     if (n === 0) {
  12086.       if (nb === buf.length) {
  12087.         ++c;
  12088.         if (p.next) list.head = p.next;else list.head = list.tail = null;
  12089.       } else {
  12090.         list.head = p;
  12091.         p.data = buf.slice(nb);
  12092.       }
  12093.       break;
  12094.     }
  12095.     ++c;
  12096.   }
  12097.   list.length -= c;
  12098.   return ret;
  12099. }
  12100.  
  12101. function endReadable(stream) {
  12102.   var state = stream._readableState;
  12103.  
  12104.   // If we get here before consuming all the bytes, then that is a
  12105.   // bug in node.  Should never happen.
  12106.   if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
  12107.  
  12108.   if (!state.endEmitted) {
  12109.     state.ended = true;
  12110.     pna.nextTick(endReadableNT, state, stream);
  12111.   }
  12112. }
  12113.  
  12114. function endReadableNT(state, stream) {
  12115.   // Check that we didn't get one last unshift.
  12116.   if (!state.endEmitted && state.length === 0) {
  12117.     state.endEmitted = true;
  12118.     stream.readable = false;
  12119.     stream.emit('end');
  12120.   }
  12121. }
  12122.  
  12123. function indexOf(xs, x) {
  12124.   for (var i = 0, l = xs.length; i < l; i++) {
  12125.     if (xs[i] === x) return i;
  12126.   }
  12127.   return -1;
  12128. }
  12129. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12130. },{"./_stream_duplex":31,"./internal/streams/BufferList":36,"./internal/streams/destroy":37,"./internal/streams/stream":38,"_process":29,"core-util-is":10,"events":11,"inherits":13,"isarray":15,"process-nextick-args":28,"safe-buffer":44,"string_decoder/":39,"util":6}],34:[function(require,module,exports){
  12131. // Copyright Joyent, Inc. and other Node contributors.
  12132. //
  12133. // Permission is hereby granted, free of charge, to any person obtaining a
  12134. // copy of this software and associated documentation files (the
  12135. // "Software"), to deal in the Software without restriction, including
  12136. // without limitation the rights to use, copy, modify, merge, publish,
  12137. // distribute, sublicense, and/or sell copies of the Software, and to permit
  12138. // persons to whom the Software is furnished to do so, subject to the
  12139. // following conditions:
  12140. //
  12141. // The above copyright notice and this permission notice shall be included
  12142. // in all copies or substantial portions of the Software.
  12143. //
  12144. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  12145. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12146. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  12147. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  12148. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  12149. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  12150. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  12151.  
  12152. // a transform stream is a readable/writable stream where you do
  12153. // something with the data.  Sometimes it's called a "filter",
  12154. // but that's not a great name for it, since that implies a thing where
  12155. // some bits pass through, and others are simply ignored.  (That would
  12156. // be a valid example of a transform, of course.)
  12157. //
  12158. // While the output is causally related to the input, it's not a
  12159. // necessarily symmetric or synchronous transformation.  For example,
  12160. // a zlib stream might take multiple plain-text writes(), and then
  12161. // emit a single compressed chunk some time in the future.
  12162. //
  12163. // Here's how this works:
  12164. //
  12165. // The Transform stream has all the aspects of the readable and writable
  12166. // stream classes.  When you write(chunk), that calls _write(chunk,cb)
  12167. // internally, and returns false if there's a lot of pending writes
  12168. // buffered up.  When you call read(), that calls _read(n) until
  12169. // there's enough pending readable data buffered up.
  12170. //
  12171. // In a transform stream, the written data is placed in a buffer.  When
  12172. // _read(n) is called, it transforms the queued up data, calling the
  12173. // buffered _write cb's as it consumes chunks.  If consuming a single
  12174. // written chunk would result in multiple output chunks, then the first
  12175. // outputted bit calls the readcb, and subsequent chunks just go into
  12176. // the read buffer, and will cause it to emit 'readable' if necessary.
  12177. //
  12178. // This way, back-pressure is actually determined by the reading side,
  12179. // since _read has to be called to start processing a new chunk.  However,
  12180. // a pathological inflate type of transform can cause excessive buffering
  12181. // here.  For example, imagine a stream where every byte of input is
  12182. // interpreted as an integer from 0-255, and then results in that many
  12183. // bytes of output.  Writing the 4 bytes {ff,ff,ff,ff} would result in
  12184. // 1kb of data being output.  In this case, you could write a very small
  12185. // amount of input, and end up with a very large amount of output.  In
  12186. // such a pathological inflating mechanism, there'd be no way to tell
  12187. // the system to stop doing the transform.  A single 4MB write could
  12188. // cause the system to run out of memory.
  12189. //
  12190. // However, even in such a pathological case, only a single written chunk
  12191. // would be consumed, and then the rest would wait (un-transformed) until
  12192. // the results of the previous transformed chunk were consumed.
  12193.  
  12194. 'use strict';
  12195.  
  12196. module.exports = Transform;
  12197.  
  12198. var Duplex = require('./_stream_duplex');
  12199.  
  12200. /*<replacement>*/
  12201. var util = require('core-util-is');
  12202. util.inherits = require('inherits');
  12203. /*</replacement>*/
  12204.  
  12205. util.inherits(Transform, Duplex);
  12206.  
  12207. function afterTransform(er, data) {
  12208.   var ts = this._transformState;
  12209.   ts.transforming = false;
  12210.  
  12211.   var cb = ts.writecb;
  12212.  
  12213.   if (!cb) {
  12214.     return this.emit('error', new Error('write callback called multiple times'));
  12215.   }
  12216.  
  12217.   ts.writechunk = null;
  12218.   ts.writecb = null;
  12219.  
  12220.   if (data != null) // single equals check for both `null` and `undefined`
  12221.     this.push(data);
  12222.  
  12223.   cb(er);
  12224.  
  12225.   var rs = this._readableState;
  12226.   rs.reading = false;
  12227.   if (rs.needReadable || rs.length < rs.highWaterMark) {
  12228.     this._read(rs.highWaterMark);
  12229.   }
  12230. }
  12231.  
  12232. function Transform(options) {
  12233.   if (!(this instanceof Transform)) return new Transform(options);
  12234.  
  12235.   Duplex.call(this, options);
  12236.  
  12237.   this._transformState = {
  12238.     afterTransform: afterTransform.bind(this),
  12239.     needTransform: false,
  12240.     transforming: false,
  12241.     writecb: null,
  12242.     writechunk: null,
  12243.     writeencoding: null
  12244.   };
  12245.  
  12246.   // start out asking for a readable event once data is transformed.
  12247.   this._readableState.needReadable = true;
  12248.  
  12249.   // we have implemented the _read method, and done the other things
  12250.   // that Readable wants before the first _read call, so unset the
  12251.   // sync guard flag.
  12252.   this._readableState.sync = false;
  12253.  
  12254.   if (options) {
  12255.     if (typeof options.transform === 'function') this._transform = options.transform;
  12256.  
  12257.     if (typeof options.flush === 'function') this._flush = options.flush;
  12258.   }
  12259.  
  12260.   // When the writable side finishes, then flush out anything remaining.
  12261.   this.on('prefinish', prefinish);
  12262. }
  12263.  
  12264. function prefinish() {
  12265.   var _this = this;
  12266.  
  12267.   if (typeof this._flush === 'function') {
  12268.     this._flush(function (er, data) {
  12269.       done(_this, er, data);
  12270.     });
  12271.   } else {
  12272.     done(this, null, null);
  12273.   }
  12274. }
  12275.  
  12276. Transform.prototype.push = function (chunk, encoding) {
  12277.   this._transformState.needTransform = false;
  12278.   return Duplex.prototype.push.call(this, chunk, encoding);
  12279. };
  12280.  
  12281. // This is the part where you do stuff!
  12282. // override this function in implementation classes.
  12283. // 'chunk' is an input chunk.
  12284. //
  12285. // Call `push(newChunk)` to pass along transformed output
  12286. // to the readable side.  You may call 'push' zero or more times.
  12287. //
  12288. // Call `cb(err)` when you are done with this chunk.  If you pass
  12289. // an error, then that'll put the hurt on the whole operation.  If you
  12290. // never call cb(), then you'll never get another chunk.
  12291. Transform.prototype._transform = function (chunk, encoding, cb) {
  12292.   throw new Error('_transform() is not implemented');
  12293. };
  12294.  
  12295. Transform.prototype._write = function (chunk, encoding, cb) {
  12296.   var ts = this._transformState;
  12297.   ts.writecb = cb;
  12298.   ts.writechunk = chunk;
  12299.   ts.writeencoding = encoding;
  12300.   if (!ts.transforming) {
  12301.     var rs = this._readableState;
  12302.     if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  12303.   }
  12304. };
  12305.  
  12306. // Doesn't matter what the args are here.
  12307. // _transform does all the work.
  12308. // That we got here means that the readable side wants more data.
  12309. Transform.prototype._read = function (n) {
  12310.   var ts = this._transformState;
  12311.  
  12312.   if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
  12313.     ts.transforming = true;
  12314.     this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  12315.   } else {
  12316.     // mark that we need a transform, so that any data that comes in
  12317.     // will get processed, now that we've asked for it.
  12318.     ts.needTransform = true;
  12319.   }
  12320. };
  12321.  
  12322. Transform.prototype._destroy = function (err, cb) {
  12323.   var _this2 = this;
  12324.  
  12325.   Duplex.prototype._destroy.call(this, err, function (err2) {
  12326.     cb(err2);
  12327.     _this2.emit('close');
  12328.   });
  12329. };
  12330.  
  12331. function done(stream, er, data) {
  12332.   if (er) return stream.emit('error', er);
  12333.  
  12334.   if (data != null) // single equals check for both `null` and `undefined`
  12335.     stream.push(data);
  12336.  
  12337.   // if there's nothing in the write buffer, then that means
  12338.   // that nothing more will ever be provided
  12339.   if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
  12340.  
  12341.   if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
  12342.  
  12343.   return stream.push(null);
  12344. }
  12345. },{"./_stream_duplex":31,"core-util-is":10,"inherits":13}],35:[function(require,module,exports){
  12346. (function (process,global,setImmediate){
  12347. // Copyright Joyent, Inc. and other Node contributors.
  12348. //
  12349. // Permission is hereby granted, free of charge, to any person obtaining a
  12350. // copy of this software and associated documentation files (the
  12351. // "Software"), to deal in the Software without restriction, including
  12352. // without limitation the rights to use, copy, modify, merge, publish,
  12353. // distribute, sublicense, and/or sell copies of the Software, and to permit
  12354. // persons to whom the Software is furnished to do so, subject to the
  12355. // following conditions:
  12356. //
  12357. // The above copyright notice and this permission notice shall be included
  12358. // in all copies or substantial portions of the Software.
  12359. //
  12360. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  12361. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12362. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  12363. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  12364. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  12365. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  12366. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  12367.  
  12368. // A bit simpler than readable streams.
  12369. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  12370. // the drain event emission and buffering.
  12371.  
  12372. 'use strict';
  12373.  
  12374. /*<replacement>*/
  12375.  
  12376. var pna = require('process-nextick-args');
  12377. /*</replacement>*/
  12378.  
  12379. module.exports = Writable;
  12380.  
  12381. /* <replacement> */
  12382. function WriteReq(chunk, encoding, cb) {
  12383.   this.chunk = chunk;
  12384.   this.encoding = encoding;
  12385.   this.callback = cb;
  12386.   this.next = null;
  12387. }
  12388.  
  12389. // It seems a linked list but it is not
  12390. // there will be only 2 of these for each stream
  12391. function CorkedRequest(state) {
  12392.   var _this = this;
  12393.  
  12394.   this.next = null;
  12395.   this.entry = null;
  12396.   this.finish = function () {
  12397.     onCorkedFinish(_this, state);
  12398.   };
  12399. }
  12400. /* </replacement> */
  12401.  
  12402. /*<replacement>*/
  12403. var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
  12404. /*</replacement>*/
  12405.  
  12406. /*<replacement>*/
  12407. var Duplex;
  12408. /*</replacement>*/
  12409.  
  12410. Writable.WritableState = WritableState;
  12411.  
  12412. /*<replacement>*/
  12413. var util = require('core-util-is');
  12414. util.inherits = require('inherits');
  12415. /*</replacement>*/
  12416.  
  12417. /*<replacement>*/
  12418. var internalUtil = {
  12419.   deprecate: require('util-deprecate')
  12420. };
  12421. /*</replacement>*/
  12422.  
  12423. /*<replacement>*/
  12424. var Stream = require('./internal/streams/stream');
  12425. /*</replacement>*/
  12426.  
  12427. /*<replacement>*/
  12428.  
  12429. var Buffer = require('safe-buffer').Buffer;
  12430. var OurUint8Array = global.Uint8Array || function () {};
  12431. function _uint8ArrayToBuffer(chunk) {
  12432.   return Buffer.from(chunk);
  12433. }
  12434. function _isUint8Array(obj) {
  12435.   return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  12436. }
  12437.  
  12438. /*</replacement>*/
  12439.  
  12440. var destroyImpl = require('./internal/streams/destroy');
  12441.  
  12442. util.inherits(Writable, Stream);
  12443.  
  12444. function nop() {}
  12445.  
  12446. function WritableState(options, stream) {
  12447.   Duplex = Duplex || require('./_stream_duplex');
  12448.  
  12449.   options = options || {};
  12450.  
  12451.   // Duplex streams are both readable and writable, but share
  12452.   // the same options object.
  12453.   // However, some cases require setting options to different
  12454.   // values for the readable and the writable sides of the duplex stream.
  12455.   // These options can be provided separately as readableXXX and writableXXX.
  12456.   var isDuplex = stream instanceof Duplex;
  12457.  
  12458.   // object stream flag to indicate whether or not this stream
  12459.   // contains buffers or objects.
  12460.   this.objectMode = !!options.objectMode;
  12461.  
  12462.   if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
  12463.  
  12464.   // the point at which write() starts returning false
  12465.   // Note: 0 is a valid value, means that we always return false if
  12466.   // the entire buffer is not flushed immediately on write()
  12467.   var hwm = options.highWaterMark;
  12468.   var writableHwm = options.writableHighWaterMark;
  12469.   var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  12470.  
  12471.   if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
  12472.  
  12473.   // cast to ints.
  12474.   this.highWaterMark = Math.floor(this.highWaterMark);
  12475.  
  12476.   // if _final has been called
  12477.   this.finalCalled = false;
  12478.  
  12479.   // drain event flag.
  12480.   this.needDrain = false;
  12481.   // at the start of calling end()
  12482.   this.ending = false;
  12483.   // when end() has been called, and returned
  12484.   this.ended = false;
  12485.   // when 'finish' is emitted
  12486.   this.finished = false;
  12487.  
  12488.   // has it been destroyed
  12489.   this.destroyed = false;
  12490.  
  12491.   // should we decode strings into buffers before passing to _write?
  12492.   // this is here so that some node-core streams can optimize string
  12493.   // handling at a lower level.
  12494.   var noDecode = options.decodeStrings === false;
  12495.   this.decodeStrings = !noDecode;
  12496.  
  12497.   // Crypto is kind of old and crusty.  Historically, its default string
  12498.   // encoding is 'binary' so we have to make this configurable.
  12499.   // Everything else in the universe uses 'utf8', though.
  12500.   this.defaultEncoding = options.defaultEncoding || 'utf8';
  12501.  
  12502.   // not an actual buffer we keep track of, but a measurement
  12503.   // of how much we're waiting to get pushed to some underlying
  12504.   // socket or file.
  12505.   this.length = 0;
  12506.  
  12507.   // a flag to see when we're in the middle of a write.
  12508.   this.writing = false;
  12509.  
  12510.   // when true all writes will be buffered until .uncork() call
  12511.   this.corked = 0;
  12512.  
  12513.   // a flag to be able to tell if the onwrite cb is called immediately,
  12514.   // or on a later tick.  We set this to true at first, because any
  12515.   // actions that shouldn't happen until "later" should generally also
  12516.   // not happen before the first write call.
  12517.   this.sync = true;
  12518.  
  12519.   // a flag to know if we're processing previously buffered items, which
  12520.   // may call the _write() callback in the same tick, so that we don't
  12521.   // end up in an overlapped onwrite situation.
  12522.   this.bufferProcessing = false;
  12523.  
  12524.   // the callback that's passed to _write(chunk,cb)
  12525.   this.onwrite = function (er) {
  12526.     onwrite(stream, er);
  12527.   };
  12528.  
  12529.   // the callback that the user supplies to write(chunk,encoding,cb)
  12530.   this.writecb = null;
  12531.  
  12532.   // the amount that is being written when _write is called.
  12533.   this.writelen = 0;
  12534.  
  12535.   this.bufferedRequest = null;
  12536.   this.lastBufferedRequest = null;
  12537.  
  12538.   // number of pending user-supplied write callbacks
  12539.   // this must be 0 before 'finish' can be emitted
  12540.   this.pendingcb = 0;
  12541.  
  12542.   // emit prefinish if the only thing we're waiting for is _write cbs
  12543.   // This is relevant for synchronous Transform streams
  12544.   this.prefinished = false;
  12545.  
  12546.   // True if the error was already emitted and should not be thrown again
  12547.   this.errorEmitted = false;
  12548.  
  12549.   // count buffered requests
  12550.   this.bufferedRequestCount = 0;
  12551.  
  12552.   // allocate the first CorkedRequest, there is always
  12553.   // one allocated and free to use, and we maintain at most two
  12554.   this.corkedRequestsFree = new CorkedRequest(this);
  12555. }
  12556.  
  12557. WritableState.prototype.getBuffer = function getBuffer() {
  12558.   var current = this.bufferedRequest;
  12559.   var out = [];
  12560.   while (current) {
  12561.     out.push(current);
  12562.     current = current.next;
  12563.   }
  12564.   return out;
  12565. };
  12566.  
  12567. (function () {
  12568.   try {
  12569.     Object.defineProperty(WritableState.prototype, 'buffer', {
  12570.       get: internalUtil.deprecate(function () {
  12571.         return this.getBuffer();
  12572.       }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
  12573.     });
  12574.   } catch (_) {}
  12575. })();
  12576.  
  12577. // Test _writableState for inheritance to account for Duplex streams,
  12578. // whose prototype chain only points to Readable.
  12579. var realHasInstance;
  12580. if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
  12581.   realHasInstance = Function.prototype[Symbol.hasInstance];
  12582.   Object.defineProperty(Writable, Symbol.hasInstance, {
  12583.     value: function (object) {
  12584.       if (realHasInstance.call(this, object)) return true;
  12585.       if (this !== Writable) return false;
  12586.  
  12587.       return object && object._writableState instanceof WritableState;
  12588.     }
  12589.   });
  12590. } else {
  12591.   realHasInstance = function (object) {
  12592.     return object instanceof this;
  12593.   };
  12594. }
  12595.  
  12596. function Writable(options) {
  12597.   Duplex = Duplex || require('./_stream_duplex');
  12598.  
  12599.   // Writable ctor is applied to Duplexes, too.
  12600.   // `realHasInstance` is necessary because using plain `instanceof`
  12601.   // would return false, as no `_writableState` property is attached.
  12602.  
  12603.   // Trying to use the custom `instanceof` for Writable here will also break the
  12604.   // Node.js LazyTransform implementation, which has a non-trivial getter for
  12605.   // `_writableState` that would lead to infinite recursion.
  12606.   if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
  12607.     return new Writable(options);
  12608.   }
  12609.  
  12610.   this._writableState = new WritableState(options, this);
  12611.  
  12612.   // legacy.
  12613.   this.writable = true;
  12614.  
  12615.   if (options) {
  12616.     if (typeof options.write === 'function') this._write = options.write;
  12617.  
  12618.     if (typeof options.writev === 'function') this._writev = options.writev;
  12619.  
  12620.     if (typeof options.destroy === 'function') this._destroy = options.destroy;
  12621.  
  12622.     if (typeof options.final === 'function') this._final = options.final;
  12623.   }
  12624.  
  12625.   Stream.call(this);
  12626. }
  12627.  
  12628. // Otherwise people can pipe Writable streams, which is just wrong.
  12629. Writable.prototype.pipe = function () {
  12630.   this.emit('error', new Error('Cannot pipe, not readable'));
  12631. };
  12632.  
  12633. function writeAfterEnd(stream, cb) {
  12634.   var er = new Error('write after end');
  12635.   // TODO: defer error events consistently everywhere, not just the cb
  12636.   stream.emit('error', er);
  12637.   pna.nextTick(cb, er);
  12638. }
  12639.  
  12640. // Checks that a user-supplied chunk is valid, especially for the particular
  12641. // mode the stream is in. Currently this means that `null` is never accepted
  12642. // and undefined/non-string values are only allowed in object mode.
  12643. function validChunk(stream, state, chunk, cb) {
  12644.   var valid = true;
  12645.   var er = false;
  12646.  
  12647.   if (chunk === null) {
  12648.     er = new TypeError('May not write null values to stream');
  12649.   } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  12650.     er = new TypeError('Invalid non-string/buffer chunk');
  12651.   }
  12652.   if (er) {
  12653.     stream.emit('error', er);
  12654.     pna.nextTick(cb, er);
  12655.     valid = false;
  12656.   }
  12657.   return valid;
  12658. }
  12659.  
  12660. Writable.prototype.write = function (chunk, encoding, cb) {
  12661.   var state = this._writableState;
  12662.   var ret = false;
  12663.   var isBuf = !state.objectMode && _isUint8Array(chunk);
  12664.  
  12665.   if (isBuf && !Buffer.isBuffer(chunk)) {
  12666.     chunk = _uint8ArrayToBuffer(chunk);
  12667.   }
  12668.  
  12669.   if (typeof encoding === 'function') {
  12670.     cb = encoding;
  12671.     encoding = null;
  12672.   }
  12673.  
  12674.   if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  12675.  
  12676.   if (typeof cb !== 'function') cb = nop;
  12677.  
  12678.   if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
  12679.     state.pendingcb++;
  12680.     ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
  12681.   }
  12682.  
  12683.   return ret;
  12684. };
  12685.  
  12686. Writable.prototype.cork = function () {
  12687.   var state = this._writableState;
  12688.  
  12689.   state.corked++;
  12690. };
  12691.  
  12692. Writable.prototype.uncork = function () {
  12693.   var state = this._writableState;
  12694.  
  12695.   if (state.corked) {
  12696.     state.corked--;
  12697.  
  12698.     if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  12699.   }
  12700. };
  12701.  
  12702. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  12703.   // node::ParseEncoding() requires lower case.
  12704.   if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  12705.   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);
  12706.   this._writableState.defaultEncoding = encoding;
  12707.   return this;
  12708. };
  12709.  
  12710. function decodeChunk(state, chunk, encoding) {
  12711.   if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  12712.     chunk = Buffer.from(chunk, encoding);
  12713.   }
  12714.   return chunk;
  12715. }
  12716.  
  12717. Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
  12718.   // making it explicit this property is not enumerable
  12719.   // because otherwise some prototype manipulation in
  12720.   // userland will fail
  12721.   enumerable: false,
  12722.   get: function () {
  12723.     return this._writableState.highWaterMark;
  12724.   }
  12725. });
  12726.  
  12727. // if we're already writing something, then just put this
  12728. // in the queue, and wait our turn.  Otherwise, call _write
  12729. // If we return false, then we need a drain event, so set that flag.
  12730. function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
  12731.   if (!isBuf) {
  12732.     var newChunk = decodeChunk(state, chunk, encoding);
  12733.     if (chunk !== newChunk) {
  12734.       isBuf = true;
  12735.       encoding = 'buffer';
  12736.       chunk = newChunk;
  12737.     }
  12738.   }
  12739.   var len = state.objectMode ? 1 : chunk.length;
  12740.  
  12741.   state.length += len;
  12742.  
  12743.   var ret = state.length < state.highWaterMark;
  12744.   // we must ensure that previous needDrain will not be reset to false.
  12745.   if (!ret) state.needDrain = true;
  12746.  
  12747.   if (state.writing || state.corked) {
  12748.     var last = state.lastBufferedRequest;
  12749.     state.lastBufferedRequest = {
  12750.       chunk: chunk,
  12751.       encoding: encoding,
  12752.       isBuf: isBuf,
  12753.       callback: cb,
  12754.       next: null
  12755.     };
  12756.     if (last) {
  12757.       last.next = state.lastBufferedRequest;
  12758.     } else {
  12759.       state.bufferedRequest = state.lastBufferedRequest;
  12760.     }
  12761.     state.bufferedRequestCount += 1;
  12762.   } else {
  12763.     doWrite(stream, state, false, len, chunk, encoding, cb);
  12764.   }
  12765.  
  12766.   return ret;
  12767. }
  12768.  
  12769. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  12770.   state.writelen = len;
  12771.   state.writecb = cb;
  12772.   state.writing = true;
  12773.   state.sync = true;
  12774.   if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  12775.   state.sync = false;
  12776. }
  12777.  
  12778. function onwriteError(stream, state, sync, er, cb) {
  12779.   --state.pendingcb;
  12780.  
  12781.   if (sync) {
  12782.     // defer the callback if we are being called synchronously
  12783.     // to avoid piling up things on the stack
  12784.     pna.nextTick(cb, er);
  12785.     // this can emit finish, and it will always happen
  12786.     // after error
  12787.     pna.nextTick(finishMaybe, stream, state);
  12788.     stream._writableState.errorEmitted = true;
  12789.     stream.emit('error', er);
  12790.   } else {
  12791.     // the caller expect this to happen before if
  12792.     // it is async
  12793.     cb(er);
  12794.     stream._writableState.errorEmitted = true;
  12795.     stream.emit('error', er);
  12796.     // this can emit finish, but finish must
  12797.     // always follow error
  12798.     finishMaybe(stream, state);
  12799.   }
  12800. }
  12801.  
  12802. function onwriteStateUpdate(state) {
  12803.   state.writing = false;
  12804.   state.writecb = null;
  12805.   state.length -= state.writelen;
  12806.   state.writelen = 0;
  12807. }
  12808.  
  12809. function onwrite(stream, er) {
  12810.   var state = stream._writableState;
  12811.   var sync = state.sync;
  12812.   var cb = state.writecb;
  12813.  
  12814.   onwriteStateUpdate(state);
  12815.  
  12816.   if (er) onwriteError(stream, state, sync, er, cb);else {
  12817.     // Check if we're actually ready to finish, but don't emit yet
  12818.     var finished = needFinish(state);
  12819.  
  12820.     if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  12821.       clearBuffer(stream, state);
  12822.     }
  12823.  
  12824.     if (sync) {
  12825.       /*<replacement>*/
  12826.       asyncWrite(afterWrite, stream, state, finished, cb);
  12827.       /*</replacement>*/
  12828.     } else {
  12829.       afterWrite(stream, state, finished, cb);
  12830.     }
  12831.   }
  12832. }
  12833.  
  12834. function afterWrite(stream, state, finished, cb) {
  12835.   if (!finished) onwriteDrain(stream, state);
  12836.   state.pendingcb--;
  12837.   cb();
  12838.   finishMaybe(stream, state);
  12839. }
  12840.  
  12841. // Must force callback to be called on nextTick, so that we don't
  12842. // emit 'drain' before the write() consumer gets the 'false' return
  12843. // value, and has a chance to attach a 'drain' listener.
  12844. function onwriteDrain(stream, state) {
  12845.   if (state.length === 0 && state.needDrain) {
  12846.     state.needDrain = false;
  12847.     stream.emit('drain');
  12848.   }
  12849. }
  12850.  
  12851. // if there's something in the buffer waiting, then process it
  12852. function clearBuffer(stream, state) {
  12853.   state.bufferProcessing = true;
  12854.   var entry = state.bufferedRequest;
  12855.  
  12856.   if (stream._writev && entry && entry.next) {
  12857.     // Fast case, write everything using _writev()
  12858.     var l = state.bufferedRequestCount;
  12859.     var buffer = new Array(l);
  12860.     var holder = state.corkedRequestsFree;
  12861.     holder.entry = entry;
  12862.  
  12863.     var count = 0;
  12864.     var allBuffers = true;
  12865.     while (entry) {
  12866.       buffer[count] = entry;
  12867.       if (!entry.isBuf) allBuffers = false;
  12868.       entry = entry.next;
  12869.       count += 1;
  12870.     }
  12871.     buffer.allBuffers = allBuffers;
  12872.  
  12873.     doWrite(stream, state, true, state.length, buffer, '', holder.finish);
  12874.  
  12875.     // doWrite is almost always async, defer these to save a bit of time
  12876.     // as the hot path ends with doWrite
  12877.     state.pendingcb++;
  12878.     state.lastBufferedRequest = null;
  12879.     if (holder.next) {
  12880.       state.corkedRequestsFree = holder.next;
  12881.       holder.next = null;
  12882.     } else {
  12883.       state.corkedRequestsFree = new CorkedRequest(state);
  12884.     }
  12885.     state.bufferedRequestCount = 0;
  12886.   } else {
  12887.     // Slow case, write chunks one-by-one
  12888.     while (entry) {
  12889.       var chunk = entry.chunk;
  12890.       var encoding = entry.encoding;
  12891.       var cb = entry.callback;
  12892.       var len = state.objectMode ? 1 : chunk.length;
  12893.  
  12894.       doWrite(stream, state, false, len, chunk, encoding, cb);
  12895.       entry = entry.next;
  12896.       state.bufferedRequestCount--;
  12897.       // if we didn't call the onwrite immediately, then
  12898.       // it means that we need to wait until it does.
  12899.       // also, that means that the chunk and cb are currently
  12900.       // being processed, so move the buffer counter past them.
  12901.       if (state.writing) {
  12902.         break;
  12903.       }
  12904.     }
  12905.  
  12906.     if (entry === null) state.lastBufferedRequest = null;
  12907.   }
  12908.  
  12909.   state.bufferedRequest = entry;
  12910.   state.bufferProcessing = false;
  12911. }
  12912.  
  12913. Writable.prototype._write = function (chunk, encoding, cb) {
  12914.   cb(new Error('_write() is not implemented'));
  12915. };
  12916.  
  12917. Writable.prototype._writev = null;
  12918.  
  12919. Writable.prototype.end = function (chunk, encoding, cb) {
  12920.   var state = this._writableState;
  12921.  
  12922.   if (typeof chunk === 'function') {
  12923.     cb = chunk;
  12924.     chunk = null;
  12925.     encoding = null;
  12926.   } else if (typeof encoding === 'function') {
  12927.     cb = encoding;
  12928.     encoding = null;
  12929.   }
  12930.  
  12931.   if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
  12932.  
  12933.   // .end() fully uncorks
  12934.   if (state.corked) {
  12935.     state.corked = 1;
  12936.     this.uncork();
  12937.   }
  12938.  
  12939.   // ignore unnecessary end() calls.
  12940.   if (!state.ending && !state.finished) endWritable(this, state, cb);
  12941. };
  12942.  
  12943. function needFinish(state) {
  12944.   return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  12945. }
  12946. function callFinal(stream, state) {
  12947.   stream._final(function (err) {
  12948.     state.pendingcb--;
  12949.     if (err) {
  12950.       stream.emit('error', err);
  12951.     }
  12952.     state.prefinished = true;
  12953.     stream.emit('prefinish');
  12954.     finishMaybe(stream, state);
  12955.   });
  12956. }
  12957. function prefinish(stream, state) {
  12958.   if (!state.prefinished && !state.finalCalled) {
  12959.     if (typeof stream._final === 'function') {
  12960.       state.pendingcb++;
  12961.       state.finalCalled = true;
  12962.       pna.nextTick(callFinal, stream, state);
  12963.     } else {
  12964.       state.prefinished = true;
  12965.       stream.emit('prefinish');
  12966.     }
  12967.   }
  12968. }
  12969.  
  12970. function finishMaybe(stream, state) {
  12971.   var need = needFinish(state);
  12972.   if (need) {
  12973.     prefinish(stream, state);
  12974.     if (state.pendingcb === 0) {
  12975.       state.finished = true;
  12976.       stream.emit('finish');
  12977.     }
  12978.   }
  12979.   return need;
  12980. }
  12981.  
  12982. function endWritable(stream, state, cb) {
  12983.   state.ending = true;
  12984.   finishMaybe(stream, state);
  12985.   if (cb) {
  12986.     if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
  12987.   }
  12988.   state.ended = true;
  12989.   stream.writable = false;
  12990. }
  12991.  
  12992. function onCorkedFinish(corkReq, state, err) {
  12993.   var entry = corkReq.entry;
  12994.   corkReq.entry = null;
  12995.   while (entry) {
  12996.     var cb = entry.callback;
  12997.     state.pendingcb--;
  12998.     cb(err);
  12999.     entry = entry.next;
  13000.   }
  13001.   if (state.corkedRequestsFree) {
  13002.     state.corkedRequestsFree.next = corkReq;
  13003.   } else {
  13004.     state.corkedRequestsFree = corkReq;
  13005.   }
  13006. }
  13007.  
  13008. Object.defineProperty(Writable.prototype, 'destroyed', {
  13009.   get: function () {
  13010.     if (this._writableState === undefined) {
  13011.       return false;
  13012.     }
  13013.     return this._writableState.destroyed;
  13014.   },
  13015.   set: function (value) {
  13016.     // we ignore the value if the stream
  13017.     // has not been initialized yet
  13018.     if (!this._writableState) {
  13019.       return;
  13020.     }
  13021.  
  13022.     // backward compatibility, the user is explicitly
  13023.     // managing destroyed
  13024.     this._writableState.destroyed = value;
  13025.   }
  13026. });
  13027.  
  13028. Writable.prototype.destroy = destroyImpl.destroy;
  13029. Writable.prototype._undestroy = destroyImpl.undestroy;
  13030. Writable.prototype._destroy = function (err, cb) {
  13031.   this.end();
  13032.   cb(err);
  13033. };
  13034. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate)
  13035. },{"./_stream_duplex":31,"./internal/streams/destroy":37,"./internal/streams/stream":38,"_process":29,"core-util-is":10,"inherits":13,"process-nextick-args":28,"safe-buffer":44,"timers":46,"util-deprecate":47}],36:[function(require,module,exports){
  13036. 'use strict';
  13037.  
  13038. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13039.  
  13040. var Buffer = require('safe-buffer').Buffer;
  13041. var util = require('util');
  13042.  
  13043. function copyBuffer(src, target, offset) {
  13044.   src.copy(target, offset);
  13045. }
  13046.  
  13047. module.exports = function () {
  13048.   function BufferList() {
  13049.     _classCallCheck(this, BufferList);
  13050.  
  13051.     this.head = null;
  13052.     this.tail = null;
  13053.     this.length = 0;
  13054.   }
  13055.  
  13056.   BufferList.prototype.push = function push(v) {
  13057.     var entry = { data: v, next: null };
  13058.     if (this.length > 0) this.tail.next = entry;else this.head = entry;
  13059.     this.tail = entry;
  13060.     ++this.length;
  13061.   };
  13062.  
  13063.   BufferList.prototype.unshift = function unshift(v) {
  13064.     var entry = { data: v, next: this.head };
  13065.     if (this.length === 0) this.tail = entry;
  13066.     this.head = entry;
  13067.     ++this.length;
  13068.   };
  13069.  
  13070.   BufferList.prototype.shift = function shift() {
  13071.     if (this.length === 0) return;
  13072.     var ret = this.head.data;
  13073.     if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  13074.     --this.length;
  13075.     return ret;
  13076.   };
  13077.  
  13078.   BufferList.prototype.clear = function clear() {
  13079.     this.head = this.tail = null;
  13080.     this.length = 0;
  13081.   };
  13082.  
  13083.   BufferList.prototype.join = function join(s) {
  13084.     if (this.length === 0) return '';
  13085.     var p = this.head;
  13086.     var ret = '' + p.data;
  13087.     while (p = p.next) {
  13088.       ret += s + p.data;
  13089.     }return ret;
  13090.   };
  13091.  
  13092.   BufferList.prototype.concat = function concat(n) {
  13093.     if (this.length === 0) return Buffer.alloc(0);
  13094.     if (this.length === 1) return this.head.data;
  13095.     var ret = Buffer.allocUnsafe(n >>> 0);
  13096.     var p = this.head;
  13097.     var i = 0;
  13098.     while (p) {
  13099.       copyBuffer(p.data, ret, i);
  13100.       i += p.data.length;
  13101.       p = p.next;
  13102.     }
  13103.     return ret;
  13104.   };
  13105.  
  13106.   return BufferList;
  13107. }();
  13108.  
  13109. if (util && util.inspect && util.inspect.custom) {
  13110.   module.exports.prototype[util.inspect.custom] = function () {
  13111.     var obj = util.inspect({ length: this.length });
  13112.     return this.constructor.name + ' ' + obj;
  13113.   };
  13114. }
  13115. },{"safe-buffer":44,"util":6}],37:[function(require,module,exports){
  13116. 'use strict';
  13117.  
  13118. /*<replacement>*/
  13119.  
  13120. var pna = require('process-nextick-args');
  13121. /*</replacement>*/
  13122.  
  13123. // undocumented cb() API, needed for core, not for public API
  13124. function destroy(err, cb) {
  13125.   var _this = this;
  13126.  
  13127.   var readableDestroyed = this._readableState && this._readableState.destroyed;
  13128.   var writableDestroyed = this._writableState && this._writableState.destroyed;
  13129.  
  13130.   if (readableDestroyed || writableDestroyed) {
  13131.     if (cb) {
  13132.       cb(err);
  13133.     } else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
  13134.       pna.nextTick(emitErrorNT, this, err);
  13135.     }
  13136.     return this;
  13137.   }
  13138.  
  13139.   // we set destroyed to true before firing error callbacks in order
  13140.   // to make it re-entrance safe in case destroy() is called within callbacks
  13141.  
  13142.   if (this._readableState) {
  13143.     this._readableState.destroyed = true;
  13144.   }
  13145.  
  13146.   // if this is a duplex stream mark the writable part as destroyed as well
  13147.   if (this._writableState) {
  13148.     this._writableState.destroyed = true;
  13149.   }
  13150.  
  13151.   this._destroy(err || null, function (err) {
  13152.     if (!cb && err) {
  13153.       pna.nextTick(emitErrorNT, _this, err);
  13154.       if (_this._writableState) {
  13155.         _this._writableState.errorEmitted = true;
  13156.       }
  13157.     } else if (cb) {
  13158.       cb(err);
  13159.     }
  13160.   });
  13161.  
  13162.   return this;
  13163. }
  13164.  
  13165. function undestroy() {
  13166.   if (this._readableState) {
  13167.     this._readableState.destroyed = false;
  13168.     this._readableState.reading = false;
  13169.     this._readableState.ended = false;
  13170.     this._readableState.endEmitted = false;
  13171.   }
  13172.  
  13173.   if (this._writableState) {
  13174.     this._writableState.destroyed = false;
  13175.     this._writableState.ended = false;
  13176.     this._writableState.ending = false;
  13177.     this._writableState.finished = false;
  13178.     this._writableState.errorEmitted = false;
  13179.   }
  13180. }
  13181.  
  13182. function emitErrorNT(self, err) {
  13183.   self.emit('error', err);
  13184. }
  13185.  
  13186. module.exports = {
  13187.   destroy: destroy,
  13188.   undestroy: undestroy
  13189. };
  13190. },{"process-nextick-args":28}],38:[function(require,module,exports){
  13191. module.exports = require('events').EventEmitter;
  13192.  
  13193. },{"events":11}],39:[function(require,module,exports){
  13194. // Copyright Joyent, Inc. and other Node contributors.
  13195. //
  13196. // Permission is hereby granted, free of charge, to any person obtaining a
  13197. // copy of this software and associated documentation files (the
  13198. // "Software"), to deal in the Software without restriction, including
  13199. // without limitation the rights to use, copy, modify, merge, publish,
  13200. // distribute, sublicense, and/or sell copies of the Software, and to permit
  13201. // persons to whom the Software is furnished to do so, subject to the
  13202. // following conditions:
  13203. //
  13204. // The above copyright notice and this permission notice shall be included
  13205. // in all copies or substantial portions of the Software.
  13206. //
  13207. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13208. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13209. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  13210. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  13211. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  13212. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  13213. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  13214.  
  13215. 'use strict';
  13216.  
  13217. /*<replacement>*/
  13218.  
  13219. var Buffer = require('safe-buffer').Buffer;
  13220. /*</replacement>*/
  13221.  
  13222. var isEncoding = Buffer.isEncoding || function (encoding) {
  13223.   encoding = '' + encoding;
  13224.   switch (encoding && encoding.toLowerCase()) {
  13225.     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':
  13226.       return true;
  13227.     default:
  13228.       return false;
  13229.   }
  13230. };
  13231.  
  13232. function _normalizeEncoding(enc) {
  13233.   if (!enc) return 'utf8';
  13234.   var retried;
  13235.   while (true) {
  13236.     switch (enc) {
  13237.       case 'utf8':
  13238.       case 'utf-8':
  13239.         return 'utf8';
  13240.       case 'ucs2':
  13241.       case 'ucs-2':
  13242.       case 'utf16le':
  13243.       case 'utf-16le':
  13244.         return 'utf16le';
  13245.       case 'latin1':
  13246.       case 'binary':
  13247.         return 'latin1';
  13248.       case 'base64':
  13249.       case 'ascii':
  13250.       case 'hex':
  13251.         return enc;
  13252.       default:
  13253.         if (retried) return; // undefined
  13254.         enc = ('' + enc).toLowerCase();
  13255.         retried = true;
  13256.     }
  13257.   }
  13258. };
  13259.  
  13260. // Do not cache `Buffer.isEncoding` when checking encoding names as some
  13261. // modules monkey-patch it to support additional encodings
  13262. function normalizeEncoding(enc) {
  13263.   var nenc = _normalizeEncoding(enc);
  13264.   if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
  13265.   return nenc || enc;
  13266. }
  13267.  
  13268. // StringDecoder provides an interface for efficiently splitting a series of
  13269. // buffers into a series of JS strings without breaking apart multi-byte
  13270. // characters.
  13271. exports.StringDecoder = StringDecoder;
  13272. function StringDecoder(encoding) {
  13273.   this.encoding = normalizeEncoding(encoding);
  13274.   var nb;
  13275.   switch (this.encoding) {
  13276.     case 'utf16le':
  13277.       this.text = utf16Text;
  13278.       this.end = utf16End;
  13279.       nb = 4;
  13280.       break;
  13281.     case 'utf8':
  13282.       this.fillLast = utf8FillLast;
  13283.       nb = 4;
  13284.       break;
  13285.     case 'base64':
  13286.       this.text = base64Text;
  13287.       this.end = base64End;
  13288.       nb = 3;
  13289.       break;
  13290.     default:
  13291.       this.write = simpleWrite;
  13292.       this.end = simpleEnd;
  13293.       return;
  13294.   }
  13295.   this.lastNeed = 0;
  13296.   this.lastTotal = 0;
  13297.   this.lastChar = Buffer.allocUnsafe(nb);
  13298. }
  13299.  
  13300. StringDecoder.prototype.write = function (buf) {
  13301.   if (buf.length === 0) return '';
  13302.   var r;
  13303.   var i;
  13304.   if (this.lastNeed) {
  13305.     r = this.fillLast(buf);
  13306.     if (r === undefined) return '';
  13307.     i = this.lastNeed;
  13308.     this.lastNeed = 0;
  13309.   } else {
  13310.     i = 0;
  13311.   }
  13312.   if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
  13313.   return r || '';
  13314. };
  13315.  
  13316. StringDecoder.prototype.end = utf8End;
  13317.  
  13318. // Returns only complete characters in a Buffer
  13319. StringDecoder.prototype.text = utf8Text;
  13320.  
  13321. // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
  13322. StringDecoder.prototype.fillLast = function (buf) {
  13323.   if (this.lastNeed <= buf.length) {
  13324.     buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
  13325.     return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  13326.   }
  13327.   buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
  13328.   this.lastNeed -= buf.length;
  13329. };
  13330.  
  13331. // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
  13332. // continuation byte. If an invalid byte is detected, -2 is returned.
  13333. function utf8CheckByte(byte) {
  13334.   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;
  13335.   return byte >> 6 === 0x02 ? -1 : -2;
  13336. }
  13337.  
  13338. // Checks at most 3 bytes at the end of a Buffer in order to detect an
  13339. // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
  13340. // needed to complete the UTF-8 character (if applicable) are returned.
  13341. function utf8CheckIncomplete(self, buf, i) {
  13342.   var j = buf.length - 1;
  13343.   if (j < i) return 0;
  13344.   var nb = utf8CheckByte(buf[j]);
  13345.   if (nb >= 0) {
  13346.     if (nb > 0) self.lastNeed = nb - 1;
  13347.     return nb;
  13348.   }
  13349.   if (--j < i || nb === -2) return 0;
  13350.   nb = utf8CheckByte(buf[j]);
  13351.   if (nb >= 0) {
  13352.     if (nb > 0) self.lastNeed = nb - 2;
  13353.     return nb;
  13354.   }
  13355.   if (--j < i || nb === -2) return 0;
  13356.   nb = utf8CheckByte(buf[j]);
  13357.   if (nb >= 0) {
  13358.     if (nb > 0) {
  13359.       if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
  13360.     }
  13361.     return nb;
  13362.   }
  13363.   return 0;
  13364. }
  13365.  
  13366. // Validates as many continuation bytes for a multi-byte UTF-8 character as
  13367. // needed or are available. If we see a non-continuation byte where we expect
  13368. // one, we "replace" the validated continuation bytes we've seen so far with
  13369. // a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
  13370. // behavior. The continuation byte check is included three times in the case
  13371. // where all of the continuation bytes for a character exist in the same buffer.
  13372. // It is also done this way as a slight performance increase instead of using a
  13373. // loop.
  13374. function utf8CheckExtraBytes(self, buf, p) {
  13375.   if ((buf[0] & 0xC0) !== 0x80) {
  13376.     self.lastNeed = 0;
  13377.     return '\ufffd';
  13378.   }
  13379.   if (self.lastNeed > 1 && buf.length > 1) {
  13380.     if ((buf[1] & 0xC0) !== 0x80) {
  13381.       self.lastNeed = 1;
  13382.       return '\ufffd';
  13383.     }
  13384.     if (self.lastNeed > 2 && buf.length > 2) {
  13385.       if ((buf[2] & 0xC0) !== 0x80) {
  13386.         self.lastNeed = 2;
  13387.         return '\ufffd';
  13388.       }
  13389.     }
  13390.   }
  13391. }
  13392.  
  13393. // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
  13394. function utf8FillLast(buf) {
  13395.   var p = this.lastTotal - this.lastNeed;
  13396.   var r = utf8CheckExtraBytes(this, buf, p);
  13397.   if (r !== undefined) return r;
  13398.   if (this.lastNeed <= buf.length) {
  13399.     buf.copy(this.lastChar, p, 0, this.lastNeed);
  13400.     return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  13401.   }
  13402.   buf.copy(this.lastChar, p, 0, buf.length);
  13403.   this.lastNeed -= buf.length;
  13404. }
  13405.  
  13406. // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
  13407. // partial character, the character's bytes are buffered until the required
  13408. // number of bytes are available.
  13409. function utf8Text(buf, i) {
  13410.   var total = utf8CheckIncomplete(this, buf, i);
  13411.   if (!this.lastNeed) return buf.toString('utf8', i);
  13412.   this.lastTotal = total;
  13413.   var end = buf.length - (total - this.lastNeed);
  13414.   buf.copy(this.lastChar, 0, end);
  13415.   return buf.toString('utf8', i, end);
  13416. }
  13417.  
  13418. // For UTF-8, a replacement character is added when ending on a partial
  13419. // character.
  13420. function utf8End(buf) {
  13421.   var r = buf && buf.length ? this.write(buf) : '';
  13422.   if (this.lastNeed) return r + '\ufffd';
  13423.   return r;
  13424. }
  13425.  
  13426. // UTF-16LE typically needs two bytes per character, but even if we have an even
  13427. // number of bytes available, we need to check if we end on a leading/high
  13428. // surrogate. In that case, we need to wait for the next two bytes in order to
  13429. // decode the last character properly.
  13430. function utf16Text(buf, i) {
  13431.   if ((buf.length - i) % 2 === 0) {
  13432.     var r = buf.toString('utf16le', i);
  13433.     if (r) {
  13434.       var c = r.charCodeAt(r.length - 1);
  13435.       if (c >= 0xD800 && c <= 0xDBFF) {
  13436.         this.lastNeed = 2;
  13437.         this.lastTotal = 4;
  13438.         this.lastChar[0] = buf[buf.length - 2];
  13439.         this.lastChar[1] = buf[buf.length - 1];
  13440.         return r.slice(0, -1);
  13441.       }
  13442.     }
  13443.     return r;
  13444.   }
  13445.   this.lastNeed = 1;
  13446.   this.lastTotal = 2;
  13447.   this.lastChar[0] = buf[buf.length - 1];
  13448.   return buf.toString('utf16le', i, buf.length - 1);
  13449. }
  13450.  
  13451. // For UTF-16LE we do not explicitly append special replacement characters if we
  13452. // end on a partial character, we simply let v8 handle that.
  13453. function utf16End(buf) {
  13454.   var r = buf && buf.length ? this.write(buf) : '';
  13455.   if (this.lastNeed) {
  13456.     var end = this.lastTotal - this.lastNeed;
  13457.     return r + this.lastChar.toString('utf16le', 0, end);
  13458.   }
  13459.   return r;
  13460. }
  13461.  
  13462. function base64Text(buf, i) {
  13463.   var n = (buf.length - i) % 3;
  13464.   if (n === 0) return buf.toString('base64', i);
  13465.   this.lastNeed = 3 - n;
  13466.   this.lastTotal = 3;
  13467.   if (n === 1) {
  13468.     this.lastChar[0] = buf[buf.length - 1];
  13469.   } else {
  13470.     this.lastChar[0] = buf[buf.length - 2];
  13471.     this.lastChar[1] = buf[buf.length - 1];
  13472.   }
  13473.   return buf.toString('base64', i, buf.length - n);
  13474. }
  13475.  
  13476. function base64End(buf) {
  13477.   var r = buf && buf.length ? this.write(buf) : '';
  13478.   if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
  13479.   return r;
  13480. }
  13481.  
  13482. // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
  13483. function simpleWrite(buf) {
  13484.   return buf.toString(this.encoding);
  13485. }
  13486.  
  13487. function simpleEnd(buf) {
  13488.   return buf && buf.length ? this.write(buf) : '';
  13489. }
  13490. },{"safe-buffer":44}],40:[function(require,module,exports){
  13491. module.exports = require('./readable').PassThrough
  13492.  
  13493. },{"./readable":41}],41:[function(require,module,exports){
  13494. exports = module.exports = require('./lib/_stream_readable.js');
  13495. exports.Stream = exports;
  13496. exports.Readable = exports;
  13497. exports.Writable = require('./lib/_stream_writable.js');
  13498. exports.Duplex = require('./lib/_stream_duplex.js');
  13499. exports.Transform = require('./lib/_stream_transform.js');
  13500. exports.PassThrough = require('./lib/_stream_passthrough.js');
  13501.  
  13502. },{"./lib/_stream_duplex.js":31,"./lib/_stream_passthrough.js":32,"./lib/_stream_readable.js":33,"./lib/_stream_transform.js":34,"./lib/_stream_writable.js":35}],42:[function(require,module,exports){
  13503. module.exports = require('./readable').Transform
  13504.  
  13505. },{"./readable":41}],43:[function(require,module,exports){
  13506. module.exports = require('./lib/_stream_writable.js');
  13507.  
  13508. },{"./lib/_stream_writable.js":35}],44:[function(require,module,exports){
  13509. /* eslint-disable node/no-deprecated-api */
  13510. var buffer = require('buffer')
  13511. var Buffer = buffer.Buffer
  13512.  
  13513. // alternative to using Object.keys for old browsers
  13514. function copyProps (src, dst) {
  13515.   for (var key in src) {
  13516.     dst[key] = src[key]
  13517.   }
  13518. }
  13519. if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
  13520.   module.exports = buffer
  13521. } else {
  13522.   // Copy properties from require('buffer')
  13523.   copyProps(buffer, exports)
  13524.   exports.Buffer = SafeBuffer
  13525. }
  13526.  
  13527. function SafeBuffer (arg, encodingOrOffset, length) {
  13528.   return Buffer(arg, encodingOrOffset, length)
  13529. }
  13530.  
  13531. // Copy static methods from Buffer
  13532. copyProps(Buffer, SafeBuffer)
  13533.  
  13534. SafeBuffer.from = function (arg, encodingOrOffset, length) {
  13535.   if (typeof arg === 'number') {
  13536.     throw new TypeError('Argument must not be a number')
  13537.   }
  13538.   return Buffer(arg, encodingOrOffset, length)
  13539. }
  13540.  
  13541. SafeBuffer.alloc = function (size, fill, encoding) {
  13542.   if (typeof size !== 'number') {
  13543.     throw new TypeError('Argument must be a number')
  13544.   }
  13545.   var buf = Buffer(size)
  13546.   if (fill !== undefined) {
  13547.     if (typeof encoding === 'string') {
  13548.       buf.fill(fill, encoding)
  13549.     } else {
  13550.       buf.fill(fill)
  13551.     }
  13552.   } else {
  13553.     buf.fill(0)
  13554.   }
  13555.   return buf
  13556. }
  13557.  
  13558. SafeBuffer.allocUnsafe = function (size) {
  13559.   if (typeof size !== 'number') {
  13560.     throw new TypeError('Argument must be a number')
  13561.   }
  13562.   return Buffer(size)
  13563. }
  13564.  
  13565. SafeBuffer.allocUnsafeSlow = function (size) {
  13566.   if (typeof size !== 'number') {
  13567.     throw new TypeError('Argument must be a number')
  13568.   }
  13569.   return buffer.SlowBuffer(size)
  13570. }
  13571.  
  13572. },{"buffer":9}],45:[function(require,module,exports){
  13573. // Copyright Joyent, Inc. and other Node contributors.
  13574. //
  13575. // Permission is hereby granted, free of charge, to any person obtaining a
  13576. // copy of this software and associated documentation files (the
  13577. // "Software"), to deal in the Software without restriction, including
  13578. // without limitation the rights to use, copy, modify, merge, publish,
  13579. // distribute, sublicense, and/or sell copies of the Software, and to permit
  13580. // persons to whom the Software is furnished to do so, subject to the
  13581. // following conditions:
  13582. //
  13583. // The above copyright notice and this permission notice shall be included
  13584. // in all copies or substantial portions of the Software.
  13585. //
  13586. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13587. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13588. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  13589. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  13590. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  13591. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  13592. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  13593.  
  13594. module.exports = Stream;
  13595.  
  13596. var EE = require('events').EventEmitter;
  13597. var inherits = require('inherits');
  13598.  
  13599. inherits(Stream, EE);
  13600. Stream.Readable = require('readable-stream/readable.js');
  13601. Stream.Writable = require('readable-stream/writable.js');
  13602. Stream.Duplex = require('readable-stream/duplex.js');
  13603. Stream.Transform = require('readable-stream/transform.js');
  13604. Stream.PassThrough = require('readable-stream/passthrough.js');
  13605.  
  13606. // Backwards-compat with node 0.4.x
  13607. Stream.Stream = Stream;
  13608.  
  13609.  
  13610.  
  13611. // old-style streams.  Note that the pipe method (the only relevant
  13612. // part of this class) is overridden in the Readable class.
  13613.  
  13614. function Stream() {
  13615.   EE.call(this);
  13616. }
  13617.  
  13618. Stream.prototype.pipe = function(dest, options) {
  13619.   var source = this;
  13620.  
  13621.   function ondata(chunk) {
  13622.     if (dest.writable) {
  13623.       if (false === dest.write(chunk) && source.pause) {
  13624.         source.pause();
  13625.       }
  13626.     }
  13627.   }
  13628.  
  13629.   source.on('data', ondata);
  13630.  
  13631.   function ondrain() {
  13632.     if (source.readable && source.resume) {
  13633.       source.resume();
  13634.     }
  13635.   }
  13636.  
  13637.   dest.on('drain', ondrain);
  13638.  
  13639.   // If the 'end' option is not supplied, dest.end() will be called when
  13640.   // source gets the 'end' or 'close' events.  Only dest.end() once.
  13641.   if (!dest._isStdio && (!options || options.end !== false)) {
  13642.     source.on('end', onend);
  13643.     source.on('close', onclose);
  13644.   }
  13645.  
  13646.   var didOnEnd = false;
  13647.   function onend() {
  13648.     if (didOnEnd) return;
  13649.     didOnEnd = true;
  13650.  
  13651.     dest.end();
  13652.   }
  13653.  
  13654.  
  13655.   function onclose() {
  13656.     if (didOnEnd) return;
  13657.     didOnEnd = true;
  13658.  
  13659.     if (typeof dest.destroy === 'function') dest.destroy();
  13660.   }
  13661.  
  13662.   // don't leave dangling pipes when there are errors.
  13663.   function onerror(er) {
  13664.     cleanup();
  13665.     if (EE.listenerCount(this, 'error') === 0) {
  13666.       throw er; // Unhandled stream error in pipe.
  13667.     }
  13668.   }
  13669.  
  13670.   source.on('error', onerror);
  13671.   dest.on('error', onerror);
  13672.  
  13673.   // remove all the event listeners that were added.
  13674.   function cleanup() {
  13675.     source.removeListener('data', ondata);
  13676.     dest.removeListener('drain', ondrain);
  13677.  
  13678.     source.removeListener('end', onend);
  13679.     source.removeListener('close', onclose);
  13680.  
  13681.     source.removeListener('error', onerror);
  13682.     dest.removeListener('error', onerror);
  13683.  
  13684.     source.removeListener('end', cleanup);
  13685.     source.removeListener('close', cleanup);
  13686.  
  13687.     dest.removeListener('close', cleanup);
  13688.   }
  13689.  
  13690.   source.on('end', cleanup);
  13691.   source.on('close', cleanup);
  13692.  
  13693.   dest.on('close', cleanup);
  13694.  
  13695.   dest.emit('pipe', source);
  13696.  
  13697.   // Allow for unix-like usage: A.pipe(B).pipe(C)
  13698.   return dest;
  13699. };
  13700.  
  13701. },{"events":11,"inherits":13,"readable-stream/duplex.js":30,"readable-stream/passthrough.js":40,"readable-stream/readable.js":41,"readable-stream/transform.js":42,"readable-stream/writable.js":43}],46:[function(require,module,exports){
  13702. (function (setImmediate,clearImmediate){
  13703. var nextTick = require('process/browser.js').nextTick;
  13704. var apply = Function.prototype.apply;
  13705. var slice = Array.prototype.slice;
  13706. var immediateIds = {};
  13707. var nextImmediateId = 0;
  13708.  
  13709. // DOM APIs, for completeness
  13710.  
  13711. exports.setTimeout = function() {
  13712.   return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
  13713. };
  13714. exports.setInterval = function() {
  13715.   return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
  13716. };
  13717. exports.clearTimeout =
  13718. exports.clearInterval = function(timeout) { timeout.close(); };
  13719.  
  13720. function Timeout(id, clearFn) {
  13721.   this._id = id;
  13722.   this._clearFn = clearFn;
  13723. }
  13724. Timeout.prototype.unref = Timeout.prototype.ref = function() {};
  13725. Timeout.prototype.close = function() {
  13726.   this._clearFn.call(window, this._id);
  13727. };
  13728.  
  13729. // Does not start the time, just sets up the members needed.
  13730. exports.enroll = function(item, msecs) {
  13731.   clearTimeout(item._idleTimeoutId);
  13732.   item._idleTimeout = msecs;
  13733. };
  13734.  
  13735. exports.unenroll = function(item) {
  13736.   clearTimeout(item._idleTimeoutId);
  13737.   item._idleTimeout = -1;
  13738. };
  13739.  
  13740. exports._unrefActive = exports.active = function(item) {
  13741.   clearTimeout(item._idleTimeoutId);
  13742.  
  13743.   var msecs = item._idleTimeout;
  13744.   if (msecs >= 0) {
  13745.     item._idleTimeoutId = setTimeout(function onTimeout() {
  13746.       if (item._onTimeout)
  13747.         item._onTimeout();
  13748.     }, msecs);
  13749.   }
  13750. };
  13751.  
  13752. // That's not how node.js implements it but the exposed api is the same.
  13753. exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function(fn) {
  13754.   var id = nextImmediateId++;
  13755.   var args = arguments.length < 2 ? false : slice.call(arguments, 1);
  13756.  
  13757.   immediateIds[id] = true;
  13758.  
  13759.   nextTick(function onNextTick() {
  13760.     if (immediateIds[id]) {
  13761.       // fn.call() is faster so we optimize for the common use-case
  13762.       // @see http://jsperf.com/call-apply-segu
  13763.       if (args) {
  13764.         fn.apply(null, args);
  13765.       } else {
  13766.         fn.call(null);
  13767.       }
  13768.       // Prevent ids from leaking
  13769.       exports.clearImmediate(id);
  13770.     }
  13771.   });
  13772.  
  13773.   return id;
  13774. };
  13775.  
  13776. exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) {
  13777.   delete immediateIds[id];
  13778. };
  13779. }).call(this,require("timers").setImmediate,require("timers").clearImmediate)
  13780. },{"process/browser.js":29,"timers":46}],47:[function(require,module,exports){
  13781. (function (global){
  13782.  
  13783. /**
  13784.  * Module exports.
  13785.  */
  13786.  
  13787. module.exports = deprecate;
  13788.  
  13789. /**
  13790.  * Mark that a method should not be used.
  13791.  * Returns a modified function which warns once by default.
  13792.  *
  13793.  * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  13794.  *
  13795.  * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  13796.  * will throw an Error when invoked.
  13797.  *
  13798.  * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  13799.  * will invoke `console.trace()` instead of `console.error()`.
  13800.  *
  13801.  * @param {Function} fn - the function to deprecate
  13802.  * @param {String} msg - the string to print to the console when `fn` is invoked
  13803.  * @returns {Function} a new "deprecated" version of `fn`
  13804.  * @api public
  13805.  */
  13806.  
  13807. function deprecate (fn, msg) {
  13808.   if (config('noDeprecation')) {
  13809.     return fn;
  13810.   }
  13811.  
  13812.   var warned = false;
  13813.   function deprecated() {
  13814.     if (!warned) {
  13815.       if (config('throwDeprecation')) {
  13816.         throw new Error(msg);
  13817.       } else if (config('traceDeprecation')) {
  13818.         console.trace(msg);
  13819.       } else {
  13820.         console.warn(msg);
  13821.       }
  13822.       warned = true;
  13823.     }
  13824.     return fn.apply(this, arguments);
  13825.   }
  13826.  
  13827.   return deprecated;
  13828. }
  13829.  
  13830. /**
  13831.  * Checks `localStorage` for boolean values for the given `name`.
  13832.  *
  13833.  * @param {String} name
  13834.  * @returns {Boolean}
  13835.  * @api private
  13836.  */
  13837.  
  13838. function config (name) {
  13839.   // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  13840.   try {
  13841.     if (!global.localStorage) return false;
  13842.   } catch (_) {
  13843.     return false;
  13844.   }
  13845.   var val = global.localStorage[name];
  13846.   if (null == val) return false;
  13847.   return String(val).toLowerCase() === 'true';
  13848. }
  13849.  
  13850. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  13851. },{}],48:[function(require,module,exports){
  13852. arguments[4][2][0].apply(exports,arguments)
  13853. },{"dup":2}],49:[function(require,module,exports){
  13854. arguments[4][3][0].apply(exports,arguments)
  13855. },{"dup":3}],50:[function(require,module,exports){
  13856. arguments[4][4][0].apply(exports,arguments)
  13857. },{"./support/isBuffer":49,"_process":29,"dup":4,"inherits":48}],51:[function(require,module,exports){
  13858. (function (Buffer){
  13859. var PNG = require('pngjs').PNG;
  13860.  
  13861. function getPNG(bin) {
  13862.     return PNG.sync.read(bin);
  13863. }
  13864.  
  13865. function loadImage(base64)
  13866. {
  13867.     var binary_string = Buffer.from(base64, 'base64');
  13868.  
  13869.     var png = getPNG(binary_string);
  13870.  
  13871.     return png;
  13872. }
  13873.  
  13874. window.getPNG = getPNG;
  13875. window.loadImage = loadImage;
  13876.  
  13877. }).call(this,require("buffer").Buffer)
  13878. },{"atob":52,"buffer":9,"pngjs":72}],52:[function(require,module,exports){
  13879. (function (Buffer){
  13880. (function (w) {
  13881.   "use strict";
  13882.  
  13883.   function findBest(atobNative) {
  13884.     // normal window
  13885.     if ('function' === typeof atobNative) { return atobNative; }
  13886.  
  13887.  
  13888.     // browserify (web worker)
  13889.     if ('function' === typeof Buffer) {
  13890.       return function atobBrowserify(a) {
  13891.         //!! Deliberately using an API that's deprecated in node.js because
  13892.         //!! this file is for browsers and we expect them to cope with it.
  13893.         //!! Discussion: github.com/node-browser-compat/atob/pull/9
  13894.         return new Buffer(a, 'base64').toString('binary');
  13895.       };
  13896.     }
  13897.  
  13898.     // ios web worker with base64js
  13899.     if ('object' === typeof w.base64js) {
  13900.       // bufferToBinaryString
  13901.       // https://git.coolaj86.com/coolaj86/unibabel.js/blob/master/index.js#L50
  13902.       return function atobWebWorker_iOS(a) {
  13903.         var buf = w.base64js.b64ToByteArray(a);
  13904.         return Array.prototype.map.call(buf, function (ch) {
  13905.           return String.fromCharCode(ch);
  13906.         }).join('');
  13907.       };
  13908.     }
  13909.  
  13910.         return function () {
  13911.             // ios web worker without base64js
  13912.             throw new Error("You're probably in an old browser or an iOS webworker." +
  13913.                 " It might help to include beatgammit's base64-js.");
  13914.     };
  13915.   }
  13916.  
  13917.   var atobBest = findBest(w.atob);
  13918.   w.atob = atobBest;
  13919.  
  13920.   if ((typeof module === 'object') && module && module.exports) {
  13921.     module.exports = atobBest;
  13922.   }
  13923. }(window));
  13924.  
  13925. }).call(this,require("buffer").Buffer)
  13926. },{"buffer":9}],53:[function(require,module,exports){
  13927. (function (Buffer){
  13928. 'use strict';
  13929.  
  13930. var interlaceUtils = require('./interlace');
  13931.  
  13932. var pixelBppMapper = [
  13933.   // 0 - dummy entry
  13934.   function() {},
  13935.  
  13936.   // 1 - L
  13937.   // 0: 0, 1: 0, 2: 0, 3: 0xff
  13938.   function(pxData, data, pxPos, rawPos) {
  13939.     if (rawPos === data.length) {
  13940.       throw new Error('Ran out of data');
  13941.     }
  13942.  
  13943.     var pixel = data[rawPos];
  13944.     pxData[pxPos] = pixel;
  13945.     pxData[pxPos + 1] = pixel;
  13946.     pxData[pxPos + 2] = pixel;
  13947.     pxData[pxPos + 3] = 0xff;
  13948.   },
  13949.  
  13950.   // 2 - LA
  13951.   // 0: 0, 1: 0, 2: 0, 3: 1
  13952.   function(pxData, data, pxPos, rawPos) {
  13953.     if (rawPos + 1 >= data.length) {
  13954.       throw new Error('Ran out of data');
  13955.     }
  13956.  
  13957.     var pixel = data[rawPos];
  13958.     pxData[pxPos] = pixel;
  13959.     pxData[pxPos + 1] = pixel;
  13960.     pxData[pxPos + 2] = pixel;
  13961.     pxData[pxPos + 3] = data[rawPos + 1];
  13962.   },
  13963.  
  13964.   // 3 - RGB
  13965.   // 0: 0, 1: 1, 2: 2, 3: 0xff
  13966.   function(pxData, data, pxPos, rawPos) {
  13967.     if (rawPos + 2 >= data.length) {
  13968.       throw new Error('Ran out of data');
  13969.     }
  13970.  
  13971.     pxData[pxPos] = data[rawPos];
  13972.     pxData[pxPos + 1] = data[rawPos + 1];
  13973.     pxData[pxPos + 2] = data[rawPos + 2];
  13974.     pxData[pxPos + 3] = 0xff;
  13975.   },
  13976.  
  13977.   // 4 - RGBA
  13978.   // 0: 0, 1: 1, 2: 2, 3: 3
  13979.   function(pxData, data, pxPos, rawPos) {
  13980.     if (rawPos + 3 >= data.length) {
  13981.       throw new Error('Ran out of data');
  13982.     }
  13983.  
  13984.     pxData[pxPos] = data[rawPos];
  13985.     pxData[pxPos + 1] = data[rawPos + 1];
  13986.     pxData[pxPos + 2] = data[rawPos + 2];
  13987.     pxData[pxPos + 3] = data[rawPos + 3];
  13988.   }
  13989. ];
  13990.  
  13991. var pixelBppCustomMapper = [
  13992.   // 0 - dummy entry
  13993.   function() {},
  13994.  
  13995.   // 1 - L
  13996.   // 0: 0, 1: 0, 2: 0, 3: 0xff
  13997.   function(pxData, pixelData, pxPos, maxBit) {
  13998.     var pixel = pixelData[0];
  13999.     pxData[pxPos] = pixel;
  14000.     pxData[pxPos + 1] = pixel;
  14001.     pxData[pxPos + 2] = pixel;
  14002.     pxData[pxPos + 3] = maxBit;
  14003.   },
  14004.  
  14005.   // 2 - LA
  14006.   // 0: 0, 1: 0, 2: 0, 3: 1
  14007.   function(pxData, pixelData, pxPos) {
  14008.     var pixel = pixelData[0];
  14009.     pxData[pxPos] = pixel;
  14010.     pxData[pxPos + 1] = pixel;
  14011.     pxData[pxPos + 2] = pixel;
  14012.     pxData[pxPos + 3] = pixelData[1];
  14013.   },
  14014.  
  14015.   // 3 - RGB
  14016.   // 0: 0, 1: 1, 2: 2, 3: 0xff
  14017.   function(pxData, pixelData, pxPos, maxBit) {
  14018.     pxData[pxPos] = pixelData[0];
  14019.     pxData[pxPos + 1] = pixelData[1];
  14020.     pxData[pxPos + 2] = pixelData[2];
  14021.     pxData[pxPos + 3] = maxBit;
  14022.   },
  14023.  
  14024.   // 4 - RGBA
  14025.   // 0: 0, 1: 1, 2: 2, 3: 3
  14026.   function(pxData, pixelData, pxPos) {
  14027.     pxData[pxPos] = pixelData[0];
  14028.     pxData[pxPos + 1] = pixelData[1];
  14029.     pxData[pxPos + 2] = pixelData[2];
  14030.     pxData[pxPos + 3] = pixelData[3];
  14031.   }
  14032. ];
  14033.  
  14034. function bitRetriever(data, depth) {
  14035.  
  14036.   var leftOver = [];
  14037.   var i = 0;
  14038.  
  14039.   function split() {
  14040.     if (i === data.length) {
  14041.       throw new Error('Ran out of data');
  14042.     }
  14043.     var byte = data[i];
  14044.     i++;
  14045.     var byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
  14046.     switch (depth) {
  14047.       default:
  14048.         throw new Error('unrecognised depth');
  14049.       case 16:
  14050.         byte2 = data[i];
  14051.         i++;
  14052.         leftOver.push(((byte << 8) + byte2));
  14053.         break;
  14054.       case 4:
  14055.         byte2 = byte & 0x0f;
  14056.         byte1 = byte >> 4;
  14057.         leftOver.push(byte1, byte2);
  14058.         break;
  14059.       case 2:
  14060.         byte4 = byte & 3;
  14061.         byte3 = byte >> 2 & 3;
  14062.         byte2 = byte >> 4 & 3;
  14063.         byte1 = byte >> 6 & 3;
  14064.         leftOver.push(byte1, byte2, byte3, byte4);
  14065.         break;
  14066.       case 1:
  14067.         byte8 = byte & 1;
  14068.         byte7 = byte >> 1 & 1;
  14069.         byte6 = byte >> 2 & 1;
  14070.         byte5 = byte >> 3 & 1;
  14071.         byte4 = byte >> 4 & 1;
  14072.         byte3 = byte >> 5 & 1;
  14073.         byte2 = byte >> 6 & 1;
  14074.         byte1 = byte >> 7 & 1;
  14075.         leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
  14076.         break;
  14077.     }
  14078.   }
  14079.  
  14080.   return {
  14081.     get: function(count) {
  14082.       while (leftOver.length < count) {
  14083.         split();
  14084.       }
  14085.       var returner = leftOver.slice(0, count);
  14086.       leftOver = leftOver.slice(count);
  14087.       return returner;
  14088.     },
  14089.     resetAfterLine: function() {
  14090.       leftOver.length = 0;
  14091.     },
  14092.     end: function() {
  14093.       if (i !== data.length) {
  14094.         throw new Error('extra data found');
  14095.       }
  14096.     }
  14097.   };
  14098. }
  14099.  
  14100. function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) { // eslint-disable-line max-params
  14101.   var imageWidth = image.width;
  14102.   var imageHeight = image.height;
  14103.   var imagePass = image.index;
  14104.   for (var y = 0; y < imageHeight; y++) {
  14105.     for (var x = 0; x < imageWidth; x++) {
  14106.       var pxPos = getPxPos(x, y, imagePass);
  14107.       pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
  14108.       rawPos += bpp; //eslint-disable-line no-param-reassign
  14109.     }
  14110.   }
  14111.   return rawPos;
  14112. }
  14113.  
  14114. function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) { // eslint-disable-line max-params
  14115.   var imageWidth = image.width;
  14116.   var imageHeight = image.height;
  14117.   var imagePass = image.index;
  14118.   for (var y = 0; y < imageHeight; y++) {
  14119.     for (var x = 0; x < imageWidth; x++) {
  14120.       var pixelData = bits.get(bpp);
  14121.       var pxPos = getPxPos(x, y, imagePass);
  14122.       pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
  14123.     }
  14124.     bits.resetAfterLine();
  14125.   }
  14126. }
  14127.  
  14128. exports.dataToBitMap = function(data, bitmapInfo) {
  14129.  
  14130.   var width = bitmapInfo.width;
  14131.   var height = bitmapInfo.height;
  14132.   var depth = bitmapInfo.depth;
  14133.   var bpp = bitmapInfo.bpp;
  14134.   var interlace = bitmapInfo.interlace;
  14135.  
  14136.   if (depth !== 8) {
  14137.     var bits = bitRetriever(data, depth);
  14138.   }
  14139.   var pxData;
  14140.   if (depth <= 8) {
  14141.     pxData = new Buffer(width * height * 4);
  14142.   }
  14143.   else {
  14144.     pxData = new Uint16Array(width * height * 4);
  14145.   }
  14146.   var maxBit = Math.pow(2, depth) - 1;
  14147.   var rawPos = 0;
  14148.   var images;
  14149.   var getPxPos;
  14150.  
  14151.   if (interlace) {
  14152.     images = interlaceUtils.getImagePasses(width, height);
  14153.     getPxPos = interlaceUtils.getInterlaceIterator(width, height);
  14154.   }
  14155.   else {
  14156.     var nonInterlacedPxPos = 0;
  14157.     getPxPos = function() {
  14158.       var returner = nonInterlacedPxPos;
  14159.       nonInterlacedPxPos += 4;
  14160.       return returner;
  14161.     };
  14162.     images = [{ width: width, height: height }];
  14163.   }
  14164.  
  14165.   for (var imageIndex = 0; imageIndex < images.length; imageIndex++) {
  14166.     if (depth === 8) {
  14167.       rawPos = mapImage8Bit(images[imageIndex], pxData, getPxPos, bpp, data, rawPos);
  14168.     }
  14169.     else {
  14170.       mapImageCustomBit(images[imageIndex], pxData, getPxPos, bpp, bits, maxBit);
  14171.     }
  14172.   }
  14173.   if (depth === 8) {
  14174.     if (rawPos !== data.length) {
  14175.       throw new Error('extra data found');
  14176.     }
  14177.   }
  14178.   else {
  14179.     bits.end();
  14180.   }
  14181.  
  14182.   return pxData;
  14183. };
  14184.  
  14185. }).call(this,require("buffer").Buffer)
  14186. },{"./interlace":63,"buffer":9}],54:[function(require,module,exports){
  14187. (function (Buffer){
  14188. 'use strict';
  14189.  
  14190. var constants = require('./constants');
  14191.  
  14192. module.exports = function(dataIn, width, height, options) {
  14193.   var outHasAlpha = [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(options.colorType) !== -1;
  14194.   if (options.colorType === options.inputColorType) {
  14195.     var bigEndian = (function() {
  14196.       var buffer = new ArrayBuffer(2);
  14197.       new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
  14198.       // Int16Array uses the platform's endianness.
  14199.       return new Int16Array(buffer)[0] !== 256;
  14200.     })();
  14201.     // If no need to convert to grayscale and alpha is present/absent in both, take a fast route
  14202.     if (options.bitDepth === 8 || (options.bitDepth === 16 && bigEndian)) {
  14203.       return dataIn;
  14204.     }
  14205.   }
  14206.  
  14207.   // map to a UInt16 array if data is 16bit, fix endianness below
  14208.   var data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
  14209.  
  14210.   var maxValue = 255;
  14211.   var inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
  14212.   if (inBpp === 4 && !options.inputHasAlpha) {
  14213.     inBpp = 3;
  14214.   }
  14215.   var outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
  14216.   if (options.bitDepth === 16) {
  14217.     maxValue = 65535;
  14218.     outBpp *= 2;
  14219.   }
  14220.   var outData = new Buffer(width * height * outBpp);
  14221.  
  14222.   var inIndex = 0;
  14223.   var outIndex = 0;
  14224.  
  14225.   var bgColor = options.bgColor || {};
  14226.   if (bgColor.red === undefined) {
  14227.     bgColor.red = maxValue;
  14228.   }
  14229.   if (bgColor.green === undefined) {
  14230.     bgColor.green = maxValue;
  14231.   }
  14232.   if (bgColor.blue === undefined) {
  14233.     bgColor.blue = maxValue;
  14234.   }
  14235.  
  14236.   function getRGBA() {
  14237.     var red;
  14238.     var green;
  14239.     var blue;
  14240.     var alpha = maxValue;
  14241.     switch (options.inputColorType) {
  14242.       case constants.COLORTYPE_COLOR_ALPHA:
  14243.         alpha = data[inIndex + 3];
  14244.         red = data[inIndex];
  14245.         green = data[inIndex + 1];
  14246.         blue = data[inIndex + 2];
  14247.         break;
  14248.       case constants.COLORTYPE_COLOR:
  14249.         red = data[inIndex];
  14250.         green = data[inIndex + 1];
  14251.         blue = data[inIndex + 2];
  14252.         break;
  14253.       case constants.COLORTYPE_ALPHA:
  14254.         alpha = data[inIndex + 1];
  14255.         red = data[inIndex];
  14256.         green = red;
  14257.         blue = red;
  14258.         break;
  14259.       case constants.COLORTYPE_GRAYSCALE:
  14260.         red = data[inIndex];
  14261.         green = red;
  14262.         blue = red;
  14263.         break;
  14264.       default:
  14265.         throw new Error('input color type:' + options.inputColorType + ' is not supported at present');
  14266.     }
  14267.  
  14268.     if (options.inputHasAlpha) {
  14269.       if (!outHasAlpha) {
  14270.         alpha /= maxValue;
  14271.         red = Math.min(Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0), maxValue);
  14272.         green = Math.min(Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0), maxValue);
  14273.         blue = Math.min(Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0), maxValue);
  14274.       }
  14275.     }
  14276.     return { red: red, green: green, blue: blue, alpha: alpha };
  14277.   }
  14278.  
  14279.   for (var y = 0; y < height; y++) {
  14280.     for (var x = 0; x < width; x++) {
  14281.       var rgba = getRGBA(data, inIndex);
  14282.  
  14283.       switch (options.colorType) {
  14284.         case constants.COLORTYPE_COLOR_ALPHA:
  14285.         case constants.COLORTYPE_COLOR:
  14286.           if (options.bitDepth === 8) {
  14287.             outData[outIndex] = rgba.red;
  14288.             outData[outIndex + 1] = rgba.green;
  14289.             outData[outIndex + 2] = rgba.blue;
  14290.             if (outHasAlpha) {
  14291.               outData[outIndex + 3] = rgba.alpha;
  14292.             }
  14293.           }
  14294.           else {
  14295.             outData.writeUInt16BE(rgba.red, outIndex);
  14296.             outData.writeUInt16BE(rgba.green, outIndex + 2);
  14297.             outData.writeUInt16BE(rgba.blue, outIndex + 4);
  14298.             if (outHasAlpha) {
  14299.               outData.writeUInt16BE(rgba.alpha, outIndex + 6);
  14300.             }
  14301.           }
  14302.           break;
  14303.         case constants.COLORTYPE_ALPHA:
  14304.         case constants.COLORTYPE_GRAYSCALE:
  14305.           // Convert to grayscale and alpha
  14306.           var grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
  14307.           if (options.bitDepth === 8) {
  14308.             outData[outIndex] = grayscale;
  14309.             if (outHasAlpha) {
  14310.               outData[outIndex + 1] = rgba.alpha;
  14311.             }
  14312.           }
  14313.           else {
  14314.             outData.writeUInt16BE(grayscale, outIndex);
  14315.             if (outHasAlpha) {
  14316.               outData.writeUInt16BE(rgba.alpha, outIndex + 2);
  14317.             }
  14318.           }
  14319.           break;
  14320.         default:
  14321.           throw new Error('unrecognised color Type ' + options.colorType);
  14322.       }
  14323.  
  14324.       inIndex += inBpp;
  14325.       outIndex += outBpp;
  14326.     }
  14327.   }
  14328.  
  14329.   return outData;
  14330. };
  14331.  
  14332. }).call(this,require("buffer").Buffer)
  14333. },{"./constants":56,"buffer":9}],55:[function(require,module,exports){
  14334. (function (process,Buffer){
  14335. 'use strict';
  14336.  
  14337.  
  14338. var util = require('util');
  14339. var Stream = require('stream');
  14340.  
  14341.  
  14342. var ChunkStream = module.exports = function() {
  14343.   Stream.call(this);
  14344.  
  14345.   this._buffers = [];
  14346.   this._buffered = 0;
  14347.  
  14348.   this._reads = [];
  14349.   this._paused = false;
  14350.  
  14351.   this._encoding = 'utf8';
  14352.   this.writable = true;
  14353. };
  14354. util.inherits(ChunkStream, Stream);
  14355.  
  14356.  
  14357. ChunkStream.prototype.read = function(length, callback) {
  14358.  
  14359.   this._reads.push({
  14360.     length: Math.abs(length), // if length < 0 then at most this length
  14361.     allowLess: length < 0,
  14362.     func: callback
  14363.   });
  14364.  
  14365.   process.nextTick(function() {
  14366.     this._process();
  14367.  
  14368.     // its paused and there is not enought data then ask for more
  14369.     if (this._paused && this._reads.length > 0) {
  14370.       this._paused = false;
  14371.  
  14372.       this.emit('drain');
  14373.     }
  14374.   }.bind(this));
  14375. };
  14376.  
  14377. ChunkStream.prototype.write = function(data, encoding) {
  14378.  
  14379.   if (!this.writable) {
  14380.     this.emit('error', new Error('Stream not writable'));
  14381.     return false;
  14382.   }
  14383.  
  14384.   var dataBuffer;
  14385.   if (Buffer.isBuffer(data)) {
  14386.     dataBuffer = data;
  14387.   }
  14388.   else {
  14389.     dataBuffer = new Buffer(data, encoding || this._encoding);
  14390.   }
  14391.  
  14392.   this._buffers.push(dataBuffer);
  14393.   this._buffered += dataBuffer.length;
  14394.  
  14395.   this._process();
  14396.  
  14397.   // ok if there are no more read requests
  14398.   if (this._reads && this._reads.length === 0) {
  14399.     this._paused = true;
  14400.   }
  14401.  
  14402.   return this.writable && !this._paused;
  14403. };
  14404.  
  14405. ChunkStream.prototype.end = function(data, encoding) {
  14406.  
  14407.   if (data) {
  14408.     this.write(data, encoding);
  14409.   }
  14410.  
  14411.   this.writable = false;
  14412.  
  14413.   // already destroyed
  14414.   if (!this._buffers) {
  14415.     return;
  14416.   }
  14417.  
  14418.   // enqueue or handle end
  14419.   if (this._buffers.length === 0) {
  14420.     this._end();
  14421.   }
  14422.   else {
  14423.     this._buffers.push(null);
  14424.     this._process();
  14425.   }
  14426. };
  14427.  
  14428. ChunkStream.prototype.destroySoon = ChunkStream.prototype.end;
  14429.  
  14430. ChunkStream.prototype._end = function() {
  14431.  
  14432.   if (this._reads.length > 0) {
  14433.     this.emit('error',
  14434.       new Error('Unexpected end of input')
  14435.     );
  14436.   }
  14437.  
  14438.   this.destroy();
  14439. };
  14440.  
  14441. ChunkStream.prototype.destroy = function() {
  14442.  
  14443.   if (!this._buffers) {
  14444.     return;
  14445.   }
  14446.  
  14447.   this.writable = false;
  14448.   this._reads = null;
  14449.   this._buffers = null;
  14450.  
  14451.   this.emit('close');
  14452. };
  14453.  
  14454. ChunkStream.prototype._processReadAllowingLess = function(read) {
  14455.   // ok there is any data so that we can satisfy this request
  14456.   this._reads.shift(); // == read
  14457.  
  14458.   // first we need to peek into first buffer
  14459.   var smallerBuf = this._buffers[0];
  14460.  
  14461.   // ok there is more data than we need
  14462.   if (smallerBuf.length > read.length) {
  14463.  
  14464.     this._buffered -= read.length;
  14465.     this._buffers[0] = smallerBuf.slice(read.length);
  14466.  
  14467.     read.func.call(this, smallerBuf.slice(0, read.length));
  14468.  
  14469.   }
  14470.   else {
  14471.     // ok this is less than maximum length so use it all
  14472.     this._buffered -= smallerBuf.length;
  14473.     this._buffers.shift(); // == smallerBuf
  14474.  
  14475.     read.func.call(this, smallerBuf);
  14476.   }
  14477. };
  14478.  
  14479. ChunkStream.prototype._processRead = function(read) {
  14480.   this._reads.shift(); // == read
  14481.  
  14482.   var pos = 0;
  14483.   var count = 0;
  14484.   var data = new Buffer(read.length);
  14485.  
  14486.   // create buffer for all data
  14487.   while (pos < read.length) {
  14488.  
  14489.     var buf = this._buffers[count++];
  14490.     var len = Math.min(buf.length, read.length - pos);
  14491.  
  14492.     buf.copy(data, pos, 0, len);
  14493.     pos += len;
  14494.  
  14495.     // last buffer wasn't used all so just slice it and leave
  14496.     if (len !== buf.length) {
  14497.       this._buffers[--count] = buf.slice(len);
  14498.     }
  14499.   }
  14500.  
  14501.   // remove all used buffers
  14502.   if (count > 0) {
  14503.     this._buffers.splice(0, count);
  14504.   }
  14505.  
  14506.   this._buffered -= read.length;
  14507.  
  14508.   read.func.call(this, data);
  14509. };
  14510.  
  14511. ChunkStream.prototype._process = function() {
  14512.  
  14513.   try {
  14514.     // as long as there is any data and read requests
  14515.     while (this._buffered > 0 && this._reads && this._reads.length > 0) {
  14516.  
  14517.       var read = this._reads[0];
  14518.  
  14519.       // read any data (but no more than length)
  14520.       if (read.allowLess) {
  14521.         this._processReadAllowingLess(read);
  14522.  
  14523.       }
  14524.       else if (this._buffered >= read.length) {
  14525.         // ok we can meet some expectations
  14526.  
  14527.         this._processRead(read);
  14528.       }
  14529.       else {
  14530.         // not enought data to satisfy first request in queue
  14531.         // so we need to wait for more
  14532.         break;
  14533.       }
  14534.     }
  14535.  
  14536.     if (this._buffers && !this.writable) {
  14537.       this._end();
  14538.     }
  14539.   }
  14540.   catch (ex) {
  14541.     this.emit('error', ex);
  14542.   }
  14543. };
  14544.  
  14545. }).call(this,require('_process'),require("buffer").Buffer)
  14546. },{"_process":29,"buffer":9,"stream":45,"util":50}],56:[function(require,module,exports){
  14547. 'use strict';
  14548.  
  14549.  
  14550. module.exports = {
  14551.  
  14552.   PNG_SIGNATURE: [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a],
  14553.  
  14554.   TYPE_IHDR: 0x49484452,
  14555.   TYPE_IEND: 0x49454e44,
  14556.   TYPE_IDAT: 0x49444154,
  14557.   TYPE_PLTE: 0x504c5445,
  14558.   TYPE_tRNS: 0x74524e53, // eslint-disable-line camelcase
  14559.   TYPE_gAMA: 0x67414d41, // eslint-disable-line camelcase
  14560.  
  14561.   // color-type bits
  14562.   COLORTYPE_GRAYSCALE: 0,
  14563.   COLORTYPE_PALETTE: 1,
  14564.   COLORTYPE_COLOR: 2,
  14565.   COLORTYPE_ALPHA: 4, // e.g. grayscale and alpha
  14566.  
  14567.   // color-type combinations
  14568.   COLORTYPE_PALETTE_COLOR: 3,
  14569.   COLORTYPE_COLOR_ALPHA: 6,
  14570.  
  14571.   COLORTYPE_TO_BPP_MAP: {
  14572.     0: 1,
  14573.     2: 3,
  14574.     3: 1,
  14575.     4: 2,
  14576.     6: 4
  14577.   },
  14578.  
  14579.   GAMMA_DIVISION: 100000
  14580. };
  14581.  
  14582. },{}],57:[function(require,module,exports){
  14583. 'use strict';
  14584.  
  14585. var crcTable = [];
  14586.  
  14587. (function() {
  14588.   for (var i = 0; i < 256; i++) {
  14589.     var currentCrc = i;
  14590.     for (var j = 0; j < 8; j++) {
  14591.       if (currentCrc & 1) {
  14592.         currentCrc = 0xedb88320 ^ (currentCrc >>> 1);
  14593.       }
  14594.       else {
  14595.         currentCrc = currentCrc >>> 1;
  14596.       }
  14597.     }
  14598.     crcTable[i] = currentCrc;
  14599.   }
  14600. }());
  14601.  
  14602. var CrcCalculator = module.exports = function() {
  14603.   this._crc = -1;
  14604. };
  14605.  
  14606. CrcCalculator.prototype.write = function(data) {
  14607.  
  14608.   for (var i = 0; i < data.length; i++) {
  14609.     this._crc = crcTable[(this._crc ^ data[i]) & 0xff] ^ (this._crc >>> 8);
  14610.   }
  14611.   return true;
  14612. };
  14613.  
  14614. CrcCalculator.prototype.crc32 = function() {
  14615.   return this._crc ^ -1;
  14616. };
  14617.  
  14618.  
  14619. CrcCalculator.crc32 = function(buf) {
  14620.  
  14621.   var crc = -1;
  14622.   for (var i = 0; i < buf.length; i++) {
  14623.     crc = crcTable[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8);
  14624.   }
  14625.   return crc ^ -1;
  14626. };
  14627.  
  14628. },{}],58:[function(require,module,exports){
  14629. (function (Buffer){
  14630. 'use strict';
  14631.  
  14632. var paethPredictor = require('./paeth-predictor');
  14633.  
  14634. function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
  14635.  
  14636.   for (var x = 0; x < byteWidth; x++) {
  14637.     rawData[rawPos + x] = pxData[pxPos + x];
  14638.   }
  14639. }
  14640.  
  14641. function filterSumNone(pxData, pxPos, byteWidth) {
  14642.  
  14643.   var sum = 0;
  14644.   var length = pxPos + byteWidth;
  14645.  
  14646.   for (var i = pxPos; i < length; i++) {
  14647.     sum += Math.abs(pxData[i]);
  14648.   }
  14649.   return sum;
  14650. }
  14651.  
  14652. function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
  14653.  
  14654.   for (var x = 0; x < byteWidth; x++) {
  14655.  
  14656.     var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
  14657.     var val = pxData[pxPos + x] - left;
  14658.  
  14659.     rawData[rawPos + x] = val;
  14660.   }
  14661. }
  14662.  
  14663. function filterSumSub(pxData, pxPos, byteWidth, bpp) {
  14664.  
  14665.   var sum = 0;
  14666.   for (var x = 0; x < byteWidth; x++) {
  14667.  
  14668.     var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
  14669.     var val = pxData[pxPos + x] - left;
  14670.  
  14671.     sum += Math.abs(val);
  14672.   }
  14673.  
  14674.   return sum;
  14675. }
  14676.  
  14677. function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
  14678.  
  14679.   for (var x = 0; x < byteWidth; x++) {
  14680.  
  14681.     var up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
  14682.     var val = pxData[pxPos + x] - up;
  14683.  
  14684.     rawData[rawPos + x] = val;
  14685.   }
  14686. }
  14687.  
  14688. function filterSumUp(pxData, pxPos, byteWidth) {
  14689.  
  14690.   var sum = 0;
  14691.   var length = pxPos + byteWidth;
  14692.   for (var x = pxPos; x < length; x++) {
  14693.  
  14694.     var up = pxPos > 0 ? pxData[x - byteWidth] : 0;
  14695.     var val = pxData[x] - up;
  14696.  
  14697.     sum += Math.abs(val);
  14698.   }
  14699.  
  14700.   return sum;
  14701. }
  14702.  
  14703. function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
  14704.  
  14705.   for (var x = 0; x < byteWidth; x++) {
  14706.  
  14707.     var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
  14708.     var up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
  14709.     var val = pxData[pxPos + x] - ((left + up) >> 1);
  14710.  
  14711.     rawData[rawPos + x] = val;
  14712.   }
  14713. }
  14714.  
  14715. function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
  14716.  
  14717.   var sum = 0;
  14718.   for (var x = 0; x < byteWidth; x++) {
  14719.  
  14720.     var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
  14721.     var up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
  14722.     var val = pxData[pxPos + x] - ((left + up) >> 1);
  14723.  
  14724.     sum += Math.abs(val);
  14725.   }
  14726.  
  14727.   return sum;
  14728. }
  14729.  
  14730. function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
  14731.  
  14732.   for (var x = 0; x < byteWidth; x++) {
  14733.  
  14734.     var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
  14735.     var up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
  14736.     var upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
  14737.     var val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
  14738.  
  14739.     rawData[rawPos + x] = val;
  14740.   }
  14741. }
  14742.  
  14743. function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
  14744.   var sum = 0;
  14745.   for (var x = 0; x < byteWidth; x++) {
  14746.  
  14747.     var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
  14748.     var up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
  14749.     var upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
  14750.     var val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
  14751.  
  14752.     sum += Math.abs(val);
  14753.   }
  14754.  
  14755.   return sum;
  14756. }
  14757.  
  14758. var filters = {
  14759.   0: filterNone,
  14760.   1: filterSub,
  14761.   2: filterUp,
  14762.   3: filterAvg,
  14763.   4: filterPaeth
  14764. };
  14765.  
  14766. var filterSums = {
  14767.   0: filterSumNone,
  14768.   1: filterSumSub,
  14769.   2: filterSumUp,
  14770.   3: filterSumAvg,
  14771.   4: filterSumPaeth
  14772. };
  14773.  
  14774. module.exports = function(pxData, width, height, options, bpp) {
  14775.  
  14776.   var filterTypes;
  14777.   if (!('filterType' in options) || options.filterType === -1) {
  14778.     filterTypes = [0, 1, 2, 3, 4];
  14779.   }
  14780.   else if (typeof options.filterType === 'number') {
  14781.     filterTypes = [options.filterType];
  14782.   }
  14783.   else {
  14784.     throw new Error('unrecognised filter types');
  14785.   }
  14786.  
  14787.   if (options.bitDepth === 16) {
  14788.     bpp *= 2;
  14789.   }
  14790.   var byteWidth = width * bpp;
  14791.   var rawPos = 0;
  14792.   var pxPos = 0;
  14793.   var rawData = new Buffer((byteWidth + 1) * height);
  14794.  
  14795.   var sel = filterTypes[0];
  14796.  
  14797.   for (var y = 0; y < height; y++) {
  14798.  
  14799.     if (filterTypes.length > 1) {
  14800.       // find best filter for this line (with lowest sum of values)
  14801.       var min = Infinity;
  14802.  
  14803.       for (var i = 0; i < filterTypes.length; i++) {
  14804.         var sum = filterSums[filterTypes[i]](pxData, pxPos, byteWidth, bpp);
  14805.         if (sum < min) {
  14806.           sel = filterTypes[i];
  14807.           min = sum;
  14808.         }
  14809.       }
  14810.     }
  14811.  
  14812.     rawData[rawPos] = sel;
  14813.     rawPos++;
  14814.     filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
  14815.     rawPos += byteWidth;
  14816.     pxPos += byteWidth;
  14817.   }
  14818.   return rawData;
  14819. };
  14820.  
  14821. }).call(this,require("buffer").Buffer)
  14822. },{"./paeth-predictor":67,"buffer":9}],59:[function(require,module,exports){
  14823. (function (Buffer){
  14824. 'use strict';
  14825.  
  14826. var util = require('util');
  14827. var ChunkStream = require('./chunkstream');
  14828. var Filter = require('./filter-parse');
  14829.  
  14830.  
  14831. var FilterAsync = module.exports = function(bitmapInfo) {
  14832.   ChunkStream.call(this);
  14833.  
  14834.   var buffers = [];
  14835.   var that = this;
  14836.   this._filter = new Filter(bitmapInfo, {
  14837.     read: this.read.bind(this),
  14838.     write: function(buffer) {
  14839.       buffers.push(buffer);
  14840.     },
  14841.     complete: function() {
  14842.       that.emit('complete', Buffer.concat(buffers));
  14843.     }
  14844.   });
  14845.  
  14846.   this._filter.start();
  14847. };
  14848. util.inherits(FilterAsync, ChunkStream);
  14849.  
  14850. }).call(this,require("buffer").Buffer)
  14851. },{"./chunkstream":55,"./filter-parse":61,"buffer":9,"util":50}],60:[function(require,module,exports){
  14852. (function (Buffer){
  14853. 'use strict';
  14854.  
  14855. var SyncReader = require('./sync-reader');
  14856. var Filter = require('./filter-parse');
  14857.  
  14858.  
  14859. exports.process = function(inBuffer, bitmapInfo) {
  14860.  
  14861.   var outBuffers = [];
  14862.   var reader = new SyncReader(inBuffer);
  14863.   var filter = new Filter(bitmapInfo, {
  14864.     read: reader.read.bind(reader),
  14865.     write: function(bufferPart) {
  14866.       outBuffers.push(bufferPart);
  14867.     },
  14868.     complete: function() {
  14869.     }
  14870.   });
  14871.  
  14872.   filter.start();
  14873.   reader.process();
  14874.  
  14875.   return Buffer.concat(outBuffers);
  14876. };
  14877. }).call(this,require("buffer").Buffer)
  14878. },{"./filter-parse":61,"./sync-reader":74,"buffer":9}],61:[function(require,module,exports){
  14879. (function (Buffer){
  14880. 'use strict';
  14881.  
  14882. var interlaceUtils = require('./interlace');
  14883. var paethPredictor = require('./paeth-predictor');
  14884.  
  14885. function getByteWidth(width, bpp, depth) {
  14886.   var byteWidth = width * bpp;
  14887.   if (depth !== 8) {
  14888.     byteWidth = Math.ceil(byteWidth / (8 / depth));
  14889.   }
  14890.   return byteWidth;
  14891. }
  14892.  
  14893. var Filter = module.exports = function(bitmapInfo, dependencies) {
  14894.  
  14895.   var width = bitmapInfo.width;
  14896.   var height = bitmapInfo.height;
  14897.   var interlace = bitmapInfo.interlace;
  14898.   var bpp = bitmapInfo.bpp;
  14899.   var depth = bitmapInfo.depth;
  14900.  
  14901.   this.read = dependencies.read;
  14902.   this.write = dependencies.write;
  14903.   this.complete = dependencies.complete;
  14904.  
  14905.   this._imageIndex = 0;
  14906.   this._images = [];
  14907.   if (interlace) {
  14908.     var passes = interlaceUtils.getImagePasses(width, height);
  14909.     for (var i = 0; i < passes.length; i++) {
  14910.       this._images.push({
  14911.         byteWidth: getByteWidth(passes[i].width, bpp, depth),
  14912.         height: passes[i].height,
  14913.         lineIndex: 0
  14914.       });
  14915.     }
  14916.   }
  14917.   else {
  14918.     this._images.push({
  14919.       byteWidth: getByteWidth(width, bpp, depth),
  14920.       height: height,
  14921.       lineIndex: 0
  14922.     });
  14923.   }
  14924.  
  14925.   // when filtering the line we look at the pixel to the left
  14926.   // the spec also says it is done on a byte level regardless of the number of pixels
  14927.   // so if the depth is byte compatible (8 or 16) we subtract the bpp in order to compare back
  14928.   // a pixel rather than just a different byte part. However if we are sub byte, we ignore.
  14929.   if (depth === 8) {
  14930.     this._xComparison = bpp;
  14931.   }
  14932.   else if (depth === 16) {
  14933.     this._xComparison = bpp * 2;
  14934.   }
  14935.   else {
  14936.     this._xComparison = 1;
  14937.   }
  14938. };
  14939.  
  14940. Filter.prototype.start = function() {
  14941.   this.read(this._images[this._imageIndex].byteWidth + 1, this._reverseFilterLine.bind(this));
  14942. };
  14943.  
  14944. Filter.prototype._unFilterType1 = function(rawData, unfilteredLine, byteWidth) {
  14945.  
  14946.   var xComparison = this._xComparison;
  14947.   var xBiggerThan = xComparison - 1;
  14948.  
  14949.   for (var x = 0; x < byteWidth; x++) {
  14950.     var rawByte = rawData[1 + x];
  14951.     var f1Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
  14952.     unfilteredLine[x] = rawByte + f1Left;
  14953.   }
  14954. };
  14955.  
  14956. Filter.prototype._unFilterType2 = function(rawData, unfilteredLine, byteWidth) {
  14957.  
  14958.   var lastLine = this._lastLine;
  14959.  
  14960.   for (var x = 0; x < byteWidth; x++) {
  14961.     var rawByte = rawData[1 + x];
  14962.     var f2Up = lastLine ? lastLine[x] : 0;
  14963.     unfilteredLine[x] = rawByte + f2Up;
  14964.   }
  14965. };
  14966.  
  14967. Filter.prototype._unFilterType3 = function(rawData, unfilteredLine, byteWidth) {
  14968.  
  14969.   var xComparison = this._xComparison;
  14970.   var xBiggerThan = xComparison - 1;
  14971.   var lastLine = this._lastLine;
  14972.  
  14973.   for (var x = 0; x < byteWidth; x++) {
  14974.     var rawByte = rawData[1 + x];
  14975.     var f3Up = lastLine ? lastLine[x] : 0;
  14976.     var f3Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
  14977.     var f3Add = Math.floor((f3Left + f3Up) / 2);
  14978.     unfilteredLine[x] = rawByte + f3Add;
  14979.   }
  14980. };
  14981.  
  14982. Filter.prototype._unFilterType4 = function(rawData, unfilteredLine, byteWidth) {
  14983.  
  14984.   var xComparison = this._xComparison;
  14985.   var xBiggerThan = xComparison - 1;
  14986.   var lastLine = this._lastLine;
  14987.  
  14988.   for (var x = 0; x < byteWidth; x++) {
  14989.     var rawByte = rawData[1 + x];
  14990.     var f4Up = lastLine ? lastLine[x] : 0;
  14991.     var f4Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
  14992.     var f4UpLeft = x > xBiggerThan && lastLine ? lastLine[x - xComparison] : 0;
  14993.     var f4Add = paethPredictor(f4Left, f4Up, f4UpLeft);
  14994.     unfilteredLine[x] = rawByte + f4Add;
  14995.   }
  14996. };
  14997.  
  14998. Filter.prototype._reverseFilterLine = function(rawData) {
  14999.  
  15000.   var filter = rawData[0];
  15001.   var unfilteredLine;
  15002.   var currentImage = this._images[this._imageIndex];
  15003.   var byteWidth = currentImage.byteWidth;
  15004.  
  15005.   if (filter === 0) {
  15006.     unfilteredLine = rawData.slice(1, byteWidth + 1);
  15007.   }
  15008.   else {
  15009.  
  15010.     unfilteredLine = new Buffer(byteWidth);
  15011.  
  15012.     switch (filter) {
  15013.       case 1:
  15014.         this._unFilterType1(rawData, unfilteredLine, byteWidth);
  15015.         break;
  15016.       case 2:
  15017.         this._unFilterType2(rawData, unfilteredLine, byteWidth);
  15018.         break;
  15019.       case 3:
  15020.         this._unFilterType3(rawData, unfilteredLine, byteWidth);
  15021.         break;
  15022.       case 4:
  15023.         this._unFilterType4(rawData, unfilteredLine, byteWidth);
  15024.         break;
  15025.       default:
  15026.         throw new Error('Unrecognised filter type - ' + filter);
  15027.     }
  15028.   }
  15029.  
  15030.   this.write(unfilteredLine);
  15031.  
  15032.   currentImage.lineIndex++;
  15033.   if (currentImage.lineIndex >= currentImage.height) {
  15034.     this._lastLine = null;
  15035.     this._imageIndex++;
  15036.     currentImage = this._images[this._imageIndex];
  15037.   }
  15038.   else {
  15039.     this._lastLine = unfilteredLine;
  15040.   }
  15041.  
  15042.   if (currentImage) {
  15043.     // read, using the byte width that may be from the new current image
  15044.     this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
  15045.   }
  15046.   else {
  15047.     this._lastLine = null;
  15048.     this.complete();
  15049.   }
  15050. };
  15051.  
  15052. }).call(this,require("buffer").Buffer)
  15053. },{"./interlace":63,"./paeth-predictor":67,"buffer":9}],62:[function(require,module,exports){
  15054. (function (Buffer){
  15055. 'use strict';
  15056.  
  15057. function dePalette(indata, outdata, width, height, palette) {
  15058.   var pxPos = 0;
  15059.   // use values from palette
  15060.   for (var y = 0; y < height; y++) {
  15061.     for (var x = 0; x < width; x++) {
  15062.       var color = palette[indata[pxPos]];
  15063.  
  15064.       if (!color) {
  15065.         throw new Error('index ' + indata[pxPos] + ' not in palette');
  15066.       }
  15067.  
  15068.       for (var i = 0; i < 4; i++) {
  15069.         outdata[pxPos + i] = color[i];
  15070.       }
  15071.       pxPos += 4;
  15072.     }
  15073.   }
  15074. }
  15075.  
  15076. function replaceTransparentColor(indata, outdata, width, height, transColor) {
  15077.   var pxPos = 0;
  15078.   for (var y = 0; y < height; y++) {
  15079.     for (var x = 0; x < width; x++) {
  15080.       var makeTrans = false;
  15081.  
  15082.       if (transColor.length === 1) {
  15083.         if (transColor[0] === indata[pxPos]) {
  15084.           makeTrans = true;
  15085.         }
  15086.       }
  15087.       else if (transColor[0] === indata[pxPos] && transColor[1] === indata[pxPos + 1] && transColor[2] === indata[pxPos + 2]) {
  15088.         makeTrans = true;
  15089.       }
  15090.       if (makeTrans) {
  15091.         for (var i = 0; i < 4; i++) {
  15092.           outdata[pxPos + i] = 0;
  15093.         }
  15094.       }
  15095.       pxPos += 4;
  15096.     }
  15097.   }
  15098. }
  15099.  
  15100. function scaleDepth(indata, outdata, width, height, depth) {
  15101.   var maxOutSample = 255;
  15102.   var maxInSample = Math.pow(2, depth) - 1;
  15103.   var pxPos = 0;
  15104.  
  15105.   for (var y = 0; y < height; y++) {
  15106.     for (var x = 0; x < width; x++) {
  15107.       for (var i = 0; i < 4; i++) {
  15108.         outdata[pxPos + i] = Math.floor((indata[pxPos + i] * maxOutSample) / maxInSample + 0.5);
  15109.       }
  15110.       pxPos += 4;
  15111.     }
  15112.   }
  15113. }
  15114.  
  15115. module.exports = function(indata, imageData) {
  15116.  
  15117.   var depth = imageData.depth;
  15118.   var width = imageData.width;
  15119.   var height = imageData.height;
  15120.   var colorType = imageData.colorType;
  15121.   var transColor = imageData.transColor;
  15122.   var palette = imageData.palette;
  15123.  
  15124.   var outdata = indata; // only different for 16 bits
  15125.  
  15126.   if (colorType === 3) { // paletted
  15127.     dePalette(indata, outdata, width, height, palette);
  15128.   }
  15129.   else {
  15130.     if (transColor) {
  15131.       replaceTransparentColor(indata, outdata, width, height, transColor);
  15132.     }
  15133.     // if it needs scaling
  15134.     if (depth !== 8) {
  15135.       // if we need to change the buffer size
  15136.       if (depth === 16) {
  15137.         outdata = new Buffer(width * height * 4);
  15138.       }
  15139.       scaleDepth(indata, outdata, width, height, depth);
  15140.     }
  15141.   }
  15142.   return outdata;
  15143. };
  15144.  
  15145. }).call(this,require("buffer").Buffer)
  15146. },{"buffer":9}],63:[function(require,module,exports){
  15147. 'use strict';
  15148.  
  15149. // Adam 7
  15150. //   0 1 2 3 4 5 6 7
  15151. // 0 x 6 4 6 x 6 4 6
  15152. // 1 7 7 7 7 7 7 7 7
  15153. // 2 5 6 5 6 5 6 5 6
  15154. // 3 7 7 7 7 7 7 7 7
  15155. // 4 3 6 4 6 3 6 4 6
  15156. // 5 7 7 7 7 7 7 7 7
  15157. // 6 5 6 5 6 5 6 5 6
  15158. // 7 7 7 7 7 7 7 7 7
  15159.  
  15160.  
  15161. var imagePasses = [
  15162.   { // pass 1 - 1px
  15163.     x: [0],
  15164.     y: [0]
  15165.   },
  15166.   { // pass 2 - 1px
  15167.     x: [4],
  15168.     y: [0]
  15169.   },
  15170.   { // pass 3 - 2px
  15171.     x: [0, 4],
  15172.     y: [4]
  15173.   },
  15174.   { // pass 4 - 4px
  15175.     x: [2, 6],
  15176.     y: [0, 4]
  15177.   },
  15178.   { // pass 5 - 8px
  15179.     x: [0, 2, 4, 6],
  15180.     y: [2, 6]
  15181.   },
  15182.   { // pass 6 - 16px
  15183.     x: [1, 3, 5, 7],
  15184.     y: [0, 2, 4, 6]
  15185.   },
  15186.   { // pass 7 - 32px
  15187.     x: [0, 1, 2, 3, 4, 5, 6, 7],
  15188.     y: [1, 3, 5, 7]
  15189.   }
  15190. ];
  15191.  
  15192. exports.getImagePasses = function(width, height) {
  15193.   var images = [];
  15194.   var xLeftOver = width % 8;
  15195.   var yLeftOver = height % 8;
  15196.   var xRepeats = (width - xLeftOver) / 8;
  15197.   var yRepeats = (height - yLeftOver) / 8;
  15198.   for (var i = 0; i < imagePasses.length; i++) {
  15199.     var pass = imagePasses[i];
  15200.     var passWidth = xRepeats * pass.x.length;
  15201.     var passHeight = yRepeats * pass.y.length;
  15202.     for (var j = 0; j < pass.x.length; j++) {
  15203.       if (pass.x[j] < xLeftOver) {
  15204.         passWidth++;
  15205.       }
  15206.       else {
  15207.         break;
  15208.       }
  15209.     }
  15210.     for (j = 0; j < pass.y.length; j++) {
  15211.       if (pass.y[j] < yLeftOver) {
  15212.         passHeight++;
  15213.       }
  15214.       else {
  15215.         break;
  15216.       }
  15217.     }
  15218.     if (passWidth > 0 && passHeight > 0) {
  15219.       images.push({ width: passWidth, height: passHeight, index: i });
  15220.     }
  15221.   }
  15222.   return images;
  15223. };
  15224.  
  15225. exports.getInterlaceIterator = function(width) {
  15226.   return function(x, y, pass) {
  15227.     var outerXLeftOver = x % imagePasses[pass].x.length;
  15228.     var outerX = (((x - outerXLeftOver) / imagePasses[pass].x.length) * 8) + imagePasses[pass].x[outerXLeftOver];
  15229.     var outerYLeftOver = y % imagePasses[pass].y.length;
  15230.     var outerY = (((y - outerYLeftOver) / imagePasses[pass].y.length) * 8) + imagePasses[pass].y[outerYLeftOver];
  15231.     return (outerX * 4) + (outerY * width * 4);
  15232.   };
  15233. };
  15234. },{}],64:[function(require,module,exports){
  15235. (function (Buffer){
  15236. 'use strict';
  15237.  
  15238. var util = require('util');
  15239. var Stream = require('stream');
  15240. var constants = require('./constants');
  15241. var Packer = require('./packer');
  15242.  
  15243. var PackerAsync = module.exports = function(opt) {
  15244.   Stream.call(this);
  15245.  
  15246.   var options = opt || {};
  15247.  
  15248.   this._packer = new Packer(options);
  15249.   this._deflate = this._packer.createDeflate();
  15250.  
  15251.   this.readable = true;
  15252. };
  15253. util.inherits(PackerAsync, Stream);
  15254.  
  15255.  
  15256. PackerAsync.prototype.pack = function(data, width, height, gamma) {
  15257.   // Signature
  15258.   this.emit('data', new Buffer(constants.PNG_SIGNATURE));
  15259.   this.emit('data', this._packer.packIHDR(width, height));
  15260.  
  15261.   if (gamma) {
  15262.     this.emit('data', this._packer.packGAMA(gamma));
  15263.   }
  15264.  
  15265.   var filteredData = this._packer.filterData(data, width, height);
  15266.  
  15267.   // compress it
  15268.   this._deflate.on('error', this.emit.bind(this, 'error'));
  15269.  
  15270.   this._deflate.on('data', function(compressedData) {
  15271.     this.emit('data', this._packer.packIDAT(compressedData));
  15272.   }.bind(this));
  15273.  
  15274.   this._deflate.on('end', function() {
  15275.     this.emit('data', this._packer.packIEND());
  15276.     this.emit('end');
  15277.   }.bind(this));
  15278.  
  15279.   this._deflate.end(filteredData);
  15280. };
  15281.  
  15282. }).call(this,require("buffer").Buffer)
  15283. },{"./constants":56,"./packer":66,"buffer":9,"stream":45,"util":50}],65:[function(require,module,exports){
  15284. (function (Buffer){
  15285. 'use strict';
  15286.  
  15287. var hasSyncZlib = true;
  15288. var zlib = require('zlib');
  15289. if (!zlib.deflateSync) {
  15290.   hasSyncZlib = false;
  15291. }
  15292. var constants = require('./constants');
  15293. var Packer = require('./packer');
  15294.  
  15295. module.exports = function(metaData, opt) {
  15296.  
  15297.   if (!hasSyncZlib) {
  15298.     throw new Error('To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0');
  15299.   }
  15300.  
  15301.   var options = opt || {};
  15302.  
  15303.   var packer = new Packer(options);
  15304.  
  15305.   var chunks = [];
  15306.  
  15307.   // Signature
  15308.   chunks.push(new Buffer(constants.PNG_SIGNATURE));
  15309.  
  15310.   // Header
  15311.   chunks.push(packer.packIHDR(metaData.width, metaData.height));
  15312.  
  15313.   if (metaData.gamma) {
  15314.     chunks.push(packer.packGAMA(metaData.gamma));
  15315.   }
  15316.  
  15317.   var filteredData = packer.filterData(metaData.data, metaData.width, metaData.height);
  15318.  
  15319.   // compress it
  15320.   var compressedData = zlib.deflateSync(filteredData, packer.getDeflateOptions());
  15321.   filteredData = null;
  15322.  
  15323.   if (!compressedData || !compressedData.length) {
  15324.     throw new Error('bad png - invalid compressed data response');
  15325.   }
  15326.   chunks.push(packer.packIDAT(compressedData));
  15327.  
  15328.   // End
  15329.   chunks.push(packer.packIEND());
  15330.  
  15331.   return Buffer.concat(chunks);
  15332. };
  15333.  
  15334. }).call(this,require("buffer").Buffer)
  15335. },{"./constants":56,"./packer":66,"buffer":9,"zlib":8}],66:[function(require,module,exports){
  15336. (function (Buffer){
  15337. 'use strict';
  15338.  
  15339. var constants = require('./constants');
  15340. var CrcStream = require('./crc');
  15341. var bitPacker = require('./bitpacker');
  15342. var filter = require('./filter-pack');
  15343. var zlib = require('zlib');
  15344.  
  15345. var Packer = module.exports = function(options) {
  15346.   this._options = options;
  15347.  
  15348.   options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
  15349.   options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9;
  15350.   options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3;
  15351.   options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
  15352.   options.deflateFactory = options.deflateFactory || zlib.createDeflate;
  15353.   options.bitDepth = options.bitDepth || 8;
  15354.   // This is outputColorType
  15355.   options.colorType = (typeof options.colorType === 'number') ? options.colorType : constants.COLORTYPE_COLOR_ALPHA;
  15356.   options.inputColorType = (typeof options.inputColorType === 'number') ? options.inputColorType : constants.COLORTYPE_COLOR_ALPHA;
  15357.  
  15358.   if ([
  15359.     constants.COLORTYPE_GRAYSCALE,
  15360.     constants.COLORTYPE_COLOR,
  15361.     constants.COLORTYPE_COLOR_ALPHA,
  15362.     constants.COLORTYPE_ALPHA
  15363.   ].indexOf(options.colorType) === -1) {
  15364.     throw new Error('option color type:' + options.colorType + ' is not supported at present');
  15365.   }
  15366.   if ([
  15367.     constants.COLORTYPE_GRAYSCALE,
  15368.     constants.COLORTYPE_COLOR,
  15369.     constants.COLORTYPE_COLOR_ALPHA,
  15370.     constants.COLORTYPE_ALPHA
  15371.   ].indexOf(options.inputColorType) === -1) {
  15372.     throw new Error('option input color type:' + options.inputColorType + ' is not supported at present');
  15373.   }
  15374.   if (options.bitDepth !== 8 && options.bitDepth !== 16) {
  15375.     throw new Error('option bit depth:' + options.bitDepth + ' is not supported at present');
  15376.   }
  15377. };
  15378.  
  15379. Packer.prototype.getDeflateOptions = function() {
  15380.   return {
  15381.     chunkSize: this._options.deflateChunkSize,
  15382.     level: this._options.deflateLevel,
  15383.     strategy: this._options.deflateStrategy
  15384.   };
  15385. };
  15386.  
  15387. Packer.prototype.createDeflate = function() {
  15388.   return this._options.deflateFactory(this.getDeflateOptions());
  15389. };
  15390.  
  15391. Packer.prototype.filterData = function(data, width, height) {
  15392.   // convert to correct format for filtering (e.g. right bpp and bit depth)
  15393.   var packedData = bitPacker(data, width, height, this._options);
  15394.  
  15395.   // filter pixel data
  15396.   var bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
  15397.   var filteredData = filter(packedData, width, height, this._options, bpp);
  15398.   return filteredData;
  15399. };
  15400.  
  15401. Packer.prototype._packChunk = function(type, data) {
  15402.  
  15403.   var len = (data ? data.length : 0);
  15404.   var buf = new Buffer(len + 12);
  15405.  
  15406.   buf.writeUInt32BE(len, 0);
  15407.   buf.writeUInt32BE(type, 4);
  15408.  
  15409.   if (data) {
  15410.     data.copy(buf, 8);
  15411.   }
  15412.  
  15413.   buf.writeInt32BE(CrcStream.crc32(buf.slice(4, buf.length - 4)), buf.length - 4);
  15414.   return buf;
  15415. };
  15416.  
  15417. Packer.prototype.packGAMA = function(gamma) {
  15418.   var buf = new Buffer(4);
  15419.   buf.writeUInt32BE(Math.floor(gamma * constants.GAMMA_DIVISION), 0);
  15420.   return this._packChunk(constants.TYPE_gAMA, buf);
  15421. };
  15422.  
  15423. Packer.prototype.packIHDR = function(width, height) {
  15424.  
  15425.   var buf = new Buffer(13);
  15426.   buf.writeUInt32BE(width, 0);
  15427.   buf.writeUInt32BE(height, 4);
  15428.   buf[8] = this._options.bitDepth; // Bit depth
  15429.   buf[9] = this._options.colorType; // colorType
  15430.   buf[10] = 0; // compression
  15431.   buf[11] = 0; // filter
  15432.   buf[12] = 0; // interlace
  15433.  
  15434.   return this._packChunk(constants.TYPE_IHDR, buf);
  15435. };
  15436.  
  15437. Packer.prototype.packIDAT = function(data) {
  15438.   return this._packChunk(constants.TYPE_IDAT, data);
  15439. };
  15440.  
  15441. Packer.prototype.packIEND = function() {
  15442.   return this._packChunk(constants.TYPE_IEND, null);
  15443. };
  15444.  
  15445. }).call(this,require("buffer").Buffer)
  15446. },{"./bitpacker":54,"./constants":56,"./crc":57,"./filter-pack":58,"buffer":9,"zlib":8}],67:[function(require,module,exports){
  15447. 'use strict';
  15448.  
  15449. module.exports = function paethPredictor(left, above, upLeft) {
  15450.  
  15451.   var paeth = left + above - upLeft;
  15452.   var pLeft = Math.abs(paeth - left);
  15453.   var pAbove = Math.abs(paeth - above);
  15454.   var pUpLeft = Math.abs(paeth - upLeft);
  15455.  
  15456.   if (pLeft <= pAbove && pLeft <= pUpLeft) {
  15457.     return left;
  15458.   }
  15459.   if (pAbove <= pUpLeft) {
  15460.     return above;
  15461.   }
  15462.   return upLeft;
  15463. };
  15464. },{}],68:[function(require,module,exports){
  15465. 'use strict';
  15466.  
  15467. var util = require('util');
  15468. var zlib = require('zlib');
  15469. var ChunkStream = require('./chunkstream');
  15470. var FilterAsync = require('./filter-parse-async');
  15471. var Parser = require('./parser');
  15472. var bitmapper = require('./bitmapper');
  15473. var formatNormaliser = require('./format-normaliser');
  15474.  
  15475. var ParserAsync = module.exports = function(options) {
  15476.   ChunkStream.call(this);
  15477.  
  15478.   this._parser = new Parser(options, {
  15479.     read: this.read.bind(this),
  15480.     error: this._handleError.bind(this),
  15481.     metadata: this._handleMetaData.bind(this),
  15482.     gamma: this.emit.bind(this, 'gamma'),
  15483.     palette: this._handlePalette.bind(this),
  15484.     transColor: this._handleTransColor.bind(this),
  15485.     finished: this._finished.bind(this),
  15486.     inflateData: this._inflateData.bind(this),
  15487.     simpleTransparency: this._simpleTransparency.bind(this),
  15488.     headersFinished: this._headersFinished.bind(this)
  15489.   });
  15490.   this._options = options;
  15491.   this.writable = true;
  15492.  
  15493.   this._parser.start();
  15494. };
  15495. util.inherits(ParserAsync, ChunkStream);
  15496.  
  15497.  
  15498. ParserAsync.prototype._handleError = function(err) {
  15499.  
  15500.   this.emit('error', err);
  15501.  
  15502.   this.writable = false;
  15503.  
  15504.   this.destroy();
  15505.  
  15506.   if (this._inflate && this._inflate.destroy) {
  15507.     this._inflate.destroy();
  15508.   }
  15509.  
  15510.   if (this._filter) {
  15511.     this._filter.destroy();
  15512.     // For backward compatibility with Node 7 and below.
  15513.     // Suppress errors due to _inflate calling write() even after
  15514.     // it's destroy()'ed.
  15515.     this._filter.on('error', function() {});
  15516.   }
  15517.  
  15518.   this.errord = true;
  15519. };
  15520.  
  15521. ParserAsync.prototype._inflateData = function(data) {
  15522.   if (!this._inflate) {
  15523.     if (this._bitmapInfo.interlace) {
  15524.       this._inflate = zlib.createInflate();
  15525.  
  15526.       this._inflate.on('error', this.emit.bind(this, 'error'));
  15527.       this._filter.on('complete', this._complete.bind(this));
  15528.  
  15529.       this._inflate.pipe(this._filter);
  15530.     }
  15531.     else {
  15532.       var rowSize = ((this._bitmapInfo.width * this._bitmapInfo.bpp * this._bitmapInfo.depth + 7) >> 3) + 1;
  15533.       var imageSize = rowSize * this._bitmapInfo.height;
  15534.       var chunkSize = Math.max(imageSize, zlib.Z_MIN_CHUNK);
  15535.  
  15536.       this._inflate = zlib.createInflate({ chunkSize: chunkSize });
  15537.       var leftToInflate = imageSize;
  15538.  
  15539.       var emitError = this.emit.bind(this, 'error');
  15540.       this._inflate.on('error', function(err) {
  15541.         if (!leftToInflate) {
  15542.           return;
  15543.         }
  15544.  
  15545.         emitError(err);
  15546.       });
  15547.       this._filter.on('complete', this._complete.bind(this));
  15548.  
  15549.       var filterWrite = this._filter.write.bind(this._filter);
  15550.       this._inflate.on('data', function(chunk) {
  15551.         if (!leftToInflate) {
  15552.           return;
  15553.         }
  15554.  
  15555.         if (chunk.length > leftToInflate) {
  15556.           chunk = chunk.slice(0, leftToInflate);
  15557.         }
  15558.  
  15559.         leftToInflate -= chunk.length;
  15560.  
  15561.         filterWrite(chunk);
  15562.       });
  15563.  
  15564.       this._inflate.on('end', this._filter.end.bind(this._filter));
  15565.     }
  15566.   }
  15567.   this._inflate.write(data);
  15568. };
  15569.  
  15570. ParserAsync.prototype._handleMetaData = function(metaData) {
  15571.   this._metaData = metaData;
  15572.   this._bitmapInfo = Object.create(metaData);
  15573.  
  15574.   this._filter = new FilterAsync(this._bitmapInfo);
  15575. };
  15576.  
  15577. ParserAsync.prototype._handleTransColor = function(transColor) {
  15578.   this._bitmapInfo.transColor = transColor;
  15579. };
  15580.  
  15581. ParserAsync.prototype._handlePalette = function(palette) {
  15582.   this._bitmapInfo.palette = palette;
  15583. };
  15584.  
  15585. ParserAsync.prototype._simpleTransparency = function() {
  15586.   this._metaData.alpha = true;
  15587. };
  15588.  
  15589. ParserAsync.prototype._headersFinished = function() {
  15590.   // Up until this point, we don't know if we have a tRNS chunk (alpha)
  15591.   // so we can't emit metadata any earlier
  15592.   this.emit('metadata', this._metaData);
  15593. };
  15594.  
  15595. ParserAsync.prototype._finished = function() {
  15596.   if (this.errord) {
  15597.     return;
  15598.   }
  15599.  
  15600.   if (!this._inflate) {
  15601.     this.emit('error', 'No Inflate block');
  15602.   }
  15603.   else {
  15604.     // no more data to inflate
  15605.     this._inflate.end();
  15606.   }
  15607.   this.destroySoon();
  15608. };
  15609.  
  15610. ParserAsync.prototype._complete = function(filteredData) {
  15611.  
  15612.   if (this.errord) {
  15613.     return;
  15614.   }
  15615.  
  15616.   try {
  15617.     var bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo);
  15618.  
  15619.     var normalisedBitmapData = formatNormaliser(bitmapData, this._bitmapInfo);
  15620.     bitmapData = null;
  15621.   }
  15622.   catch (ex) {
  15623.     this._handleError(ex);
  15624.     return;
  15625.   }
  15626.  
  15627.   this.emit('parsed', normalisedBitmapData);
  15628. };
  15629.  
  15630. },{"./bitmapper":53,"./chunkstream":55,"./filter-parse-async":59,"./format-normaliser":62,"./parser":70,"util":50,"zlib":8}],69:[function(require,module,exports){
  15631. (function (Buffer){
  15632. 'use strict';
  15633.  
  15634. var hasSyncZlib = true;
  15635. var zlib = require('zlib');
  15636. var inflateSync = require('./sync-inflate');
  15637. if (!zlib.deflateSync) {
  15638.   hasSyncZlib = false;
  15639. }
  15640. var SyncReader = require('./sync-reader');
  15641. var FilterSync = require('./filter-parse-sync');
  15642. var Parser = require('./parser');
  15643. var bitmapper = require('./bitmapper');
  15644. var formatNormaliser = require('./format-normaliser');
  15645.  
  15646.  
  15647. module.exports = function(buffer, options) {
  15648.  
  15649.   if (!hasSyncZlib) {
  15650.     throw new Error('To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0');
  15651.   }
  15652.  
  15653.   var err;
  15654.   function handleError(_err_) {
  15655.     err = _err_;
  15656.   }
  15657.  
  15658.   var metaData;
  15659.   function handleMetaData(_metaData_) {
  15660.     metaData = _metaData_;
  15661.   }
  15662.  
  15663.   function handleTransColor(transColor) {
  15664.     metaData.transColor = transColor;
  15665.   }
  15666.  
  15667.   function handlePalette(palette) {
  15668.     metaData.palette = palette;
  15669.   }
  15670.  
  15671.   function handleSimpleTransparency() {
  15672.     metaData.alpha = true;
  15673.   }
  15674.  
  15675.   var gamma;
  15676.   function handleGamma(_gamma_) {
  15677.     gamma = _gamma_;
  15678.   }
  15679.  
  15680.   var inflateDataList = [];
  15681.   function handleInflateData(inflatedData) {
  15682.     inflateDataList.push(inflatedData);
  15683.   }
  15684.  
  15685.   var reader = new SyncReader(buffer);
  15686.  
  15687.   var parser = new Parser(options, {
  15688.     read: reader.read.bind(reader),
  15689.     error: handleError,
  15690.     metadata: handleMetaData,
  15691.     gamma: handleGamma,
  15692.     palette: handlePalette,
  15693.     transColor: handleTransColor,
  15694.     inflateData: handleInflateData,
  15695.     simpleTransparency: handleSimpleTransparency
  15696.   });
  15697.  
  15698.   parser.start();
  15699.   reader.process();
  15700.  
  15701.   if (err) {
  15702.     throw err;
  15703.   }
  15704.  
  15705.   //join together the inflate datas
  15706.   var inflateData = Buffer.concat(inflateDataList);
  15707.   inflateDataList.length = 0;
  15708.  
  15709.   var inflatedData;
  15710.   if (metaData.interlace) {
  15711.     inflatedData = zlib.inflateSync(inflateData);
  15712.   }
  15713.   else {
  15714.     var rowSize = ((metaData.width * metaData.bpp * metaData.depth + 7) >> 3) + 1;
  15715.     var imageSize = rowSize * metaData.height;
  15716.     inflatedData = inflateSync(inflateData, { chunkSize: imageSize, maxLength: imageSize });
  15717.   }
  15718.   inflateData = null;
  15719.  
  15720.   if (!inflatedData || !inflatedData.length) {
  15721.     throw new Error('bad png - invalid inflate data response');
  15722.   }
  15723.  
  15724.   var unfilteredData = FilterSync.process(inflatedData, metaData);
  15725.   inflateData = null;
  15726.  
  15727.   var bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
  15728.   unfilteredData = null;
  15729.  
  15730.   var normalisedBitmapData = formatNormaliser(bitmapData, metaData);
  15731.  
  15732.   metaData.data = normalisedBitmapData;
  15733.   metaData.gamma = gamma || 0;
  15734.  
  15735.   return metaData;
  15736. };
  15737.  
  15738. }).call(this,require("buffer").Buffer)
  15739. },{"./bitmapper":53,"./filter-parse-sync":60,"./format-normaliser":62,"./parser":70,"./sync-inflate":73,"./sync-reader":74,"buffer":9,"zlib":8}],70:[function(require,module,exports){
  15740. (function (Buffer){
  15741. 'use strict';
  15742.  
  15743. var constants = require('./constants');
  15744. var CrcCalculator = require('./crc');
  15745.  
  15746.  
  15747. var Parser = module.exports = function(options, dependencies) {
  15748.  
  15749.   this._options = options;
  15750.   options.checkCRC = options.checkCRC !== false;
  15751.  
  15752.   this._hasIHDR = false;
  15753.   this._hasIEND = false;
  15754.   this._emittedHeadersFinished = false;
  15755.  
  15756.   // input flags/metadata
  15757.   this._palette = [];
  15758.   this._colorType = 0;
  15759.  
  15760.   this._chunks = {};
  15761.   this._chunks[constants.TYPE_IHDR] = this._handleIHDR.bind(this);
  15762.   this._chunks[constants.TYPE_IEND] = this._handleIEND.bind(this);
  15763.   this._chunks[constants.TYPE_IDAT] = this._handleIDAT.bind(this);
  15764.   this._chunks[constants.TYPE_PLTE] = this._handlePLTE.bind(this);
  15765.   this._chunks[constants.TYPE_tRNS] = this._handleTRNS.bind(this);
  15766.   this._chunks[constants.TYPE_gAMA] = this._handleGAMA.bind(this);
  15767.  
  15768.   this.read = dependencies.read;
  15769.   this.error = dependencies.error;
  15770.   this.metadata = dependencies.metadata;
  15771.   this.gamma = dependencies.gamma;
  15772.   this.transColor = dependencies.transColor;
  15773.   this.palette = dependencies.palette;
  15774.   this.parsed = dependencies.parsed;
  15775.   this.inflateData = dependencies.inflateData;
  15776.   this.finished = dependencies.finished;
  15777.   this.simpleTransparency = dependencies.simpleTransparency;
  15778.   this.headersFinished = dependencies.headersFinished || function() {};
  15779. };
  15780.  
  15781. Parser.prototype.start = function() {
  15782.   this.read(constants.PNG_SIGNATURE.length,
  15783.     this._parseSignature.bind(this)
  15784.   );
  15785. };
  15786.  
  15787. Parser.prototype._parseSignature = function(data) {
  15788.  
  15789.   var signature = constants.PNG_SIGNATURE;
  15790.  
  15791.   for (var i = 0; i < signature.length; i++) {
  15792.     if (data[i] !== signature[i]) {
  15793.       this.error(new Error('Invalid file signature'));
  15794.       return;
  15795.     }
  15796.   }
  15797.   this.read(8, this._parseChunkBegin.bind(this));
  15798. };
  15799.  
  15800. Parser.prototype._parseChunkBegin = function(data) {
  15801.  
  15802.   // chunk content length
  15803.   var length = data.readUInt32BE(0);
  15804.  
  15805.   // chunk type
  15806.   var type = data.readUInt32BE(4);
  15807.   var name = '';
  15808.   for (var i = 4; i < 8; i++) {
  15809.     name += String.fromCharCode(data[i]);
  15810.   }
  15811.  
  15812.   //console.log('chunk ', name, length);
  15813.  
  15814.   // chunk flags
  15815.   var ancillary = Boolean(data[4] & 0x20); // or critical
  15816.   //    priv = Boolean(data[5] & 0x20), // or public
  15817.   //    safeToCopy = Boolean(data[7] & 0x20); // or unsafe
  15818.  
  15819.   if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
  15820.     this.error(new Error('Expected IHDR on beggining'));
  15821.     return;
  15822.   }
  15823.  
  15824.   this._crc = new CrcCalculator();
  15825.   this._crc.write(new Buffer(name));
  15826.  
  15827.   if (this._chunks[type]) {
  15828.     return this._chunks[type](length);
  15829.   }
  15830.  
  15831.   if (!ancillary) {
  15832.     this.error(new Error('Unsupported critical chunk type ' + name));
  15833.     return;
  15834.   }
  15835.  
  15836.   this.read(length + 4, this._skipChunk.bind(this));
  15837. };
  15838.  
  15839. Parser.prototype._skipChunk = function(/*data*/) {
  15840.   this.read(8, this._parseChunkBegin.bind(this));
  15841. };
  15842.  
  15843. Parser.prototype._handleChunkEnd = function() {
  15844.   this.read(4, this._parseChunkEnd.bind(this));
  15845. };
  15846.  
  15847. Parser.prototype._parseChunkEnd = function(data) {
  15848.  
  15849.   var fileCrc = data.readInt32BE(0);
  15850.   var calcCrc = this._crc.crc32();
  15851.  
  15852.   // check CRC
  15853.   if (this._options.checkCRC && calcCrc !== fileCrc) {
  15854.     this.error(new Error('Crc error - ' + fileCrc + ' - ' + calcCrc));
  15855.     return;
  15856.   }
  15857.  
  15858.   if (!this._hasIEND) {
  15859.     this.read(8, this._parseChunkBegin.bind(this));
  15860.   }
  15861. };
  15862.  
  15863. Parser.prototype._handleIHDR = function(length) {
  15864.   this.read(length, this._parseIHDR.bind(this));
  15865. };
  15866. Parser.prototype._parseIHDR = function(data) {
  15867.  
  15868.   this._crc.write(data);
  15869.  
  15870.   var width = data.readUInt32BE(0);
  15871.   var height = data.readUInt32BE(4);
  15872.   var depth = data[8];
  15873.   var colorType = data[9]; // bits: 1 palette, 2 color, 4 alpha
  15874.   var compr = data[10];
  15875.   var filter = data[11];
  15876.   var interlace = data[12];
  15877.  
  15878.   // console.log('    width', width, 'height', height,
  15879.   //     'depth', depth, 'colorType', colorType,
  15880.   //     'compr', compr, 'filter', filter, 'interlace', interlace
  15881.   // );
  15882.  
  15883.   if (depth !== 8 && depth !== 4 && depth !== 2 && depth !== 1 && depth !== 16) {
  15884.     this.error(new Error('Unsupported bit depth ' + depth));
  15885.     return;
  15886.   }
  15887.   if (!(colorType in constants.COLORTYPE_TO_BPP_MAP)) {
  15888.     this.error(new Error('Unsupported color type'));
  15889.     return;
  15890.   }
  15891.   if (compr !== 0) {
  15892.     this.error(new Error('Unsupported compression method'));
  15893.     return;
  15894.   }
  15895.   if (filter !== 0) {
  15896.     this.error(new Error('Unsupported filter method'));
  15897.     return;
  15898.   }
  15899.   if (interlace !== 0 && interlace !== 1) {
  15900.     this.error(new Error('Unsupported interlace method'));
  15901.     return;
  15902.   }
  15903.  
  15904.   this._colorType = colorType;
  15905.  
  15906.   var bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
  15907.  
  15908.   this._hasIHDR = true;
  15909.  
  15910.   this.metadata({
  15911.     width: width,
  15912.     height: height,
  15913.     depth: depth,
  15914.     interlace: Boolean(interlace),
  15915.     palette: Boolean(colorType & constants.COLORTYPE_PALETTE),
  15916.     color: Boolean(colorType & constants.COLORTYPE_COLOR),
  15917.     alpha: Boolean(colorType & constants.COLORTYPE_ALPHA),
  15918.     bpp: bpp,
  15919.     colorType: colorType
  15920.   });
  15921.  
  15922.   this._handleChunkEnd();
  15923. };
  15924.  
  15925.  
  15926. Parser.prototype._handlePLTE = function(length) {
  15927.   this.read(length, this._parsePLTE.bind(this));
  15928. };
  15929. Parser.prototype._parsePLTE = function(data) {
  15930.  
  15931.   this._crc.write(data);
  15932.  
  15933.   var entries = Math.floor(data.length / 3);
  15934.   // console.log('Palette:', entries);
  15935.  
  15936.   for (var i = 0; i < entries; i++) {
  15937.     this._palette.push([
  15938.       data[i * 3],
  15939.       data[i * 3 + 1],
  15940.       data[i * 3 + 2],
  15941.       0xff
  15942.     ]);
  15943.   }
  15944.  
  15945.   this.palette(this._palette);
  15946.  
  15947.   this._handleChunkEnd();
  15948. };
  15949.  
  15950. Parser.prototype._handleTRNS = function(length) {
  15951.   this.simpleTransparency();
  15952.   this.read(length, this._parseTRNS.bind(this));
  15953. };
  15954. Parser.prototype._parseTRNS = function(data) {
  15955.  
  15956.   this._crc.write(data);
  15957.  
  15958.   // palette
  15959.   if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
  15960.     if (this._palette.length === 0) {
  15961.       this.error(new Error('Transparency chunk must be after palette'));
  15962.       return;
  15963.     }
  15964.     if (data.length > this._palette.length) {
  15965.       this.error(new Error('More transparent colors than palette size'));
  15966.       return;
  15967.     }
  15968.     for (var i = 0; i < data.length; i++) {
  15969.       this._palette[i][3] = data[i];
  15970.     }
  15971.     this.palette(this._palette);
  15972.   }
  15973.  
  15974.   // for colorType 0 (grayscale) and 2 (rgb)
  15975.   // there might be one gray/color defined as transparent
  15976.   if (this._colorType === constants.COLORTYPE_GRAYSCALE) {
  15977.     // grey, 2 bytes
  15978.     this.transColor([data.readUInt16BE(0)]);
  15979.   }
  15980.   if (this._colorType === constants.COLORTYPE_COLOR) {
  15981.     this.transColor([data.readUInt16BE(0), data.readUInt16BE(2), data.readUInt16BE(4)]);
  15982.   }
  15983.  
  15984.   this._handleChunkEnd();
  15985. };
  15986.  
  15987. Parser.prototype._handleGAMA = function(length) {
  15988.   this.read(length, this._parseGAMA.bind(this));
  15989. };
  15990. Parser.prototype._parseGAMA = function(data) {
  15991.  
  15992.   this._crc.write(data);
  15993.   this.gamma(data.readUInt32BE(0) / constants.GAMMA_DIVISION);
  15994.  
  15995.   this._handleChunkEnd();
  15996. };
  15997.  
  15998. Parser.prototype._handleIDAT = function(length) {
  15999.   if (!this._emittedHeadersFinished) {
  16000.     this._emittedHeadersFinished = true;
  16001.     this.headersFinished();
  16002.   }
  16003.   this.read(-length, this._parseIDAT.bind(this, length));
  16004. };
  16005. Parser.prototype._parseIDAT = function(length, data) {
  16006.  
  16007.   this._crc.write(data);
  16008.  
  16009.   if (this._colorType === constants.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
  16010.     throw new Error('Expected palette not found');
  16011.   }
  16012.  
  16013.   this.inflateData(data);
  16014.   var leftOverLength = length - data.length;
  16015.  
  16016.   if (leftOverLength > 0) {
  16017.     this._handleIDAT(leftOverLength);
  16018.   }
  16019.   else {
  16020.     this._handleChunkEnd();
  16021.   }
  16022. };
  16023.  
  16024. Parser.prototype._handleIEND = function(length) {
  16025.   this.read(length, this._parseIEND.bind(this));
  16026. };
  16027. Parser.prototype._parseIEND = function(data) {
  16028.  
  16029.   this._crc.write(data);
  16030.  
  16031.   this._hasIEND = true;
  16032.   this._handleChunkEnd();
  16033.  
  16034.   if (this.finished) {
  16035.     this.finished();
  16036.   }
  16037. };
  16038.  
  16039. }).call(this,require("buffer").Buffer)
  16040. },{"./constants":56,"./crc":57,"buffer":9}],71:[function(require,module,exports){
  16041. 'use strict';
  16042.  
  16043.  
  16044. var parse = require('./parser-sync');
  16045. var pack = require('./packer-sync');
  16046.  
  16047.  
  16048. exports.read = function(buffer, options) {
  16049.  
  16050.   return parse(buffer, options || {});
  16051. };
  16052.  
  16053. exports.write = function(png, options) {
  16054.  
  16055.   return pack(png, options);
  16056. };
  16057.  
  16058. },{"./packer-sync":65,"./parser-sync":69}],72:[function(require,module,exports){
  16059. (function (process,Buffer){
  16060. 'use strict';
  16061.  
  16062. var util = require('util');
  16063. var Stream = require('stream');
  16064. var Parser = require('./parser-async');
  16065. var Packer = require('./packer-async');
  16066. var PNGSync = require('./png-sync');
  16067.  
  16068.  
  16069. var PNG = exports.PNG = function(options) {
  16070.   Stream.call(this);
  16071.  
  16072.   options = options || {}; // eslint-disable-line no-param-reassign
  16073.  
  16074.   // coerce pixel dimensions to integers (also coerces undefined -> 0):
  16075.   this.width = options.width | 0;
  16076.   this.height = options.height | 0;
  16077.  
  16078.   this.data = this.width > 0 && this.height > 0 ?
  16079.     new Buffer(4 * this.width * this.height) : null;
  16080.  
  16081.   if (options.fill && this.data) {
  16082.     this.data.fill(0);
  16083.   }
  16084.  
  16085.   this.gamma = 0;
  16086.   this.readable = this.writable = true;
  16087.  
  16088.   this._parser = new Parser(options);
  16089.  
  16090.   this._parser.on('error', this.emit.bind(this, 'error'));
  16091.   this._parser.on('close', this._handleClose.bind(this));
  16092.   this._parser.on('metadata', this._metadata.bind(this));
  16093.   this._parser.on('gamma', this._gamma.bind(this));
  16094.   this._parser.on('parsed', function(data) {
  16095.     this.data = data;
  16096.     this.emit('parsed', data);
  16097.   }.bind(this));
  16098.  
  16099.   this._packer = new Packer(options);
  16100.   this._packer.on('data', this.emit.bind(this, 'data'));
  16101.   this._packer.on('end', this.emit.bind(this, 'end'));
  16102.   this._parser.on('close', this._handleClose.bind(this));
  16103.   this._packer.on('error', this.emit.bind(this, 'error'));
  16104.  
  16105. };
  16106. util.inherits(PNG, Stream);
  16107.  
  16108. PNG.sync = PNGSync;
  16109.  
  16110. PNG.prototype.pack = function() {
  16111.  
  16112.   if (!this.data || !this.data.length) {
  16113.     this.emit('error', 'No data provided');
  16114.     return this;
  16115.   }
  16116.  
  16117.   process.nextTick(function() {
  16118.     this._packer.pack(this.data, this.width, this.height, this.gamma);
  16119.   }.bind(this));
  16120.  
  16121.   return this;
  16122. };
  16123.  
  16124.  
  16125. PNG.prototype.parse = function(data, callback) {
  16126.  
  16127.   if (callback) {
  16128.     var onParsed, onError;
  16129.  
  16130.     onParsed = function(parsedData) {
  16131.       this.removeListener('error', onError);
  16132.  
  16133.       this.data = parsedData;
  16134.       callback(null, this);
  16135.     }.bind(this);
  16136.  
  16137.     onError = function(err) {
  16138.       this.removeListener('parsed', onParsed);
  16139.  
  16140.       callback(err, null);
  16141.     }.bind(this);
  16142.  
  16143.     this.once('parsed', onParsed);
  16144.     this.once('error', onError);
  16145.   }
  16146.  
  16147.   this.end(data);
  16148.   return this;
  16149. };
  16150.  
  16151. PNG.prototype.write = function(data) {
  16152.   this._parser.write(data);
  16153.   return true;
  16154. };
  16155.  
  16156. PNG.prototype.end = function(data) {
  16157.   this._parser.end(data);
  16158. };
  16159.  
  16160. PNG.prototype._metadata = function(metadata) {
  16161.   this.width = metadata.width;
  16162.   this.height = metadata.height;
  16163.  
  16164.   this.emit('metadata', metadata);
  16165. };
  16166.  
  16167. PNG.prototype._gamma = function(gamma) {
  16168.   this.gamma = gamma;
  16169. };
  16170.  
  16171. PNG.prototype._handleClose = function() {
  16172.   if (!this._parser.writable && !this._packer.readable) {
  16173.     this.emit('close');
  16174.   }
  16175. };
  16176.  
  16177.  
  16178. PNG.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) { // eslint-disable-line max-params
  16179.   // coerce pixel dimensions to integers (also coerces undefined -> 0):
  16180.   /* eslint-disable no-param-reassign */
  16181.   srcX |= 0;
  16182.   srcY |= 0;
  16183.   width |= 0;
  16184.   height |= 0;
  16185.   deltaX |= 0;
  16186.   deltaY |= 0;
  16187.   /* eslint-enable no-param-reassign */
  16188.  
  16189.   if (srcX > src.width || srcY > src.height || srcX + width > src.width || srcY + height > src.height) {
  16190.     throw new Error('bitblt reading outside image');
  16191.   }
  16192.  
  16193.   if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) {
  16194.     throw new Error('bitblt writing outside image');
  16195.   }
  16196.  
  16197.   for (var y = 0; y < height; y++) {
  16198.     src.data.copy(dst.data,
  16199.       ((deltaY + y) * dst.width + deltaX) << 2,
  16200.       ((srcY + y) * src.width + srcX) << 2,
  16201.       ((srcY + y) * src.width + srcX + width) << 2
  16202.     );
  16203.   }
  16204. };
  16205.  
  16206.  
  16207. PNG.prototype.bitblt = function(dst, srcX, srcY, width, height, deltaX, deltaY) { // eslint-disable-line max-params
  16208.  
  16209.   PNG.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
  16210.   return this;
  16211. };
  16212.  
  16213. PNG.adjustGamma = function(src) {
  16214.   if (src.gamma) {
  16215.     for (var y = 0; y < src.height; y++) {
  16216.       for (var x = 0; x < src.width; x++) {
  16217.         var idx = (src.width * y + x) << 2;
  16218.  
  16219.         for (var i = 0; i < 3; i++) {
  16220.           var sample = src.data[idx + i] / 255;
  16221.           sample = Math.pow(sample, 1 / 2.2 / src.gamma);
  16222.           src.data[idx + i] = Math.round(sample * 255);
  16223.         }
  16224.       }
  16225.     }
  16226.     src.gamma = 0;
  16227.   }
  16228. };
  16229.  
  16230. PNG.prototype.adjustGamma = function() {
  16231.   PNG.adjustGamma(this);
  16232. };
  16233.  
  16234. }).call(this,require('_process'),require("buffer").Buffer)
  16235. },{"./packer-async":64,"./parser-async":68,"./png-sync":71,"_process":29,"buffer":9,"stream":45,"util":50}],73:[function(require,module,exports){
  16236. (function (process,Buffer){
  16237. 'use strict';
  16238.  
  16239. var assert = require('assert').ok;
  16240. var zlib = require('zlib');
  16241. var util = require('util');
  16242.  
  16243. var kMaxLength = require('buffer').kMaxLength;
  16244.  
  16245. function Inflate(opts) {
  16246.   if (!(this instanceof Inflate)) {
  16247.     return new Inflate(opts);
  16248.   }
  16249.  
  16250.   if (opts && opts.chunkSize < zlib.Z_MIN_CHUNK) {
  16251.     opts.chunkSize = zlib.Z_MIN_CHUNK;
  16252.   }
  16253.  
  16254.   zlib.Inflate.call(this, opts);
  16255.  
  16256.   // Node 8 --> 9 compatibility check
  16257.   this._offset = this._offset === undefined ? this._outOffset : this._offset;
  16258.   this._buffer = this._buffer || this._outBuffer;
  16259.  
  16260.   if (opts && opts.maxLength != null) {
  16261.     this._maxLength = opts.maxLength;
  16262.   }
  16263. }
  16264.  
  16265. function createInflate(opts) {
  16266.   return new Inflate(opts);
  16267. }
  16268.  
  16269. function _close(engine, callback) {
  16270.   if (callback) {
  16271.     process.nextTick(callback);
  16272.   }
  16273.  
  16274.   // Caller may invoke .close after a zlib error (which will null _handle).
  16275.   if (!engine._handle) {
  16276.     return;
  16277.   }
  16278.  
  16279.   engine._handle.close();
  16280.   engine._handle = null;
  16281. }
  16282.  
  16283. Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
  16284.   if (typeof asyncCb === 'function') {
  16285.     return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
  16286.   }
  16287.  
  16288.   var self = this;
  16289.  
  16290.   var availInBefore = chunk && chunk.length;
  16291.   var availOutBefore = this._chunkSize - this._offset;
  16292.   var leftToInflate = this._maxLength;
  16293.   var inOff = 0;
  16294.  
  16295.   var buffers = [];
  16296.   var nread = 0;
  16297.  
  16298.   var error;
  16299.   this.on('error', function(err) {
  16300.     error = err;
  16301.   });
  16302.  
  16303.   function handleChunk(availInAfter, availOutAfter) {
  16304.     if (self._hadError) {
  16305.       return;
  16306.     }
  16307.  
  16308.     var have = availOutBefore - availOutAfter;
  16309.     assert(have >= 0, 'have should not go down');
  16310.  
  16311.     if (have > 0) {
  16312.       var out = self._buffer.slice(self._offset, self._offset + have);
  16313.       self._offset += have;
  16314.  
  16315.       if (out.length > leftToInflate) {
  16316.         out = out.slice(0, leftToInflate);
  16317.       }
  16318.  
  16319.       buffers.push(out);
  16320.       nread += out.length;
  16321.       leftToInflate -= out.length;
  16322.  
  16323.       if (leftToInflate === 0) {
  16324.         return false;
  16325.       }
  16326.     }
  16327.  
  16328.     if (availOutAfter === 0 || self._offset >= self._chunkSize) {
  16329.       availOutBefore = self._chunkSize;
  16330.       self._offset = 0;
  16331.       self._buffer = Buffer.allocUnsafe(self._chunkSize);
  16332.     }
  16333.  
  16334.     if (availOutAfter === 0) {
  16335.       inOff += (availInBefore - availInAfter);
  16336.       availInBefore = availInAfter;
  16337.  
  16338.       return true;
  16339.     }
  16340.  
  16341.     return false;
  16342.   }
  16343.  
  16344.   assert(this._handle, 'zlib binding closed');
  16345.   do {
  16346.     var res = this._handle.writeSync(flushFlag,
  16347.       chunk, // in
  16348.       inOff, // in_off
  16349.       availInBefore, // in_len
  16350.       this._buffer, // out
  16351.       this._offset, //out_off
  16352.       availOutBefore); // out_len
  16353.     // Node 8 --> 9 compatibility check
  16354.     res = res || this._writeState;
  16355.   } while (!this._hadError && handleChunk(res[0], res[1]));
  16356.  
  16357.   if (this._hadError) {
  16358.     throw error;
  16359.   }
  16360.  
  16361.   if (nread >= kMaxLength) {
  16362.     _close(this);
  16363.     throw new RangeError('Cannot create final Buffer. It would be larger than 0x' + kMaxLength.toString(16) + ' bytes');
  16364.   }
  16365.  
  16366.   var buf = Buffer.concat(buffers, nread);
  16367.   _close(this);
  16368.  
  16369.   return buf;
  16370. };
  16371.  
  16372. util.inherits(Inflate, zlib.Inflate);
  16373.  
  16374. function zlibBufferSync(engine, buffer) {
  16375.   if (typeof buffer === 'string') {
  16376.     buffer = Buffer.from(buffer);
  16377.   }
  16378.   if (!(buffer instanceof Buffer)) {
  16379.     throw new TypeError('Not a string or buffer');
  16380.   }
  16381.  
  16382.   var flushFlag = engine._finishFlushFlag;
  16383.   if (flushFlag == null) {
  16384.     flushFlag = zlib.Z_FINISH;
  16385.   }
  16386.  
  16387.   return engine._processChunk(buffer, flushFlag);
  16388. }
  16389.  
  16390. function inflateSync(buffer, opts) {
  16391.   return zlibBufferSync(new Inflate(opts), buffer);
  16392. }
  16393.  
  16394. module.exports = exports = inflateSync;
  16395. exports.Inflate = Inflate;
  16396. exports.createInflate = createInflate;
  16397. exports.inflateSync = inflateSync;
  16398.  
  16399. }).call(this,require('_process'),require("buffer").Buffer)
  16400. },{"_process":29,"assert":1,"buffer":9,"util":50,"zlib":8}],74:[function(require,module,exports){
  16401. 'use strict';
  16402.  
  16403. var SyncReader = module.exports = function(buffer) {
  16404.  
  16405.   this._buffer = buffer;
  16406.   this._reads = [];
  16407. };
  16408.  
  16409. SyncReader.prototype.read = function(length, callback) {
  16410.  
  16411.   this._reads.push({
  16412.     length: Math.abs(length), // if length < 0 then at most this length
  16413.     allowLess: length < 0,
  16414.     func: callback
  16415.   });
  16416. };
  16417.  
  16418. SyncReader.prototype.process = function() {
  16419.  
  16420.   // as long as there is any data and read requests
  16421.   while (this._reads.length > 0 && this._buffer.length) {
  16422.  
  16423.     var read = this._reads[0];
  16424.  
  16425.     if (this._buffer.length && (this._buffer.length >= read.length || read.allowLess)) {
  16426.  
  16427.       // ok there is any data so that we can satisfy this request
  16428.       this._reads.shift(); // == read
  16429.  
  16430.       var buf = this._buffer;
  16431.  
  16432.       this._buffer = buf.slice(read.length);
  16433.  
  16434.       read.func.call(this, buf.slice(0, read.length));
  16435.  
  16436.     }
  16437.     else {
  16438.       break;
  16439.     }
  16440.  
  16441.   }
  16442.  
  16443.   if (this._reads.length > 0) {
  16444.     return new Error('There are some read requests waitng on finished stream');
  16445.   }
  16446.  
  16447.   if (this._buffer.length > 0) {
  16448.     return new Error('unrecognised content at end of stream');
  16449.   }
  16450.  
  16451. };
  16452.  
  16453. },{}]},{},[51]);
Add Comment
Please, Sign In to add comment