www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

pako_inflate.js (96022B)


      1 /* pako 1.0.0 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
      2 'use strict';
      3 
      4 
      5 var TYPED_OK =  (typeof Uint8Array !== 'undefined') &&
      6                 (typeof Uint16Array !== 'undefined') &&
      7                 (typeof Int32Array !== 'undefined');
      8 
      9 
     10 exports.assign = function (obj /*from1, from2, from3, ...*/) {
     11   var sources = Array.prototype.slice.call(arguments, 1);
     12   while (sources.length) {
     13     var source = sources.shift();
     14     if (!source) { continue; }
     15 
     16     if (typeof source !== 'object') {
     17       throw new TypeError(source + 'must be non-object');
     18     }
     19 
     20     for (var p in source) {
     21       if (source.hasOwnProperty(p)) {
     22         obj[p] = source[p];
     23       }
     24     }
     25   }
     26 
     27   return obj;
     28 };
     29 
     30 
     31 // reduce buffer size, avoiding mem copy
     32 exports.shrinkBuf = function (buf, size) {
     33   if (buf.length === size) { return buf; }
     34   if (buf.subarray) { return buf.subarray(0, size); }
     35   buf.length = size;
     36   return buf;
     37 };
     38 
     39 
     40 var fnTyped = {
     41   arraySet: function (dest, src, src_offs, len, dest_offs) {
     42     if (src.subarray && dest.subarray) {
     43       dest.set(src.subarray(src_offs, src_offs + len), dest_offs);
     44       return;
     45     }
     46     // Fallback to ordinary array
     47     for (var i = 0; i < len; i++) {
     48       dest[dest_offs + i] = src[src_offs + i];
     49     }
     50   },
     51   // Join array of chunks to single array.
     52   flattenChunks: function (chunks) {
     53     var i, l, len, pos, chunk, result;
     54 
     55     // calculate data length
     56     len = 0;
     57     for (i = 0, l = chunks.length; i < l; i++) {
     58       len += chunks[i].length;
     59     }
     60 
     61     // join chunks
     62     result = new Uint8Array(len);
     63     pos = 0;
     64     for (i = 0, l = chunks.length; i < l; i++) {
     65       chunk = chunks[i];
     66       result.set(chunk, pos);
     67       pos += chunk.length;
     68     }
     69 
     70     return result;
     71   }
     72 };
     73 
     74 var fnUntyped = {
     75   arraySet: function (dest, src, src_offs, len, dest_offs) {
     76     for (var i = 0; i < len; i++) {
     77       dest[dest_offs + i] = src[src_offs + i];
     78     }
     79   },
     80   // Join array of chunks to single array.
     81   flattenChunks: function (chunks) {
     82     return [].concat.apply([], chunks);
     83   }
     84 };
     85 
     86 
     87 // Enable/Disable typed arrays use, for testing
     88 //
     89 exports.setTyped = function (on) {
     90   if (on) {
     91     exports.Buf8  = Uint8Array;
     92     exports.Buf16 = Uint16Array;
     93     exports.Buf32 = Int32Array;
     94     exports.assign(exports, fnTyped);
     95   } else {
     96     exports.Buf8  = Array;
     97     exports.Buf16 = Array;
     98     exports.Buf32 = Array;
     99     exports.assign(exports, fnUntyped);
    100   }
    101 };
    102 
    103 exports.setTyped(TYPED_OK);
    104 
    105 },{}],2:[function(require,module,exports){
    106 // String encode/decode helpers
    107 'use strict';
    108 
    109 
    110 var utils = require('./common');
    111 
    112 
    113 // Quick check if we can use fast array to bin string conversion
    114 //
    115 // - apply(Array) can fail on Android 2.2
    116 // - apply(Uint8Array) can fail on iOS 5.1 Safary
    117 //
    118 var STR_APPLY_OK = true;
    119 var STR_APPLY_UIA_OK = true;
    120 
    121 try { String.fromCharCode.apply(null, [ 0 ]); } catch (__) { STR_APPLY_OK = false; }
    122 try { String.fromCharCode.apply(null, new Uint8Array(1)); } catch (__) { STR_APPLY_UIA_OK = false; }
    123 
    124 
    125 // Table with utf8 lengths (calculated by first byte of sequence)
    126 // Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
    127 // because max possible codepoint is 0x10ffff
    128 var _utf8len = new utils.Buf8(256);
    129 for (var q = 0; q < 256; q++) {
    130   _utf8len[q] = (q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1);
    131 }
    132 _utf8len[254] = _utf8len[254] = 1; // Invalid sequence start
    133 
    134 
    135 // convert string to array (typed, when possible)
    136 exports.string2buf = function (str) {
    137   var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;
    138 
    139   // count binary size
    140   for (m_pos = 0; m_pos < str_len; m_pos++) {
    141     c = str.charCodeAt(m_pos);
    142     if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
    143       c2 = str.charCodeAt(m_pos + 1);
    144       if ((c2 & 0xfc00) === 0xdc00) {
    145         c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
    146         m_pos++;
    147       }
    148     }
    149     buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
    150   }
    151 
    152   // allocate buffer
    153   buf = new utils.Buf8(buf_len);
    154 
    155   // convert
    156   for (i = 0, m_pos = 0; i < buf_len; m_pos++) {
    157     c = str.charCodeAt(m_pos);
    158     if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
    159       c2 = str.charCodeAt(m_pos + 1);
    160       if ((c2 & 0xfc00) === 0xdc00) {
    161         c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
    162         m_pos++;
    163       }
    164     }
    165     if (c < 0x80) {
    166       /* one byte */
    167       buf[i++] = c;
    168     } else if (c < 0x800) {
    169       /* two bytes */
    170       buf[i++] = 0xC0 | (c >>> 6);
    171       buf[i++] = 0x80 | (c & 0x3f);
    172     } else if (c < 0x10000) {
    173       /* three bytes */
    174       buf[i++] = 0xE0 | (c >>> 12);
    175       buf[i++] = 0x80 | (c >>> 6 & 0x3f);
    176       buf[i++] = 0x80 | (c & 0x3f);
    177     } else {
    178       /* four bytes */
    179       buf[i++] = 0xf0 | (c >>> 18);
    180       buf[i++] = 0x80 | (c >>> 12 & 0x3f);
    181       buf[i++] = 0x80 | (c >>> 6 & 0x3f);
    182       buf[i++] = 0x80 | (c & 0x3f);
    183     }
    184   }
    185 
    186   return buf;
    187 };
    188 
    189 // Helper (used in 2 places)
    190 function buf2binstring(buf, len) {
    191   // use fallback for big arrays to avoid stack overflow
    192   if (len < 65537) {
    193     if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) {
    194       return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len));
    195     }
    196   }
    197 
    198   var result = '';
    199   for (var i = 0; i < len; i++) {
    200     result += String.fromCharCode(buf[i]);
    201   }
    202   return result;
    203 }
    204 
    205 
    206 // Convert byte array to binary string
    207 exports.buf2binstring = function (buf) {
    208   return buf2binstring(buf, buf.length);
    209 };
    210 
    211 
    212 // Convert binary string (typed, when possible)
    213 exports.binstring2buf = function (str) {
    214   var buf = new utils.Buf8(str.length);
    215   for (var i = 0, len = buf.length; i < len; i++) {
    216     buf[i] = str.charCodeAt(i);
    217   }
    218   return buf;
    219 };
    220 
    221 
    222 // convert array to string
    223 exports.buf2string = function (buf, max) {
    224   var i, out, c, c_len;
    225   var len = max || buf.length;
    226 
    227   // Reserve max possible length (2 words per char)
    228   // NB: by unknown reasons, Array is significantly faster for
    229   //     String.fromCharCode.apply than Uint16Array.
    230   var utf16buf = new Array(len * 2);
    231 
    232   for (out = 0, i = 0; i < len;) {
    233     c = buf[i++];
    234     // quick process ascii
    235     if (c < 0x80) { utf16buf[out++] = c; continue; }
    236 
    237     c_len = _utf8len[c];
    238     // skip 5 & 6 byte codes
    239     if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len - 1; continue; }
    240 
    241     // apply mask on first byte
    242     c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;
    243     // join the rest
    244     while (c_len > 1 && i < len) {
    245       c = (c << 6) | (buf[i++] & 0x3f);
    246       c_len--;
    247     }
    248 
    249     // terminated by end of string?
    250     if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }
    251 
    252     if (c < 0x10000) {
    253       utf16buf[out++] = c;
    254     } else {
    255       c -= 0x10000;
    256       utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);
    257       utf16buf[out++] = 0xdc00 | (c & 0x3ff);
    258     }
    259   }
    260 
    261   return buf2binstring(utf16buf, out);
    262 };
    263 
    264 
    265 // Calculate max possible position in utf8 buffer,
    266 // that will not break sequence. If that's not possible
    267 // - (very small limits) return max size as is.
    268 //
    269 // buf[] - utf8 bytes array
    270 // max   - length limit (mandatory);
    271 exports.utf8border = function (buf, max) {
    272   var pos;
    273 
    274   max = max || buf.length;
    275   if (max > buf.length) { max = buf.length; }
    276 
    277   // go back from last position, until start of sequence found
    278   pos = max - 1;
    279   while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }
    280 
    281   // Fuckup - very small and broken sequence,
    282   // return max, because we should return something anyway.
    283   if (pos < 0) { return max; }
    284 
    285   // If we came to start of buffer - that means vuffer is too small,
    286   // return max too.
    287   if (pos === 0) { return max; }
    288 
    289   return (pos + _utf8len[buf[pos]] > max) ? pos : max;
    290 };
    291 
    292 },{"./common":1}],3:[function(require,module,exports){
    293 'use strict';
    294 
    295 // Note: adler32 takes 12% for level 0 and 2% for level 6.
    296 // It doesn't worth to make additional optimizationa as in original.
    297 // Small size is preferable.
    298 
    299 function adler32(adler, buf, len, pos) {
    300   var s1 = (adler & 0xffff) |0,
    301       s2 = ((adler >>> 16) & 0xffff) |0,
    302       n = 0;
    303 
    304   while (len !== 0) {
    305     // Set limit ~ twice less than 5552, to keep
    306     // s2 in 31-bits, because we force signed ints.
    307     // in other case %= will fail.
    308     n = len > 2000 ? 2000 : len;
    309     len -= n;
    310 
    311     do {
    312       s1 = (s1 + buf[pos++]) |0;
    313       s2 = (s2 + s1) |0;
    314     } while (--n);
    315 
    316     s1 %= 65521;
    317     s2 %= 65521;
    318   }
    319 
    320   return (s1 | (s2 << 16)) |0;
    321 }
    322 
    323 
    324 module.exports = adler32;
    325 
    326 },{}],4:[function(require,module,exports){
    327 'use strict';
    328 
    329 
    330 module.exports = {
    331 
    332   /* Allowed flush values; see deflate() and inflate() below for details */
    333   Z_NO_FLUSH:         0,
    334   Z_PARTIAL_FLUSH:    1,
    335   Z_SYNC_FLUSH:       2,
    336   Z_FULL_FLUSH:       3,
    337   Z_FINISH:           4,
    338   Z_BLOCK:            5,
    339   Z_TREES:            6,
    340 
    341   /* Return codes for the compression/decompression functions. Negative values
    342   * are errors, positive values are used for special but normal events.
    343   */
    344   Z_OK:               0,
    345   Z_STREAM_END:       1,
    346   Z_NEED_DICT:        2,
    347   Z_ERRNO:           -1,
    348   Z_STREAM_ERROR:    -2,
    349   Z_DATA_ERROR:      -3,
    350   //Z_MEM_ERROR:     -4,
    351   Z_BUF_ERROR:       -5,
    352   //Z_VERSION_ERROR: -6,
    353 
    354   /* compression levels */
    355   Z_NO_COMPRESSION:         0,
    356   Z_BEST_SPEED:             1,
    357   Z_BEST_COMPRESSION:       9,
    358   Z_DEFAULT_COMPRESSION:   -1,
    359 
    360 
    361   Z_FILTERED:               1,
    362   Z_HUFFMAN_ONLY:           2,
    363   Z_RLE:                    3,
    364   Z_FIXED:                  4,
    365   Z_DEFAULT_STRATEGY:       0,
    366 
    367   /* Possible values of the data_type field (though see inflate()) */
    368   Z_BINARY:                 0,
    369   Z_TEXT:                   1,
    370   //Z_ASCII:                1, // = Z_TEXT (deprecated)
    371   Z_UNKNOWN:                2,
    372 
    373   /* The deflate compression method */
    374   Z_DEFLATED:               8
    375   //Z_NULL:                 null // Use -1 or null inline, depending on var type
    376 };
    377 
    378 },{}],5:[function(require,module,exports){
    379 'use strict';
    380 
    381 // Note: we can't get significant speed boost here.
    382 // So write code to minimize size - no pregenerated tables
    383 // and array tools dependencies.
    384 
    385 
    386 // Use ordinary array, since untyped makes no boost here
    387 function makeTable() {
    388   var c, table = [];
    389 
    390   for (var n = 0; n < 256; n++) {
    391     c = n;
    392     for (var k = 0; k < 8; k++) {
    393       c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
    394     }
    395     table[n] = c;
    396   }
    397 
    398   return table;
    399 }
    400 
    401 // Create table on load. Just 255 signed longs. Not a problem.
    402 var crcTable = makeTable();
    403 
    404 
    405 function crc32(crc, buf, len, pos) {
    406   var t = crcTable,
    407       end = pos + len;
    408 
    409   crc ^= -1;
    410 
    411   for (var i = pos; i < end; i++) {
    412     crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];
    413   }
    414 
    415   return (crc ^ (-1)); // >>> 0;
    416 }
    417 
    418 
    419 module.exports = crc32;
    420 
    421 },{}],6:[function(require,module,exports){
    422 'use strict';
    423 
    424 
    425 function GZheader() {
    426   /* true if compressed data believed to be text */
    427   this.text       = 0;
    428   /* modification time */
    429   this.time       = 0;
    430   /* extra flags (not used when writing a gzip file) */
    431   this.xflags     = 0;
    432   /* operating system */
    433   this.os         = 0;
    434   /* pointer to extra field or Z_NULL if none */
    435   this.extra      = null;
    436   /* extra field length (valid if extra != Z_NULL) */
    437   this.extra_len  = 0; // Actually, we don't need it in JS,
    438                        // but leave for few code modifications
    439 
    440   //
    441   // Setup limits is not necessary because in js we should not preallocate memory
    442   // for inflate use constant limit in 65536 bytes
    443   //
    444 
    445   /* space at extra (only when reading header) */
    446   // this.extra_max  = 0;
    447   /* pointer to zero-terminated file name or Z_NULL */
    448   this.name       = '';
    449   /* space at name (only when reading header) */
    450   // this.name_max   = 0;
    451   /* pointer to zero-terminated comment or Z_NULL */
    452   this.comment    = '';
    453   /* space at comment (only when reading header) */
    454   // this.comm_max   = 0;
    455   /* true if there was or will be a header crc */
    456   this.hcrc       = 0;
    457   /* true when done reading gzip header (not used when writing a gzip file) */
    458   this.done       = false;
    459 }
    460 
    461 module.exports = GZheader;
    462 
    463 },{}],7:[function(require,module,exports){
    464 'use strict';
    465 
    466 // See state defs from inflate.js
    467 var BAD = 30;       /* got a data error -- remain here until reset */
    468 var TYPE = 12;      /* i: waiting for type bits, including last-flag bit */
    469 
    470 /*
    471    Decode literal, length, and distance codes and write out the resulting
    472    literal and match bytes until either not enough input or output is
    473    available, an end-of-block is encountered, or a data error is encountered.
    474    When large enough input and output buffers are supplied to inflate(), for
    475    example, a 16K input buffer and a 64K output buffer, more than 95% of the
    476    inflate execution time is spent in this routine.
    477 
    478    Entry assumptions:
    479 
    480         state.mode === LEN
    481         strm.avail_in >= 6
    482         strm.avail_out >= 258
    483         start >= strm.avail_out
    484         state.bits < 8
    485 
    486    On return, state.mode is one of:
    487 
    488         LEN -- ran out of enough output space or enough available input
    489         TYPE -- reached end of block code, inflate() to interpret next block
    490         BAD -- error in block data
    491 
    492    Notes:
    493 
    494     - The maximum input bits used by a length/distance pair is 15 bits for the
    495       length code, 5 bits for the length extra, 15 bits for the distance code,
    496       and 13 bits for the distance extra.  This totals 48 bits, or six bytes.
    497       Therefore if strm.avail_in >= 6, then there is enough input to avoid
    498       checking for available input while decoding.
    499 
    500     - The maximum bytes that a single length/distance pair can output is 258
    501       bytes, which is the maximum length that can be coded.  inflate_fast()
    502       requires strm.avail_out >= 258 for each loop to avoid checking for
    503       output space.
    504  */
    505 module.exports = function inflate_fast(strm, start) {
    506   var state;
    507   var _in;                    /* local strm.input */
    508   var last;                   /* have enough input while in < last */
    509   var _out;                   /* local strm.output */
    510   var beg;                    /* inflate()'s initial strm.output */
    511   var end;                    /* while out < end, enough space available */
    512 //#ifdef INFLATE_STRICT
    513   var dmax;                   /* maximum distance from zlib header */
    514 //#endif
    515   var wsize;                  /* window size or zero if not using window */
    516   var whave;                  /* valid bytes in the window */
    517   var wnext;                  /* window write index */
    518   // Use `s_window` instead `window`, avoid conflict with instrumentation tools
    519   var s_window;               /* allocated sliding window, if wsize != 0 */
    520   var hold;                   /* local strm.hold */
    521   var bits;                   /* local strm.bits */
    522   var lcode;                  /* local strm.lencode */
    523   var dcode;                  /* local strm.distcode */
    524   var lmask;                  /* mask for first level of length codes */
    525   var dmask;                  /* mask for first level of distance codes */
    526   var here;                   /* retrieved table entry */
    527   var op;                     /* code bits, operation, extra bits, or */
    528                               /*  window position, window bytes to copy */
    529   var len;                    /* match length, unused bytes */
    530   var dist;                   /* match distance */
    531   var from;                   /* where to copy match from */
    532   var from_source;
    533 
    534 
    535   var input, output; // JS specific, because we have no pointers
    536 
    537   /* copy state to local variables */
    538   state = strm.state;
    539   //here = state.here;
    540   _in = strm.next_in;
    541   input = strm.input;
    542   last = _in + (strm.avail_in - 5);
    543   _out = strm.next_out;
    544   output = strm.output;
    545   beg = _out - (start - strm.avail_out);
    546   end = _out + (strm.avail_out - 257);
    547 //#ifdef INFLATE_STRICT
    548   dmax = state.dmax;
    549 //#endif
    550   wsize = state.wsize;
    551   whave = state.whave;
    552   wnext = state.wnext;
    553   s_window = state.window;
    554   hold = state.hold;
    555   bits = state.bits;
    556   lcode = state.lencode;
    557   dcode = state.distcode;
    558   lmask = (1 << state.lenbits) - 1;
    559   dmask = (1 << state.distbits) - 1;
    560 
    561 
    562   /* decode literals and length/distances until end-of-block or not enough
    563      input data or output space */
    564 
    565   top:
    566   do {
    567     if (bits < 15) {
    568       hold += input[_in++] << bits;
    569       bits += 8;
    570       hold += input[_in++] << bits;
    571       bits += 8;
    572     }
    573 
    574     here = lcode[hold & lmask];
    575 
    576     dolen:
    577     for (;;) { // Goto emulation
    578       op = here >>> 24/*here.bits*/;
    579       hold >>>= op;
    580       bits -= op;
    581       op = (here >>> 16) & 0xff/*here.op*/;
    582       if (op === 0) {                          /* literal */
    583         //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
    584         //        "inflate:         literal '%c'\n" :
    585         //        "inflate:         literal 0x%02x\n", here.val));
    586         output[_out++] = here & 0xffff/*here.val*/;
    587       }
    588       else if (op & 16) {                     /* length base */
    589         len = here & 0xffff/*here.val*/;
    590         op &= 15;                           /* number of extra bits */
    591         if (op) {
    592           if (bits < op) {
    593             hold += input[_in++] << bits;
    594             bits += 8;
    595           }
    596           len += hold & ((1 << op) - 1);
    597           hold >>>= op;
    598           bits -= op;
    599         }
    600         //Tracevv((stderr, "inflate:         length %u\n", len));
    601         if (bits < 15) {
    602           hold += input[_in++] << bits;
    603           bits += 8;
    604           hold += input[_in++] << bits;
    605           bits += 8;
    606         }
    607         here = dcode[hold & dmask];
    608 
    609         dodist:
    610         for (;;) { // goto emulation
    611           op = here >>> 24/*here.bits*/;
    612           hold >>>= op;
    613           bits -= op;
    614           op = (here >>> 16) & 0xff/*here.op*/;
    615 
    616           if (op & 16) {                      /* distance base */
    617             dist = here & 0xffff/*here.val*/;
    618             op &= 15;                       /* number of extra bits */
    619             if (bits < op) {
    620               hold += input[_in++] << bits;
    621               bits += 8;
    622               if (bits < op) {
    623                 hold += input[_in++] << bits;
    624                 bits += 8;
    625               }
    626             }
    627             dist += hold & ((1 << op) - 1);
    628 //#ifdef INFLATE_STRICT
    629             if (dist > dmax) {
    630               strm.msg = 'invalid distance too far back';
    631               state.mode = BAD;
    632               break top;
    633             }
    634 //#endif
    635             hold >>>= op;
    636             bits -= op;
    637             //Tracevv((stderr, "inflate:         distance %u\n", dist));
    638             op = _out - beg;                /* max distance in output */
    639             if (dist > op) {                /* see if copy from window */
    640               op = dist - op;               /* distance back in window */
    641               if (op > whave) {
    642                 if (state.sane) {
    643                   strm.msg = 'invalid distance too far back';
    644                   state.mode = BAD;
    645                   break top;
    646                 }
    647 
    648 // (!) This block is disabled in zlib defailts,
    649 // don't enable it for binary compatibility
    650 //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
    651 //                if (len <= op - whave) {
    652 //                  do {
    653 //                    output[_out++] = 0;
    654 //                  } while (--len);
    655 //                  continue top;
    656 //                }
    657 //                len -= op - whave;
    658 //                do {
    659 //                  output[_out++] = 0;
    660 //                } while (--op > whave);
    661 //                if (op === 0) {
    662 //                  from = _out - dist;
    663 //                  do {
    664 //                    output[_out++] = output[from++];
    665 //                  } while (--len);
    666 //                  continue top;
    667 //                }
    668 //#endif
    669               }
    670               from = 0; // window index
    671               from_source = s_window;
    672               if (wnext === 0) {           /* very common case */
    673                 from += wsize - op;
    674                 if (op < len) {         /* some from window */
    675                   len -= op;
    676                   do {
    677                     output[_out++] = s_window[from++];
    678                   } while (--op);
    679                   from = _out - dist;  /* rest from output */
    680                   from_source = output;
    681                 }
    682               }
    683               else if (wnext < op) {      /* wrap around window */
    684                 from += wsize + wnext - op;
    685                 op -= wnext;
    686                 if (op < len) {         /* some from end of window */
    687                   len -= op;
    688                   do {
    689                     output[_out++] = s_window[from++];
    690                   } while (--op);
    691                   from = 0;
    692                   if (wnext < len) {  /* some from start of window */
    693                     op = wnext;
    694                     len -= op;
    695                     do {
    696                       output[_out++] = s_window[from++];
    697                     } while (--op);
    698                     from = _out - dist;      /* rest from output */
    699                     from_source = output;
    700                   }
    701                 }
    702               }
    703               else {                      /* contiguous in window */
    704                 from += wnext - op;
    705                 if (op < len) {         /* some from window */
    706                   len -= op;
    707                   do {
    708                     output[_out++] = s_window[from++];
    709                   } while (--op);
    710                   from = _out - dist;  /* rest from output */
    711                   from_source = output;
    712                 }
    713               }
    714               while (len > 2) {
    715                 output[_out++] = from_source[from++];
    716                 output[_out++] = from_source[from++];
    717                 output[_out++] = from_source[from++];
    718                 len -= 3;
    719               }
    720               if (len) {
    721                 output[_out++] = from_source[from++];
    722                 if (len > 1) {
    723                   output[_out++] = from_source[from++];
    724                 }
    725               }
    726             }
    727             else {
    728               from = _out - dist;          /* copy direct from output */
    729               do {                        /* minimum length is three */
    730                 output[_out++] = output[from++];
    731                 output[_out++] = output[from++];
    732                 output[_out++] = output[from++];
    733                 len -= 3;
    734               } while (len > 2);
    735               if (len) {
    736                 output[_out++] = output[from++];
    737                 if (len > 1) {
    738                   output[_out++] = output[from++];
    739                 }
    740               }
    741             }
    742           }
    743           else if ((op & 64) === 0) {          /* 2nd level distance code */
    744             here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
    745             continue dodist;
    746           }
    747           else {
    748             strm.msg = 'invalid distance code';
    749             state.mode = BAD;
    750             break top;
    751           }
    752 
    753           break; // need to emulate goto via "continue"
    754         }
    755       }
    756       else if ((op & 64) === 0) {              /* 2nd level length code */
    757         here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
    758         continue dolen;
    759       }
    760       else if (op & 32) {                     /* end-of-block */
    761         //Tracevv((stderr, "inflate:         end of block\n"));
    762         state.mode = TYPE;
    763         break top;
    764       }
    765       else {
    766         strm.msg = 'invalid literal/length code';
    767         state.mode = BAD;
    768         break top;
    769       }
    770 
    771       break; // need to emulate goto via "continue"
    772     }
    773   } while (_in < last && _out < end);
    774 
    775   /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
    776   len = bits >> 3;
    777   _in -= len;
    778   bits -= len << 3;
    779   hold &= (1 << bits) - 1;
    780 
    781   /* update state and return */
    782   strm.next_in = _in;
    783   strm.next_out = _out;
    784   strm.avail_in = (_in < last ? 5 + (last - _in) : 5 - (_in - last));
    785   strm.avail_out = (_out < end ? 257 + (end - _out) : 257 - (_out - end));
    786   state.hold = hold;
    787   state.bits = bits;
    788   return;
    789 };
    790 
    791 },{}],8:[function(require,module,exports){
    792 'use strict';
    793 
    794 
    795 var utils         = require('../utils/common');
    796 var adler32       = require('./adler32');
    797 var crc32         = require('./crc32');
    798 var inflate_fast  = require('./inffast');
    799 var inflate_table = require('./inftrees');
    800 
    801 var CODES = 0;
    802 var LENS = 1;
    803 var DISTS = 2;
    804 
    805 /* Public constants ==========================================================*/
    806 /* ===========================================================================*/
    807 
    808 
    809 /* Allowed flush values; see deflate() and inflate() below for details */
    810 //var Z_NO_FLUSH      = 0;
    811 //var Z_PARTIAL_FLUSH = 1;
    812 //var Z_SYNC_FLUSH    = 2;
    813 //var Z_FULL_FLUSH    = 3;
    814 var Z_FINISH        = 4;
    815 var Z_BLOCK         = 5;
    816 var Z_TREES         = 6;
    817 
    818 
    819 /* Return codes for the compression/decompression functions. Negative values
    820  * are errors, positive values are used for special but normal events.
    821  */
    822 var Z_OK            = 0;
    823 var Z_STREAM_END    = 1;
    824 var Z_NEED_DICT     = 2;
    825 //var Z_ERRNO         = -1;
    826 var Z_STREAM_ERROR  = -2;
    827 var Z_DATA_ERROR    = -3;
    828 var Z_MEM_ERROR     = -4;
    829 var Z_BUF_ERROR     = -5;
    830 //var Z_VERSION_ERROR = -6;
    831 
    832 /* The deflate compression method */
    833 var Z_DEFLATED  = 8;
    834 
    835 
    836 /* STATES ====================================================================*/
    837 /* ===========================================================================*/
    838 
    839 
    840 var    HEAD = 1;       /* i: waiting for magic header */
    841 var    FLAGS = 2;      /* i: waiting for method and flags (gzip) */
    842 var    TIME = 3;       /* i: waiting for modification time (gzip) */
    843 var    OS = 4;         /* i: waiting for extra flags and operating system (gzip) */
    844 var    EXLEN = 5;      /* i: waiting for extra length (gzip) */
    845 var    EXTRA = 6;      /* i: waiting for extra bytes (gzip) */
    846 var    NAME = 7;       /* i: waiting for end of file name (gzip) */
    847 var    COMMENT = 8;    /* i: waiting for end of comment (gzip) */
    848 var    HCRC = 9;       /* i: waiting for header crc (gzip) */
    849 var    DICTID = 10;    /* i: waiting for dictionary check value */
    850 var    DICT = 11;      /* waiting for inflateSetDictionary() call */
    851 var        TYPE = 12;      /* i: waiting for type bits, including last-flag bit */
    852 var        TYPEDO = 13;    /* i: same, but skip check to exit inflate on new block */
    853 var        STORED = 14;    /* i: waiting for stored size (length and complement) */
    854 var        COPY_ = 15;     /* i/o: same as COPY below, but only first time in */
    855 var        COPY = 16;      /* i/o: waiting for input or output to copy stored block */
    856 var        TABLE = 17;     /* i: waiting for dynamic block table lengths */
    857 var        LENLENS = 18;   /* i: waiting for code length code lengths */
    858 var        CODELENS = 19;  /* i: waiting for length/lit and distance code lengths */
    859 var            LEN_ = 20;      /* i: same as LEN below, but only first time in */
    860 var            LEN = 21;       /* i: waiting for length/lit/eob code */
    861 var            LENEXT = 22;    /* i: waiting for length extra bits */
    862 var            DIST = 23;      /* i: waiting for distance code */
    863 var            DISTEXT = 24;   /* i: waiting for distance extra bits */
    864 var            MATCH = 25;     /* o: waiting for output space to copy string */
    865 var            LIT = 26;       /* o: waiting for output space to write literal */
    866 var    CHECK = 27;     /* i: waiting for 32-bit check value */
    867 var    LENGTH = 28;    /* i: waiting for 32-bit length (gzip) */
    868 var    DONE = 29;      /* finished check, done -- remain here until reset */
    869 var    BAD = 30;       /* got a data error -- remain here until reset */
    870 var    MEM = 31;       /* got an inflate() memory error -- remain here until reset */
    871 var    SYNC = 32;      /* looking for synchronization bytes to restart inflate() */
    872 
    873 /* ===========================================================================*/
    874 
    875 
    876 
    877 var ENOUGH_LENS = 852;
    878 var ENOUGH_DISTS = 592;
    879 //var ENOUGH =  (ENOUGH_LENS+ENOUGH_DISTS);
    880 
    881 var MAX_WBITS = 15;
    882 /* 32K LZ77 window */
    883 var DEF_WBITS = MAX_WBITS;
    884 
    885 
    886 function zswap32(q) {
    887   return  (((q >>> 24) & 0xff) +
    888           ((q >>> 8) & 0xff00) +
    889           ((q & 0xff00) << 8) +
    890           ((q & 0xff) << 24));
    891 }
    892 
    893 
    894 function InflateState() {
    895   this.mode = 0;             /* current inflate mode */
    896   this.last = false;          /* true if processing last block */
    897   this.wrap = 0;              /* bit 0 true for zlib, bit 1 true for gzip */
    898   this.havedict = false;      /* true if dictionary provided */
    899   this.flags = 0;             /* gzip header method and flags (0 if zlib) */
    900   this.dmax = 0;              /* zlib header max distance (INFLATE_STRICT) */
    901   this.check = 0;             /* protected copy of check value */
    902   this.total = 0;             /* protected copy of output count */
    903   // TODO: may be {}
    904   this.head = null;           /* where to save gzip header information */
    905 
    906   /* sliding window */
    907   this.wbits = 0;             /* log base 2 of requested window size */
    908   this.wsize = 0;             /* window size or zero if not using window */
    909   this.whave = 0;             /* valid bytes in the window */
    910   this.wnext = 0;             /* window write index */
    911   this.window = null;         /* allocated sliding window, if needed */
    912 
    913   /* bit accumulator */
    914   this.hold = 0;              /* input bit accumulator */
    915   this.bits = 0;              /* number of bits in "in" */
    916 
    917   /* for string and stored block copying */
    918   this.length = 0;            /* literal or length of data to copy */
    919   this.offset = 0;            /* distance back to copy string from */
    920 
    921   /* for table and code decoding */
    922   this.extra = 0;             /* extra bits needed */
    923 
    924   /* fixed and dynamic code tables */
    925   this.lencode = null;          /* starting table for length/literal codes */
    926   this.distcode = null;         /* starting table for distance codes */
    927   this.lenbits = 0;           /* index bits for lencode */
    928   this.distbits = 0;          /* index bits for distcode */
    929 
    930   /* dynamic table building */
    931   this.ncode = 0;             /* number of code length code lengths */
    932   this.nlen = 0;              /* number of length code lengths */
    933   this.ndist = 0;             /* number of distance code lengths */
    934   this.have = 0;              /* number of code lengths in lens[] */
    935   this.next = null;              /* next available space in codes[] */
    936 
    937   this.lens = new utils.Buf16(320); /* temporary storage for code lengths */
    938   this.work = new utils.Buf16(288); /* work area for code table building */
    939 
    940   /*
    941    because we don't have pointers in js, we use lencode and distcode directly
    942    as buffers so we don't need codes
    943   */
    944   //this.codes = new utils.Buf32(ENOUGH);       /* space for code tables */
    945   this.lendyn = null;              /* dynamic table for length/literal codes (JS specific) */
    946   this.distdyn = null;             /* dynamic table for distance codes (JS specific) */
    947   this.sane = 0;                   /* if false, allow invalid distance too far */
    948   this.back = 0;                   /* bits back of last unprocessed length/lit */
    949   this.was = 0;                    /* initial length of match */
    950 }
    951 
    952 function inflateResetKeep(strm) {
    953   var state;
    954 
    955   if (!strm || !strm.state) { return Z_STREAM_ERROR; }
    956   state = strm.state;
    957   strm.total_in = strm.total_out = state.total = 0;
    958   strm.msg = ''; /*Z_NULL*/
    959   if (state.wrap) {       /* to support ill-conceived Java test suite */
    960     strm.adler = state.wrap & 1;
    961   }
    962   state.mode = HEAD;
    963   state.last = 0;
    964   state.havedict = 0;
    965   state.dmax = 32768;
    966   state.head = null/*Z_NULL*/;
    967   state.hold = 0;
    968   state.bits = 0;
    969   //state.lencode = state.distcode = state.next = state.codes;
    970   state.lencode = state.lendyn = new utils.Buf32(ENOUGH_LENS);
    971   state.distcode = state.distdyn = new utils.Buf32(ENOUGH_DISTS);
    972 
    973   state.sane = 1;
    974   state.back = -1;
    975   //Tracev((stderr, "inflate: reset\n"));
    976   return Z_OK;
    977 }
    978 
    979 function inflateReset(strm) {
    980   var state;
    981 
    982   if (!strm || !strm.state) { return Z_STREAM_ERROR; }
    983   state = strm.state;
    984   state.wsize = 0;
    985   state.whave = 0;
    986   state.wnext = 0;
    987   return inflateResetKeep(strm);
    988 
    989 }
    990 
    991 function inflateReset2(strm, windowBits) {
    992   var wrap;
    993   var state;
    994 
    995   /* get the state */
    996   if (!strm || !strm.state) { return Z_STREAM_ERROR; }
    997   state = strm.state;
    998 
    999   /* extract wrap request from windowBits parameter */
   1000   if (windowBits < 0) {
   1001     wrap = 0;
   1002     windowBits = -windowBits;
   1003   }
   1004   else {
   1005     wrap = (windowBits >> 4) + 1;
   1006     if (windowBits < 48) {
   1007       windowBits &= 15;
   1008     }
   1009   }
   1010 
   1011   /* set number of window bits, free window if different */
   1012   if (windowBits && (windowBits < 8 || windowBits > 15)) {
   1013     return Z_STREAM_ERROR;
   1014   }
   1015   if (state.window !== null && state.wbits !== windowBits) {
   1016     state.window = null;
   1017   }
   1018 
   1019   /* update state and reset the rest of it */
   1020   state.wrap = wrap;
   1021   state.wbits = windowBits;
   1022   return inflateReset(strm);
   1023 }
   1024 
   1025 function inflateInit2(strm, windowBits) {
   1026   var ret;
   1027   var state;
   1028 
   1029   if (!strm) { return Z_STREAM_ERROR; }
   1030   //strm.msg = Z_NULL;                 /* in case we return an error */
   1031 
   1032   state = new InflateState();
   1033 
   1034   //if (state === Z_NULL) return Z_MEM_ERROR;
   1035   //Tracev((stderr, "inflate: allocated\n"));
   1036   strm.state = state;
   1037   state.window = null/*Z_NULL*/;
   1038   ret = inflateReset2(strm, windowBits);
   1039   if (ret !== Z_OK) {
   1040     strm.state = null/*Z_NULL*/;
   1041   }
   1042   return ret;
   1043 }
   1044 
   1045 function inflateInit(strm) {
   1046   return inflateInit2(strm, DEF_WBITS);
   1047 }
   1048 
   1049 
   1050 /*
   1051  Return state with length and distance decoding tables and index sizes set to
   1052  fixed code decoding.  Normally this returns fixed tables from inffixed.h.
   1053  If BUILDFIXED is defined, then instead this routine builds the tables the
   1054  first time it's called, and returns those tables the first time and
   1055  thereafter.  This reduces the size of the code by about 2K bytes, in
   1056  exchange for a little execution time.  However, BUILDFIXED should not be
   1057  used for threaded applications, since the rewriting of the tables and virgin
   1058  may not be thread-safe.
   1059  */
   1060 var virgin = true;
   1061 
   1062 var lenfix, distfix; // We have no pointers in JS, so keep tables separate
   1063 
   1064 function fixedtables(state) {
   1065   /* build fixed huffman tables if first call (may not be thread safe) */
   1066   if (virgin) {
   1067     var sym;
   1068 
   1069     lenfix = new utils.Buf32(512);
   1070     distfix = new utils.Buf32(32);
   1071 
   1072     /* literal/length table */
   1073     sym = 0;
   1074     while (sym < 144) { state.lens[sym++] = 8; }
   1075     while (sym < 256) { state.lens[sym++] = 9; }
   1076     while (sym < 280) { state.lens[sym++] = 7; }
   1077     while (sym < 288) { state.lens[sym++] = 8; }
   1078 
   1079     inflate_table(LENS,  state.lens, 0, 288, lenfix,   0, state.work, { bits: 9 });
   1080 
   1081     /* distance table */
   1082     sym = 0;
   1083     while (sym < 32) { state.lens[sym++] = 5; }
   1084 
   1085     inflate_table(DISTS, state.lens, 0, 32,   distfix, 0, state.work, { bits: 5 });
   1086 
   1087     /* do this just once */
   1088     virgin = false;
   1089   }
   1090 
   1091   state.lencode = lenfix;
   1092   state.lenbits = 9;
   1093   state.distcode = distfix;
   1094   state.distbits = 5;
   1095 }
   1096 
   1097 
   1098 /*
   1099  Update the window with the last wsize (normally 32K) bytes written before
   1100  returning.  If window does not exist yet, create it.  This is only called
   1101  when a window is already in use, or when output has been written during this
   1102  inflate call, but the end of the deflate stream has not been reached yet.
   1103  It is also called to create a window for dictionary data when a dictionary
   1104  is loaded.
   1105 
   1106  Providing output buffers larger than 32K to inflate() should provide a speed
   1107  advantage, since only the last 32K of output is copied to the sliding window
   1108  upon return from inflate(), and since all distances after the first 32K of
   1109  output will fall in the output data, making match copies simpler and faster.
   1110  The advantage may be dependent on the size of the processor's data caches.
   1111  */
   1112 function updatewindow(strm, src, end, copy) {
   1113   var dist;
   1114   var state = strm.state;
   1115 
   1116   /* if it hasn't been done already, allocate space for the window */
   1117   if (state.window === null) {
   1118     state.wsize = 1 << state.wbits;
   1119     state.wnext = 0;
   1120     state.whave = 0;
   1121 
   1122     state.window = new utils.Buf8(state.wsize);
   1123   }
   1124 
   1125   /* copy state->wsize or less output bytes into the circular window */
   1126   if (copy >= state.wsize) {
   1127     utils.arraySet(state.window, src, end - state.wsize, state.wsize, 0);
   1128     state.wnext = 0;
   1129     state.whave = state.wsize;
   1130   }
   1131   else {
   1132     dist = state.wsize - state.wnext;
   1133     if (dist > copy) {
   1134       dist = copy;
   1135     }
   1136     //zmemcpy(state->window + state->wnext, end - copy, dist);
   1137     utils.arraySet(state.window, src, end - copy, dist, state.wnext);
   1138     copy -= dist;
   1139     if (copy) {
   1140       //zmemcpy(state->window, end - copy, copy);
   1141       utils.arraySet(state.window, src, end - copy, copy, 0);
   1142       state.wnext = copy;
   1143       state.whave = state.wsize;
   1144     }
   1145     else {
   1146       state.wnext += dist;
   1147       if (state.wnext === state.wsize) { state.wnext = 0; }
   1148       if (state.whave < state.wsize) { state.whave += dist; }
   1149     }
   1150   }
   1151   return 0;
   1152 }
   1153 
   1154 function inflate(strm, flush) {
   1155   var state;
   1156   var input, output;          // input/output buffers
   1157   var next;                   /* next input INDEX */
   1158   var put;                    /* next output INDEX */
   1159   var have, left;             /* available input and output */
   1160   var hold;                   /* bit buffer */
   1161   var bits;                   /* bits in bit buffer */
   1162   var _in, _out;              /* save starting available input and output */
   1163   var copy;                   /* number of stored or match bytes to copy */
   1164   var from;                   /* where to copy match bytes from */
   1165   var from_source;
   1166   var here = 0;               /* current decoding table entry */
   1167   var here_bits, here_op, here_val; // paked "here" denormalized (JS specific)
   1168   //var last;                   /* parent table entry */
   1169   var last_bits, last_op, last_val; // paked "last" denormalized (JS specific)
   1170   var len;                    /* length to copy for repeats, bits to drop */
   1171   var ret;                    /* return code */
   1172   var hbuf = new utils.Buf8(4);    /* buffer for gzip header crc calculation */
   1173   var opts;
   1174 
   1175   var n; // temporary var for NEED_BITS
   1176 
   1177   var order = /* permutation of code lengths */
   1178     [ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 ];
   1179 
   1180 
   1181   if (!strm || !strm.state || !strm.output ||
   1182       (!strm.input && strm.avail_in !== 0)) {
   1183     return Z_STREAM_ERROR;
   1184   }
   1185 
   1186   state = strm.state;
   1187   if (state.mode === TYPE) { state.mode = TYPEDO; }    /* skip check */
   1188 
   1189 
   1190   //--- LOAD() ---
   1191   put = strm.next_out;
   1192   output = strm.output;
   1193   left = strm.avail_out;
   1194   next = strm.next_in;
   1195   input = strm.input;
   1196   have = strm.avail_in;
   1197   hold = state.hold;
   1198   bits = state.bits;
   1199   //---
   1200 
   1201   _in = have;
   1202   _out = left;
   1203   ret = Z_OK;
   1204 
   1205   inf_leave: // goto emulation
   1206   for (;;) {
   1207     switch (state.mode) {
   1208     case HEAD:
   1209       if (state.wrap === 0) {
   1210         state.mode = TYPEDO;
   1211         break;
   1212       }
   1213       //=== NEEDBITS(16);
   1214       while (bits < 16) {
   1215         if (have === 0) { break inf_leave; }
   1216         have--;
   1217         hold += input[next++] << bits;
   1218         bits += 8;
   1219       }
   1220       //===//
   1221       if ((state.wrap & 2) && hold === 0x8b1f) {  /* gzip header */
   1222         state.check = 0/*crc32(0L, Z_NULL, 0)*/;
   1223         //=== CRC2(state.check, hold);
   1224         hbuf[0] = hold & 0xff;
   1225         hbuf[1] = (hold >>> 8) & 0xff;
   1226         state.check = crc32(state.check, hbuf, 2, 0);
   1227         //===//
   1228 
   1229         //=== INITBITS();
   1230         hold = 0;
   1231         bits = 0;
   1232         //===//
   1233         state.mode = FLAGS;
   1234         break;
   1235       }
   1236       state.flags = 0;           /* expect zlib header */
   1237       if (state.head) {
   1238         state.head.done = false;
   1239       }
   1240       if (!(state.wrap & 1) ||   /* check if zlib header allowed */
   1241         (((hold & 0xff)/*BITS(8)*/ << 8) + (hold >> 8)) % 31) {
   1242         strm.msg = 'incorrect header check';
   1243         state.mode = BAD;
   1244         break;
   1245       }
   1246       if ((hold & 0x0f)/*BITS(4)*/ !== Z_DEFLATED) {
   1247         strm.msg = 'unknown compression method';
   1248         state.mode = BAD;
   1249         break;
   1250       }
   1251       //--- DROPBITS(4) ---//
   1252       hold >>>= 4;
   1253       bits -= 4;
   1254       //---//
   1255       len = (hold & 0x0f)/*BITS(4)*/ + 8;
   1256       if (state.wbits === 0) {
   1257         state.wbits = len;
   1258       }
   1259       else if (len > state.wbits) {
   1260         strm.msg = 'invalid window size';
   1261         state.mode = BAD;
   1262         break;
   1263       }
   1264       state.dmax = 1 << len;
   1265       //Tracev((stderr, "inflate:   zlib header ok\n"));
   1266       strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
   1267       state.mode = hold & 0x200 ? DICTID : TYPE;
   1268       //=== INITBITS();
   1269       hold = 0;
   1270       bits = 0;
   1271       //===//
   1272       break;
   1273     case FLAGS:
   1274       //=== NEEDBITS(16); */
   1275       while (bits < 16) {
   1276         if (have === 0) { break inf_leave; }
   1277         have--;
   1278         hold += input[next++] << bits;
   1279         bits += 8;
   1280       }
   1281       //===//
   1282       state.flags = hold;
   1283       if ((state.flags & 0xff) !== Z_DEFLATED) {
   1284         strm.msg = 'unknown compression method';
   1285         state.mode = BAD;
   1286         break;
   1287       }
   1288       if (state.flags & 0xe000) {
   1289         strm.msg = 'unknown header flags set';
   1290         state.mode = BAD;
   1291         break;
   1292       }
   1293       if (state.head) {
   1294         state.head.text = ((hold >> 8) & 1);
   1295       }
   1296       if (state.flags & 0x0200) {
   1297         //=== CRC2(state.check, hold);
   1298         hbuf[0] = hold & 0xff;
   1299         hbuf[1] = (hold >>> 8) & 0xff;
   1300         state.check = crc32(state.check, hbuf, 2, 0);
   1301         //===//
   1302       }
   1303       //=== INITBITS();
   1304       hold = 0;
   1305       bits = 0;
   1306       //===//
   1307       state.mode = TIME;
   1308       /* falls through */
   1309     case TIME:
   1310       //=== NEEDBITS(32); */
   1311       while (bits < 32) {
   1312         if (have === 0) { break inf_leave; }
   1313         have--;
   1314         hold += input[next++] << bits;
   1315         bits += 8;
   1316       }
   1317       //===//
   1318       if (state.head) {
   1319         state.head.time = hold;
   1320       }
   1321       if (state.flags & 0x0200) {
   1322         //=== CRC4(state.check, hold)
   1323         hbuf[0] = hold & 0xff;
   1324         hbuf[1] = (hold >>> 8) & 0xff;
   1325         hbuf[2] = (hold >>> 16) & 0xff;
   1326         hbuf[3] = (hold >>> 24) & 0xff;
   1327         state.check = crc32(state.check, hbuf, 4, 0);
   1328         //===
   1329       }
   1330       //=== INITBITS();
   1331       hold = 0;
   1332       bits = 0;
   1333       //===//
   1334       state.mode = OS;
   1335       /* falls through */
   1336     case OS:
   1337       //=== NEEDBITS(16); */
   1338       while (bits < 16) {
   1339         if (have === 0) { break inf_leave; }
   1340         have--;
   1341         hold += input[next++] << bits;
   1342         bits += 8;
   1343       }
   1344       //===//
   1345       if (state.head) {
   1346         state.head.xflags = (hold & 0xff);
   1347         state.head.os = (hold >> 8);
   1348       }
   1349       if (state.flags & 0x0200) {
   1350         //=== CRC2(state.check, hold);
   1351         hbuf[0] = hold & 0xff;
   1352         hbuf[1] = (hold >>> 8) & 0xff;
   1353         state.check = crc32(state.check, hbuf, 2, 0);
   1354         //===//
   1355       }
   1356       //=== INITBITS();
   1357       hold = 0;
   1358       bits = 0;
   1359       //===//
   1360       state.mode = EXLEN;
   1361       /* falls through */
   1362     case EXLEN:
   1363       if (state.flags & 0x0400) {
   1364         //=== NEEDBITS(16); */
   1365         while (bits < 16) {
   1366           if (have === 0) { break inf_leave; }
   1367           have--;
   1368           hold += input[next++] << bits;
   1369           bits += 8;
   1370         }
   1371         //===//
   1372         state.length = hold;
   1373         if (state.head) {
   1374           state.head.extra_len = hold;
   1375         }
   1376         if (state.flags & 0x0200) {
   1377           //=== CRC2(state.check, hold);
   1378           hbuf[0] = hold & 0xff;
   1379           hbuf[1] = (hold >>> 8) & 0xff;
   1380           state.check = crc32(state.check, hbuf, 2, 0);
   1381           //===//
   1382         }
   1383         //=== INITBITS();
   1384         hold = 0;
   1385         bits = 0;
   1386         //===//
   1387       }
   1388       else if (state.head) {
   1389         state.head.extra = null/*Z_NULL*/;
   1390       }
   1391       state.mode = EXTRA;
   1392       /* falls through */
   1393     case EXTRA:
   1394       if (state.flags & 0x0400) {
   1395         copy = state.length;
   1396         if (copy > have) { copy = have; }
   1397         if (copy) {
   1398           if (state.head) {
   1399             len = state.head.extra_len - state.length;
   1400             if (!state.head.extra) {
   1401               // Use untyped array for more conveniend processing later
   1402               state.head.extra = new Array(state.head.extra_len);
   1403             }
   1404             utils.arraySet(
   1405               state.head.extra,
   1406               input,
   1407               next,
   1408               // extra field is limited to 65536 bytes
   1409               // - no need for additional size check
   1410               copy,
   1411               /*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
   1412               len
   1413             );
   1414             //zmemcpy(state.head.extra + len, next,
   1415             //        len + copy > state.head.extra_max ?
   1416             //        state.head.extra_max - len : copy);
   1417           }
   1418           if (state.flags & 0x0200) {
   1419             state.check = crc32(state.check, input, copy, next);
   1420           }
   1421           have -= copy;
   1422           next += copy;
   1423           state.length -= copy;
   1424         }
   1425         if (state.length) { break inf_leave; }
   1426       }
   1427       state.length = 0;
   1428       state.mode = NAME;
   1429       /* falls through */
   1430     case NAME:
   1431       if (state.flags & 0x0800) {
   1432         if (have === 0) { break inf_leave; }
   1433         copy = 0;
   1434         do {
   1435           // TODO: 2 or 1 bytes?
   1436           len = input[next + copy++];
   1437           /* use constant limit because in js we should not preallocate memory */
   1438           if (state.head && len &&
   1439               (state.length < 65536 /*state.head.name_max*/)) {
   1440             state.head.name += String.fromCharCode(len);
   1441           }
   1442         } while (len && copy < have);
   1443 
   1444         if (state.flags & 0x0200) {
   1445           state.check = crc32(state.check, input, copy, next);
   1446         }
   1447         have -= copy;
   1448         next += copy;
   1449         if (len) { break inf_leave; }
   1450       }
   1451       else if (state.head) {
   1452         state.head.name = null;
   1453       }
   1454       state.length = 0;
   1455       state.mode = COMMENT;
   1456       /* falls through */
   1457     case COMMENT:
   1458       if (state.flags & 0x1000) {
   1459         if (have === 0) { break inf_leave; }
   1460         copy = 0;
   1461         do {
   1462           len = input[next + copy++];
   1463           /* use constant limit because in js we should not preallocate memory */
   1464           if (state.head && len &&
   1465               (state.length < 65536 /*state.head.comm_max*/)) {
   1466             state.head.comment += String.fromCharCode(len);
   1467           }
   1468         } while (len && copy < have);
   1469         if (state.flags & 0x0200) {
   1470           state.check = crc32(state.check, input, copy, next);
   1471         }
   1472         have -= copy;
   1473         next += copy;
   1474         if (len) { break inf_leave; }
   1475       }
   1476       else if (state.head) {
   1477         state.head.comment = null;
   1478       }
   1479       state.mode = HCRC;
   1480       /* falls through */
   1481     case HCRC:
   1482       if (state.flags & 0x0200) {
   1483         //=== NEEDBITS(16); */
   1484         while (bits < 16) {
   1485           if (have === 0) { break inf_leave; }
   1486           have--;
   1487           hold += input[next++] << bits;
   1488           bits += 8;
   1489         }
   1490         //===//
   1491         if (hold !== (state.check & 0xffff)) {
   1492           strm.msg = 'header crc mismatch';
   1493           state.mode = BAD;
   1494           break;
   1495         }
   1496         //=== INITBITS();
   1497         hold = 0;
   1498         bits = 0;
   1499         //===//
   1500       }
   1501       if (state.head) {
   1502         state.head.hcrc = ((state.flags >> 9) & 1);
   1503         state.head.done = true;
   1504       }
   1505       strm.adler = state.check = 0;
   1506       state.mode = TYPE;
   1507       break;
   1508     case DICTID:
   1509       //=== NEEDBITS(32); */
   1510       while (bits < 32) {
   1511         if (have === 0) { break inf_leave; }
   1512         have--;
   1513         hold += input[next++] << bits;
   1514         bits += 8;
   1515       }
   1516       //===//
   1517       strm.adler = state.check = zswap32(hold);
   1518       //=== INITBITS();
   1519       hold = 0;
   1520       bits = 0;
   1521       //===//
   1522       state.mode = DICT;
   1523       /* falls through */
   1524     case DICT:
   1525       if (state.havedict === 0) {
   1526         //--- RESTORE() ---
   1527         strm.next_out = put;
   1528         strm.avail_out = left;
   1529         strm.next_in = next;
   1530         strm.avail_in = have;
   1531         state.hold = hold;
   1532         state.bits = bits;
   1533         //---
   1534         return Z_NEED_DICT;
   1535       }
   1536       strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
   1537       state.mode = TYPE;
   1538       /* falls through */
   1539     case TYPE:
   1540       if (flush === Z_BLOCK || flush === Z_TREES) { break inf_leave; }
   1541       /* falls through */
   1542     case TYPEDO:
   1543       if (state.last) {
   1544         //--- BYTEBITS() ---//
   1545         hold >>>= bits & 7;
   1546         bits -= bits & 7;
   1547         //---//
   1548         state.mode = CHECK;
   1549         break;
   1550       }
   1551       //=== NEEDBITS(3); */
   1552       while (bits < 3) {
   1553         if (have === 0) { break inf_leave; }
   1554         have--;
   1555         hold += input[next++] << bits;
   1556         bits += 8;
   1557       }
   1558       //===//
   1559       state.last = (hold & 0x01)/*BITS(1)*/;
   1560       //--- DROPBITS(1) ---//
   1561       hold >>>= 1;
   1562       bits -= 1;
   1563       //---//
   1564 
   1565       switch ((hold & 0x03)/*BITS(2)*/) {
   1566       case 0:                             /* stored block */
   1567         //Tracev((stderr, "inflate:     stored block%s\n",
   1568         //        state.last ? " (last)" : ""));
   1569         state.mode = STORED;
   1570         break;
   1571       case 1:                             /* fixed block */
   1572         fixedtables(state);
   1573         //Tracev((stderr, "inflate:     fixed codes block%s\n",
   1574         //        state.last ? " (last)" : ""));
   1575         state.mode = LEN_;             /* decode codes */
   1576         if (flush === Z_TREES) {
   1577           //--- DROPBITS(2) ---//
   1578           hold >>>= 2;
   1579           bits -= 2;
   1580           //---//
   1581           break inf_leave;
   1582         }
   1583         break;
   1584       case 2:                             /* dynamic block */
   1585         //Tracev((stderr, "inflate:     dynamic codes block%s\n",
   1586         //        state.last ? " (last)" : ""));
   1587         state.mode = TABLE;
   1588         break;
   1589       case 3:
   1590         strm.msg = 'invalid block type';
   1591         state.mode = BAD;
   1592       }
   1593       //--- DROPBITS(2) ---//
   1594       hold >>>= 2;
   1595       bits -= 2;
   1596       //---//
   1597       break;
   1598     case STORED:
   1599       //--- BYTEBITS() ---// /* go to byte boundary */
   1600       hold >>>= bits & 7;
   1601       bits -= bits & 7;
   1602       //---//
   1603       //=== NEEDBITS(32); */
   1604       while (bits < 32) {
   1605         if (have === 0) { break inf_leave; }
   1606         have--;
   1607         hold += input[next++] << bits;
   1608         bits += 8;
   1609       }
   1610       //===//
   1611       if ((hold & 0xffff) !== ((hold >>> 16) ^ 0xffff)) {
   1612         strm.msg = 'invalid stored block lengths';
   1613         state.mode = BAD;
   1614         break;
   1615       }
   1616       state.length = hold & 0xffff;
   1617       //Tracev((stderr, "inflate:       stored length %u\n",
   1618       //        state.length));
   1619       //=== INITBITS();
   1620       hold = 0;
   1621       bits = 0;
   1622       //===//
   1623       state.mode = COPY_;
   1624       if (flush === Z_TREES) { break inf_leave; }
   1625       /* falls through */
   1626     case COPY_:
   1627       state.mode = COPY;
   1628       /* falls through */
   1629     case COPY:
   1630       copy = state.length;
   1631       if (copy) {
   1632         if (copy > have) { copy = have; }
   1633         if (copy > left) { copy = left; }
   1634         if (copy === 0) { break inf_leave; }
   1635         //--- zmemcpy(put, next, copy); ---
   1636         utils.arraySet(output, input, next, copy, put);
   1637         //---//
   1638         have -= copy;
   1639         next += copy;
   1640         left -= copy;
   1641         put += copy;
   1642         state.length -= copy;
   1643         break;
   1644       }
   1645       //Tracev((stderr, "inflate:       stored end\n"));
   1646       state.mode = TYPE;
   1647       break;
   1648     case TABLE:
   1649       //=== NEEDBITS(14); */
   1650       while (bits < 14) {
   1651         if (have === 0) { break inf_leave; }
   1652         have--;
   1653         hold += input[next++] << bits;
   1654         bits += 8;
   1655       }
   1656       //===//
   1657       state.nlen = (hold & 0x1f)/*BITS(5)*/ + 257;
   1658       //--- DROPBITS(5) ---//
   1659       hold >>>= 5;
   1660       bits -= 5;
   1661       //---//
   1662       state.ndist = (hold & 0x1f)/*BITS(5)*/ + 1;
   1663       //--- DROPBITS(5) ---//
   1664       hold >>>= 5;
   1665       bits -= 5;
   1666       //---//
   1667       state.ncode = (hold & 0x0f)/*BITS(4)*/ + 4;
   1668       //--- DROPBITS(4) ---//
   1669       hold >>>= 4;
   1670       bits -= 4;
   1671       //---//
   1672 //#ifndef PKZIP_BUG_WORKAROUND
   1673       if (state.nlen > 286 || state.ndist > 30) {
   1674         strm.msg = 'too many length or distance symbols';
   1675         state.mode = BAD;
   1676         break;
   1677       }
   1678 //#endif
   1679       //Tracev((stderr, "inflate:       table sizes ok\n"));
   1680       state.have = 0;
   1681       state.mode = LENLENS;
   1682       /* falls through */
   1683     case LENLENS:
   1684       while (state.have < state.ncode) {
   1685         //=== NEEDBITS(3);
   1686         while (bits < 3) {
   1687           if (have === 0) { break inf_leave; }
   1688           have--;
   1689           hold += input[next++] << bits;
   1690           bits += 8;
   1691         }
   1692         //===//
   1693         state.lens[order[state.have++]] = (hold & 0x07);//BITS(3);
   1694         //--- DROPBITS(3) ---//
   1695         hold >>>= 3;
   1696         bits -= 3;
   1697         //---//
   1698       }
   1699       while (state.have < 19) {
   1700         state.lens[order[state.have++]] = 0;
   1701       }
   1702       // We have separate tables & no pointers. 2 commented lines below not needed.
   1703       //state.next = state.codes;
   1704       //state.lencode = state.next;
   1705       // Switch to use dynamic table
   1706       state.lencode = state.lendyn;
   1707       state.lenbits = 7;
   1708 
   1709       opts = { bits: state.lenbits };
   1710       ret = inflate_table(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts);
   1711       state.lenbits = opts.bits;
   1712 
   1713       if (ret) {
   1714         strm.msg = 'invalid code lengths set';
   1715         state.mode = BAD;
   1716         break;
   1717       }
   1718       //Tracev((stderr, "inflate:       code lengths ok\n"));
   1719       state.have = 0;
   1720       state.mode = CODELENS;
   1721       /* falls through */
   1722     case CODELENS:
   1723       while (state.have < state.nlen + state.ndist) {
   1724         for (;;) {
   1725           here = state.lencode[hold & ((1 << state.lenbits) - 1)];/*BITS(state.lenbits)*/
   1726           here_bits = here >>> 24;
   1727           here_op = (here >>> 16) & 0xff;
   1728           here_val = here & 0xffff;
   1729 
   1730           if ((here_bits) <= bits) { break; }
   1731           //--- PULLBYTE() ---//
   1732           if (have === 0) { break inf_leave; }
   1733           have--;
   1734           hold += input[next++] << bits;
   1735           bits += 8;
   1736           //---//
   1737         }
   1738         if (here_val < 16) {
   1739           //--- DROPBITS(here.bits) ---//
   1740           hold >>>= here_bits;
   1741           bits -= here_bits;
   1742           //---//
   1743           state.lens[state.have++] = here_val;
   1744         }
   1745         else {
   1746           if (here_val === 16) {
   1747             //=== NEEDBITS(here.bits + 2);
   1748             n = here_bits + 2;
   1749             while (bits < n) {
   1750               if (have === 0) { break inf_leave; }
   1751               have--;
   1752               hold += input[next++] << bits;
   1753               bits += 8;
   1754             }
   1755             //===//
   1756             //--- DROPBITS(here.bits) ---//
   1757             hold >>>= here_bits;
   1758             bits -= here_bits;
   1759             //---//
   1760             if (state.have === 0) {
   1761               strm.msg = 'invalid bit length repeat';
   1762               state.mode = BAD;
   1763               break;
   1764             }
   1765             len = state.lens[state.have - 1];
   1766             copy = 3 + (hold & 0x03);//BITS(2);
   1767             //--- DROPBITS(2) ---//
   1768             hold >>>= 2;
   1769             bits -= 2;
   1770             //---//
   1771           }
   1772           else if (here_val === 17) {
   1773             //=== NEEDBITS(here.bits + 3);
   1774             n = here_bits + 3;
   1775             while (bits < n) {
   1776               if (have === 0) { break inf_leave; }
   1777               have--;
   1778               hold += input[next++] << bits;
   1779               bits += 8;
   1780             }
   1781             //===//
   1782             //--- DROPBITS(here.bits) ---//
   1783             hold >>>= here_bits;
   1784             bits -= here_bits;
   1785             //---//
   1786             len = 0;
   1787             copy = 3 + (hold & 0x07);//BITS(3);
   1788             //--- DROPBITS(3) ---//
   1789             hold >>>= 3;
   1790             bits -= 3;
   1791             //---//
   1792           }
   1793           else {
   1794             //=== NEEDBITS(here.bits + 7);
   1795             n = here_bits + 7;
   1796             while (bits < n) {
   1797               if (have === 0) { break inf_leave; }
   1798               have--;
   1799               hold += input[next++] << bits;
   1800               bits += 8;
   1801             }
   1802             //===//
   1803             //--- DROPBITS(here.bits) ---//
   1804             hold >>>= here_bits;
   1805             bits -= here_bits;
   1806             //---//
   1807             len = 0;
   1808             copy = 11 + (hold & 0x7f);//BITS(7);
   1809             //--- DROPBITS(7) ---//
   1810             hold >>>= 7;
   1811             bits -= 7;
   1812             //---//
   1813           }
   1814           if (state.have + copy > state.nlen + state.ndist) {
   1815             strm.msg = 'invalid bit length repeat';
   1816             state.mode = BAD;
   1817             break;
   1818           }
   1819           while (copy--) {
   1820             state.lens[state.have++] = len;
   1821           }
   1822         }
   1823       }
   1824 
   1825       /* handle error breaks in while */
   1826       if (state.mode === BAD) { break; }
   1827 
   1828       /* check for end-of-block code (better have one) */
   1829       if (state.lens[256] === 0) {
   1830         strm.msg = 'invalid code -- missing end-of-block';
   1831         state.mode = BAD;
   1832         break;
   1833       }
   1834 
   1835       /* build code tables -- note: do not change the lenbits or distbits
   1836          values here (9 and 6) without reading the comments in inftrees.h
   1837          concerning the ENOUGH constants, which depend on those values */
   1838       state.lenbits = 9;
   1839 
   1840       opts = { bits: state.lenbits };
   1841       ret = inflate_table(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts);
   1842       // We have separate tables & no pointers. 2 commented lines below not needed.
   1843       // state.next_index = opts.table_index;
   1844       state.lenbits = opts.bits;
   1845       // state.lencode = state.next;
   1846 
   1847       if (ret) {
   1848         strm.msg = 'invalid literal/lengths set';
   1849         state.mode = BAD;
   1850         break;
   1851       }
   1852 
   1853       state.distbits = 6;
   1854       //state.distcode.copy(state.codes);
   1855       // Switch to use dynamic table
   1856       state.distcode = state.distdyn;
   1857       opts = { bits: state.distbits };
   1858       ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts);
   1859       // We have separate tables & no pointers. 2 commented lines below not needed.
   1860       // state.next_index = opts.table_index;
   1861       state.distbits = opts.bits;
   1862       // state.distcode = state.next;
   1863 
   1864       if (ret) {
   1865         strm.msg = 'invalid distances set';
   1866         state.mode = BAD;
   1867         break;
   1868       }
   1869       //Tracev((stderr, 'inflate:       codes ok\n'));
   1870       state.mode = LEN_;
   1871       if (flush === Z_TREES) { break inf_leave; }
   1872       /* falls through */
   1873     case LEN_:
   1874       state.mode = LEN;
   1875       /* falls through */
   1876     case LEN:
   1877       if (have >= 6 && left >= 258) {
   1878         //--- RESTORE() ---
   1879         strm.next_out = put;
   1880         strm.avail_out = left;
   1881         strm.next_in = next;
   1882         strm.avail_in = have;
   1883         state.hold = hold;
   1884         state.bits = bits;
   1885         //---
   1886         inflate_fast(strm, _out);
   1887         //--- LOAD() ---
   1888         put = strm.next_out;
   1889         output = strm.output;
   1890         left = strm.avail_out;
   1891         next = strm.next_in;
   1892         input = strm.input;
   1893         have = strm.avail_in;
   1894         hold = state.hold;
   1895         bits = state.bits;
   1896         //---
   1897 
   1898         if (state.mode === TYPE) {
   1899           state.back = -1;
   1900         }
   1901         break;
   1902       }
   1903       state.back = 0;
   1904       for (;;) {
   1905         here = state.lencode[hold & ((1 << state.lenbits) - 1)];  /*BITS(state.lenbits)*/
   1906         here_bits = here >>> 24;
   1907         here_op = (here >>> 16) & 0xff;
   1908         here_val = here & 0xffff;
   1909 
   1910         if (here_bits <= bits) { break; }
   1911         //--- PULLBYTE() ---//
   1912         if (have === 0) { break inf_leave; }
   1913         have--;
   1914         hold += input[next++] << bits;
   1915         bits += 8;
   1916         //---//
   1917       }
   1918       if (here_op && (here_op & 0xf0) === 0) {
   1919         last_bits = here_bits;
   1920         last_op = here_op;
   1921         last_val = here_val;
   1922         for (;;) {
   1923           here = state.lencode[last_val +
   1924                   ((hold & ((1 << (last_bits + last_op)) - 1))/*BITS(last.bits + last.op)*/ >> last_bits)];
   1925           here_bits = here >>> 24;
   1926           here_op = (here >>> 16) & 0xff;
   1927           here_val = here & 0xffff;
   1928 
   1929           if ((last_bits + here_bits) <= bits) { break; }
   1930           //--- PULLBYTE() ---//
   1931           if (have === 0) { break inf_leave; }
   1932           have--;
   1933           hold += input[next++] << bits;
   1934           bits += 8;
   1935           //---//
   1936         }
   1937         //--- DROPBITS(last.bits) ---//
   1938         hold >>>= last_bits;
   1939         bits -= last_bits;
   1940         //---//
   1941         state.back += last_bits;
   1942       }
   1943       //--- DROPBITS(here.bits) ---//
   1944       hold >>>= here_bits;
   1945       bits -= here_bits;
   1946       //---//
   1947       state.back += here_bits;
   1948       state.length = here_val;
   1949       if (here_op === 0) {
   1950         //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
   1951         //        "inflate:         literal '%c'\n" :
   1952         //        "inflate:         literal 0x%02x\n", here.val));
   1953         state.mode = LIT;
   1954         break;
   1955       }
   1956       if (here_op & 32) {
   1957         //Tracevv((stderr, "inflate:         end of block\n"));
   1958         state.back = -1;
   1959         state.mode = TYPE;
   1960         break;
   1961       }
   1962       if (here_op & 64) {
   1963         strm.msg = 'invalid literal/length code';
   1964         state.mode = BAD;
   1965         break;
   1966       }
   1967       state.extra = here_op & 15;
   1968       state.mode = LENEXT;
   1969       /* falls through */
   1970     case LENEXT:
   1971       if (state.extra) {
   1972         //=== NEEDBITS(state.extra);
   1973         n = state.extra;
   1974         while (bits < n) {
   1975           if (have === 0) { break inf_leave; }
   1976           have--;
   1977           hold += input[next++] << bits;
   1978           bits += 8;
   1979         }
   1980         //===//
   1981         state.length += hold & ((1 << state.extra) - 1)/*BITS(state.extra)*/;
   1982         //--- DROPBITS(state.extra) ---//
   1983         hold >>>= state.extra;
   1984         bits -= state.extra;
   1985         //---//
   1986         state.back += state.extra;
   1987       }
   1988       //Tracevv((stderr, "inflate:         length %u\n", state.length));
   1989       state.was = state.length;
   1990       state.mode = DIST;
   1991       /* falls through */
   1992     case DIST:
   1993       for (;;) {
   1994         here = state.distcode[hold & ((1 << state.distbits) - 1)];/*BITS(state.distbits)*/
   1995         here_bits = here >>> 24;
   1996         here_op = (here >>> 16) & 0xff;
   1997         here_val = here & 0xffff;
   1998 
   1999         if ((here_bits) <= bits) { break; }
   2000         //--- PULLBYTE() ---//
   2001         if (have === 0) { break inf_leave; }
   2002         have--;
   2003         hold += input[next++] << bits;
   2004         bits += 8;
   2005         //---//
   2006       }
   2007       if ((here_op & 0xf0) === 0) {
   2008         last_bits = here_bits;
   2009         last_op = here_op;
   2010         last_val = here_val;
   2011         for (;;) {
   2012           here = state.distcode[last_val +
   2013                   ((hold & ((1 << (last_bits + last_op)) - 1))/*BITS(last.bits + last.op)*/ >> last_bits)];
   2014           here_bits = here >>> 24;
   2015           here_op = (here >>> 16) & 0xff;
   2016           here_val = here & 0xffff;
   2017 
   2018           if ((last_bits + here_bits) <= bits) { break; }
   2019           //--- PULLBYTE() ---//
   2020           if (have === 0) { break inf_leave; }
   2021           have--;
   2022           hold += input[next++] << bits;
   2023           bits += 8;
   2024           //---//
   2025         }
   2026         //--- DROPBITS(last.bits) ---//
   2027         hold >>>= last_bits;
   2028         bits -= last_bits;
   2029         //---//
   2030         state.back += last_bits;
   2031       }
   2032       //--- DROPBITS(here.bits) ---//
   2033       hold >>>= here_bits;
   2034       bits -= here_bits;
   2035       //---//
   2036       state.back += here_bits;
   2037       if (here_op & 64) {
   2038         strm.msg = 'invalid distance code';
   2039         state.mode = BAD;
   2040         break;
   2041       }
   2042       state.offset = here_val;
   2043       state.extra = (here_op) & 15;
   2044       state.mode = DISTEXT;
   2045       /* falls through */
   2046     case DISTEXT:
   2047       if (state.extra) {
   2048         //=== NEEDBITS(state.extra);
   2049         n = state.extra;
   2050         while (bits < n) {
   2051           if (have === 0) { break inf_leave; }
   2052           have--;
   2053           hold += input[next++] << bits;
   2054           bits += 8;
   2055         }
   2056         //===//
   2057         state.offset += hold & ((1 << state.extra) - 1)/*BITS(state.extra)*/;
   2058         //--- DROPBITS(state.extra) ---//
   2059         hold >>>= state.extra;
   2060         bits -= state.extra;
   2061         //---//
   2062         state.back += state.extra;
   2063       }
   2064 //#ifdef INFLATE_STRICT
   2065       if (state.offset > state.dmax) {
   2066         strm.msg = 'invalid distance too far back';
   2067         state.mode = BAD;
   2068         break;
   2069       }
   2070 //#endif
   2071       //Tracevv((stderr, "inflate:         distance %u\n", state.offset));
   2072       state.mode = MATCH;
   2073       /* falls through */
   2074     case MATCH:
   2075       if (left === 0) { break inf_leave; }
   2076       copy = _out - left;
   2077       if (state.offset > copy) {         /* copy from window */
   2078         copy = state.offset - copy;
   2079         if (copy > state.whave) {
   2080           if (state.sane) {
   2081             strm.msg = 'invalid distance too far back';
   2082             state.mode = BAD;
   2083             break;
   2084           }
   2085 // (!) This block is disabled in zlib defailts,
   2086 // don't enable it for binary compatibility
   2087 //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
   2088 //          Trace((stderr, "inflate.c too far\n"));
   2089 //          copy -= state.whave;
   2090 //          if (copy > state.length) { copy = state.length; }
   2091 //          if (copy > left) { copy = left; }
   2092 //          left -= copy;
   2093 //          state.length -= copy;
   2094 //          do {
   2095 //            output[put++] = 0;
   2096 //          } while (--copy);
   2097 //          if (state.length === 0) { state.mode = LEN; }
   2098 //          break;
   2099 //#endif
   2100         }
   2101         if (copy > state.wnext) {
   2102           copy -= state.wnext;
   2103           from = state.wsize - copy;
   2104         }
   2105         else {
   2106           from = state.wnext - copy;
   2107         }
   2108         if (copy > state.length) { copy = state.length; }
   2109         from_source = state.window;
   2110       }
   2111       else {                              /* copy from output */
   2112         from_source = output;
   2113         from = put - state.offset;
   2114         copy = state.length;
   2115       }
   2116       if (copy > left) { copy = left; }
   2117       left -= copy;
   2118       state.length -= copy;
   2119       do {
   2120         output[put++] = from_source[from++];
   2121       } while (--copy);
   2122       if (state.length === 0) { state.mode = LEN; }
   2123       break;
   2124     case LIT:
   2125       if (left === 0) { break inf_leave; }
   2126       output[put++] = state.length;
   2127       left--;
   2128       state.mode = LEN;
   2129       break;
   2130     case CHECK:
   2131       if (state.wrap) {
   2132         //=== NEEDBITS(32);
   2133         while (bits < 32) {
   2134           if (have === 0) { break inf_leave; }
   2135           have--;
   2136           // Use '|' insdead of '+' to make sure that result is signed
   2137           hold |= input[next++] << bits;
   2138           bits += 8;
   2139         }
   2140         //===//
   2141         _out -= left;
   2142         strm.total_out += _out;
   2143         state.total += _out;
   2144         if (_out) {
   2145           strm.adler = state.check =
   2146               /*UPDATE(state.check, put - _out, _out);*/
   2147               (state.flags ? crc32(state.check, output, _out, put - _out) : adler32(state.check, output, _out, put - _out));
   2148 
   2149         }
   2150         _out = left;
   2151         // NB: crc32 stored as signed 32-bit int, zswap32 returns signed too
   2152         if ((state.flags ? hold : zswap32(hold)) !== state.check) {
   2153           strm.msg = 'incorrect data check';
   2154           state.mode = BAD;
   2155           break;
   2156         }
   2157         //=== INITBITS();
   2158         hold = 0;
   2159         bits = 0;
   2160         //===//
   2161         //Tracev((stderr, "inflate:   check matches trailer\n"));
   2162       }
   2163       state.mode = LENGTH;
   2164       /* falls through */
   2165     case LENGTH:
   2166       if (state.wrap && state.flags) {
   2167         //=== NEEDBITS(32);
   2168         while (bits < 32) {
   2169           if (have === 0) { break inf_leave; }
   2170           have--;
   2171           hold += input[next++] << bits;
   2172           bits += 8;
   2173         }
   2174         //===//
   2175         if (hold !== (state.total & 0xffffffff)) {
   2176           strm.msg = 'incorrect length check';
   2177           state.mode = BAD;
   2178           break;
   2179         }
   2180         //=== INITBITS();
   2181         hold = 0;
   2182         bits = 0;
   2183         //===//
   2184         //Tracev((stderr, "inflate:   length matches trailer\n"));
   2185       }
   2186       state.mode = DONE;
   2187       /* falls through */
   2188     case DONE:
   2189       ret = Z_STREAM_END;
   2190       break inf_leave;
   2191     case BAD:
   2192       ret = Z_DATA_ERROR;
   2193       break inf_leave;
   2194     case MEM:
   2195       return Z_MEM_ERROR;
   2196     case SYNC:
   2197       /* falls through */
   2198     default:
   2199       return Z_STREAM_ERROR;
   2200     }
   2201   }
   2202 
   2203   // inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave"
   2204 
   2205   /*
   2206      Return from inflate(), updating the total counts and the check value.
   2207      If there was no progress during the inflate() call, return a buffer
   2208      error.  Call updatewindow() to create and/or update the window state.
   2209      Note: a memory error from inflate() is non-recoverable.
   2210    */
   2211 
   2212   //--- RESTORE() ---
   2213   strm.next_out = put;
   2214   strm.avail_out = left;
   2215   strm.next_in = next;
   2216   strm.avail_in = have;
   2217   state.hold = hold;
   2218   state.bits = bits;
   2219   //---
   2220 
   2221   if (state.wsize || (_out !== strm.avail_out && state.mode < BAD &&
   2222                       (state.mode < CHECK || flush !== Z_FINISH))) {
   2223     if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) {
   2224       state.mode = MEM;
   2225       return Z_MEM_ERROR;
   2226     }
   2227   }
   2228   _in -= strm.avail_in;
   2229   _out -= strm.avail_out;
   2230   strm.total_in += _in;
   2231   strm.total_out += _out;
   2232   state.total += _out;
   2233   if (state.wrap && _out) {
   2234     strm.adler = state.check = /*UPDATE(state.check, strm.next_out - _out, _out);*/
   2235       (state.flags ? crc32(state.check, output, _out, strm.next_out - _out) : adler32(state.check, output, _out, strm.next_out - _out));
   2236   }
   2237   strm.data_type = state.bits + (state.last ? 64 : 0) +
   2238                     (state.mode === TYPE ? 128 : 0) +
   2239                     (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);
   2240   if (((_in === 0 && _out === 0) || flush === Z_FINISH) && ret === Z_OK) {
   2241     ret = Z_BUF_ERROR;
   2242   }
   2243   return ret;
   2244 }
   2245 
   2246 function inflateEnd(strm) {
   2247 
   2248   if (!strm || !strm.state /*|| strm->zfree == (free_func)0*/) {
   2249     return Z_STREAM_ERROR;
   2250   }
   2251 
   2252   var state = strm.state;
   2253   if (state.window) {
   2254     state.window = null;
   2255   }
   2256   strm.state = null;
   2257   return Z_OK;
   2258 }
   2259 
   2260 function inflateGetHeader(strm, head) {
   2261   var state;
   2262 
   2263   /* check state */
   2264   if (!strm || !strm.state) { return Z_STREAM_ERROR; }
   2265   state = strm.state;
   2266   if ((state.wrap & 2) === 0) { return Z_STREAM_ERROR; }
   2267 
   2268   /* save header structure */
   2269   state.head = head;
   2270   head.done = false;
   2271   return Z_OK;
   2272 }
   2273 
   2274 
   2275 exports.inflateReset = inflateReset;
   2276 exports.inflateReset2 = inflateReset2;
   2277 exports.inflateResetKeep = inflateResetKeep;
   2278 exports.inflateInit = inflateInit;
   2279 exports.inflateInit2 = inflateInit2;
   2280 exports.inflate = inflate;
   2281 exports.inflateEnd = inflateEnd;
   2282 exports.inflateGetHeader = inflateGetHeader;
   2283 exports.inflateInfo = 'pako inflate (from Nodeca project)';
   2284 
   2285 /* Not implemented
   2286 exports.inflateCopy = inflateCopy;
   2287 exports.inflateGetDictionary = inflateGetDictionary;
   2288 exports.inflateMark = inflateMark;
   2289 exports.inflatePrime = inflatePrime;
   2290 exports.inflateSetDictionary = inflateSetDictionary;
   2291 exports.inflateSync = inflateSync;
   2292 exports.inflateSyncPoint = inflateSyncPoint;
   2293 exports.inflateUndermine = inflateUndermine;
   2294 */
   2295 
   2296 },{"../utils/common":1,"./adler32":3,"./crc32":5,"./inffast":7,"./inftrees":9}],9:[function(require,module,exports){
   2297 'use strict';
   2298 
   2299 
   2300 var utils = require('../utils/common');
   2301 
   2302 var MAXBITS = 15;
   2303 var ENOUGH_LENS = 852;
   2304 var ENOUGH_DISTS = 592;
   2305 //var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
   2306 
   2307 var CODES = 0;
   2308 var LENS = 1;
   2309 var DISTS = 2;
   2310 
   2311 var lbase = [ /* Length codes 257..285 base */
   2312   3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
   2313   35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
   2314 ];
   2315 
   2316 var lext = [ /* Length codes 257..285 extra */
   2317   16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
   2318   19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78
   2319 ];
   2320 
   2321 var dbase = [ /* Distance codes 0..29 base */
   2322   1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
   2323   257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
   2324   8193, 12289, 16385, 24577, 0, 0
   2325 ];
   2326 
   2327 var dext = [ /* Distance codes 0..29 extra */
   2328   16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
   2329   23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
   2330   28, 28, 29, 29, 64, 64
   2331 ];
   2332 
   2333 module.exports = function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts)
   2334 {
   2335   var bits = opts.bits;
   2336       //here = opts.here; /* table entry for duplication */
   2337 
   2338   var len = 0;               /* a code's length in bits */
   2339   var sym = 0;               /* index of code symbols */
   2340   var min = 0, max = 0;          /* minimum and maximum code lengths */
   2341   var root = 0;              /* number of index bits for root table */
   2342   var curr = 0;              /* number of index bits for current table */
   2343   var drop = 0;              /* code bits to drop for sub-table */
   2344   var left = 0;                   /* number of prefix codes available */
   2345   var used = 0;              /* code entries in table used */
   2346   var huff = 0;              /* Huffman code */
   2347   var incr;              /* for incrementing code, index */
   2348   var fill;              /* index for replicating entries */
   2349   var low;               /* low bits for current root entry */
   2350   var mask;              /* mask for low root bits */
   2351   var next;             /* next available space in table */
   2352   var base = null;     /* base value table to use */
   2353   var base_index = 0;
   2354 //  var shoextra;    /* extra bits table to use */
   2355   var end;                    /* use base and extra for symbol > end */
   2356   var count = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1];    /* number of codes of each length */
   2357   var offs = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1];     /* offsets in table for each length */
   2358   var extra = null;
   2359   var extra_index = 0;
   2360 
   2361   var here_bits, here_op, here_val;
   2362 
   2363   /*
   2364    Process a set of code lengths to create a canonical Huffman code.  The
   2365    code lengths are lens[0..codes-1].  Each length corresponds to the
   2366    symbols 0..codes-1.  The Huffman code is generated by first sorting the
   2367    symbols by length from short to long, and retaining the symbol order
   2368    for codes with equal lengths.  Then the code starts with all zero bits
   2369    for the first code of the shortest length, and the codes are integer
   2370    increments for the same length, and zeros are appended as the length
   2371    increases.  For the deflate format, these bits are stored backwards
   2372    from their more natural integer increment ordering, and so when the
   2373    decoding tables are built in the large loop below, the integer codes
   2374    are incremented backwards.
   2375 
   2376    This routine assumes, but does not check, that all of the entries in
   2377    lens[] are in the range 0..MAXBITS.  The caller must assure this.
   2378    1..MAXBITS is interpreted as that code length.  zero means that that
   2379    symbol does not occur in this code.
   2380 
   2381    The codes are sorted by computing a count of codes for each length,
   2382    creating from that a table of starting indices for each length in the
   2383    sorted table, and then entering the symbols in order in the sorted
   2384    table.  The sorted table is work[], with that space being provided by
   2385    the caller.
   2386 
   2387    The length counts are used for other purposes as well, i.e. finding
   2388    the minimum and maximum length codes, determining if there are any
   2389    codes at all, checking for a valid set of lengths, and looking ahead
   2390    at length counts to determine sub-table sizes when building the
   2391    decoding tables.
   2392    */
   2393 
   2394   /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
   2395   for (len = 0; len <= MAXBITS; len++) {
   2396     count[len] = 0;
   2397   }
   2398   for (sym = 0; sym < codes; sym++) {
   2399     count[lens[lens_index + sym]]++;
   2400   }
   2401 
   2402   /* bound code lengths, force root to be within code lengths */
   2403   root = bits;
   2404   for (max = MAXBITS; max >= 1; max--) {
   2405     if (count[max] !== 0) { break; }
   2406   }
   2407   if (root > max) {
   2408     root = max;
   2409   }
   2410   if (max === 0) {                     /* no symbols to code at all */
   2411     //table.op[opts.table_index] = 64;  //here.op = (var char)64;    /* invalid code marker */
   2412     //table.bits[opts.table_index] = 1;   //here.bits = (var char)1;
   2413     //table.val[opts.table_index++] = 0;   //here.val = (var short)0;
   2414     table[table_index++] = (1 << 24) | (64 << 16) | 0;
   2415 
   2416 
   2417     //table.op[opts.table_index] = 64;
   2418     //table.bits[opts.table_index] = 1;
   2419     //table.val[opts.table_index++] = 0;
   2420     table[table_index++] = (1 << 24) | (64 << 16) | 0;
   2421 
   2422     opts.bits = 1;
   2423     return 0;     /* no symbols, but wait for decoding to report error */
   2424   }
   2425   for (min = 1; min < max; min++) {
   2426     if (count[min] !== 0) { break; }
   2427   }
   2428   if (root < min) {
   2429     root = min;
   2430   }
   2431 
   2432   /* check for an over-subscribed or incomplete set of lengths */
   2433   left = 1;
   2434   for (len = 1; len <= MAXBITS; len++) {
   2435     left <<= 1;
   2436     left -= count[len];
   2437     if (left < 0) {
   2438       return -1;
   2439     }        /* over-subscribed */
   2440   }
   2441   if (left > 0 && (type === CODES || max !== 1)) {
   2442     return -1;                      /* incomplete set */
   2443   }
   2444 
   2445   /* generate offsets into symbol table for each length for sorting */
   2446   offs[1] = 0;
   2447   for (len = 1; len < MAXBITS; len++) {
   2448     offs[len + 1] = offs[len] + count[len];
   2449   }
   2450 
   2451   /* sort symbols by length, by symbol order within each length */
   2452   for (sym = 0; sym < codes; sym++) {
   2453     if (lens[lens_index + sym] !== 0) {
   2454       work[offs[lens[lens_index + sym]]++] = sym;
   2455     }
   2456   }
   2457 
   2458   /*
   2459    Create and fill in decoding tables.  In this loop, the table being
   2460    filled is at next and has curr index bits.  The code being used is huff
   2461    with length len.  That code is converted to an index by dropping drop
   2462    bits off of the bottom.  For codes where len is less than drop + curr,
   2463    those top drop + curr - len bits are incremented through all values to
   2464    fill the table with replicated entries.
   2465 
   2466    root is the number of index bits for the root table.  When len exceeds
   2467    root, sub-tables are created pointed to by the root entry with an index
   2468    of the low root bits of huff.  This is saved in low to check for when a
   2469    new sub-table should be started.  drop is zero when the root table is
   2470    being filled, and drop is root when sub-tables are being filled.
   2471 
   2472    When a new sub-table is needed, it is necessary to look ahead in the
   2473    code lengths to determine what size sub-table is needed.  The length
   2474    counts are used for this, and so count[] is decremented as codes are
   2475    entered in the tables.
   2476 
   2477    used keeps track of how many table entries have been allocated from the
   2478    provided *table space.  It is checked for LENS and DIST tables against
   2479    the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
   2480    the initial root table size constants.  See the comments in inftrees.h
   2481    for more information.
   2482 
   2483    sym increments through all symbols, and the loop terminates when
   2484    all codes of length max, i.e. all codes, have been processed.  This
   2485    routine permits incomplete codes, so another loop after this one fills
   2486    in the rest of the decoding tables with invalid code markers.
   2487    */
   2488 
   2489   /* set up for code type */
   2490   // poor man optimization - use if-else instead of switch,
   2491   // to avoid deopts in old v8
   2492   if (type === CODES) {
   2493     base = extra = work;    /* dummy value--not used */
   2494     end = 19;
   2495 
   2496   } else if (type === LENS) {
   2497     base = lbase;
   2498     base_index -= 257;
   2499     extra = lext;
   2500     extra_index -= 257;
   2501     end = 256;
   2502 
   2503   } else {                    /* DISTS */
   2504     base = dbase;
   2505     extra = dext;
   2506     end = -1;
   2507   }
   2508 
   2509   /* initialize opts for loop */
   2510   huff = 0;                   /* starting code */
   2511   sym = 0;                    /* starting code symbol */
   2512   len = min;                  /* starting code length */
   2513   next = table_index;              /* current table to fill in */
   2514   curr = root;                /* current table index bits */
   2515   drop = 0;                   /* current bits to drop from code for index */
   2516   low = -1;                   /* trigger new sub-table when len > root */
   2517   used = 1 << root;          /* use root table entries */
   2518   mask = used - 1;            /* mask for comparing low */
   2519 
   2520   /* check available table space */
   2521   if ((type === LENS && used > ENOUGH_LENS) ||
   2522     (type === DISTS && used > ENOUGH_DISTS)) {
   2523     return 1;
   2524   }
   2525 
   2526   var i = 0;
   2527   /* process all codes and make table entries */
   2528   for (;;) {
   2529     i++;
   2530     /* create table entry */
   2531     here_bits = len - drop;
   2532     if (work[sym] < end) {
   2533       here_op = 0;
   2534       here_val = work[sym];
   2535     }
   2536     else if (work[sym] > end) {
   2537       here_op = extra[extra_index + work[sym]];
   2538       here_val = base[base_index + work[sym]];
   2539     }
   2540     else {
   2541       here_op = 32 + 64;         /* end of block */
   2542       here_val = 0;
   2543     }
   2544 
   2545     /* replicate for those indices with low len bits equal to huff */
   2546     incr = 1 << (len - drop);
   2547     fill = 1 << curr;
   2548     min = fill;                 /* save offset to next table */
   2549     do {
   2550       fill -= incr;
   2551       table[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val |0;
   2552     } while (fill !== 0);
   2553 
   2554     /* backwards increment the len-bit code huff */
   2555     incr = 1 << (len - 1);
   2556     while (huff & incr) {
   2557       incr >>= 1;
   2558     }
   2559     if (incr !== 0) {
   2560       huff &= incr - 1;
   2561       huff += incr;
   2562     } else {
   2563       huff = 0;
   2564     }
   2565 
   2566     /* go to next symbol, update count, len */
   2567     sym++;
   2568     if (--count[len] === 0) {
   2569       if (len === max) { break; }
   2570       len = lens[lens_index + work[sym]];
   2571     }
   2572 
   2573     /* create new sub-table if needed */
   2574     if (len > root && (huff & mask) !== low) {
   2575       /* if first time, transition to sub-tables */
   2576       if (drop === 0) {
   2577         drop = root;
   2578       }
   2579 
   2580       /* increment past last table */
   2581       next += min;            /* here min is 1 << curr */
   2582 
   2583       /* determine length of next table */
   2584       curr = len - drop;
   2585       left = 1 << curr;
   2586       while (curr + drop < max) {
   2587         left -= count[curr + drop];
   2588         if (left <= 0) { break; }
   2589         curr++;
   2590         left <<= 1;
   2591       }
   2592 
   2593       /* check for enough space */
   2594       used += 1 << curr;
   2595       if ((type === LENS && used > ENOUGH_LENS) ||
   2596         (type === DISTS && used > ENOUGH_DISTS)) {
   2597         return 1;
   2598       }
   2599 
   2600       /* point entry in root table to sub-table */
   2601       low = huff & mask;
   2602       /*table.op[low] = curr;
   2603       table.bits[low] = root;
   2604       table.val[low] = next - opts.table_index;*/
   2605       table[low] = (root << 24) | (curr << 16) | (next - table_index) |0;
   2606     }
   2607   }
   2608 
   2609   /* fill in remaining table entry if code is incomplete (guaranteed to have
   2610    at most one remaining entry, since if the code is incomplete, the
   2611    maximum code length that was allowed to get this far is one bit) */
   2612   if (huff !== 0) {
   2613     //table.op[next + huff] = 64;            /* invalid code marker */
   2614     //table.bits[next + huff] = len - drop;
   2615     //table.val[next + huff] = 0;
   2616     table[next + huff] = ((len - drop) << 24) | (64 << 16) |0;
   2617   }
   2618 
   2619   /* set return parameters */
   2620   //opts.table_index += used;
   2621   opts.bits = root;
   2622   return 0;
   2623 };
   2624 
   2625 },{"../utils/common":1}],10:[function(require,module,exports){
   2626 'use strict';
   2627 
   2628 module.exports = {
   2629   2:      'need dictionary',     /* Z_NEED_DICT       2  */
   2630   1:      'stream end',          /* Z_STREAM_END      1  */
   2631   0:      '',                    /* Z_OK              0  */
   2632   '-1':   'file error',          /* Z_ERRNO         (-1) */
   2633   '-2':   'stream error',        /* Z_STREAM_ERROR  (-2) */
   2634   '-3':   'data error',          /* Z_DATA_ERROR    (-3) */
   2635   '-4':   'insufficient memory', /* Z_MEM_ERROR     (-4) */
   2636   '-5':   'buffer error',        /* Z_BUF_ERROR     (-5) */
   2637   '-6':   'incompatible version' /* Z_VERSION_ERROR (-6) */
   2638 };
   2639 
   2640 },{}],11:[function(require,module,exports){
   2641 'use strict';
   2642 
   2643 
   2644 function ZStream() {
   2645   /* next input byte */
   2646   this.input = null; // JS specific, because we have no pointers
   2647   this.next_in = 0;
   2648   /* number of bytes available at input */
   2649   this.avail_in = 0;
   2650   /* total number of input bytes read so far */
   2651   this.total_in = 0;
   2652   /* next output byte should be put there */
   2653   this.output = null; // JS specific, because we have no pointers
   2654   this.next_out = 0;
   2655   /* remaining free space at output */
   2656   this.avail_out = 0;
   2657   /* total number of bytes output so far */
   2658   this.total_out = 0;
   2659   /* last error message, NULL if no error */
   2660   this.msg = ''/*Z_NULL*/;
   2661   /* not visible by applications */
   2662   this.state = null;
   2663   /* best guess about the data type: binary or text */
   2664   this.data_type = 2/*Z_UNKNOWN*/;
   2665   /* adler32 value of the uncompressed data */
   2666   this.adler = 0;
   2667 }
   2668 
   2669 module.exports = ZStream;
   2670 
   2671 },{}],"/lib/inflate.js":[function(require,module,exports){
   2672 'use strict';
   2673 
   2674 
   2675 var zlib_inflate = require('./zlib/inflate');
   2676 var utils        = require('./utils/common');
   2677 var strings      = require('./utils/strings');
   2678 var c            = require('./zlib/constants');
   2679 var msg          = require('./zlib/messages');
   2680 var ZStream      = require('./zlib/zstream');
   2681 var GZheader     = require('./zlib/gzheader');
   2682 
   2683 var toString = Object.prototype.toString;
   2684 
   2685 /**
   2686  * class Inflate
   2687  *
   2688  * Generic JS-style wrapper for zlib calls. If you don't need
   2689  * streaming behaviour - use more simple functions: [[inflate]]
   2690  * and [[inflateRaw]].
   2691  **/
   2692 
   2693 /* internal
   2694  * inflate.chunks -> Array
   2695  *
   2696  * Chunks of output data, if [[Inflate#onData]] not overriden.
   2697  **/
   2698 
   2699 /**
   2700  * Inflate.result -> Uint8Array|Array|String
   2701  *
   2702  * Uncompressed result, generated by default [[Inflate#onData]]
   2703  * and [[Inflate#onEnd]] handlers. Filled after you push last chunk
   2704  * (call [[Inflate#push]] with `Z_FINISH` / `true` param) or if you
   2705  * push a chunk with explicit flush (call [[Inflate#push]] with
   2706  * `Z_SYNC_FLUSH` param).
   2707  **/
   2708 
   2709 /**
   2710  * Inflate.err -> Number
   2711  *
   2712  * Error code after inflate finished. 0 (Z_OK) on success.
   2713  * Should be checked if broken data possible.
   2714  **/
   2715 
   2716 /**
   2717  * Inflate.msg -> String
   2718  *
   2719  * Error message, if [[Inflate.err]] != 0
   2720  **/
   2721 
   2722 
   2723 /**
   2724  * new Inflate(options)
   2725  * - options (Object): zlib inflate options.
   2726  *
   2727  * Creates new inflator instance with specified params. Throws exception
   2728  * on bad params. Supported options:
   2729  *
   2730  * - `windowBits`
   2731  *
   2732  * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
   2733  * for more information on these.
   2734  *
   2735  * Additional options, for internal needs:
   2736  *
   2737  * - `chunkSize` - size of generated data chunks (16K by default)
   2738  * - `raw` (Boolean) - do raw inflate
   2739  * - `to` (String) - if equal to 'string', then result will be converted
   2740  *   from utf8 to utf16 (javascript) string. When string output requested,
   2741  *   chunk length can differ from `chunkSize`, depending on content.
   2742  *
   2743  * By default, when no options set, autodetect deflate/gzip data format via
   2744  * wrapper header.
   2745  *
   2746  * ##### Example:
   2747  *
   2748  * ```javascript
   2749  * var pako = require('pako')
   2750  *   , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
   2751  *   , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
   2752  *
   2753  * var inflate = new pako.Inflate({ level: 3});
   2754  *
   2755  * inflate.push(chunk1, false);
   2756  * inflate.push(chunk2, true);  // true -> last chunk
   2757  *
   2758  * if (inflate.err) { throw new Error(inflate.err); }
   2759  *
   2760  * console.log(inflate.result);
   2761  * ```
   2762  **/
   2763 function Inflate(options) {
   2764   if (!(this instanceof Inflate)) return new Inflate(options);
   2765 
   2766   this.options = utils.assign({
   2767     chunkSize: 16384,
   2768     windowBits: 0,
   2769     to: ''
   2770   }, options || {});
   2771 
   2772   var opt = this.options;
   2773 
   2774   // Force window size for `raw` data, if not set directly,
   2775   // because we have no header for autodetect.
   2776   if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {
   2777     opt.windowBits = -opt.windowBits;
   2778     if (opt.windowBits === 0) { opt.windowBits = -15; }
   2779   }
   2780 
   2781   // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
   2782   if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&
   2783       !(options && options.windowBits)) {
   2784     opt.windowBits += 32;
   2785   }
   2786 
   2787   // Gzip header has no info about windows size, we can do autodetect only
   2788   // for deflate. So, if window size not set, force it to max when gzip possible
   2789   if ((opt.windowBits > 15) && (opt.windowBits < 48)) {
   2790     // bit 3 (16) -> gzipped data
   2791     // bit 4 (32) -> autodetect gzip/deflate
   2792     if ((opt.windowBits & 15) === 0) {
   2793       opt.windowBits |= 15;
   2794     }
   2795   }
   2796 
   2797   this.err    = 0;      // error code, if happens (0 = Z_OK)
   2798   this.msg    = '';     // error message
   2799   this.ended  = false;  // used to avoid multiple onEnd() calls
   2800   this.chunks = [];     // chunks of compressed data
   2801 
   2802   this.strm   = new ZStream();
   2803   this.strm.avail_out = 0;
   2804 
   2805   var status  = zlib_inflate.inflateInit2(
   2806     this.strm,
   2807     opt.windowBits
   2808   );
   2809 
   2810   if (status !== c.Z_OK) {
   2811     throw new Error(msg[status]);
   2812   }
   2813 
   2814   this.header = new GZheader();
   2815 
   2816   zlib_inflate.inflateGetHeader(this.strm, this.header);
   2817 }
   2818 
   2819 /**
   2820  * Inflate#push(data[, mode]) -> Boolean
   2821  * - data (Uint8Array|Array|ArrayBuffer|String): input data
   2822  * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
   2823  *   See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.
   2824  *
   2825  * Sends input data to inflate pipe, generating [[Inflate#onData]] calls with
   2826  * new output chunks. Returns `true` on success. The last data block must have
   2827  * mode Z_FINISH (or `true`). That will flush internal pending buffers and call
   2828  * [[Inflate#onEnd]]. For interim explicit flushes (without ending the stream) you
   2829  * can use mode Z_SYNC_FLUSH, keeping the decompression context.
   2830  *
   2831  * On fail call [[Inflate#onEnd]] with error code and return false.
   2832  *
   2833  * We strongly recommend to use `Uint8Array` on input for best speed (output
   2834  * format is detected automatically). Also, don't skip last param and always
   2835  * use the same type in your code (boolean or number). That will improve JS speed.
   2836  *
   2837  * For regular `Array`-s make sure all elements are [0..255].
   2838  *
   2839  * ##### Example
   2840  *
   2841  * ```javascript
   2842  * push(chunk, false); // push one of data chunks
   2843  * ...
   2844  * push(chunk, true);  // push last chunk
   2845  * ```
   2846  **/
   2847 Inflate.prototype.push = function (data, mode) {
   2848   var strm = this.strm;
   2849   var chunkSize = this.options.chunkSize;
   2850   var status, _mode;
   2851   var next_out_utf8, tail, utf8str;
   2852 
   2853   // Flag to properly process Z_BUF_ERROR on testing inflate call
   2854   // when we check that all output data was flushed.
   2855   var allowBufError = false;
   2856 
   2857   if (this.ended) { return false; }
   2858   _mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH);
   2859 
   2860   // Convert data if needed
   2861   if (typeof data === 'string') {
   2862     // Only binary strings can be decompressed on practice
   2863     strm.input = strings.binstring2buf(data);
   2864   } else if (toString.call(data) === '[object ArrayBuffer]') {
   2865     strm.input = new Uint8Array(data);
   2866   } else {
   2867     strm.input = data;
   2868   }
   2869 
   2870   strm.next_in = 0;
   2871   strm.avail_in = strm.input.length;
   2872 
   2873   do {
   2874     if (strm.avail_out === 0) {
   2875       strm.output = new utils.Buf8(chunkSize);
   2876       strm.next_out = 0;
   2877       strm.avail_out = chunkSize;
   2878     }
   2879 
   2880     status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH);    /* no bad return value */
   2881 
   2882     if (status === c.Z_BUF_ERROR && allowBufError === true) {
   2883       status = c.Z_OK;
   2884       allowBufError = false;
   2885     }
   2886 
   2887     if (status !== c.Z_STREAM_END && status !== c.Z_OK) {
   2888       this.onEnd(status);
   2889       this.ended = true;
   2890       return false;
   2891     }
   2892 
   2893     if (strm.next_out) {
   2894       if (strm.avail_out === 0 || status === c.Z_STREAM_END || (strm.avail_in === 0 && (_mode === c.Z_FINISH || _mode === c.Z_SYNC_FLUSH))) {
   2895 
   2896         if (this.options.to === 'string') {
   2897 
   2898           next_out_utf8 = strings.utf8border(strm.output, strm.next_out);
   2899 
   2900           tail = strm.next_out - next_out_utf8;
   2901           utf8str = strings.buf2string(strm.output, next_out_utf8);
   2902 
   2903           // move tail
   2904           strm.next_out = tail;
   2905           strm.avail_out = chunkSize - tail;
   2906           if (tail) { utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0); }
   2907 
   2908           this.onData(utf8str);
   2909 
   2910         } else {
   2911           this.onData(utils.shrinkBuf(strm.output, strm.next_out));
   2912         }
   2913       }
   2914     }
   2915 
   2916     // When no more input data, we should check that internal inflate buffers
   2917     // are flushed. The only way to do it when avail_out = 0 - run one more
   2918     // inflate pass. But if output data not exists, inflate return Z_BUF_ERROR.
   2919     // Here we set flag to process this error properly.
   2920     //
   2921     // NOTE. Deflate does not return error in this case and does not needs such
   2922     // logic.
   2923     if (strm.avail_in === 0 && strm.avail_out === 0) {
   2924       allowBufError = true;
   2925     }
   2926 
   2927   } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== c.Z_STREAM_END);
   2928 
   2929   if (status === c.Z_STREAM_END) {
   2930     _mode = c.Z_FINISH;
   2931   }
   2932 
   2933   // Finalize on the last chunk.
   2934   if (_mode === c.Z_FINISH) {
   2935     status = zlib_inflate.inflateEnd(this.strm);
   2936     this.onEnd(status);
   2937     this.ended = true;
   2938     return status === c.Z_OK;
   2939   }
   2940 
   2941   // callback interim results if Z_SYNC_FLUSH.
   2942   if (_mode === c.Z_SYNC_FLUSH) {
   2943     this.onEnd(c.Z_OK);
   2944     strm.avail_out = 0;
   2945     return true;
   2946   }
   2947 
   2948   return true;
   2949 };
   2950 
   2951 
   2952 /**
   2953  * Inflate#onData(chunk) -> Void
   2954  * - chunk (Uint8Array|Array|String): ouput data. Type of array depends
   2955  *   on js engine support. When string output requested, each chunk
   2956  *   will be string.
   2957  *
   2958  * By default, stores data blocks in `chunks[]` property and glue
   2959  * those in `onEnd`. Override this handler, if you need another behaviour.
   2960  **/
   2961 Inflate.prototype.onData = function (chunk) {
   2962   this.chunks.push(chunk);
   2963 };
   2964 
   2965 
   2966 /**
   2967  * Inflate#onEnd(status) -> Void
   2968  * - status (Number): inflate status. 0 (Z_OK) on success,
   2969  *   other if not.
   2970  *
   2971  * Called either after you tell inflate that the input stream is
   2972  * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)
   2973  * or if an error happened. By default - join collected chunks,
   2974  * free memory and fill `results` / `err` properties.
   2975  **/
   2976 Inflate.prototype.onEnd = function (status) {
   2977   // On success - join
   2978   if (status === c.Z_OK) {
   2979     if (this.options.to === 'string') {
   2980       // Glue & convert here, until we teach pako to send
   2981       // utf8 alligned strings to onData
   2982       this.result = this.chunks.join('');
   2983     } else {
   2984       this.result = utils.flattenChunks(this.chunks);
   2985     }
   2986   }
   2987   this.chunks = [];
   2988   this.err = status;
   2989   this.msg = this.strm.msg;
   2990 };
   2991 
   2992 
   2993 /**
   2994  * inflate(data[, options]) -> Uint8Array|Array|String
   2995  * - data (Uint8Array|Array|String): input data to decompress.
   2996  * - options (Object): zlib inflate options.
   2997  *
   2998  * Decompress `data` with inflate/ungzip and `options`. Autodetect
   2999  * format via wrapper header by default. That's why we don't provide
   3000  * separate `ungzip` method.
   3001  *
   3002  * Supported options are:
   3003  *
   3004  * - windowBits
   3005  *
   3006  * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
   3007  * for more information.
   3008  *
   3009  * Sugar (options):
   3010  *
   3011  * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
   3012  *   negative windowBits implicitly.
   3013  * - `to` (String) - if equal to 'string', then result will be converted
   3014  *   from utf8 to utf16 (javascript) string. When string output requested,
   3015  *   chunk length can differ from `chunkSize`, depending on content.
   3016  *
   3017  *
   3018  * ##### Example:
   3019  *
   3020  * ```javascript
   3021  * var pako = require('pako')
   3022  *   , input = pako.deflate([1,2,3,4,5,6,7,8,9])
   3023  *   , output;
   3024  *
   3025  * try {
   3026  *   output = pako.inflate(input);
   3027  * } catch (err)
   3028  *   console.log(err);
   3029  * }
   3030  * ```
   3031  **/
   3032 function inflate(input, options) {
   3033   var inflator = new Inflate(options);
   3034 
   3035   inflator.push(input, true);
   3036 
   3037   // That will never happens, if you don't cheat with options :)
   3038   if (inflator.err) { throw inflator.msg; }
   3039 
   3040   return inflator.result;
   3041 }
   3042 
   3043 
   3044 /**
   3045  * inflateRaw(data[, options]) -> Uint8Array|Array|String
   3046  * - data (Uint8Array|Array|String): input data to decompress.
   3047  * - options (Object): zlib inflate options.
   3048  *
   3049  * The same as [[inflate]], but creates raw data, without wrapper
   3050  * (header and adler32 crc).
   3051  **/
   3052 function inflateRaw(input, options) {
   3053   options = options || {};
   3054   options.raw = true;
   3055   return inflate(input, options);
   3056 }
   3057 
   3058 
   3059 /**
   3060  * ungzip(data[, options]) -> Uint8Array|Array|String
   3061  * - data (Uint8Array|Array|String): input data to decompress.
   3062  * - options (Object): zlib inflate options.
   3063  *
   3064  * Just shortcut to [[inflate]], because it autodetects format
   3065  * by header.content. Done for convenience.
   3066  **/
   3067 
   3068 
   3069 exports.Inflate = Inflate;
   3070 exports.inflate = inflate;
   3071 exports.inflateRaw = inflateRaw;
   3072 exports.ungzip  = inflate;
   3073 
   3074 },{"./utils/common":1,"./utils/strings":2,"./zlib/constants":4,"./zlib/gzheader":6,"./zlib/inflate":8,"./zlib/messages":10,"./zlib/zstream":11}]},{},[])("/lib/inflate.js")
   3075 });