From 8ad663f623bd3dd0d3169f15ce0b4e0d4ad6d1a9 Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Fri, 14 Mar 2014 02:08:47 +0400 Subject: [PATCH] updated browserified files --- dist/pako.js | 2445 ++++++++++++++++++++++++++++++++++---- dist/pako.min.js | 3 +- dist/pako_deflate.js | 200 ++-- dist/pako_deflate.min.js | 2 +- dist/pako_inflate.js | 2437 +++++++++++++++++++++++++++++++++---- dist/pako_inflate.min.js | 2 +- 6 files changed, 4527 insertions(+), 562 deletions(-) diff --git a/dist/pako.js b/dist/pako.js index 882981b..fd03c10 100644 --- a/dist/pako.js +++ b/dist/pako.js @@ -13,7 +13,7 @@ var pako = {}; assign(pako, deflate, inflate, constants); module.exports = pako; -},{"./lib/deflate":2,"./lib/inflate":3,"./lib/zlib/constants":5,"./lib/zlib/utils":11}],2:[function(_dereq_,module,exports){ +},{"./lib/deflate":2,"./lib/inflate":3,"./lib/zlib/constants":5,"./lib/zlib/utils":13}],2:[function(_dereq_,module,exports){ 'use strict'; @@ -41,13 +41,6 @@ var Z_DEFLATED = 8; /* ===========================================================================*/ -// return sliced buffer, trying to avoid new objects creation and mem copy -function sliceBuf(buf, size) { - if (buf.length === size) { return buf; } - - return utils.typedOk() ? buf.subarray(0, size) : buf.slice(0, size); -} - /** * class Deflate * @@ -205,7 +198,7 @@ Deflate.prototype.push = function(data, mode) { strm.next_in = data; strm.next_in_index = 0; strm.avail_in = strm.next_in.length; - strm.next_out = utils.arrayCreate(chunkSize); + strm.next_out = new utils.Buf8(chunkSize); do { strm.avail_out = this.options.chunkSize; @@ -218,10 +211,10 @@ Deflate.prototype.push = function(data, mode) { return false; } if(strm.next_out_index) { - this.onData(sliceBuf(strm.next_out, strm.next_out_index)); + this.onData(utils.shrinkBuf(strm.next_out, strm.next_out_index)); // Allocate buffer for next chunk, if not last if (strm.avail_in > 0 || strm.avail_out === 0) { - strm.next_out = utils.arrayCreate(this.options.chunkSize); + strm.next_out = new utils.Buf8(this.options.chunkSize); } } } while (strm.avail_in > 0 || strm.avail_out === 0); @@ -267,7 +260,7 @@ Deflate.prototype.onEnd = function(status) { } this.chunks = []; this.err = status; - this.msg = msg[status]; + this.msg = this.strm.msg; }; @@ -303,7 +296,7 @@ function deflate(input, options) { deflator.push(input, true); // That will never happens, if you don't cheat with options :) - if (deflator.err) { throw msg[deflator.err]; } + if (deflator.err) { throw deflator.msg; } return deflator.result; } @@ -343,7 +336,7 @@ exports.Deflate = Deflate; exports.deflate = deflate; exports.deflateRaw = deflateRaw; exports.gzip = gzip; -},{"./zlib/deflate.js":7,"./zlib/messages":9,"./zlib/utils":11,"./zlib/zstream":12}],3:[function(_dereq_,module,exports){ +},{"./zlib/deflate.js":7,"./zlib/messages":11,"./zlib/utils":13,"./zlib/zstream":14}],3:[function(_dereq_,module,exports){ 'use strict'; @@ -353,12 +346,6 @@ var c = _dereq_('./zlib/constants'); var msg = _dereq_('./zlib/messages'); var zstream = _dereq_('./zlib/zstream'); -// return sliced buffer, trying to avoid new objects creation and mem copy -function sliceBuf(buf, size) { - if (buf.length === size) { return buf; } - - return utils.typedOk() ? buf.subarray(0, size) : buf.slice(0, size); -} /** * class Inflate @@ -413,6 +400,9 @@ function sliceBuf(buf, size) { * - `chunkSize` - size of generated data chunks (16K by default) * - `raw` (boolean) - do raw inflate * + * By default, when no options set, autodetect deflate/gzip data format via + * wrapper header. + * * ##### Example: * * ```javascript @@ -434,13 +424,32 @@ var Inflate = function(options) { this.options = utils.assign({ chunkSize: 16384, - windowBits: 15 + 32 // By default - autodetect deflate/gzip + windowBits: 0 }, options || {}); var opt = this.options; - if (opt.raw && (opt.windowBits > 0)) { + // Force window size for `raw` data, if not set directly, + // because we have no header for autodetect. + if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) { opt.windowBits = -opt.windowBits; + if (opt.windowBits === 0) { opt.windowBits = -15; } + } + + // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate + if ((opt.windowBits >= 0) && (opt.windowBits < 16) && + !(options && options.windowBits)) { + opt.windowBits += 32; + } + + // Gzip header has no info about windows size, we can do autodetect only + // for deflate. So, if window size not set, force it to max when gzip possible + if ((opt.windowBits > 15) && (opt.windowBits < 48)) { + // bit 3 (16) -> gzipped data + // bit 4 (32) -> autodetect gzip/deflate + if ((opt.windowBits & 15) === 0) { + opt.windowBits |= 15; + } } this.err = 0; // error code, if happens (0 = Z_OK) @@ -493,13 +502,12 @@ Inflate.prototype.push = function(data, mode) { var status, _mode; if (this.ended) { return false; } - - _mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH); + _mode = c.Z_NO_FLUSH; strm.next_in = data; strm.next_in_index = 0; strm.avail_in = strm.next_in.length; - strm.next_out = utils.arrayCreate(chunkSize); + strm.next_out = new utils.Buf8(chunkSize); do { strm.avail_out = this.options.chunkSize; @@ -512,14 +520,15 @@ Inflate.prototype.push = function(data, mode) { return false; } if(strm.next_out_index) { - this.onData(sliceBuf(strm.next_out, strm.next_out_index)); + this.onData(utils.shrinkBuf(strm.next_out, strm.next_out_index)); // Allocate buffer for next chunk, if not last if (strm.avail_in > 0 || strm.avail_out === 0) { - strm.next_out = utils.arrayCreate(this.options.chunkSize); + strm.next_out = new utils.Buf8(this.options.chunkSize); } } } while (strm.avail_in > 0 || strm.avail_out === 0); + _mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH); // Finalize on the last chunk. if (_mode === c.Z_FINISH) { status = zlib_inflate.inflateEnd(this.strm); @@ -561,7 +570,7 @@ Inflate.prototype.onEnd = function(status) { } this.chunks = []; this.err = status; - this.msg = msg[status]; + this.msg = this.strm.msg; }; @@ -570,25 +579,35 @@ Inflate.prototype.onEnd = function(status) { * - data (Uint8Array|Array): input data to compress. * - options (Object): zlib inflate options. * - * Decompress `data` with inflate alrorythm and `options`. + * Decompress `data` with inflate/ungzip and `options`. Autodetect + * format via wrapper header by default. That's why we don't provide + * separate `ungzip` method. * * Supported options are: * * - windowBits * * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced) - * for more information on these. + * for more information. + * + * Sugar (options): + * + * - raw (Boolean) - say that we work with raw stream, if you don't wish to specify + * negative windowBits implicitly. + * * * ##### Example: * * ```javascript * var pako = require('pako') - * , in = Uint8Array([1,2,3,4,5,6,7,8,9]) - * , out; + * , input = pako.deflate([1,2,3,4,5,6,7,8,9]) + * , output; * - * out = pako.inflate(data); - * if (out.err) { throw new Error(out.err); } - * console.log(pako.inflate(out.result)); + * try { + * output = pako.inflate(input); + * } catch (err) + * console.log(err); + * } * ``` **/ function inflate(input, options) { @@ -597,7 +616,7 @@ function inflate(input, options) { inflator.push(input, true); // That will never happens, if you don't cheat with options :) - if (inflator.err) { throw msg[inflator.err]; } + if (inflator.err) { throw inflator.msg; } return inflator.result; } @@ -622,7 +641,7 @@ exports.Inflate = Inflate; exports.inflate = inflate; exports.inflateRaw = inflateRaw; -},{"./zlib/constants":5,"./zlib/inflate.js":8,"./zlib/messages":9,"./zlib/utils":11,"./zlib/zstream":12}],4:[function(_dereq_,module,exports){ +},{"./zlib/constants":5,"./zlib/inflate.js":9,"./zlib/messages":11,"./zlib/utils":13,"./zlib/zstream":14}],4:[function(_dereq_,module,exports){ 'use strict'; // Note: adler32 takes 12% for level 0 and 2% for level 6. @@ -630,24 +649,27 @@ exports.inflateRaw = inflateRaw; // Small size is preferable. function adler32(adler, buf, len, pos) { - var s1 = adler & 0xffff - , s2 = (adler >>> 16) & 0xffff + var s1 = (adler & 0xffff) |0 + , s2 = ((adler >>> 16) & 0xffff) |0 , n = 0; while (len !== 0) { - n = len > 5552 ? 5552 : len; + // Set limit ~ twice less than 5552, to keep + // s2 in 31-bits, because we force signed ints. + // in other case %= will fail. + n = len > 2000 ? 2000 : len; len -= n; do { - s1 += buf[pos++]; - s2 += s1; + s1 = (s1 + buf[pos++]) |0; + s2 = (s2 + s1) |0; } while (--n); s1 %= 65521; s2 %= 65521; } - return (s1 | (s2 << 16)); + return (s1 | (s2 << 16)) |0; } @@ -673,9 +695,9 @@ module.exports = { Z_ERRNO: (-1), Z_STREAM_ERROR: (-2), Z_DATA_ERROR: (-3), - Z_MEM_ERROR: (-4), + //Z_MEM_ERROR: (-4), Z_BUF_ERROR: (-5), - Z_VERSION_ERROR: (-6), + //Z_VERSION_ERROR: (-6), /* compression levels */ Z_NO_COMPRESSION: 0, @@ -697,7 +719,7 @@ module.exports = { Z_UNKNOWN: 2, /* The deflate compression method */ - Z_DEFLATED: 8, + Z_DEFLATED: 8 //Z_NULL: null // Use -1 or null, depending on var type }; },{}],6:[function(_dereq_,module,exports){ @@ -749,6 +771,7 @@ var utils = _dereq_('./utils'); var trees = _dereq_('./trees'); var adler32 = _dereq_('./adler32'); var crc32 = _dereq_('./crc32'); +var msg = _dereq_('./messages'); /* Public constants ==========================================================*/ /* ===========================================================================*/ @@ -847,6 +870,10 @@ var BS_FINISH_DONE = 4; /* finish done, accept no more input or output */ var OS_CODE = 0x03; // Unix :) . Don't detect, use this default. +function err(strm, errorCode) { + strm.msg = msg[errorCode]; + return errorCode; +} function rank(f) { return ((f) << 1) - ((f) > 4 ? 9 : 0); @@ -1912,9 +1939,9 @@ function DeflateState() { // Use flat array of DOUBLE size, with interleaved fata, // because JS does not support effective - this.dyn_ltree = utils.array16Create(HEAP_SIZE * 2); - this.dyn_dtree = utils.array16Create((2*D_CODES+1) * 2); - this.bl_tree = utils.array16Create((2*BL_CODES+1) * 2); + this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2); + this.dyn_dtree = new utils.Buf16((2*D_CODES+1) * 2); + this.bl_tree = new utils.Buf16((2*BL_CODES+1) * 2); zero(this.dyn_ltree); zero(this.dyn_dtree); zero(this.bl_tree); @@ -1931,11 +1958,11 @@ function DeflateState() { this.bl_desc = null; /* desc. for bit length tree */ //ush bl_count[MAX_BITS+1]; - this.bl_count = utils.array16Create(MAX_BITS+1); + this.bl_count = new utils.Buf16(MAX_BITS+1); /* number of codes at each bit length for an optimal tree */ //int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ - this.heap = utils.array16Create(2*L_CODES+1); /* heap used to build the Huffman trees */ + this.heap = new utils.Buf16(2*L_CODES+1); /* heap used to build the Huffman trees */ zero(this.heap); this.heap_len = 0; /* number of elements in the heap */ @@ -1944,7 +1971,7 @@ function DeflateState() { * The same heap array is used to build all trees. */ - this.depth = utils.array16Create(2*L_CODES+1); //uch depth[2*L_CODES+1]; + this.depth = new utils.Buf16(2*L_CODES+1); //uch depth[2*L_CODES+1]; zero(this.depth); /* Depth of each subtree used as tie breaker for trees of equal frequency */ @@ -2006,7 +2033,7 @@ function deflateResetKeep(strm) { var s; if (!strm || !strm.state) { - return Z_STREAM_ERROR; + return err(strm, Z_STREAM_ERROR); } strm.total_in = strm.total_out = 0; @@ -2040,7 +2067,7 @@ function deflateReset(strm) { function deflateInit2(strm, level, method, windowBits, memLevel, strategy) { if (!strm) { // === Z_NULL - return Z_STREAM_ERROR; + return err(strm, Z_STREAM_ERROR); } var wrap = 1; @@ -2062,7 +2089,7 @@ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) { if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED || windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; + return err(strm, Z_STREAM_ERROR); } @@ -2087,16 +2114,16 @@ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) { s.hash_mask = s.hash_size - 1; s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH); - s.window = utils.arrayCreate(s.w_size * 2); - s.head = utils.array16Create(s.hash_size); - s.prev = utils.array16Create(s.w_size); + s.window = new utils.Buf8(s.w_size * 2); + s.head = new utils.Buf16(s.hash_size); + s.prev = new utils.Buf16(s.w_size); s.high_water = 0; /* nothing written to s->window yet */ s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ s.pending_buf_size = s.lit_bufsize * 4; - s.pending_buf = utils.arrayCreate(s.pending_buf_size); + s.pending_buf = new utils.Buf8(s.pending_buf_size); s.d_buf = s.lit_bufsize >> 1; s.l_buf = (1 + 2) * s.lit_bufsize; @@ -2118,7 +2145,7 @@ function deflate(strm, flush) { if (!strm || !strm.state || flush > Z_BLOCK || flush < 0) { - return Z_STREAM_ERROR; + return err(strm, Z_STREAM_ERROR); } s = strm.state; @@ -2126,7 +2153,7 @@ function deflate(strm, flush) { if (!strm.next_out || (!strm.next_in && strm.avail_in !== 0) || (s.status === FINISH_STATE && flush !== Z_FINISH)) { - return (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR; + return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR); } s.strm = strm; /* just in case */ @@ -2207,12 +2234,12 @@ function deflate(strm, flush) { */ } else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) && flush !== Z_FINISH) { - return Z_BUF_ERROR; + return err(strm, Z_BUF_ERROR); } /* User must not provide more input after the first FINISH: */ if (s.status === FINISH_STATE && strm.avail_in !== 0) { - return Z_BUF_ERROR; + return err(strm, Z_BUF_ERROR); } /* Start a new block or continue the current one. @@ -2310,12 +2337,12 @@ function deflateEnd(strm) { status !== BUSY_STATE && status !== FINISH_STATE ) { - return Z_STREAM_ERROR; + return err(strm, Z_STREAM_ERROR); } strm.state = null; - return status === BUSY_STATE ? Z_DATA_ERROR : Z_OK; + return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK; } /* ========================================================================= @@ -2330,7 +2357,7 @@ exports.deflateInit2 = deflateInit2; exports.deflateReset = deflateReset; exports.deflate = deflate; exports.deflateEnd = deflateEnd; -exports.deflate_info = 'pako deflate'; +exports.deflateInfo = 'pako deflate (from Nodeca project)'; /* Not implemented exports.deflateSetDictionary = deflateSetDictionary; @@ -2339,90 +2366,615 @@ exports.deflateSetHeader = deflateSetHeader; exports.deflateBound = deflateBound; exports.deflatePending = deflatePending; */ -},{"./adler32":4,"./crc32":6,"./trees":10,"./utils":11}],8:[function(_dereq_,module,exports){ +},{"./adler32":4,"./crc32":6,"./messages":11,"./trees":12,"./utils":13}],8:[function(_dereq_,module,exports){ 'use strict'; -//var utils = require('utils'); +// See state defs from inflate.js +var BAD = 30; /* got a data error -- remain here until reset */ +var TYPE = 12; /* i: waiting for type bits, including last-flag bit */ + +/* + Decode literal, length, and distance codes and write out the resulting + literal and match bytes until either not enough input or output is + available, an end-of-block is encountered, or a data error is encountered. + When large enough input and output buffers are supplied to inflate(), for + example, a 16K input buffer and a 64K output buffer, more than 95% of the + inflate execution time is spent in this routine. + + Entry assumptions: + + state.mode === LEN + strm.avail_in >= 6 + strm.avail_out >= 258 + start >= strm.avail_out + state.bits < 8 + + On return, state.mode is one of: + + LEN -- ran out of enough output space or enough available input + TYPE -- reached end of block code, inflate() to interpret next block + BAD -- error in block data + + Notes: + + - The maximum input bits used by a length/distance pair is 15 bits for the + length code, 5 bits for the length extra, 15 bits for the distance code, + and 13 bits for the distance extra. This totals 48 bits, or six bytes. + Therefore if strm.avail_in >= 6, then there is enough input to avoid + checking for available input while decoding. + + - The maximum bytes that a single length/distance pair can output is 258 + bytes, which is the maximum length that can be coded. inflate_fast() + requires strm.avail_out >= 258 for each loop to avoid checking for + output space. + */ +module.exports = function inflate_fast(strm, start) { + var state; + var _in; /* local strm.next_in */ + var last; /* have enough input while in < last */ + var _out; /* local strm.next_out */ + var beg; /* inflate()'s initial strm.next_out */ + var end; /* while out < end, enough space available */ +//#ifdef INFLATE_STRICT + var dmax; /* maximum distance from zlib header */ +//#endif + var wsize; /* window size or zero if not using window */ + var whave; /* valid bytes in the window */ + var wnext; /* window write index */ + var window; /* allocated sliding window, if wsize != 0 */ + var hold; /* local strm.hold */ + var bits; /* local strm.bits */ + var lcode; /* local strm.lencode */ + var dcode; /* local strm.distcode */ + var lmask; /* mask for first level of length codes */ + var dmask; /* mask for first level of distance codes */ + var here; /* retrieved table entry */ + var op; /* code bits, operation, extra bits, or */ + /* window position, window bytes to copy */ + var len; /* match length, unused bytes */ + var dist; /* match distance */ + var from; /* where to copy match from */ + var from_source; + + + var input, output; // JS specific, because we have no pointers + + /* copy state to local variables */ + state = strm.state; + //here = state.here; + _in = strm.next_in_index; + input = strm.next_in; + last = _in + (strm.avail_in - 5); + _out = strm.next_out_index; + output = strm.next_out; + beg = _out - (start - strm.avail_out); + end = _out + (strm.avail_out - 257); +//#ifdef INFLATE_STRICT + dmax = state.dmax; +//#endif + wsize = state.wsize; + whave = state.whave; + wnext = state.wnext; + window = state.window; + hold = state.hold; + bits = state.bits; + lcode = state.lencode; + dcode = state.distcode; + lmask = (1 << state.lenbits) - 1; + dmask = (1 << state.distbits) - 1; + + + /* decode literals and length/distances until end-of-block or not enough + input data or output space */ + + top: + do { + if (bits < 15) { + hold += input[_in++] << bits; + bits += 8; + hold += input[_in++] << bits; + bits += 8; + } + + here = lcode[hold & lmask]; + + dolen: + for (;;) { // Goto emulation + op = here >>> 24/*here.bits*/; + hold >>>= op; + bits -= op; + op = (here >>> 16) & 0xff/*here.op*/; + if (op === 0) { /* literal */ + //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + // "inflate: literal '%c'\n" : + // "inflate: literal 0x%02x\n", here.val)); + output[_out++] = here & 0xffff/*here.val*/; + } + else if (op & 16) { /* length base */ + len = here & 0xffff/*here.val*/; + op &= 15; /* number of extra bits */ + if (op) { + if (bits < op) { + hold += input[_in++] << bits; + bits += 8; + } + len += hold & ((1 << op) - 1); + hold >>>= op; + bits -= op; + } + //Tracevv((stderr, "inflate: length %u\n", len)); + if (bits < 15) { + hold += input[_in++] << bits; + bits += 8; + hold += input[_in++] << bits; + bits += 8; + } + here = dcode[hold & dmask]; + + dodist: + for (;;) { // goto emulation + op = here >>> 24/*here.bits*/; + hold >>>= op; + bits -= op; + op = (here >>> 16) & 0xff/*here.op*/; + + if (op & 16) { /* distance base */ + dist = here & 0xffff/*here.val*/; + op &= 15; /* number of extra bits */ + if (bits < op) { + hold += input[_in++] << bits; + bits += 8; + if (bits < op) { + hold += input[_in++] << bits; + bits += 8; + } + } + dist += hold & ((1 << op) - 1); +//#ifdef INFLATE_STRICT + if (dist > dmax) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break top; + } +//#endif + hold >>>= op; + bits -= op; + //Tracevv((stderr, "inflate: distance %u\n", dist)); + op = _out - beg; /* max distance in output */ + if (dist > op) { /* see if copy from window */ + op = dist - op; /* distance back in window */ + if (op > whave) { + if (state.sane) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break top; + } +//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR +// if (len <= op - whave) { +// do { +// output[_out++] = 0; +// } while (--len); +// continue top; +// } +// len -= op - whave; +// do { +// output[_out++] = 0; +// } while (--op > whave); +// if (op === 0) { +// from = _out - dist; +// do { +// output[_out++] = output[from++]; +// } while (--len); +// continue top; +// } +//#endif + } + from = 0; // window index + from_source = window; + if (wnext === 0) { /* very common case */ + from += wsize - op; + if (op < len) { /* some from window */ + len -= op; + do { + output[_out++] = window[from++]; + } while (--op); + from = _out - dist; /* rest from output */ + from_source = output; + } + } + else if (wnext < op) { /* wrap around window */ + from += wsize + wnext - op; + op -= wnext; + if (op < len) { /* some from end of window */ + len -= op; + do { + output[_out++] = window[from++]; + } while (--op); + from = 0; + if (wnext < len) { /* some from start of window */ + op = wnext; + len -= op; + do { + output[_out++] = window[from++]; + } while (--op); + from = _out - dist; /* rest from output */ + from_source = output; + } + } + } + else { /* contiguous in window */ + from += wnext - op; + if (op < len) { /* some from window */ + len -= op; + do { + output[_out++] = window[from++]; + } while (--op); + from = _out - dist; /* rest from output */ + from_source = output; + } + } + while (len > 2) { + output[_out++] = from_source[from++]; + output[_out++] = from_source[from++]; + output[_out++] = from_source[from++]; + len -= 3; + } + if (len) { + output[_out++] = from_source[from++]; + if (len > 1) { + output[_out++] = from_source[from++]; + } + } + } + else { + from = _out - dist; /* copy direct from output */ + do { /* minimum length is three */ + output[_out++] = output[from++]; + output[_out++] = output[from++]; + output[_out++] = output[from++]; + len -= 3; + } while (len > 2); + if (len) { + output[_out++] = output[from++]; + if (len > 1) { + output[_out++] = output[from++]; + } + } + } + } + else if ((op & 64) === 0) { /* 2nd level distance code */ + here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))]; + continue dodist; + } + else { + strm.msg = 'invalid distance code'; + state.mode = BAD; + break top; + } + + break; // need to emulate goto via "continue" + } + } + else if ((op & 64) === 0) { /* 2nd level length code */ + here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))]; + continue dolen; + } + else if (op & 32) { /* end-of-block */ + //Tracevv((stderr, "inflate: end of block\n")); + state.mode = TYPE; + break top; + } + else { + strm.msg = 'invalid literal/length code'; + state.mode = BAD; + break top; + } + + break; // need to emulate goto via "continue" + } + } while (_in < last && _out < end); + + /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ + len = bits >> 3; + _in -= len; + bits -= len << 3; + hold &= (1 << bits) - 1; + + /* update state and return */ + strm.next_in_index = _in; + strm.next_out_index = _out; + strm.avail_in = (_in < last ? 5 + (last - _in) : 5 - (_in - last)); + strm.avail_out = (_out < end ? 257 + (end - _out) : 257 - (_out - end)); + state.hold = hold; + state.bits = bits; + return; +}; + +},{}],9:[function(_dereq_,module,exports){ +'use strict'; + + +var utils = _dereq_('./utils'); +var adler32 = _dereq_('./adler32'); +var crc32 = _dereq_('./crc32'); +var inflate_fast = _dereq_('./inffast'); +var inflate_table = _dereq_('./inftrees'); + +var CODES = 0; +var LENS = 1; +var DISTS = 2; + +/* Public constants ==========================================================*/ +/* ===========================================================================*/ + + +/* Allowed flush values; see deflate() and inflate() below for details */ +//var Z_NO_FLUSH = 0; +//var Z_PARTIAL_FLUSH = 1; +//var Z_SYNC_FLUSH = 2; +//var Z_FULL_FLUSH = 3; +var Z_FINISH = 4; +var Z_BLOCK = 5; +var Z_TREES = 6; + + +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ +var Z_OK = 0; +var Z_STREAM_END = 1; +var Z_NEED_DICT = 2; +//var Z_ERRNO = -1; +var Z_STREAM_ERROR = -2; +var Z_DATA_ERROR = -3; +var Z_MEM_ERROR = -4; +var Z_BUF_ERROR = -5; +//var Z_VERSION_ERROR = -6; + +/* The deflate compression method */ +var Z_DEFLATED = 8; + + +/* STATES ====================================================================*/ +/* ===========================================================================*/ + + +var HEAD = 1; /* i: waiting for magic header */ +var FLAGS = 2; /* i: waiting for method and flags (gzip) */ +var TIME = 3; /* i: waiting for modification time (gzip) */ +var OS = 4; /* i: waiting for extra flags and operating system (gzip) */ +var EXLEN = 5; /* i: waiting for extra length (gzip) */ +var EXTRA = 6; /* i: waiting for extra bytes (gzip) */ +var NAME = 7; /* i: waiting for end of file name (gzip) */ +var COMMENT = 8; /* i: waiting for end of comment (gzip) */ +var HCRC = 9; /* i: waiting for header crc (gzip) */ +var DICTID = 10; /* i: waiting for dictionary check value */ +var DICT = 11; /* waiting for inflateSetDictionary() call */ +var TYPE = 12; /* i: waiting for type bits, including last-flag bit */ +var TYPEDO = 13; /* i: same, but skip check to exit inflate on new block */ +var STORED = 14; /* i: waiting for stored size (length and complement) */ +var COPY_ = 15; /* i/o: same as COPY below, but only first time in */ +var COPY = 16; /* i/o: waiting for input or output to copy stored block */ +var TABLE = 17; /* i: waiting for dynamic block table lengths */ +var LENLENS = 18; /* i: waiting for code length code lengths */ +var CODELENS = 19; /* i: waiting for length/lit and distance code lengths */ +var LEN_ = 20; /* i: same as LEN below, but only first time in */ +var LEN = 21; /* i: waiting for length/lit/eob code */ +var LENEXT = 22; /* i: waiting for length extra bits */ +var DIST = 23; /* i: waiting for distance code */ +var DISTEXT = 24; /* i: waiting for distance extra bits */ +var MATCH = 25; /* o: waiting for output space to copy string */ +var LIT = 26; /* o: waiting for output space to write literal */ +var CHECK = 27; /* i: waiting for 32-bit check value */ +var LENGTH = 28; /* i: waiting for 32-bit length (gzip) */ +var DONE = 29; /* finished check, done -- remain here until reset */ +var BAD = 30; /* got a data error -- remain here until reset */ +var MEM = 31; /* got an inflate() memory error -- remain here until reset */ +var SYNC = 32; /* looking for synchronization bytes to restart inflate() */ + +/* ===========================================================================*/ + + var ENOUGH_LENS = 852; var ENOUGH_DISTS = 592; var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS); -//function Code() { -// this.op = 0; /* operation, extra bits, table bits */ -// this.bits = 0; /* bits in this part of the code */ -// this.val = 0; /* offset in table or code value */ -//} +var MAX_WBITS = 15; +/* 32K LZ77 window */ +var DEF_WBITS = MAX_WBITS; + + +function ZSWAP32(q) { + return (((q >>> 24) & 0xff) + + ((q >>> 8) & 0xff00) + + ((q & 0xff00) << 8) + + ((q & 0xff) << 24)); +} + function InflateState() { - this.mode = -1; /* current inflate mode */ - this.last = 0; /* true if processing last block */ + this.mode = 0; /* current inflate mode */ + this.last = false; /* true if processing last block */ this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */ - this.havedict = 0; /* true if dictionary provided */ + this.havedict = false; /* true if dictionary provided */ this.flags = 0; /* gzip header method and flags (0 if zlib) */ this.dmax = 0; /* zlib header max distance (INFLATE_STRICT) */ this.check = 0; /* protected copy of check value */ this.total = 0; /* protected copy of output count */ - this.head = 0; /* where to save gzip header information */ + // TODO: may be {} + this.head = null; /* where to save gzip header information */ + /* sliding window */ this.wbits = 0; /* log base 2 of requested window size */ this.wsize = 0; /* window size or zero if not using window */ this.whave = 0; /* valid bytes in the window */ this.wnext = 0; /* window write index */ - this.window = -1; /* allocated sliding window, if needed */ + this.window = null; /* allocated sliding window, if needed */ + /* bit accumulator */ this.hold = 0; /* input bit accumulator */ this.bits = 0; /* number of bits in "in" */ + /* for string and stored block copying */ this.length = 0; /* literal or length of data to copy */ this.offset = 0; /* distance back to copy string from */ + /* for table and code decoding */ this.extra = 0; /* extra bits needed */ + /* fixed and dynamic code tables */ - this.lencode = -1; /* starting table for length/literal codes */ - this.distcode = -1; /* starting table for distance codes */ + this.lencode = null; /* starting table for length/literal codes */ + this.distcode = null; /* starting table for distance codes */ this.lenbits = 0; /* index bits for lencode */ this.distbits = 0; /* index bits for distcode */ + /* dynamic table building */ this.ncode = 0; /* number of code length code lengths */ this.nlen = 0; /* number of length code lengths */ this.ndist = 0; /* number of distance code lengths */ this.have = 0; /* number of code lengths in lens[] */ - this.next = 0; /* next available space in codes[] */ + this.next = null; /* next available space in codes[] */ + this.next_index = 0; //unsigned short array //todo: test later with Uint16Array - this.lens = new Array(320); /* temporary storage for code lengths */ - this.work = new Array(280); /* work area for code table building */ + this.lens = new utils.Buf16(320); /* temporary storage for code lengths */ + this.work = new utils.Buf16(280); /* work area for code table building */ - this.codes = new Array(ENOUGH); /* space for code tables */ + // TODO: 8 or 16 bits? + this.codes = new utils.Buf32(ENOUGH); /* space for code tables */ this.sane = 0; /* if false, allow invalid distance too far */ this.back = 0; /* bits back of last unprocessed length/lit */ this.was = 0; /* initial length of match */ } -function inflateResetKeep(/*strm*/) { +function InfTableOptions(type, lens, lens_index, codes, table, table_index, bits, work) { + this.type = type; + this.lens = lens; + this.lens_index = lens_index; + this.codes = codes; + this.table = table; + this.table_index = table_index; + this.bits = bits; + this.work = work; +} + +function inflateResetKeep(strm) { + var state; + + if (!strm || !strm.state) { return Z_STREAM_ERROR; } + state = strm.state; + strm.total_in = strm.total_out = state.total = 0; + //strm.msg = Z_NULL; + if (state.wrap) { /* to support ill-conceived Java test suite */ + strm.adler = state.wrap & 1; + } + state.mode = HEAD; + state.last = 0; + state.havedict = 0; + state.dmax = 32768; + // TODO: may be {} + state.head = null/*Z_NULL*/; + state.hold = 0; + state.bits = 0; + //state.lencode = state.distcode = state.next = state.codes; + //utils.arraySet(state.lencode,state.codes,0,state.codes.length,0); + //utils.arraySet(state.distcode,state.codes,0,state.codes.length,0); + state.lencode = new utils.Buf32(ENOUGH); + state.distcode = new utils.Buf32(ENOUGH); + + state.sane = 1; + state.back = -1; + //Tracev((stderr, "inflate: reset\n")); + return Z_OK; +} + +function inflateReset(strm) { + var state; + + if (!strm || !strm.state) { return Z_STREAM_ERROR; } + state = strm.state; + state.wsize = 0; + state.whave = 0; + state.wnext = 0; + return inflateResetKeep(strm); } -function inflateReset(/*strm*/) { +function inflateReset2(strm, windowBits) { + var wrap; + var state; + /* get the state */ + if (!strm || !strm.state) { return Z_STREAM_ERROR; } + state = strm.state; + + /* extract wrap request from windowBits parameter */ + if (windowBits < 0) { + wrap = 0; + windowBits = -windowBits; + } + else { + wrap = (windowBits >> 4) + 1; + if (windowBits < 48) { + windowBits &= 15; + } + } + + /* set number of window bits, free window if different */ + if (windowBits && (windowBits < 8 || windowBits > 15)) { + return Z_STREAM_ERROR; + } + if (state.window !== null && state.wbits !== windowBits) { + state.window = null; + } + + /* update state and reset the rest of it */ + state.wrap = wrap; + state.wbits = windowBits; + return inflateReset(strm); } -function inflateReset2(/*strm, windowBits*/) { +function inflateInit2(strm, windowBits) { + var ret; + var state; + if (!strm) { return Z_STREAM_ERROR; } + //strm.msg = Z_NULL; /* in case we return an error */ + + state = new InflateState(); + + //if (state === Z_NULL) return Z_MEM_ERROR; + //Tracev((stderr, "inflate: allocated\n")); + strm.state = state; + state.window = null/*Z_NULL*/; + ret = inflateReset2(strm, windowBits); + if (ret !== Z_OK) { + strm.state = null/*Z_NULL*/; + } + return ret; } -function inflateInit2(strm/*, windowBits, version, stream_size*/) { - strm.state = new InflateState(); +function inflateInit(strm) { + return inflateInit2(strm, DEF_WBITS); } -function inflateInit(/*strm, version, stream_size*/) { - -} - -function inflatePrime(/*strm, bits, value*/) { +function inflatePrime(strm, bits, value) { + var state; + if (!strm || !strm.state) { return Z_STREAM_ERROR; } + state = strm.state; + if (bits < 0) { + state.hold = 0; + state.bits = 0; + return Z_OK; + } + if (bits > 16 || state.bits + bits > 32) { return Z_STREAM_ERROR; } + value &= (1 << bits) - 1; + state.hold += value << state.bits; + state.bits += bits; + return Z_OK; } /* @@ -2435,31 +2987,47 @@ function inflatePrime(/*strm, bits, value*/) { used for threaded applications, since the rewriting of the tables and virgin may not be thread-safe. */ -//function fixedtables(state) { -// -//} +var virgin = true; -/* - Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also - defines BUILDFIXED, so the tables are built on the fly. makefixed() writes - those tables to stdout, which would be piped to inffixed.h. A small program - can simply call makefixed to do this: +// TODO: check if we can use single array forbetter CPU cache use +// That will require to pass offset, when operating with distance tables. +var lenfix, distfix; // We have no pointers in JS, so keep tables separate - void makefixed(void); +function fixedtables(state) { + /* build fixed huffman tables if first call (may not be thread safe) */ + if (virgin) { + var sym, bits; - int main(void) - { - makefixed(); - return 0; - } + lenfix = new utils.Buf32(512); + distfix = new utils.Buf32(32); - Then that can be linked with zlib built with MAKEFIXED defined and run: + /* literal/length table */ + sym = 0; + while (sym < 144) { state.lens[sym++] = 8; } + while (sym < 256) { state.lens[sym++] = 9; } + while (sym < 280) { state.lens[sym++] = 7; } + while (sym < 288) { state.lens[sym++] = 8; } + + bits = 9; + inflate_table(new InfTableOptions(LENS, state.lens, 0, 288, lenfix, 0, bits, state.work)); + + /* distance table */ + sym = 0; + while (sym < 32) { state.lens[sym++] = 5; } + bits = 5; + + inflate_table(new InfTableOptions(DISTS, state.lens, 0, 32, distfix, 0, bits, state.work)); + + /* do this just once */ + virgin = false; + } + + state.lencode = lenfix; + state.lenbits = 9; + state.distcode = distfix; + state.distbits = 5; +} - a.out > inffixed.h - */ -//function makefixed() { -// -//} /* Update the window with the last wsize (normally 32K) bytes written before @@ -2475,97 +3043,1487 @@ function inflatePrime(/*strm, bits, value*/) { output will fall in the output data, making match copies simpler and faster. The advantage may be dependent on the size of the processor's data caches. */ -//function updatewindow(strm, end, copy) { -// -//} +function updatewindow(strm, src, end, copy) { + var dist; + var state = strm.state; -function inflate(/*strm, flush*/) { + /* if it hasn't been done already, allocate space for the window */ + if (state.window === null) { + state.wsize = 1 << state.wbits; + state.wnext = 0; + state.whave = 0; + state.window = new utils.Buf8(state.wsize); + } + + /* copy state->wsize or less output bytes into the circular window */ + if (copy >= state.wsize) { + utils.arraySet(state.window,src, end - state.wsize, state.wsize, 0); + state.wnext = 0; + state.whave = state.wsize; + } + else { + dist = state.wsize - state.wnext; + if (dist > copy) { + dist = copy; + } + //zmemcpy(state->window + state->wnext, end - copy, dist); + utils.arraySet(state.window,src, end - copy, dist, state.wnext); + copy -= dist; + if (copy) { + //zmemcpy(state->window, end - copy, copy); + utils.arraySet(state.window,src, end - copy, copy, 0); + state.wnext = copy; + state.whave = state.wsize; + } + else { + state.wnext += dist; + if (state.wnext === state.wsize) { state.wnext = 0; } + if (state.whave < state.wsize) { state.whave += dist; } + } + } + return 0; } -function inflateEnd(/*strm*/) { +function inflate(strm, flush) { + var state; + var input, output; // input/output buffers + var next; /* next input INDEX */ + var put; /* next output INDEX */ + var have, left; /* available input and output */ + var hold; /* bit buffer */ + var bits; /* bits in bit buffer */ + var _in, _out; /* save starting available input and output */ + var copy; /* number of stored or match bytes to copy */ + var from; /* where to copy match bytes from */ + var from_source; + var here = 0; /* current decoding table entry */ + var here_bits, here_op, here_val; + //var last; /* parent table entry */ + var last_bits, last_op, last_val; // paked "last" denormalized + var len; /* length to copy for repeats, bits to drop */ + var ret; /* return code */ + var hbuf = new utils.Buf8(4); /* buffer for gzip header crc calculation */ + var opts; + var n; // temporary var for NEED_BITS + + var order = /* permutation of code lengths */ + [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; + + + // TODO: check if needed and don't affect speed + //if (strm === Z_NULL || strm.state === Z_NULL || strm.next_out === Z_NULL || + // (strm.next_in === Z_NULL && strm.avail_in !== 0)) + // return Z_STREAM_ERROR; + + state = strm.state; + if (state.mode === TYPE) { state.mode = TYPEDO; } /* skip check */ + + + //--- LOAD() --- + put = strm.next_out_index; + output = strm.next_out; + left = strm.avail_out; + next = strm.next_in_index; + input = strm.next_in; + have = strm.avail_in; + hold = state.hold; + bits = state.bits; + //--- + + _in = have; + _out = left; + ret = Z_OK; + + inf_leave: // goto emulation + for (;;) { + switch (state.mode) { + case HEAD: + if (state.wrap === 0) { + state.mode = TYPEDO; + break; + } + //=== NEEDBITS(16); + while (bits < 16) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if ((state.wrap & 2) && hold === 0x8b1f) { /* gzip header */ + state.check = 0/*crc32(0L, Z_NULL, 0)*/; + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = FLAGS; + break; + } + state.flags = 0; /* expect zlib header */ + if (state.head) { + state.head.done = -1; + } + if (!(state.wrap & 1) || /* check if zlib header allowed */ + (((hold & 0xff)/*BITS(8)*/ << 8) + (hold >> 8)) % 31) { + strm.msg = 'incorrect header check'; + state.mode = BAD; + break; + } + if ((hold & 0x0f)/*BITS(4)*/ !== Z_DEFLATED) { + strm.msg = 'unknown compression method'; + state.mode = BAD; + break; + } + //--- DROPBITS(4) ---// + hold >>>= 4; + bits -= 4; + //---// + len = (hold & 0x0f)/*BITS(4)*/ + 8; + if (state.wbits === 0) { + state.wbits = len; + } + else if (len > state.wbits) { + strm.msg = 'invalid window size'; + state.mode = BAD; + break; + } + state.dmax = 1 << len; + //Tracev((stderr, "inflate: zlib header ok\n")); + strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/; + state.mode = hold & 0x200 ? DICTID : TYPE; + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + break; + case FLAGS: + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.flags = hold; + if ((state.flags & 0xff) !== Z_DEFLATED) { + strm.msg = 'unknown compression method'; + state.mode = BAD; + break; + } + if (state.flags & 0xe000) { + strm.msg = 'unknown header flags set'; + state.mode = BAD; + break; + } + if (state.head) { + state.head.text = ((hold >> 8) & 1); + } + if (state.flags & 0x0200) { + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = TIME; + /* falls through */ + case TIME: + //=== NEEDBITS(32); */ + while (bits < 32) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (state.head) { + state.head.time = hold; + } + if (state.flags & 0x0200) { + //=== CRC4(state.check, hold) + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + hbuf[2] = (hold >>> 16) & 0xff; + hbuf[3] = (hold >>> 24) & 0xff; + state.check = crc32(state.check, hbuf, 4, 0); + //=== + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = OS; + /* falls through */ + case OS: + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (state.head) { + state.head.xflags = (hold & 0xff); + state.head.os = (hold >> 8); + } + if (state.flags & 0x0200) { + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = EXLEN; + /* falls through */ + case EXLEN: + if (state.flags & 0x0400) { + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.length = hold; + if (state.head) { + state.head.extra_len = hold; + } + if (state.flags & 0x0200) { + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + } + else if (state.head) { + state.head.extra = null/*Z_NULL*/; + } + state.mode = EXTRA; + /* falls through */ + case EXTRA: + if (state.flags & 0x0400) { + copy = state.length; + if (copy > have) { copy = have; } + if (copy) { + if (state.head && + state.head.extra) { + len = state.head.extra_len - state.length; + //zmemcpy(state.head.extra + len, next, + // len + copy > state.head.extra_max ? + // state.head.extra_max - len : copy); + throw 'Review & implement right'; + } + if (state.flags & 0x0200) { + state.check = crc32(state.check, input, copy, next); + } + have -= copy; + next += copy; + state.length -= copy; + } + if (state.length) { break inf_leave; } + } + state.length = 0; + state.mode = NAME; + /* falls through */ + case NAME: + if (state.flags & 0x0800) { + if (have === 0) { break inf_leave; } + copy = 0; + do { + // TODO: 2 or 1 bytes? + len = input[next + copy++]; + if (state.head && state.head.name && + (state.length < state.head.name_max)) { + state.head.name[state.length++] = len; + } + } while (len && copy < have); + if (state.flags & 0x0200) { + state.check = crc32(state.check, input, copy, next); + } + have -= copy; + next += copy; + if (len) { break inf_leave; } + } + else if (state.head) { + state.head.name = null; + } + state.length = 0; + state.mode = COMMENT; + /* falls through */ + case COMMENT: + if (state.flags & 0x1000) { + if (have === 0) { break inf_leave; } + copy = 0; + do { + len = input[next + copy++]; + if (state.head && state.head.comment && + (state.length < state.head.comm_max)) { + state.head.comment[state.length++] = len; + } + } while (len && copy < have); + if (state.flags & 0x0200) { + state.check = crc32(state.check, input, copy, next); + } + have -= copy; + next += copy; + if (len) { break inf_leave; } + } + else if (state.head) { + state.head.comment = null; + } + state.mode = HCRC; + /* falls through */ + case HCRC: + if (state.flags & 0x0200) { + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (hold !== (state.check & 0xffff)) { + strm.msg = 'header crc mismatch'; + state.mode = BAD; + break; + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + } + if (state.head) { + state.head.hcrc = ((state.flags >> 9) & 1); + state.head.done = 1; + } + strm.adler = state.check = 0 /*crc32(0L, Z_NULL, 0)*/; + state.mode = TYPE; + break; + case DICTID: + //=== NEEDBITS(32); */ + while (bits < 32) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + strm.adler = state.check = ZSWAP32(hold); + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = DICT; + /* falls through */ + case DICT: + if (state.havedict === 0) { + //--- RESTORE() --- + strm.next_out_index = put; + strm.avail_out = left; + strm.next_in_index = next; + strm.avail_in = have; + state.hold = hold; + state.bits = bits; + //--- + return Z_NEED_DICT; + } + strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/; + state.mode = TYPE; + /* falls through */ + case TYPE: + if (flush === Z_BLOCK || flush === Z_TREES) { break inf_leave; } + /* falls through */ + case TYPEDO: + if (state.last) { + //--- BYTEBITS() ---// + hold >>>= bits & 7; + bits -= bits & 7; + //---// + state.mode = CHECK; + break; + } + //=== NEEDBITS(3); */ + while (bits < 3) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.last = (hold & 0x01)/*BITS(1)*/; + //--- DROPBITS(1) ---// + hold >>>= 1; + bits -= 1; + //---// + + switch ((hold & 0x03)/*BITS(2)*/) { + case 0: /* stored block */ + //Tracev((stderr, "inflate: stored block%s\n", + // state.last ? " (last)" : "")); + state.mode = STORED; + break; + case 1: /* fixed block */ + fixedtables(state); + //Tracev((stderr, "inflate: fixed codes block%s\n", + // state.last ? " (last)" : "")); + state.mode = LEN_; /* decode codes */ + if (flush === Z_TREES) { + //--- DROPBITS(2) ---// + hold >>>= 2; + bits -= 2; + //---// + break inf_leave; + } + break; + case 2: /* dynamic block */ + //Tracev((stderr, "inflate: dynamic codes block%s\n", + // state.last ? " (last)" : "")); + state.mode = TABLE; + break; + case 3: + strm.msg = 'invalid block type'; + state.mode = BAD; + } + //--- DROPBITS(2) ---// + hold >>>= 2; + bits -= 2; + //---// + break; + case STORED: + //--- BYTEBITS() ---// /* go to byte boundary */ + hold >>>= bits & 7; + bits -= bits & 7; + //---// + //=== NEEDBITS(32); */ + while (bits < 32) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if ((hold & 0xffff) !== ((hold >>> 16) ^ 0xffff)) { + strm.msg = 'invalid stored block lengths'; + state.mode = BAD; + break; + } + state.length = hold & 0xffff; + //Tracev((stderr, "inflate: stored length %u\n", + // state.length)); + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = COPY_; + if (flush === Z_TREES) { break inf_leave; } + /* falls through */ + case COPY_: + state.mode = COPY; + /* falls through */ + case COPY: + copy = state.length; + if (copy) { + if (copy > have) { copy = have; } + if (copy > left) { copy = left; } + if (copy === 0) { break inf_leave; } + //--- zmemcpy(put, next, copy); --- + utils.arraySet(output, input, next, copy, put); + //---// + have -= copy; + next += copy; + left -= copy; + put += copy; + state.length -= copy; + break; + } + //Tracev((stderr, "inflate: stored end\n")); + state.mode = TYPE; + break; + case TABLE: + //=== NEEDBITS(14); */ + while (bits < 14) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.nlen = (hold & 0x1f)/*BITS(5)*/ + 257; + //--- DROPBITS(5) ---// + hold >>>= 5; + bits -= 5; + //---// + state.ndist = (hold & 0x1f)/*BITS(5)*/ + 1; + //--- DROPBITS(5) ---// + hold >>>= 5; + bits -= 5; + //---// + state.ncode = (hold & 0x0f)/*BITS(4)*/ + 4; + //--- DROPBITS(4) ---// + hold >>>= 4; + bits -= 4; + //---// +//#ifndef PKZIP_BUG_WORKAROUND + if (state.nlen > 286 || state.ndist > 30) { + strm.msg = 'too many length or distance symbols'; + state.mode = BAD; + break; + } +//#endif + //Tracev((stderr, "inflate: table sizes ok\n")); + state.have = 0; + state.mode = LENLENS; + /* falls through */ + case LENLENS: + while (state.have < state.ncode) { + //=== NEEDBITS(3); + while (bits < 3) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.lens[order[state.have++]] = (hold & 0x07);//BITS(3); + //--- DROPBITS(3) ---// + hold >>>= 3; + bits -= 3; + //---// + } + while (state.have < 19) { + state.lens[order[state.have++]] = 0; + } + //state.next = state.codes; + // TODO: + //state.lencode = state.next; + //state.lencode.copy(state.codes); + utils.arraySet(state.lencode, state.codes, 0, state.codes.length, 0); + state.lenbits = 7; + + opts = new InfTableOptions(CODES, state.lens, 0, 19, state.lencode, 0, state.lenbits, state.work); + ret = inflate_table(opts); + state.lenbits = opts.bits; + + if (ret) { + strm.msg = 'invalid code lengths set'; + state.mode = BAD; + break; + } + //Tracev((stderr, "inflate: code lengths ok\n")); + state.have = 0; + state.mode = CODELENS; + /* falls through */ + case CODELENS: + while (state.have < state.nlen + state.ndist) { + for (;;) { + here = state.lencode[hold & ((1 << state.lenbits) - 1)];/*BITS(state.lenbits)*/ + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if ((here_bits) <= bits) { break; } + //--- PULLBYTE() ---// + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + if (here_val < 16) { + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + state.lens[state.have++] = here_val; + } + else { + if (here_val === 16) { + //=== NEEDBITS(here.bits + 2); + n = here_bits + 2; + while (bits < n) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + if (state.have === 0) { + strm.msg = 'invalid bit length repeat'; + state.mode = BAD; + break; + } + len = state.lens[state.have - 1]; + copy = 3 + (hold & 0x03);//BITS(2); + //--- DROPBITS(2) ---// + hold >>>= 2; + bits -= 2; + //---// + } + else if (here_val === 17) { + //=== NEEDBITS(here.bits + 3); + n = here_bits + 3; + while (bits < n) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + len = 0; + copy = 3 + (hold & 0x07);//BITS(3); + //--- DROPBITS(3) ---// + hold >>>= 3; + bits -= 3; + //---// + } + else { + //=== NEEDBITS(here.bits + 7); + n = here_bits + 7; + while (bits < n) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + len = 0; + copy = 11 + (hold & 0x7f);//BITS(7); + //--- DROPBITS(7) ---// + hold >>>= 7; + bits -= 7; + //---// + } + if (state.have + copy > state.nlen + state.ndist) { + strm.msg = 'invalid bit length repeat'; + state.mode = BAD; + break; + } + while (copy--) { + state.lens[state.have++] = len; + } + } + } + + /* handle error breaks in while */ + if (state.mode === BAD) { break; } + + /* check for end-of-block code (better have one) */ + if (state.lens[256] === 0) { + strm.msg = 'invalid code -- missing end-of-block'; + state.mode = BAD; + break; + } + + /* build code tables -- note: do not change the lenbits or distbits + values here (9 and 6) without reading the comments in inftrees.h + concerning the ENOUGH constants, which depend on those values */ + //state.lencode.copy(state.codes); + utils.arraySet(state.lencode, state.codes, 0, state.codes.length, 0); + state.lenbits = 9; + + opts = new InfTableOptions(LENS, state.lens, 0, state.nlen,state.lencode,0, state.lenbits, state.work); + ret = inflate_table(opts); +// state.next_index = opts.table_index; + state.lenbits = opts.bits; +// state.lencode = state.next; + + if (ret) { + strm.msg = 'invalid literal/lengths set'; + state.mode = BAD; + break; + } + + state.distbits = 6; + //state.distcode.copy(state.codes); + utils.arraySet(state.distcode, state.codes, 0, state.codes.length, 0); + opts = new InfTableOptions(DISTS, state.lens, state.nlen, state.ndist, state.distcode,0, state.distbits, state.work); + ret = inflate_table(opts); +// state.next_index = opts.table_index; + state.distbits = opts.bits; +// state.distcode = state.next; + + if (ret) { + strm.msg = 'invalid distances set'; + state.mode = BAD; + break; + } + //Tracev((stderr, 'inflate: codes ok\n')); + state.mode = LEN_; + if (flush === Z_TREES) { break inf_leave; } + /* falls through */ + case LEN_: + state.mode = LEN; + /* falls through */ + case LEN: + if (have >= 6 && left >= 258) { + //--- RESTORE() --- + strm.next_out_index = put; + strm.avail_out = left; + strm.next_in_index = next; + strm.avail_in = have; + state.hold = hold; + state.bits = bits; + //--- + inflate_fast(strm, _out); + //--- LOAD() --- + put = strm.next_out_index; + output = strm.next_out; + left = strm.avail_out; + next = strm.next_in_index; + input = strm.next_in; + have = strm.avail_in; + hold = state.hold; + bits = state.bits; + //--- + + if (state.mode === TYPE) { + state.back = -1; + } + break; + } + state.back = 0; + for (;;) { + here = state.lencode[hold & ((1 << state.lenbits) -1)]; /*BITS(state.lenbits)*/ + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if (here_bits <= bits) { break; } + //--- PULLBYTE() ---// + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + if (here_op && (here_op & 0xf0) === 0) { + last_bits = here_bits; + last_op = here_op; + last_val = here_val; + for (;;) { + here = state.lencode[last_val + + ((hold & ((1 << (last_bits + last_op)) -1))/*BITS(last.bits + last.op)*/ >> last_bits)]; + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if ((last_bits + here_bits) <= bits) { break; } + //--- PULLBYTE() ---// + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + //--- DROPBITS(last.bits) ---// + hold >>>= last_bits; + bits -= last_bits; + //---// + state.back += last_bits; + } + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + state.back += here_bits; + state.length = here_val; + if (here_op === 0) { + //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + // "inflate: literal '%c'\n" : + // "inflate: literal 0x%02x\n", here.val)); + state.mode = LIT; + break; + } + if (here_op & 32) { + //Tracevv((stderr, "inflate: end of block\n")); + state.back = -1; + state.mode = TYPE; + break; + } + if (here_op & 64) { + strm.msg = 'invalid literal/length code'; + state.mode = BAD; + break; + } + state.extra = here_op & 15; + state.mode = LENEXT; + /* falls through */ + case LENEXT: + if (state.extra) { + //=== NEEDBITS(state.extra); + n = state.extra; + while (bits < n) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.length += hold & ((1 << state.extra) -1)/*BITS(state.extra)*/; + //--- DROPBITS(state.extra) ---// + hold >>>= state.extra; + bits -= state.extra; + //---// + state.back += state.extra; + } + //Tracevv((stderr, "inflate: length %u\n", state.length)); + state.was = state.length; + state.mode = DIST; + /* falls through */ + case DIST: + for (;;) { + here = state.distcode[hold & ((1 << state.distbits) -1)];/*BITS(state.distbits)*/ + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if ((here_bits) <= bits) { break; } + //--- PULLBYTE() ---// + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + if ((here_op & 0xf0) === 0) { + last_bits = here_bits; + last_op = here_op; + last_val = here_val; + for (;;) { + here = state.distcode[last_val + + ((hold & ((1 << (last_bits + last_op)) -1))/*BITS(last.bits + last.op)*/ >> last_bits)]; + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if ((last_bits + here_bits) <= bits) { break; } + //--- PULLBYTE() ---// + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + //--- DROPBITS(last.bits) ---// + hold >>>= last_bits; + bits -= last_bits; + //---// + state.back += last_bits; + } + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + state.back += here_bits; + if (here_op & 64) { + strm.msg = 'invalid distance code'; + state.mode = BAD; + break; + } + state.offset = here_val; + state.extra = (here_op) & 15; + state.mode = DISTEXT; + /* falls through */ + case DISTEXT: + if (state.extra) { + //=== NEEDBITS(state.extra); + n = state.extra; + while (bits < n) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.offset += hold & ((1 << state.extra) -1)/*BITS(state.extra)*/; + //--- DROPBITS(state.extra) ---// + hold >>>= state.extra; + bits -= state.extra; + //---// + state.back += state.extra; + } +//#ifdef INFLATE_STRICT + if (state.offset > state.dmax) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break; + } +//#endif + //Tracevv((stderr, "inflate: distance %u\n", state.offset)); + state.mode = MATCH; + /* falls through */ + case MATCH: + if (left === 0) { break inf_leave; } + copy = _out - left; + if (state.offset > copy) { /* copy from window */ + copy = state.offset - copy; + if (copy > state.whave) { + if (state.sane) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break; + } +//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR + //Trace((stderr, "inflate.c too far\n")); +// copy -= state.whave; +// if (copy > state.length) { copy = state.length; } +// if (copy > left) { copy = left; } +// left -= copy; +// state.length -= copy; +// do { +// output[put++] = 0; +// } while (--copy); +// if (state.length === 0) { state.mode = LEN; } +// break; +//#endif + } + if (copy > state.wnext) { + copy -= state.wnext; + from = state.wsize - copy; + } + else { + from = state.wnext - copy; + } + if (copy > state.length) { copy = state.length; } + from_source = state.window; + } + else { /* copy from output */ + from_source = output; + from = put - state.offset; + copy = state.length; + } + if (copy > left) { copy = left; } + left -= copy; + state.length -= copy; + do { + output[put++] = from_source[from++]; + } while (--copy); + if (state.length === 0) { state.mode = LEN; } + break; + case LIT: + if (left === 0) { break inf_leave; } + output[put++] = state.length; + left--; + state.mode = LEN; + break; + case CHECK: + if (state.wrap) { + //=== NEEDBITS(32); + while (bits < 32) { + if (have === 0) { break inf_leave; } + have--; + // Use '|' insdead of '+' to make sure that result is signed + hold |= input[next++] << bits; + bits += 8; + } + //===// + _out -= left; + strm.total_out += _out; + state.total += _out; + if (_out) { + strm.adler = state.check = + /*UPDATE(state.check, put - _out, _out);*/ + (state.flags ? crc32(state.check, output, _out, put - _out) : adler32(state.check, output, _out, put - _out)); + + } + _out = left; + // NB: crc32 stored as signed 32-bit int, ZSWAP32 returns signed too + if ((state.flags ? hold : ZSWAP32(hold)) !== state.check) { + strm.msg = 'incorrect data check'; + state.mode = BAD; + break; + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + //Tracev((stderr, "inflate: check matches trailer\n")); + } + state.mode = LENGTH; + /* falls through */ + case LENGTH: + if (state.wrap && state.flags) { + //=== NEEDBITS(32); + while (bits < 32) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (hold !== (state.total & 0xffffffff)) { + strm.msg = 'incorrect length check'; + state.mode = BAD; + break; + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + //Tracev((stderr, "inflate: length matches trailer\n")); + } + state.mode = DONE; + /* falls through */ + case DONE: + ret = Z_STREAM_END; + break inf_leave; + case BAD: + ret = Z_DATA_ERROR; + break inf_leave; + case MEM: + return Z_MEM_ERROR; + case SYNC: + /* falls through */ + default: + return Z_STREAM_ERROR; + } + } + + // inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave" + + /* + Return from inflate(), updating the total counts and the check value. + If there was no progress during the inflate() call, return a buffer + error. Call updatewindow() to create and/or update the window state. + Note: a memory error from inflate() is non-recoverable. + */ + + //--- RESTORE() --- + strm.next_out_index = put; + strm.avail_out = left; + strm.next_in_index = next; + strm.avail_in = have; + state.hold = hold; + state.bits = bits; + //--- + + if (state.wsize || (_out !== strm.avail_out && state.mode < BAD && + (state.mode < CHECK || flush !== Z_FINISH))) { + if (updatewindow(strm, strm.next_out, strm.next_out_index, _out - strm.avail_out)) { + state.mode = MEM; + return Z_MEM_ERROR; + } + } + _in -= strm.avail_in; + _out -= strm.avail_out; + strm.total_in += _in; + strm.total_out += _out; + state.total += _out; + if (state.wrap && _out) { + strm.adler = state.check = /*UPDATE(state.check, strm.next_out_index - _out, _out);*/ + (state.flags ? crc32(state.check, output, _out, strm.next_out_index - _out) : adler32(state.check, output, _out, strm.next_out_index - _out)); + } + strm.data_type = state.bits + (state.last ? 64 : 0) + + (state.mode === TYPE ? 128 : 0) + + (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0); + if (((_in === 0 && _out === 0) || flush === Z_FINISH) && ret === Z_OK) { + ret = Z_BUF_ERROR; + } + return ret; } -function inflateGetDictionary(/*strm, dictionary, dictLength*/) { - +function inflateEnd(strm) { +// if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) +// return Z_STREAM_ERROR; + var state = strm.state; + if (state.window) { + state.window = null; + } + strm.state = null; + return Z_OK; } -function inflateSetDictionary(/*strm, dictionary, dictLength*/) { - -} - -function inflateGetHeader(/*strm, head*/) { - -} - -/* - Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found - or when out of input. When called, *have is the number of pattern bytes - found in order so far, in 0..3. On return *have is updated to the new - state. If on return *have equals four, then the pattern was found and the - return value is how many bytes were read including the last byte of the - pattern. If *have is less than four, then the pattern has not been found - yet and the return value is len. In the latter case, syncsearch() can be - called again with more data and the *have state. *have is initialized to - zero for the first call. - */ -//function syncsearch(/*have, buf, len*/) { -// -//} - -function inflateSync(/*strm*/) { - -} - -function inflateSyncPoint(/*strm*/) { - -} - -function inflateCopy(/*dest, source*/) { - -} - -function inflateUndermine(/*strm, subvert*/) { - -} - -function inflateMark(/*strm*/) { - -} - -exports.inflateResetKeep = inflateResetKeep; exports.inflateReset = inflateReset; - exports.inflateReset2 = inflateReset2; - -exports.inflateInit2 = inflateInit2; - +exports.inflateResetKeep = inflateResetKeep; exports.inflateInit = inflateInit; - +exports.inflateInit2 = inflateInit2; exports.inflatePrime = inflatePrime; - exports.inflate = inflate; - exports.inflateEnd = inflateEnd; +exports.inflateInfo = 'pako inflate (from Nodeca project)'; +/* Not implemented exports.inflateGetDictionary = inflateGetDictionary; - exports.inflateGetHeader = inflateGetHeader; - exports.inflateSetDictionary = inflateSetDictionary; - exports.inflateSync = inflateSync; - exports.inflateSyncPoint = inflateSyncPoint; - exports.inflateCopy = inflateCopy; - exports.inflateUndermine = inflateUndermine; - exports.inflateMark = inflateMark; -},{}],9:[function(_dereq_,module,exports){ +*/ +},{"./adler32":4,"./crc32":6,"./inffast":8,"./inftrees":10,"./utils":13}],10:[function(_dereq_,module,exports){ +'use strict'; + + +var utils = _dereq_('./utils'); + +var MAXBITS = 15; +var ENOUGH_LENS = 852; +var ENOUGH_DISTS = 592; +//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS); + +var CODES = 0; +var LENS = 1; +var DISTS = 2; + +var lbase = [ /* Length codes 257..285 base */ + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 +]; + +var lext = [ /* Length codes 257..285 extra */ + 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78 +]; + +var dbase = [ /* Distance codes 0..29 base */ + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, + 8193, 12289, 16385, 24577, 0, 0 +]; + +var dext = [ /* Distance codes 0..29 extra */ + 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, + 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, + 28, 28, 29, 29, 64, 64 +]; + +module.exports = function inflate_table(opts) +{ + var type = opts.type, + lens = opts.lens, + codes = opts.codes, + table = opts.table, + bits = opts.bits, + work = opts.work; + //here = opts.here; /* table entry for duplication */ + + var len = 0; /* a code's length in bits */ + var sym = 0; /* index of code symbols */ + var min = 0, max = 0; /* minimum and maximum code lengths */ + var root = 0; /* number of index bits for root table */ + var curr = 0; /* number of index bits for current table */ + var drop = 0; /* code bits to drop for sub-table */ + var left = 0; /* number of prefix codes available */ + var used = 0; /* code entries in table used */ + var huff = 0; /* Huffman code */ + var incr; /* for incrementing code, index */ + var fill; /* index for replicating entries */ + var low; /* low bits for current root entry */ + var mask; /* mask for low root bits */ + var next; /* next available space in table */ + var base = null; /* base value table to use */ + var base_index = 0; +// var shoextra; /* extra bits table to use */ + var end; /* use base and extra for symbol > end */ + var count = new utils.Buf16(MAXBITS+1); //[MAXBITS+1]; /* number of codes of each length */ + var offs = new utils.Buf16(MAXBITS+1); //[MAXBITS+1]; /* offsets in table for each length */ + var extra = null; + var extra_index = 0; + + var here_bits, here_op, here_val; + + /* + Process a set of code lengths to create a canonical Huffman code. The + code lengths are lens[0..codes-1]. Each length corresponds to the + symbols 0..codes-1. The Huffman code is generated by first sorting the + symbols by length from short to long, and retaining the symbol order + for codes with equal lengths. Then the code starts with all zero bits + for the first code of the shortest length, and the codes are integer + increments for the same length, and zeros are appended as the length + increases. For the deflate format, these bits are stored backwards + from their more natural integer increment ordering, and so when the + decoding tables are built in the large loop below, the integer codes + are incremented backwards. + + This routine assumes, but does not check, that all of the entries in + lens[] are in the range 0..MAXBITS. The caller must assure this. + 1..MAXBITS is interpreted as that code length. zero means that that + symbol does not occur in this code. + + The codes are sorted by computing a count of codes for each length, + creating from that a table of starting indices for each length in the + sorted table, and then entering the symbols in order in the sorted + table. The sorted table is work[], with that space being provided by + the caller. + + The length counts are used for other purposes as well, i.e. finding + the minimum and maximum length codes, determining if there are any + codes at all, checking for a valid set of lengths, and looking ahead + at length counts to determine sub-table sizes when building the + decoding tables. + */ + + /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ + for (len = 0; len <= MAXBITS; len++) { + count[len] = 0; + } + for (sym = 0; sym < codes; sym++) { + count[lens[opts.lens_index + sym]]++; + } + + /* bound code lengths, force root to be within code lengths */ + root = bits; + for (max = MAXBITS; max >= 1; max--) { + if (count[max] !== 0) { break; } + } + if (root > max) { + root = max; + } + if (max === 0) { /* no symbols to code at all */ + //table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */ + //table.bits[opts.table_index] = 1; //here.bits = (var char)1; + //table.val[opts.table_index++] = 0; //here.val = (var short)0; + table[opts.table_index++] = (1 << 24) | (64 << 16) | 0; + + + //table.op[opts.table_index] = 64; + //table.bits[opts.table_index] = 1; + //table.val[opts.table_index++] = 0; + table[opts.table_index++] = (1 << 24) | (64 << 16) | 0; + + opts.bits = 1; + return 0; /* no symbols, but wait for decoding to report error */ + } + for (min = 1; min < max; min++) { + if (count[min] !== 0) { break; } + } + if (root < min) { + root = min; + } + + /* check for an over-subscribed or incomplete set of lengths */ + left = 1; + for (len = 1; len <= MAXBITS; len++) { + left <<= 1; + left -= count[len]; + if (left < 0) { + return -1; + } /* over-subscribed */ + } + if (left > 0 && (type === CODES || max !== 1)) { + return -1; /* incomplete set */ + } + + /* generate offsets into symbol table for each length for sorting */ + offs[1] = 0; + for (len = 1; len < MAXBITS; len++) { + offs[len + 1] = offs[len] + count[len]; + } + + /* sort symbols by length, by symbol order within each length */ + for (sym = 0; sym < codes; sym++) { + if (lens[opts.lens_index + sym] !== 0) { + work[offs[lens[opts.lens_index + sym]]++] = sym; + } + } + + /* + Create and fill in decoding tables. In this loop, the table being + filled is at next and has curr index bits. The code being used is huff + with length len. That code is converted to an index by dropping drop + bits off of the bottom. For codes where len is less than drop + curr, + those top drop + curr - len bits are incremented through all values to + fill the table with replicated entries. + + root is the number of index bits for the root table. When len exceeds + root, sub-tables are created pointed to by the root entry with an index + of the low root bits of huff. This is saved in low to check for when a + new sub-table should be started. drop is zero when the root table is + being filled, and drop is root when sub-tables are being filled. + + When a new sub-table is needed, it is necessary to look ahead in the + code lengths to determine what size sub-table is needed. The length + counts are used for this, and so count[] is decremented as codes are + entered in the tables. + + used keeps track of how many table entries have been allocated from the + provided *table space. It is checked for LENS and DIST tables against + the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in + the initial root table size constants. See the comments in inftrees.h + for more information. + + sym increments through all symbols, and the loop terminates when + all codes of length max, i.e. all codes, have been processed. This + routine permits incomplete codes, so another loop after this one fills + in the rest of the decoding tables with invalid code markers. + */ + + /* set up for code type */ + switch (type) { + case CODES: + base = extra = work; /* dummy value--not used */ + end = 19; + break; + case LENS: + base = lbase; + base_index -= 257; + extra = lext; + extra_index -= 257; + end = 256; + break; + default: /* DISTS */ + base = dbase; + extra = dext; + end = -1; + } + + /* initialize opts for loop */ + huff = 0; /* starting code */ + sym = 0; /* starting code symbol */ + len = min; /* starting code length */ + next = opts.table_index; /* current table to fill in */ + curr = root; /* current table index bits */ + drop = 0; /* current bits to drop from code for index */ + low = -1; /* trigger new sub-table when len > root */ + used = 1 << root; /* use root table entries */ + mask = used - 1; /* mask for comparing low */ + + /* check available table space */ + if ((type === LENS && used > ENOUGH_LENS) || + (type === DISTS && used > ENOUGH_DISTS)) { + return 1; + } + + var i=0; + /* process all codes and make table entries */ + for (;;) { + i++; + /* create table entry */ + here_bits = len - drop; + if (work[sym] < end) { + here_op = 0; + here_val = work[sym]; + } + else if (work[sym] > end) { + here_op = extra[extra_index + work[sym]]; + here_val = base[base_index + work[sym]]; + } + else { + here_op = 32 + 64; /* end of block */ + here_val = 0; + } + + /* replicate for those indices with low len bits equal to huff */ + incr = 1 << (len - drop); + fill = 1 << curr; + min = fill; /* save offset to next table */ + do { + fill -= incr; + table[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val |0; + } while (fill !== 0); + + /* backwards increment the len-bit code huff */ + incr = 1 << (len - 1); + while (huff & incr) { + incr >>= 1; + } + if (incr !== 0) { + huff &= incr - 1; + huff += incr; + } else { + huff = 0; + } + + /* go to next symbol, update count, len */ + sym++; + if (--(count[len]) === 0) { + if (len === max) { break; } + len = lens[opts.lens_index + work[sym]]; + } + + /* create new sub-table if needed */ + if (len > root && (huff & mask) !== low) { + /* if first time, transition to sub-tables */ + if (drop === 0) { + drop = root; + } + + /* increment past last table */ + next += min; /* here min is 1 << curr */ + + /* determine length of next table */ + curr = len - drop; + left = 1 << curr; + while (curr + drop < max) { + left -= count[curr + drop]; + if (left <= 0) { break; } + curr++; + left <<= 1; + } + + /* check for enough space */ + used += 1 << curr; + if ((type === LENS && used > ENOUGH_LENS) || + (type === DISTS && used > ENOUGH_DISTS)) { + return 1; + } + + /* point entry in root table to sub-table */ + low = huff & mask; + /*table.op[low] = curr; + table.bits[low] = root; + table.val[low] = next - opts.table_index;*/ + table[low] = (root << 24) | (curr << 16) | (next - opts.table_index); + } + } + + /* fill in remaining table entry if code is incomplete (guaranteed to have + at most one remaining entry, since if the code is incomplete, the + maximum code length that was allowed to get this far is one bit) */ + if (huff !== 0) { + //table.op[next + huff] = 64; /* invalid code marker */ + //table.bits[next + huff] = len - drop; + //table.val[next + huff] = 0; + table[next + huff] = ((len - drop) << 24) | (64 << 16) | 0; + } + + /* set return parameters */ + opts.table_index += used; + opts.bits = root; + return 0; +}; +},{"./utils":13}],11:[function(_dereq_,module,exports){ 'use strict'; module.exports = { @@ -2579,7 +4537,7 @@ module.exports = { '-5': 'buffer error', /* Z_BUF_ERROR (-5) */ '-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */ }; -},{}],10:[function(_dereq_,module,exports){ +},{}],12:[function(_dereq_,module,exports){ 'use strict'; @@ -3774,25 +5732,13 @@ exports._tr_stored_block = _tr_stored_block; exports._tr_flush_block = _tr_flush_block; exports._tr_tally = _tr_tally; exports._tr_align = _tr_align; -},{"./utils":11}],11:[function(_dereq_,module,exports){ +},{"./utils":13}],13:[function(_dereq_,module,exports){ 'use strict'; var TYPED_OK = (typeof Uint8Array !== 'undefined') && (typeof Uint16Array !== 'undefined') && - (typeof Uint32Array !== 'undefined'); - -var _toString = Function.prototype.call.bind(Object.prototype.toString); -var isArray = Array.isArray || function (obj) { return _toString(obj) === '[object Array]'; }; - -// For debug/testing. Set true to force use untyped arrays -exports.forceUntyped = false; - -function typedOk() { - return TYPED_OK && !exports.forceUntyped; -} - -exports.typedOk = typedOk; + (typeof Int32Array !== 'undefined'); exports.assign = function (obj /*from1, from2, from3, ...*/) { @@ -3816,58 +5762,32 @@ exports.assign = function (obj /*from1, from2, from3, ...*/) { }; -exports.arraySet = function (dest, src, src_offs, len, dest_offs) { - - // Suppose, that with typed array support destination is - // always typed - don't check it - if (typedOk() && (!isArray(src))) { - - // optimize full copy - //if ((src_offs === 0) && (src.length === len)) { - // dest.set(src, dest_offs); - // return; - //} - - dest.set(src.subarray(src_offs, src_offs+len), dest_offs); - return; - } - - // Fallback to ordinary array - for(var i=0; i0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new o;var a=_.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(a!==f)throw new Error(h[a])};v.prototype.push=function(t,e){var a,n,r=this.strm,s=this.options.chunkSize;if(this.ended)return!1;n=e===~~e?e:e===!0?d:u,r.next_in=t,r.next_in_index=0,r.avail_in=r.next_in.length,r.next_out=l.arrayCreate(s);do{if(r.avail_out=this.options.chunkSize,r.next_out_index=0,a=_.deflate(r,n),a!==c&&a!==f)return this.onEnd(a),this.ended=!0,!1;r.next_out_index&&(this.onData(i(r.next_out,r.next_out_index)),(r.avail_in>0||0===r.avail_out)&&(r.next_out=l.arrayCreate(this.options.chunkSize)))}while(r.avail_in>0||0===r.avail_out);return n===d?(a=_.deflateEnd(this.strm),this.onEnd(a),this.ended=!0,a===f):!0},v.prototype.onData=function(t){this.chunks.push(t)},v.prototype.onEnd=function(t){t===f&&(this.result=l.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=h[t]},a.Deflate=v,a.deflate=n,a.deflateRaw=r,a.gzip=s},{"./zlib/deflate.js":7,"./zlib/messages":9,"./zlib/utils":11,"./zlib/zstream":12}],3:[function(t,e,a){"use strict";function i(t,e){return t.length===e?t:_.typedOk()?t.subarray(0,e):t.slice(0,e)}function n(t,e){var a=new u(e);if(a.push(t,!0),a.err)throw h[a.err];return a.result}function r(t,e){return e=e||{},e.raw=!0,n(t,e)}var s=t("./zlib/inflate.js"),_=t("./zlib/utils"),l=t("./zlib/constants"),h=t("./zlib/messages"),o=t("./zlib/zstream"),u=function(t){this.options=_.assign({chunkSize:16384,windowBits:47},t||{});var e=this.options;e.raw&&e.windowBits>0&&(e.windowBits=-e.windowBits),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new o;var a=s.inflateInit2(this.strm,e.windowBits);if(a!==l.Z_OK)throw new Error(h[a])};u.prototype.push=function(t,e){var a,n,r=this.strm,h=this.options.chunkSize;if(this.ended)return!1;n=e===~~e?e:e===!0?l.Z_FINISH:l.Z_NO_FLUSH,r.next_in=t,r.next_in_index=0,r.avail_in=r.next_in.length,r.next_out=_.arrayCreate(h);do{if(r.avail_out=this.options.chunkSize,r.next_out_index=0,a=s.inflate(r,n),a!==l.Z_STREAM_END&&a!==l.Z_OK)return this.onEnd(a),this.ended=!0,!1;r.next_out_index&&(this.onData(i(r.next_out,r.next_out_index)),(r.avail_in>0||0===r.avail_out)&&(r.next_out=_.arrayCreate(this.options.chunkSize)))}while(r.avail_in>0||0===r.avail_out);return n===l.Z_FINISH?(a=s.inflateEnd(this.strm),this.onEnd(a),this.ended=!0,a===l.Z_OK):!0},u.prototype.onData=function(t){this.chunks.push(t)},u.prototype.onEnd=function(t){t===l.Z_OK&&(this.result=_.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=h[t]},a.Inflate=u,a.inflate=n,a.inflateRaw=r},{"./zlib/constants":5,"./zlib/inflate.js":8,"./zlib/messages":9,"./zlib/utils":11,"./zlib/zstream":12}],4:[function(t,e){"use strict";function a(t,e,a,i){for(var n=65535&t,r=t>>>16&65535,s=0;0!==a;){s=a>5552?5552:a,a-=s;do n+=e[i++],r+=n;while(--s);n%=65521,r%=65521}return n|r<<16}e.exports=a},{}],5:[function(t,e){e.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],6:[function(t,e){"use strict";function a(){for(var t,e=[],a=0;256>a;a++){t=a;for(var i=0;8>i;i++)t=1&t?3988292384^t>>>1:t>>>1;e[a]=t}return e}function i(t,e,a,i){var r=n,s=i+a;t=-1^t;for(var _=i;s>_;_++)t=t>>>8^r[255&(t^e[_])];return-1^t}var n=a();e.exports=i},{}],7:[function(t,e,a){"use strict";function i(t){return(t<<1)-(t>4?9:0)}function n(t){for(var e=t.length;--e;)t[e]=0}function r(t){var e=t.state,a=e.pending;a>t.avail_out&&(a=t.avail_out),0!==a&&(S.arraySet(t.next_out,e.pending_buf,e.pending_out,a,t.next_out_index),t.next_out_index+=a,e.pending_out+=a,t.total_out+=a,t.avail_out-=a,e.pending-=a,0===e.pending&&(e.pending_out=0))}function s(t,e){Z._tr_flush_block(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,r(t.strm)}function _(t,e){t.pending_buf[t.pending++]=e}function l(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e}function h(t,e,a,i){var n=t.avail_in;return n>i&&(n=i),0===n?0:(t.avail_in-=n,S.arraySet(e,t.next_in,t.next_in_index,n,a),1===t.state.wrap?t.adler=A(t.adler,e,n,a):2===t.state.wrap&&(t.adler=R(t.adler,e,n,a)),t.next_in_index+=n,t.total_in+=n,n)}function o(t,e){var a,i,n=t.max_chain_length,r=t.strstart,s=t.prev_length,_=t.nice_match,l=t.strstart>t.w_size-se?t.strstart-(t.w_size-se):0,h=t.window,o=t.w_mask,u=t.prev,d=t.strstart+re,f=h[r+s-1],c=h[r+s];t.prev_length>=t.good_match&&(n>>=2),_>t.lookahead&&(_=t.lookahead);do if(a=e,h[a+s]===c&&h[a+s-1]===f&&h[a]===h[r]&&h[++a]===h[r+1]){r+=2,a++;do;while(h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&d>r);if(i=re-(d-r),r=d-re,i>s){if(t.match_start=e,s=i,i>=_)break;f=h[r+s-1],c=h[r+s]}}while((e=u[e&o])>l&&0!==--n);return s<=t.lookahead?s:t.lookahead}function u(t){var e,a,i,n,r,s=t.w_size;do{if(n=t.window_size-t.lookahead-t.strstart,t.strstart>=s+(s-se)){S.arraySet(t.window,t.window,s,s,0),t.match_start-=s,t.strstart-=s,t.block_start-=s,a=t.hash_size,e=a;do i=t.head[--e],t.head[e]=i>=s?i-s:0;while(--a);a=s,e=a;do i=t.prev[--e],t.prev[e]=i>=s?i-s:0;while(--a);n+=s}if(0===t.strm.avail_in)break;if(a=h(t.strm,t.window,t.strstart+t.lookahead,n),t.lookahead+=a,t.lookahead+t.insert>=ne)for(r=t.strstart-t.insert,t.ins_h=t.window[r],t.ins_h=(t.ins_h<t.pending_buf_size-5&&(a=t.pending_buf_size-5);;){if(t.lookahead<=1){if(u(t),0===t.lookahead&&e===O)return pe;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var i=t.block_start+a;if((0===t.strstart||t.strstart>=i)&&(t.lookahead=t.strstart-i,t.strstart=i,s(t,!1),0===t.strm.avail_out))return pe;if(t.strstart-t.block_start>=t.w_size-se&&(s(t,!1),0===t.strm.avail_out))return pe}return t.insert=0,e===N?(s(t,!0),0===t.strm.avail_out?be:ve):t.strstart>t.block_start&&(s(t,!1),0===t.strm.avail_out)?pe:pe}function f(t,e){for(var a,i;;){if(t.lookahead=ne&&(t.ins_h=(t.ins_h<=ne)if(i=Z._tr_tally(t,t.strstart-t.match_start,t.match_length-ne),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=ne){t.match_length--;do t.strstart++,t.ins_h=(t.ins_h<=ne&&(t.ins_h=(t.ins_h<4096)&&(t.match_length=ne-1)),t.prev_length>=ne&&t.match_length<=t.prev_length){n=t.strstart+t.lookahead-ne,i=Z._tr_tally(t,t.strstart-1-t.match_start,t.prev_length-ne),t.lookahead-=t.prev_length-1,t.prev_length-=2;do++t.strstart<=n&&(t.ins_h=(t.ins_h<=ne&&t.strstart>0&&(n=t.strstart-1,i=_[n],i===_[++n]&&i===_[++n]&&i===_[++n])){r=t.strstart+re;do;while(i===_[++n]&&i===_[++n]&&i===_[++n]&&i===_[++n]&&i===_[++n]&&i===_[++n]&&i===_[++n]&&i===_[++n]&&r>n);t.match_length=re-(r-n),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=ne?(a=Z._tr_tally(t,1,t.match_length-ne),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(a=Z._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),a&&(s(t,!1),0===t.strm.avail_out))return pe}return t.insert=0,e===N?(s(t,!0),0===t.strm.avail_out?be:ve):t.last_lit&&(s(t,!1),0===t.strm.avail_out)?pe:we}function w(t,e){for(var a;;){if(0===t.lookahead&&(u(t),0===t.lookahead)){if(e===O)return pe;break}if(t.match_length=0,a=Z._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,a&&(s(t,!1),0===t.strm.avail_out))return pe}return t.insert=0,e===N?(s(t,!0),0===t.strm.avail_out?be:ve):t.last_lit&&(s(t,!1),0===t.strm.avail_out)?pe:we}function b(t){t.window_size=2*t.w_size,n(t.head),t.max_lazy_match=E[t.level].max_lazy,t.good_match=E[t.level].good_length,t.nice_match=E[t.level].nice_length,t.max_chain_length=E[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=ne-1,t.match_available=0,t.ins_h=0}function v(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Y,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=S.array16Create(2*ae),this.dyn_dtree=S.array16Create(2*(2*te+1)),this.bl_tree=S.array16Create(2*(2*ee+1)),n(this.dyn_ltree),n(this.dyn_dtree),n(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=S.array16Create(ie+1),this.heap=S.array16Create(2*$+1),n(this.heap),this.heap_len=0,this.heap_max=0,this.depth=S.array16Create(2*$+1),n(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0,this.high_water=0}function m(t){var e;return t&&t.state?(t.total_in=t.total_out=0,t.data_type=G,e=t.state,e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?le:fe,t.adler=2===e.wrap?0:1,e.last_flush=O,Z._tr_init(e),D):F}function g(t){var e=m(t);return e===D&&b(t.state),e}function y(t,e,a,i,n,r){if(!t)return F;var s=1;if(e===H&&(e=6),0>i?(s=0,i=-i):i>15&&(s=2,i-=16),1>n||n>X||a!==Y||8>i||i>15||0>e||e>9||0>r||r>K)return F;8===i&&(i=9);var _=new v;return t.state=_,_.strm=t,_.wrap=s,_.gzhead=null,_.w_bits=i,_.w_size=1<<_.w_bits,_.w_mask=_.w_size-1,_.hash_bits=n+7,_.hash_size=1<<_.hash_bits,_.hash_mask=_.hash_size-1,_.hash_shift=~~((_.hash_bits+ne-1)/ne),_.window=S.arrayCreate(2*_.w_size),_.head=S.array16Create(_.hash_size),_.prev=S.array16Create(_.w_size),_.high_water=0,_.lit_bufsize=1<>1,_.l_buf=3*_.lit_bufsize,_.level=e,_.strategy=r,_.method=a,g(t)}function k(t,e){return y(t,e,Y,V,W,q)}function x(t,e){var a,s;if(!t||!t.state||e>U||0>e)return F;if(s=t.state,!t.next_out||!t.next_in&&0!==t.avail_in||s.status===ce&&e!==N)return 0===t.avail_out?L:F;if(s.strm=t,a=s.last_flush,s.last_flush=e,s.status===le)if(2===s.wrap){if(t.adler=0,_(s,31),_(s,139),_(s,8),s.gzhead)throw new Error("Custom GZIP headers not supported");_(s,0),_(s,0),_(s,0),_(s,0),_(s,0),_(s,9===s.level?2:s.strategy>=j||s.level<2?4:0),_(s,me),s.status=fe}else{var h=Y+(s.w_bits-8<<4)<<8,o=-1;o=s.strategy>=j||s.level<2?0:s.level<6?1:6===s.level?2:3,h|=o<<6,0!==s.strstart&&(h|=_e),h+=31-h%31,s.status=fe,l(s,h),0!==s.strstart&&(l(s,t.adler>>>16),l(s,65535&t.adler)),t.adler=1}if(0!==s.pending){if(r(t),0===t.avail_out)return s.last_flush=-1,D}else if(0===t.avail_in&&i(e)<=i(a)&&e!==N)return L;if(s.status===ce&&0!==t.avail_in)return L;if(0!==t.avail_in||0!==s.lookahead||e!==O&&s.status!==ce){var u=s.strategy===j?w(s,e):s.strategy===P?p(s,e):E[s.level].func(s,e);if((u===be||u===ve)&&(s.status=ce),u===pe||u===be)return 0===t.avail_out&&(s.last_flush=-1),D;if(u===we&&(e===C?Z._tr_align(s):e!==U&&(Z._tr_stored_block(s,0,0,!1),e===I&&(n(s.head),0===s.lookahead&&(s.strstart=0,s.block_start=0,s.insert=0))),r(t),0===t.avail_out))return s.last_flush=-1,D}return e!==N?D:s.wrap<=0?B:(2===s.wrap?(_(s,255&t.adler),_(s,t.adler>>8&255),_(s,t.adler>>16&255),_(s,t.adler>>24&255),_(s,255&t.total_in),_(s,t.total_in>>8&255),_(s,t.total_in>>16&255),_(s,t.total_in>>24&255)):(l(s,t.adler>>>16),l(s,65535&t.adler)),r(t),s.wrap>0&&(s.wrap=-s.wrap),0!==s.pending?D:B)}function z(t){var e=t.state.status;return e!==le&&e!==he&&e!==oe&&e!==ue&&e!==de&&e!==fe&&e!==ce?F:(t.state=null,e===fe?T:D)}var E,S=t("./utils"),Z=t("./trees"),A=t("./adler32"),R=t("./crc32"),O=0,C=1,I=3,N=4,U=5,D=0,B=1,F=-2,T=-3,L=-5,H=-1,M=1,j=2,P=3,K=4,q=0,G=2,Y=8,X=9,V=15,W=8,J=29,Q=256,$=Q+1+J,te=30,ee=19,ae=2*$+1,ie=15,ne=3,re=258,se=re+ne+1,_e=32,le=42,he=69,oe=73,ue=91,de=103,fe=113,ce=666,pe=1,we=2,be=3,ve=4,me=3,ge=function(t,e,a,i,n){this.good_length=t,this.max_lazy=e,this.nice_length=a,this.max_chain=i,this.func=n};E=[new ge(0,0,0,0,d),new ge(4,4,8,4,f),new ge(4,5,16,8,f),new ge(4,6,32,32,f),new ge(4,4,16,16,c),new ge(8,16,32,32,c),new ge(8,16,128,128,c),new ge(8,32,128,256,c),new ge(32,128,258,1024,c),new ge(32,258,258,4096,c)],a.deflateInit=k,a.deflateInit2=y,a.deflateReset=g,a.deflate=x,a.deflateEnd=z,a.deflate_info="pako deflate"},{"./adler32":4,"./crc32":6,"./trees":10,"./utils":11}],8:[function(t,e,a){"use strict";function i(){this.mode=-1,this.last=0,this.wrap=0,this.havedict=0,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=0,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=-1,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=-1,this.distcode=-1,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=0,this.lens=new Array(320),this.work=new Array(280),this.codes=new Array(k),this.sane=0,this.back=0,this.was=0}function n(){}function r(){}function s(){}function _(t){t.state=new i}function l(){}function h(){}function o(){}function u(){}function d(){}function f(){}function c(){}function p(){}function w(){}function b(){}function v(){}function m(){}var g=852,y=592,k=g+y;a.inflateResetKeep=n,a.inflateReset=r,a.inflateReset2=s,a.inflateInit2=_,a.inflateInit=l,a.inflatePrime=h,a.inflate=o,a.inflateEnd=u,a.inflateGetDictionary=d,a.inflateGetHeader=c,a.inflateSetDictionary=f,a.inflateSync=p,a.inflateSyncPoint=w,a.inflateCopy=b,a.inflateUndermine=v,a.inflateMark=m},{}],9:[function(t,e){"use strict";e.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],10:[function(t,e,a){"use strict";function i(t){for(var e=t.length;--e;)t[e]=0}function n(t){return 256>t?se[t]:se[256+(t>>>7)]}function r(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255}function s(t,e,a){t.bi_valid>Y-a?(t.bi_buf|=e<>Y-t.bi_valid,t.bi_valid+=a-Y):(t.bi_buf|=e<>>=1,a<<=1;while(--e>0);return a>>>1}function h(t){16===t.bi_valid?(r(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}function o(t,e){var a,i,n,r,s,_,l=e.dyn_tree,h=e.max_code,o=e.stat_desc.static_tree,u=e.stat_desc.has_stree,d=e.stat_desc.extra_bits,f=e.stat_desc.extra_base,c=e.stat_desc.max_length,p=0;for(r=0;G>=r;r++)t.bl_count[r]=0;for(l[2*t.heap[t.heap_max]+1]=0,a=t.heap_max+1;q>a;a++)i=t.heap[a],r=l[2*l[2*i+1]+1]+1,r>c&&(r=c,p++),l[2*i+1]=r,i>h||(t.bl_count[r]++,s=0,i>=f&&(s=d[i-f]),_=l[2*i],t.opt_len+=_*(r+s),u&&(t.static_len+=_*(o[2*i+1]+s)));if(0!==p){do{for(r=c-1;0===t.bl_count[r];)r--;t.bl_count[r]--,t.bl_count[r+1]+=2,t.bl_count[c]--,p-=2}while(p>0);for(r=c;0!==r;r--)for(i=t.bl_count[r];0!==i;)n=t.heap[--a],n>h||(l[2*n+1]!==r&&(t.opt_len+=(r-l[2*n+1])*l[2*n],l[2*n+1]=r),i--)}}function u(t,e,a){var i,n,r=new Array(G+1),s=0;for(i=1;G>=i;i++)r[i]=s=s+a[i-1]<<1;for(n=0;e>=n;n++){var _=t[2*n+1];0!==_&&(t[2*n]=l(r[_]++,_))}}function d(){var t,e,a,i,n,r=new Array(G+1);for(a=0,i=0;H-1>i;i++)for(le[i]=a,t=0;t<1<<$[i];t++)_e[a++]=i;for(_e[a-1]=i,n=0,i=0;16>i;i++)for(he[i]=n,t=0;t<1<>=7;P>i;i++)for(he[i]=n<<7,t=0;t<1<=e;e++)r[e]=0;for(t=0;143>=t;)ne[2*t+1]=8,t++,r[8]++;for(;255>=t;)ne[2*t+1]=9,t++,r[9]++;for(;279>=t;)ne[2*t+1]=7,t++,r[7]++;for(;287>=t;)ne[2*t+1]=8,t++,r[8]++;for(u(ne,j+1,r),t=0;P>t;t++)re[2*t+1]=5,re[2*t]=l(t,5);oe=new fe(ne,$,M+1,j,G),ue=new fe(re,te,0,P,G),de=new fe(new Array(0),ee,0,K,X)}function f(t){var e;for(e=0;j>e;e++)t.dyn_ltree[2*e]=0;for(e=0;P>e;e++)t.dyn_dtree[2*e]=0;for(e=0;K>e;e++)t.bl_tree[2*e]=0;t.dyn_ltree[2*V]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0}function c(t){t.bi_valid>8?r(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0}function p(t,e,a,i){c(t),i&&(r(t,a),r(t,~a)),O.arraySet(t.pending_buf,t.window,e,a,t.pending),t.pending+=a}function w(t,e,a,i){var n=2*e,r=2*a;return t[n]a;a++)0!==r[2*a]?(t.heap[++t.heap_len]=h=a,t.depth[a]=0):r[2*a+1]=0;for(;t.heap_len<2;)n=t.heap[++t.heap_len]=2>h?++h:0,r[2*n]=1,t.depth[n]=0,t.opt_len--,_&&(t.static_len-=s[2*n+1]);for(e.max_code=h,a=t.heap_len>>1;a>=1;a--)b(t,r,a);n=l;do a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],b(t,r,1),i=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=i,r[2*n]=r[2*a]+r[2*i],t.depth[n]=(t.depth[a]>=t.depth[i]?t.depth[a]:t.depth[i])+1,r[2*a+1]=r[2*i+1]=n,t.heap[1]=n++,b(t,r,1);while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],o(t,e),u(r,h,t.bl_count)}function g(t,e,a){var i,n,r=-1,s=e[1],_=0,l=7,h=4;for(0===s&&(l=138,h=3),e[2*(a+1)+1]=65535,i=0;a>=i;i++)n=s,s=e[2*(i+1)+1],++__?t.bl_tree[2*n]+=_:0!==n?(n!==r&&t.bl_tree[2*n]++,t.bl_tree[2*W]++):10>=_?t.bl_tree[2*J]++:t.bl_tree[2*Q]++,_=0,r=n,0===s?(l=138,h=3):n===s?(l=6,h=3):(l=7,h=4))}function y(t,e,a){var i,n,r=-1,l=e[1],h=0,o=7,u=4;for(0===l&&(o=138,u=3),i=0;a>=i;i++)if(n=l,l=e[2*(i+1)+1],!(++hh){do _(t,n,t.bl_tree);while(0!==--h)}else 0!==n?(n!==r&&(_(t,n,t.bl_tree),h--),_(t,W,t.bl_tree),s(t,h-3,2)):10>=h?(_(t,J,t.bl_tree),s(t,h-3,3)):(_(t,Q,t.bl_tree),s(t,h-11,7));h=0,r=n,0===l?(o=138,u=3):n===l?(o=6,u=3):(o=7,u=4)}}function k(t){var e;for(g(t,t.dyn_ltree,t.l_desc.max_code),g(t,t.dyn_dtree,t.d_desc.max_code),m(t,t.bl_desc),e=K-1;e>=3&&0===t.bl_tree[2*ae[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}function x(t,e,a,i){var n;for(s(t,e-257,5),s(t,a-1,5),s(t,i-4,4),n=0;i>n;n++)s(t,t.bl_tree[2*ae[n]+1],3);y(t,t.dyn_ltree,e-1),y(t,t.dyn_dtree,a-1)}function z(t){var e,a=4093624447;for(e=0;31>=e;e++,a>>>=1)if(1&a&&0!==t.dyn_ltree[2*e])return I;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return N;for(e=32;M>e;e++)if(0!==t.dyn_ltree[2*e])return N;return I}function E(t){pe||(d(),pe=!0),t.l_desc=new ce(t.dyn_ltree,oe),t.d_desc=new ce(t.dyn_dtree,ue),t.bl_desc=new ce(t.bl_tree,de),t.bi_buf=0,t.bi_valid=0,f(t)}function S(t,e,a,i){s(t,(D<<1)+(i?1:0),3),p(t,e,a,!0)}function Z(t){s(t,B<<1,3),_(t,V,ne),h(t)}function A(t,e,a,i){var n,r,_=0;t.level>0?(t.strm.data_type===U&&(t.strm.data_type=z(t)),m(t,t.l_desc),m(t,t.d_desc),_=k(t),n=t.opt_len+3+7>>>3,r=t.static_len+3+7>>>3,n>=r&&(n=r)):n=r=a+5,n>=a+4&&-1!==e?S(t,e,a,i):t.strategy===C||r===n?(s(t,(B<<1)+(i?1:0),3),v(t,ne,re)):(s(t,(F<<1)+(i?1:0),3),x(t,t.l_desc.max_code+1,t.d_desc.max_code+1,_+1),v(t,t.dyn_ltree,t.dyn_dtree)),f(t),i&&c(t)}function R(t,e,a){var i,r,s;if(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&a,t.last_lit++,0===e?t.dyn_ltree[2*a]++:(t.matches++,e--,t.dyn_ltree[2*(_e[a]+M+1)]++,t.dyn_dtree[2*n(e)]++),0===(8191&t.last_lit)&&t.level>2){for(i=8*t.last_lit,r=t.strstart-t.block_start,s=0;P>s;s++)i+=t.dyn_dtree[2*s]*(5+te[s]);if(i>>>=3,t.matches>1&&r>>1>i)return!0}return t.last_lit===t.lit_bufsize-1}var O=t("./utils"),C=4,I=0,N=1,U=2,D=0,B=1,F=2,T=3,L=258,H=29,M=256,j=M+1+H,P=30,K=19,q=2*j+1,G=15,Y=16,X=7,V=256,W=16,J=17,Q=18,$=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],te=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],ee=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],ae=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],ie=512,ne=new Array(2*(j+2));i(ne);var re=new Array(2*P);i(re);var se=new Array(ie);i(se);var _e=new Array(L-T+1);i(_e);var le=new Array(H);i(le);var he=new Array(P);i(he);var oe,ue,de,fe=function(t,e,a,i,n){this.static_tree=t,this.extra_bits=e,this.extra_base=a,this.elems=i,this.max_length=n,this.has_stree=t&&t.length},ce=function(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e},pe=!1;a._tr_init=E,a._tr_stored_block=S,a._tr_flush_block=A,a._tr_tally=R,a._tr_align=Z},{"./utils":11}],11:[function(t,e,a){"use strict";function i(){return n&&!a.forceUntyped}var n="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,r=Function.prototype.call.bind(Object.prototype.toString),s=Array.isArray||function(t){return"[object Array]"===r(t)};a.forceUntyped=!1,a.typedOk=i,a.assign=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var a=e.shift();if(a){if("object"!=typeof a)throw new TypeError(a+"must be non-object");for(var i in a)a.hasOwnProperty(i)&&(t[i]=a[i])}}return t},a.arraySet=function(t,e,a,n,r){if(i()&&!s(e))return void t.set(e.subarray(a,a+n),r);for(var _=0;n>_;_++)t[r+_]=e[a+_]},a.arrayCreate=function(t){return i()?new Uint8Array(t):new Array(t)},a.array16Create=function(t){return i()?new Uint16Array(t):new Array(t)},a.flattenChunks=function(t){var e,a,n,r,s,_;if(i()){for(n=0,e=0,a=t.length;a>e;e++)n+=t[e].length;for(_=new Uint8Array(n),r=0,e=0,a=t.length;a>e;e++)s=t[e],_.set(s,r),r+=s.length;return _}return[].concat.apply([],t)}},{}],12:[function(t,e){"use strict";function a(){this.next_in=null,this.avail_in=0,this.total_in=0,this.next_out=null,this.avail_out=0,this.total_out=0,this.state=null,this.data_type=2,this.adler=0}e.exports=a},{}]},{},[1])(1)}); \ No newline at end of file +!function(t){if("object"==typeof exports)module.exports=t();else if("function"==typeof define&&define.amd)define(t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.pako=t()}}(function(){return function t(e,a,i){function n(r,o){if(!a[r]){if(!e[r]){var l="function"==typeof require&&require;if(!o&&l)return l(r,!0);if(s)return s(r,!0);throw new Error("Cannot find module '"+r+"'")}var h=a[r]={exports:{}};e[r][0].call(h.exports,function(t){var a=e[r][1][t];return n(a?a:t)},h,h.exports,t,e,a,i)}return a[r].exports}for(var s="function"==typeof require&&require,r=0;r0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new h;var a=r.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(a!==f)throw new Error(l[a])};m.prototype.push=function(t,e){var a,i,n=this.strm,s=this.options.chunkSize;if(this.ended)return!1;i=e===~~e?e:e===!0?_:d,n.next_in=t,n.next_in_index=0,n.avail_in=n.next_in.length,n.next_out=new o.Buf8(s);do{if(n.avail_out=this.options.chunkSize,n.next_out_index=0,a=r.deflate(n,i),a!==u&&a!==f)return this.onEnd(a),this.ended=!0,!1;n.next_out_index&&(this.onData(o.shrinkBuf(n.next_out,n.next_out_index)),(n.avail_in>0||0===n.avail_out)&&(n.next_out=new o.Buf8(this.options.chunkSize)))}while(n.avail_in>0||0===n.avail_out);return i===_?(a=r.deflateEnd(this.strm),this.onEnd(a),this.ended=!0,a===f):!0},m.prototype.onData=function(t){this.chunks.push(t)},m.prototype.onEnd=function(t){t===f&&(this.result=o.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},a.Deflate=m,a.deflate=i,a.deflateRaw=n,a.gzip=s},{"./zlib/deflate.js":7,"./zlib/messages":11,"./zlib/utils":13,"./zlib/zstream":14}],3:[function(t,e,a){"use strict";function i(t,e){var a=new d(e);if(a.push(t,!0),a.err)throw a.msg;return a.result}function n(t,e){return e=e||{},e.raw=!0,i(t,e)}var s=t("./zlib/inflate.js"),r=t("./zlib/utils"),o=t("./zlib/constants"),l=t("./zlib/messages"),h=t("./zlib/zstream"),d=function(t){this.options=r.assign({chunkSize:16384,windowBits:0},t||{});var e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0===(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new h;var a=s.inflateInit2(this.strm,e.windowBits);if(a!==o.Z_OK)throw new Error(l[a])};d.prototype.push=function(t,e){var a,i,n=this.strm,l=this.options.chunkSize;if(this.ended)return!1;i=o.Z_NO_FLUSH,n.next_in=t,n.next_in_index=0,n.avail_in=n.next_in.length,n.next_out=new r.Buf8(l);do{if(n.avail_out=this.options.chunkSize,n.next_out_index=0,a=s.inflate(n,i),a!==o.Z_STREAM_END&&a!==o.Z_OK)return this.onEnd(a),this.ended=!0,!1;n.next_out_index&&(this.onData(r.shrinkBuf(n.next_out,n.next_out_index)),(n.avail_in>0||0===n.avail_out)&&(n.next_out=new r.Buf8(this.options.chunkSize)))}while(n.avail_in>0||0===n.avail_out);return i=e===~~e?e:e===!0?o.Z_FINISH:o.Z_NO_FLUSH,i===o.Z_FINISH?(a=s.inflateEnd(this.strm),this.onEnd(a),this.ended=!0,a===o.Z_OK):!0},d.prototype.onData=function(t){this.chunks.push(t)},d.prototype.onEnd=function(t){t===o.Z_OK&&(this.result=r.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},a.Inflate=d,a.inflate=i,a.inflateRaw=n},{"./zlib/constants":5,"./zlib/inflate.js":9,"./zlib/messages":11,"./zlib/utils":13,"./zlib/zstream":14}],4:[function(t,e){"use strict";function a(t,e,a,i){for(var n=65535&t|0,s=t>>>16&65535|0,r=0;0!==a;){r=a>2e3?2e3:a,a-=r;do n=n+e[i++]|0,s=s+n|0;while(--r);n%=65521,s%=65521}return n|s<<16|0}e.exports=a},{}],5:[function(t,e){e.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],6:[function(t,e){"use strict";function a(){for(var t,e=[],a=0;256>a;a++){t=a;for(var i=0;8>i;i++)t=1&t?3988292384^t>>>1:t>>>1;e[a]=t}return e}function i(t,e,a,i){var s=n,r=i+a;t=-1^t;for(var o=i;r>o;o++)t=t>>>8^s[255&(t^e[o])];return-1^t}var n=a();e.exports=i},{}],7:[function(t,e,a){"use strict";function i(t,e){return t.msg=I[e],e}function n(t){return(t<<1)-(t>4?9:0)}function s(t){for(var e=t.length;--e;)t[e]=0}function r(t){var e=t.state,a=e.pending;a>t.avail_out&&(a=t.avail_out),0!==a&&(S.arraySet(t.next_out,e.pending_buf,e.pending_out,a,t.next_out_index),t.next_out_index+=a,e.pending_out+=a,t.total_out+=a,t.avail_out-=a,e.pending-=a,0===e.pending&&(e.pending_out=0))}function o(t,e){Z._tr_flush_block(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,r(t.strm)}function l(t,e){t.pending_buf[t.pending++]=e}function h(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e}function d(t,e,a,i){var n=t.avail_in;return n>i&&(n=i),0===n?0:(t.avail_in-=n,S.arraySet(e,t.next_in,t.next_in_index,n,a),1===t.state.wrap?t.adler=A(t.adler,e,n,a):2===t.state.wrap&&(t.adler=R(t.adler,e,n,a)),t.next_in_index+=n,t.total_in+=n,n)}function _(t,e){var a,i,n=t.max_chain_length,s=t.strstart,r=t.prev_length,o=t.nice_match,l=t.strstart>t.w_size-le?t.strstart-(t.w_size-le):0,h=t.window,d=t.w_mask,_=t.prev,f=t.strstart+oe,u=h[s+r-1],c=h[s+r];t.prev_length>=t.good_match&&(n>>=2),o>t.lookahead&&(o=t.lookahead);do if(a=e,h[a+r]===c&&h[a+r-1]===u&&h[a]===h[s]&&h[++a]===h[s+1]){s+=2,a++;do;while(h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&h[++s]===h[++a]&&f>s);if(i=oe-(f-s),s=f-oe,i>r){if(t.match_start=e,r=i,i>=o)break;u=h[s+r-1],c=h[s+r]}}while((e=_[e&d])>l&&0!==--n);return r<=t.lookahead?r:t.lookahead}function f(t){var e,a,i,n,s,r=t.w_size;do{if(n=t.window_size-t.lookahead-t.strstart,t.strstart>=r+(r-le)){S.arraySet(t.window,t.window,r,r,0),t.match_start-=r,t.strstart-=r,t.block_start-=r,a=t.hash_size,e=a;do i=t.head[--e],t.head[e]=i>=r?i-r:0;while(--a);a=r,e=a;do i=t.prev[--e],t.prev[e]=i>=r?i-r:0;while(--a);n+=r}if(0===t.strm.avail_in)break;if(a=d(t.strm,t.window,t.strstart+t.lookahead,n),t.lookahead+=a,t.lookahead+t.insert>=re)for(s=t.strstart-t.insert,t.ins_h=t.window[s],t.ins_h=(t.ins_h<t.pending_buf_size-5&&(a=t.pending_buf_size-5);;){if(t.lookahead<=1){if(f(t),0===t.lookahead&&e===N)return me;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var i=t.block_start+a;if((0===t.strstart||t.strstart>=i)&&(t.lookahead=t.strstart-i,t.strstart=i,o(t,!1),0===t.strm.avail_out))return me;if(t.strstart-t.block_start>=t.w_size-le&&(o(t,!1),0===t.strm.avail_out))return me}return t.insert=0,e===F?(o(t,!0),0===t.strm.avail_out?ke:ge):t.strstart>t.block_start&&(o(t,!1),0===t.strm.avail_out)?me:me}function c(t,e){for(var a,i;;){if(t.lookahead=re&&(t.ins_h=(t.ins_h<=re)if(i=Z._tr_tally(t,t.strstart-t.match_start,t.match_length-re),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=re){t.match_length--;do t.strstart++,t.ins_h=(t.ins_h<=re&&(t.ins_h=(t.ins_h<4096)&&(t.match_length=re-1)),t.prev_length>=re&&t.match_length<=t.prev_length){n=t.strstart+t.lookahead-re,i=Z._tr_tally(t,t.strstart-1-t.match_start,t.prev_length-re),t.lookahead-=t.prev_length-1,t.prev_length-=2;do++t.strstart<=n&&(t.ins_h=(t.ins_h<=re&&t.strstart>0&&(n=t.strstart-1,i=r[n],i===r[++n]&&i===r[++n]&&i===r[++n])){s=t.strstart+oe;do;while(i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&s>n);t.match_length=oe-(s-n),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=re?(a=Z._tr_tally(t,1,t.match_length-re),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(a=Z._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),a&&(o(t,!1),0===t.strm.avail_out))return me}return t.insert=0,e===F?(o(t,!0),0===t.strm.avail_out?ke:ge):t.last_lit&&(o(t,!1),0===t.strm.avail_out)?me:ve}function m(t,e){for(var a;;){if(0===t.lookahead&&(f(t),0===t.lookahead)){if(e===N)return me;break}if(t.match_length=0,a=Z._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,a&&(o(t,!1),0===t.strm.avail_out))return me}return t.insert=0,e===F?(o(t,!0),0===t.strm.avail_out?ke:ge):t.last_lit&&(o(t,!1),0===t.strm.avail_out)?me:ve}function v(t){t.window_size=2*t.w_size,s(t.head),t.max_lazy_match=E[t.level].max_lazy,t.good_match=E[t.level].good_length,t.nice_match=E[t.level].nice_length,t.max_chain_length=E[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=re-1,t.match_available=0,t.ins_h=0}function k(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=W,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new S.Buf16(2*ne),this.dyn_dtree=new S.Buf16(2*(2*ae+1)),this.bl_tree=new S.Buf16(2*(2*ie+1)),s(this.dyn_ltree),s(this.dyn_dtree),s(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new S.Buf16(se+1),this.heap=new S.Buf16(2*ee+1),s(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new S.Buf16(2*ee+1),s(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0,this.high_water=0}function g(t){var e;return t&&t.state?(t.total_in=t.total_out=0,t.data_type=X,e=t.state,e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?de:we,t.adler=2===e.wrap?0:1,e.last_flush=N,Z._tr_init(e),D):i(t,C)}function p(t){var e=g(t);return e===D&&v(t.state),e}function x(t,e,a,n,s,r){if(!t)return i(t,C);var o=1;if(e===K&&(e=6),0>n?(o=0,n=-n):n>15&&(o=2,n-=16),1>s||s>J||a!==W||8>n||n>15||0>e||e>9||0>r||r>Y)return i(t,C);8===n&&(n=9);var l=new k;return t.state=l,l.strm=t,l.wrap=o,l.gzhead=null,l.w_bits=n,l.w_size=1<>1,l.l_buf=3*l.lit_bufsize,l.level=e,l.strategy=r,l.method=a,p(t)}function y(t,e){return x(t,e,W,Q,V,G)}function z(t,e){var a,o;if(!t||!t.state||e>L||0>e)return i(t,C);if(o=t.state,!t.next_out||!t.next_in&&0!==t.avail_in||o.status===be&&e!==F)return i(t,0===t.avail_out?j:C);if(o.strm=t,a=o.last_flush,o.last_flush=e,o.status===de)if(2===o.wrap){if(t.adler=0,l(o,31),l(o,139),l(o,8),o.gzhead)throw new Error("Custom GZIP headers not supported");l(o,0),l(o,0),l(o,0),l(o,0),l(o,0),l(o,9===o.level?2:o.strategy>=M||o.level<2?4:0),l(o,pe),o.status=we}else{var d=W+(o.w_bits-8<<4)<<8,_=-1;_=o.strategy>=M||o.level<2?0:o.level<6?1:6===o.level?2:3,d|=_<<6,0!==o.strstart&&(d|=he),d+=31-d%31,o.status=we,h(o,d),0!==o.strstart&&(h(o,t.adler>>>16),h(o,65535&t.adler)),t.adler=1}if(0!==o.pending){if(r(t),0===t.avail_out)return o.last_flush=-1,D}else if(0===t.avail_in&&n(e)<=n(a)&&e!==F)return i(t,j);if(o.status===be&&0!==t.avail_in)return i(t,j);if(0!==t.avail_in||0!==o.lookahead||e!==N&&o.status!==be){var f=o.strategy===M?m(o,e):o.strategy===q?b(o,e):E[o.level].func(o,e);if((f===ke||f===ge)&&(o.status=be),f===me||f===ke)return 0===t.avail_out&&(o.last_flush=-1),D;if(f===ve&&(e===O?Z._tr_align(o):e!==L&&(Z._tr_stored_block(o,0,0,!1),e===T&&(s(o.head),0===o.lookahead&&(o.strstart=0,o.block_start=0,o.insert=0))),r(t),0===t.avail_out))return o.last_flush=-1,D}return e!==F?D:o.wrap<=0?U:(2===o.wrap?(l(o,255&t.adler),l(o,t.adler>>8&255),l(o,t.adler>>16&255),l(o,t.adler>>24&255),l(o,255&t.total_in),l(o,t.total_in>>8&255),l(o,t.total_in>>16&255),l(o,t.total_in>>24&255)):(h(o,t.adler>>>16),h(o,65535&t.adler)),r(t),o.wrap>0&&(o.wrap=-o.wrap),0!==o.pending?D:U)}function B(t){var e=t.state.status;return e!==de&&e!==_e&&e!==fe&&e!==ue&&e!==ce&&e!==we&&e!==be?i(t,C):(t.state=null,e===we?i(t,H):D)}var E,S=t("./utils"),Z=t("./trees"),A=t("./adler32"),R=t("./crc32"),I=t("./messages"),N=0,O=1,T=3,F=4,L=5,D=0,U=1,C=-2,H=-3,j=-5,K=-1,P=1,M=2,q=3,Y=4,G=0,X=2,W=8,J=9,Q=15,V=8,$=29,te=256,ee=te+1+$,ae=30,ie=19,ne=2*ee+1,se=15,re=3,oe=258,le=oe+re+1,he=32,de=42,_e=69,fe=73,ue=91,ce=103,we=113,be=666,me=1,ve=2,ke=3,ge=4,pe=3,xe=function(t,e,a,i,n){this.good_length=t,this.max_lazy=e,this.nice_length=a,this.max_chain=i,this.func=n};E=[new xe(0,0,0,0,u),new xe(4,4,8,4,c),new xe(4,5,16,8,c),new xe(4,6,32,32,c),new xe(4,4,16,16,w),new xe(8,16,32,32,w),new xe(8,16,128,128,w),new xe(8,32,128,256,w),new xe(32,128,258,1024,w),new xe(32,258,258,4096,w)],a.deflateInit=y,a.deflateInit2=x,a.deflateReset=p,a.deflate=z,a.deflateEnd=B,a.deflateInfo="pako deflate (from Nodeca project)"},{"./adler32":4,"./crc32":6,"./messages":11,"./trees":12,"./utils":13}],8:[function(t,e){"use strict";var a=30,i=12;e.exports=function(t,e){var n,s,r,o,l,h,d,_,f,u,c,w,b,m,v,k,g,p,x,y,z,B,E,S,Z;n=t.state,s=t.next_in_index,S=t.next_in,r=s+(t.avail_in-5),o=t.next_out_index,Z=t.next_out,l=o-(e-t.avail_out),h=o+(t.avail_out-257),d=n.dmax,_=n.wsize,f=n.whave,u=n.wnext,c=n.window,w=n.hold,b=n.bits,m=n.lencode,v=n.distcode,k=(1<b&&(w+=S[s++]<>>24,w>>>=x,b-=x,x=p>>>16&255,0===x)Z[o++]=65535&p;else{if(!(16&x)){if(0===(64&x)){p=m[(65535&p)+(w&(1<b&&(w+=S[s++]<>>=x,b-=x),15>b&&(w+=S[s++]<>>24,w>>>=x,b-=x,x=p>>>16&255,!(16&x)){if(0===(64&x)){p=v[(65535&p)+(w&(1<b&&(w+=S[s++]<b&&(w+=S[s++]<d){t.msg="invalid distance too far back",n.mode=a;break t}if(w>>>=x,b-=x,x=o-l,z>x){if(x=z-x,x>f&&n.sane){t.msg="invalid distance too far back",n.mode=a;break t}if(B=0,E=c,0===u){if(B+=_-x,y>x){y-=x;do Z[o++]=c[B++];while(--x);B=o-z,E=Z}}else if(x>u){if(B+=_+u-x,x-=u,y>x){y-=x;do Z[o++]=c[B++];while(--x);if(B=0,y>u){x=u,y-=x;do Z[o++]=c[B++];while(--x);B=o-z,E=Z}}}else if(B+=u-x,y>x){y-=x;do Z[o++]=c[B++];while(--x);B=o-z,E=Z}for(;y>2;)Z[o++]=E[B++],Z[o++]=E[B++],Z[o++]=E[B++],y-=3;y&&(Z[o++]=E[B++],y>1&&(Z[o++]=E[B++]))}else{B=o-z;do Z[o++]=Z[B++],Z[o++]=Z[B++],Z[o++]=Z[B++],y-=3;while(y>2);y&&(Z[o++]=Z[B++],y>1&&(Z[o++]=Z[B++]))}break}}break}}while(r>s&&h>o);y=b>>3,s-=y,b-=y<<3,w&=(1<s?5+(r-s):5-(s-r),t.avail_out=h>o?257+(h-o):257-(o-h),n.hold=w,n.bits=b}},{}],9:[function(t,e,a){"use strict";function i(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)}function n(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.next_index=0,this.lens=new v.Buf16(320),this.work=new v.Buf16(280),this.codes=new v.Buf32(me),this.sane=0,this.back=0,this.was=0}function s(t,e,a,i,n,s,r,o){this.type=t,this.lens=e,this.lens_index=a,this.codes=i,this.table=n,this.table_index=s,this.bits=r,this.work=o}function r(t){var e;return t&&t.state?(e=t.state,t.total_in=t.total_out=e.total=0,e.wrap&&(t.adler=1&e.wrap),e.mode=D,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=new v.Buf32(me),e.distcode=new v.Buf32(me),e.sane=1,e.back=-1,A):N}function o(t){var e;return t&&t.state?(e=t.state,e.wsize=0,e.whave=0,e.wnext=0,r(t)):N}function l(t,e){var a,i;return t&&t.state?(i=t.state,0>e?(a=0,e=-e):(a=(e>>4)+1,48>e&&(e&=15)),e&&(8>e||e>15)?N:(null!==i.window&&i.wbits!==e&&(i.window=null),i.wrap=a,i.wbits=e,o(t))):N}function h(t,e){var a,i;return t?(i=new n,t.state=i,i.window=null,a=l(t,e),a!==A&&(t.state=null),a):N}function d(t){return h(t,ke)}function _(t,e,a){var i;return t&&t.state?(i=t.state,0>e?(i.hold=0,i.bits=0,A):e>16||i.bits+e>32?N:(a&=(1<e;)t.lens[e++]=8;for(;256>e;)t.lens[e++]=9;for(;280>e;)t.lens[e++]=7;for(;288>e;)t.lens[e++]=8;for(a=9,x(new s(z,t.lens,0,288,b,0,a,t.work)),e=0;32>e;)t.lens[e++]=5;a=5,x(new s(B,t.lens,0,32,m,0,a,t.work)),ge=!1}t.lencode=b,t.lenbits=9,t.distcode=m,t.distbits=5}function u(t,e,a,i){var n,s=t.state;return null===s.window&&(s.wsize=1<=s.wsize?(v.arraySet(s.window,e,a-s.wsize,s.wsize,0),s.wnext=0,s.whave=s.wsize):(n=s.wsize-s.wnext,n>i&&(n=i),v.arraySet(s.window,e,a-i,n,s.wnext),i-=n,i?(v.arraySet(s.window,e,a-i,i,0),s.wnext=i,s.whave=s.wsize):(s.wnext+=n,s.wnext===s.wsize&&(s.wnext=0),s.whavec;){if(0===h)break t;h--,_+=n[o++]<>>8&255,a.check=g(a.check,Ze,2,0),_=0,c=0,a.mode=U;break}if(a.flags=0,a.head&&(a.head.done=-1),!(1&a.wrap)||(((255&_)<<8)+(_>>8))%31){t.msg="incorrect header check",a.mode=fe;break}if((15&_)!==L){t.msg="unknown compression method",a.mode=fe;break}if(_>>>=4,c-=4,ye=(15&_)+8,0===a.wbits)a.wbits=ye;else if(ye>a.wbits){t.msg="invalid window size",a.mode=fe;break}a.dmax=1<c;){if(0===h)break t;h--,_+=n[o++]<>8&1),512&a.flags&&(Ze[0]=255&_,Ze[1]=_>>>8&255,a.check=g(a.check,Ze,2,0)),_=0,c=0,a.mode=C;case C:for(;32>c;){if(0===h)break t;h--,_+=n[o++]<>>8&255,Ze[2]=_>>>16&255,Ze[3]=_>>>24&255,a.check=g(a.check,Ze,4,0)),_=0,c=0,a.mode=H;case H:for(;16>c;){if(0===h)break t;h--,_+=n[o++]<>8),512&a.flags&&(Ze[0]=255&_,Ze[1]=_>>>8&255,a.check=g(a.check,Ze,2,0)),_=0,c=0,a.mode=j;case j:if(1024&a.flags){for(;16>c;){if(0===h)break t;h--,_+=n[o++]<>>8&255,a.check=g(a.check,Ze,2,0)),_=0,c=0}else a.head&&(a.head.extra=null);a.mode=K;case K:if(1024&a.flags){if(m=a.length,m>h&&(m=h),m){if(a.head&&a.head.extra)throw ye=a.head.extra_len-a.length,"Review & implement right";512&a.flags&&(a.check=g(a.check,n,m,o)),h-=m,o+=m,a.length-=m}if(a.length)break t}a.length=0,a.mode=P;case P:if(2048&a.flags){if(0===h)break t;m=0;do ye=n[o+m++],a.head&&a.head.name&&a.lengthm);if(512&a.flags&&(a.check=g(a.check,n,m,o)),h-=m,o+=m,ye)break t}else a.head&&(a.head.name=null);a.length=0,a.mode=M;case M:if(4096&a.flags){if(0===h)break t;m=0;do ye=n[o+m++],a.head&&a.head.comment&&a.lengthm);if(512&a.flags&&(a.check=g(a.check,n,m,o)),h-=m,o+=m,ye)break t}else a.head&&(a.head.comment=null);a.mode=q;case q:if(512&a.flags){for(;16>c;){if(0===h)break t;h--,_+=n[o++]<>9&1,a.head.done=1),t.adler=a.check=0,a.mode=X;break;case Y:for(;32>c;){if(0===h)break t;h--,_+=n[o++]<>>=7&c,c-=7&c,a.mode=he;break}for(;3>c;){if(0===h)break t;h--,_+=n[o++]<>>=1,c-=1,3&_){case 0:a.mode=J;break;case 1:if(f(a),a.mode=ae,e===Z){_>>>=2,c-=2;break t}break;case 2:a.mode=$;break;case 3:t.msg="invalid block type",a.mode=fe}_>>>=2,c-=2;break;case J:for(_>>>=7&c,c-=7&c;32>c;){if(0===h)break t;h--,_+=n[o++]<>>16^65535)){t.msg="invalid stored block lengths",a.mode=fe;break}if(a.length=65535&_,_=0,c=0,a.mode=Q,e===Z)break t;case Q:a.mode=V;case V:if(m=a.length){if(m>h&&(m=h),m>d&&(m=d),0===m)break t;v.arraySet(r,n,o,m,l),h-=m,o+=m,d-=m,l+=m,a.length-=m;break}a.mode=X;break;case $:for(;14>c;){if(0===h)break t;h--,_+=n[o++]<>>=5,c-=5,a.ndist=(31&_)+1,_>>>=5,c-=5,a.ncode=(15&_)+4,_>>>=4,c-=4,a.nlen>286||a.ndist>30){t.msg="too many length or distance symbols",a.mode=fe;break}a.have=0,a.mode=te;case te:for(;a.havec;){if(0===h)break t;h--,_+=n[o++]<>>=3,c-=3}for(;a.have<19;)a.lens[Ae[a.have++]]=0;if(v.arraySet(a.lencode,a.codes,0,a.codes.length,0),a.lenbits=7,Be=new s(y,a.lens,0,19,a.lencode,0,a.lenbits,a.work),ze=x(Be),a.lenbits=Be.bits,ze){t.msg="invalid code lengths set",a.mode=fe;break}a.have=0,a.mode=ee;case ee:for(;a.have>>24,ve=Se>>>16&255,ke=65535&Se,!(c>=me);){if(0===h)break t;h--,_+=n[o++]<ke)_>>>=me,c-=me,a.lens[a.have++]=ke;else{if(16===ke){for(Ee=me+2;Ee>c;){if(0===h)break t;h--,_+=n[o++]<>>=me,c-=me,0===a.have){t.msg="invalid bit length repeat",a.mode=fe;break}ye=a.lens[a.have-1],m=3+(3&_),_>>>=2,c-=2}else if(17===ke){for(Ee=me+3;Ee>c;){if(0===h)break t;h--,_+=n[o++]<>>=me,c-=me,ye=0,m=3+(7&_),_>>>=3,c-=3}else{for(Ee=me+7;Ee>c;){if(0===h)break t;h--,_+=n[o++]<>>=me,c-=me,ye=0,m=11+(127&_),_>>>=7,c-=7}if(a.have+m>a.nlen+a.ndist){t.msg="invalid bit length repeat",a.mode=fe;break}for(;m--;)a.lens[a.have++]=ye}}if(a.mode===fe)break;if(0===a.lens[256]){t.msg="invalid code -- missing end-of-block",a.mode=fe;break}if(v.arraySet(a.lencode,a.codes,0,a.codes.length,0),a.lenbits=9,Be=new s(z,a.lens,0,a.nlen,a.lencode,0,a.lenbits,a.work),ze=x(Be),a.lenbits=Be.bits,ze){t.msg="invalid literal/lengths set",a.mode=fe;break}if(a.distbits=6,v.arraySet(a.distcode,a.codes,0,a.codes.length,0),Be=new s(B,a.lens,a.nlen,a.ndist,a.distcode,0,a.distbits,a.work),ze=x(Be),a.distbits=Be.bits,ze){t.msg="invalid distances set",a.mode=fe;break}if(a.mode=ae,e===Z)break t;case ae:a.mode=ie;case ie:if(h>=6&&d>=258){t.next_out_index=l,t.avail_out=d,t.next_in_index=o,t.avail_in=h,a.hold=_,a.bits=c,p(t,b),l=t.next_out_index,r=t.next_out,d=t.avail_out,o=t.next_in_index,n=t.next_in,h=t.avail_in,_=a.hold,c=a.bits,a.mode===X&&(a.back=-1);break}for(a.back=0;Se=a.lencode[_&(1<>>24,ve=Se>>>16&255,ke=65535&Se,!(c>=me);){if(0===h)break t;h--,_+=n[o++]<>ge)],me=Se>>>24,ve=Se>>>16&255,ke=65535&Se,!(c>=ge+me);){if(0===h)break t;h--,_+=n[o++]<>>=ge,c-=ge,a.back+=ge}if(_>>>=me,c-=me,a.back+=me,a.length=ke,0===ve){a.mode=le;break}if(32&ve){a.back=-1,a.mode=X;break}if(64&ve){t.msg="invalid literal/length code",a.mode=fe;break}a.extra=15&ve,a.mode=ne;case ne:if(a.extra){for(Ee=a.extra;Ee>c;){if(0===h)break t;h--,_+=n[o++]<>>=a.extra,c-=a.extra,a.back+=a.extra}a.was=a.length,a.mode=se;case se:for(;Se=a.distcode[_&(1<>>24,ve=Se>>>16&255,ke=65535&Se,!(c>=me);){if(0===h)break t;h--,_+=n[o++]<>ge)],me=Se>>>24,ve=Se>>>16&255,ke=65535&Se,!(c>=ge+me);){if(0===h)break t;h--,_+=n[o++]<>>=ge,c-=ge,a.back+=ge}if(_>>>=me,c-=me,a.back+=me,64&ve){t.msg="invalid distance code",a.mode=fe;break}a.offset=ke,a.extra=15&ve,a.mode=re;case re:if(a.extra){for(Ee=a.extra;Ee>c;){if(0===h)break t;h--,_+=n[o++]<>>=a.extra,c-=a.extra,a.back+=a.extra}if(a.offset>a.dmax){t.msg="invalid distance too far back",a.mode=fe;break}a.mode=oe;case oe:if(0===d)break t;if(m=b-d,a.offset>m){if(m=a.offset-m,m>a.whave&&a.sane){t.msg="invalid distance too far back",a.mode=fe;break}m>a.wnext?(m-=a.wnext,we=a.wsize-m):we=a.wnext-m,m>a.length&&(m=a.length),be=a.window}else be=r,we=l-a.offset,m=a.length;m>d&&(m=d),d-=m,a.length-=m;do r[l++]=be[we++];while(--m);0===a.length&&(a.mode=ie);break;case le:if(0===d)break t;r[l++]=a.length,d--,a.mode=ie;break;case he:if(a.wrap){for(;32>c;){if(0===h)break t;h--,_|=n[o++]<c;){if(0===h)break t;h--,_+=n[o++]<=S;S++)C[S]=0;for(Z=0;y>Z;Z++)C[x[t.lens_index+Z]]++;for(I=B,R=i;R>=1&&0===C[R];R--);if(I>R&&(I=R),0===R)return z[t.table_index++]=20971520,z[t.table_index++]=20971520,t.bits=1,0;for(A=1;R>A&&0===C[A];A++);for(A>I&&(I=A),T=1,S=1;i>=S;S++)if(T<<=1,T-=C[S],0>T)return-1;if(T>0&&(p===r||1!==R))return-1;for(H[1]=0,S=1;i>S;S++)H[S+1]=H[S]+C[S];for(Z=0;y>Z;Z++)0!==x[t.lens_index+Z]&&(E[H[x[t.lens_index+Z]]++]=Z);switch(p){case r:D=j=E,m=19;break;case o:D=h,U-=257,j=d,K-=257,m=256;break;default:D=_,j=f,m=-1}if(L=0,Z=0,S=A,b=t.table_index,N=I,O=0,c=-1,F=1<n||p===l&&F>s)return 1;for(var P=0;;){P++,v=S-O,E[Z]m?(k=j[K+E[Z]],g=D[U+E[Z]]):(k=96,g=0),e=1<>O)+u]=v<<24|k<<16|g|0; +while(0!==u);for(e=1<>=1;if(0!==e?(L&=e-1,L+=e):L=0,Z++,0===--C[S]){if(S===R)break;S=x[t.lens_index+E[Z]]}if(S>I&&(L&w)!==c){for(0===O&&(O=I),b+=A,N=S-O,T=1<N+O&&(T-=C[N+O],!(0>=T));)N++,T<<=1;if(F+=1<n||p===l&&F>s)return 1;c=L&w,z[c]=I<<24|N<<16|b-t.table_index}}return 0!==L&&(z[b+L]=S-O<<24|64<<16|0),t.table_index+=F,t.bits=I,0}},{"./utils":13}],11:[function(t,e){"use strict";e.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],12:[function(t,e,a){"use strict";function i(t){for(var e=t.length;--e;)t[e]=0}function n(t){return 256>t?re[t]:re[256+(t>>>7)]}function s(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255}function r(t,e,a){t.bi_valid>G-a?(t.bi_buf|=e<>G-t.bi_valid,t.bi_valid+=a-G):(t.bi_buf|=e<>>=1,a<<=1;while(--e>0);return a>>>1}function h(t){16===t.bi_valid?(s(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}function d(t,e){var a,i,n,s,r,o,l=e.dyn_tree,h=e.max_code,d=e.stat_desc.static_tree,_=e.stat_desc.has_stree,f=e.stat_desc.extra_bits,u=e.stat_desc.extra_base,c=e.stat_desc.max_length,w=0;for(s=0;Y>=s;s++)t.bl_count[s]=0;for(l[2*t.heap[t.heap_max]+1]=0,a=t.heap_max+1;q>a;a++)i=t.heap[a],s=l[2*l[2*i+1]+1]+1,s>c&&(s=c,w++),l[2*i+1]=s,i>h||(t.bl_count[s]++,r=0,i>=u&&(r=f[i-u]),o=l[2*i],t.opt_len+=o*(s+r),_&&(t.static_len+=o*(d[2*i+1]+r)));if(0!==w){do{for(s=c-1;0===t.bl_count[s];)s--;t.bl_count[s]--,t.bl_count[s+1]+=2,t.bl_count[c]--,w-=2}while(w>0);for(s=c;0!==s;s--)for(i=t.bl_count[s];0!==i;)n=t.heap[--a],n>h||(l[2*n+1]!==s&&(t.opt_len+=(s-l[2*n+1])*l[2*n],l[2*n+1]=s),i--)}}function _(t,e,a){var i,n,s=new Array(Y+1),r=0;for(i=1;Y>=i;i++)s[i]=r=r+a[i-1]<<1;for(n=0;e>=n;n++){var o=t[2*n+1];0!==o&&(t[2*n]=l(s[o]++,o))}}function f(){var t,e,a,i,n,s=new Array(Y+1);for(a=0,i=0;H-1>i;i++)for(le[i]=a,t=0;t<1<<$[i];t++)oe[a++]=i;for(oe[a-1]=i,n=0,i=0;16>i;i++)for(he[i]=n,t=0;t<1<>=7;P>i;i++)for(he[i]=n<<7,t=0;t<1<=e;e++)s[e]=0;for(t=0;143>=t;)ne[2*t+1]=8,t++,s[8]++;for(;255>=t;)ne[2*t+1]=9,t++,s[9]++;for(;279>=t;)ne[2*t+1]=7,t++,s[7]++;for(;287>=t;)ne[2*t+1]=8,t++,s[8]++;for(_(ne,K+1,s),t=0;P>t;t++)se[2*t+1]=5,se[2*t]=l(t,5);de=new ue(ne,$,j+1,K,Y),_e=new ue(se,te,0,P,Y),fe=new ue(new Array(0),ee,0,M,X)}function u(t){var e;for(e=0;K>e;e++)t.dyn_ltree[2*e]=0;for(e=0;P>e;e++)t.dyn_dtree[2*e]=0;for(e=0;M>e;e++)t.bl_tree[2*e]=0;t.dyn_ltree[2*W]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0}function c(t){t.bi_valid>8?s(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0}function w(t,e,a,i){c(t),i&&(s(t,a),s(t,~a)),R.arraySet(t.pending_buf,t.window,e,a,t.pending),t.pending+=a}function b(t,e,a,i){var n=2*e,s=2*a;return t[n]a;a++)0!==s[2*a]?(t.heap[++t.heap_len]=h=a,t.depth[a]=0):s[2*a+1]=0;for(;t.heap_len<2;)n=t.heap[++t.heap_len]=2>h?++h:0,s[2*n]=1,t.depth[n]=0,t.opt_len--,o&&(t.static_len-=r[2*n+1]);for(e.max_code=h,a=t.heap_len>>1;a>=1;a--)m(t,s,a);n=l;do a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],m(t,s,1),i=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=i,s[2*n]=s[2*a]+s[2*i],t.depth[n]=(t.depth[a]>=t.depth[i]?t.depth[a]:t.depth[i])+1,s[2*a+1]=s[2*i+1]=n,t.heap[1]=n++,m(t,s,1);while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],d(t,e),_(s,h,t.bl_count)}function g(t,e,a){var i,n,s=-1,r=e[1],o=0,l=7,h=4;for(0===r&&(l=138,h=3),e[2*(a+1)+1]=65535,i=0;a>=i;i++)n=r,r=e[2*(i+1)+1],++oo?t.bl_tree[2*n]+=o:0!==n?(n!==s&&t.bl_tree[2*n]++,t.bl_tree[2*J]++):10>=o?t.bl_tree[2*Q]++:t.bl_tree[2*V]++,o=0,s=n,0===r?(l=138,h=3):n===r?(l=6,h=3):(l=7,h=4))}function p(t,e,a){var i,n,s=-1,l=e[1],h=0,d=7,_=4;for(0===l&&(d=138,_=3),i=0;a>=i;i++)if(n=l,l=e[2*(i+1)+1],!(++hh){do o(t,n,t.bl_tree);while(0!==--h)}else 0!==n?(n!==s&&(o(t,n,t.bl_tree),h--),o(t,J,t.bl_tree),r(t,h-3,2)):10>=h?(o(t,Q,t.bl_tree),r(t,h-3,3)):(o(t,V,t.bl_tree),r(t,h-11,7));h=0,s=n,0===l?(d=138,_=3):n===l?(d=6,_=3):(d=7,_=4)}}function x(t){var e;for(g(t,t.dyn_ltree,t.l_desc.max_code),g(t,t.dyn_dtree,t.d_desc.max_code),k(t,t.bl_desc),e=M-1;e>=3&&0===t.bl_tree[2*ae[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}function y(t,e,a,i){var n;for(r(t,e-257,5),r(t,a-1,5),r(t,i-4,4),n=0;i>n;n++)r(t,t.bl_tree[2*ae[n]+1],3);p(t,t.dyn_ltree,e-1),p(t,t.dyn_dtree,a-1)}function z(t){var e,a=4093624447;for(e=0;31>=e;e++,a>>>=1)if(1&a&&0!==t.dyn_ltree[2*e])return N;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return O;for(e=32;j>e;e++)if(0!==t.dyn_ltree[2*e])return O;return N}function B(t){we||(f(),we=!0),t.l_desc=new ce(t.dyn_ltree,de),t.d_desc=new ce(t.dyn_dtree,_e),t.bl_desc=new ce(t.bl_tree,fe),t.bi_buf=0,t.bi_valid=0,u(t)}function E(t,e,a,i){r(t,(F<<1)+(i?1:0),3),w(t,e,a,!0)}function S(t){r(t,L<<1,3),o(t,W,ne),h(t)}function Z(t,e,a,i){var n,s,o=0;t.level>0?(t.strm.data_type===T&&(t.strm.data_type=z(t)),k(t,t.l_desc),k(t,t.d_desc),o=x(t),n=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,n>=s&&(n=s)):n=s=a+5,n>=a+4&&-1!==e?E(t,e,a,i):t.strategy===I||s===n?(r(t,(L<<1)+(i?1:0),3),v(t,ne,se)):(r(t,(D<<1)+(i?1:0),3),y(t,t.l_desc.max_code+1,t.d_desc.max_code+1,o+1),v(t,t.dyn_ltree,t.dyn_dtree)),u(t),i&&c(t)}function A(t,e,a){var i,s,r;if(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&a,t.last_lit++,0===e?t.dyn_ltree[2*a]++:(t.matches++,e--,t.dyn_ltree[2*(oe[a]+j+1)]++,t.dyn_dtree[2*n(e)]++),0===(8191&t.last_lit)&&t.level>2){for(i=8*t.last_lit,s=t.strstart-t.block_start,r=0;P>r;r++)i+=t.dyn_dtree[2*r]*(5+te[r]);if(i>>>=3,t.matches>1&&s>>1>i)return!0}return t.last_lit===t.lit_bufsize-1}var R=t("./utils"),I=4,N=0,O=1,T=2,F=0,L=1,D=2,U=3,C=258,H=29,j=256,K=j+1+H,P=30,M=19,q=2*K+1,Y=15,G=16,X=7,W=256,J=16,Q=17,V=18,$=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],te=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],ee=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],ae=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],ie=512,ne=new Array(2*(K+2));i(ne);var se=new Array(2*P);i(se);var re=new Array(ie);i(re);var oe=new Array(C-U+1);i(oe);var le=new Array(H);i(le);var he=new Array(P);i(he);var de,_e,fe,ue=function(t,e,a,i,n){this.static_tree=t,this.extra_bits=e,this.extra_base=a,this.elems=i,this.max_length=n,this.has_stree=t&&t.length},ce=function(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e},we=!1;a._tr_init=B,a._tr_stored_block=E,a._tr_flush_block=Z,a._tr_tally=A,a._tr_align=S},{"./utils":13}],13:[function(t,e,a){"use strict";var i="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;a.assign=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var a=e.shift();if(a){if("object"!=typeof a)throw new TypeError(a+"must be non-object");for(var i in a)a.hasOwnProperty(i)&&(t[i]=a[i])}}return t},a.shrinkBuf=function(t,e){return t.length===e?t:t.subarray?t.subarray(0,e):(t.length=e,t)};var n={arraySet:function(t,e,a,i,n){if(e.subarray)return void t.set(e.subarray(a,a+i),n);for(var s=0;i>s;s++)t[n+s]=e[a+s]},flattenChunks:function(t){var e,a,i,n,s,r;for(i=0,e=0,a=t.length;a>e;e++)i+=t[e].length;for(r=new Uint8Array(i),n=0,e=0,a=t.length;a>e;e++)s=t[e],r.set(s,n),n+=s.length;return r}},s={arraySet:function(t,e,a,i,n){for(var s=0;i>s;s++)t[n+s]=e[a+s]},flattenChunks:function(t){return[].concat.apply([],t)}};a.setTyped=function(t){t?(a.Buf8=Uint8Array,a.Buf16=Uint16Array,a.Buf32=Int32Array,a.assign(a,n)):(a.Buf8=Array,a.Buf16=Array,a.Buf32=Array,a.assign(a,s))},a.setTyped(i)},{}],14:[function(t,e){"use strict";function a(){this.next_in=null,this.next_in_index=0,this.avail_in=0,this.total_in=0,this.next_out=null,this.next_out_index=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}e.exports=a},{}]},{},[1])(1)}); \ No newline at end of file diff --git a/dist/pako_deflate.js b/dist/pako_deflate.js index 022f527..2ed006c 100644 --- a/dist/pako_deflate.js +++ b/dist/pako_deflate.js @@ -26,13 +26,6 @@ var Z_DEFLATED = 8; /* ===========================================================================*/ -// return sliced buffer, trying to avoid new objects creation and mem copy -function sliceBuf(buf, size) { - if (buf.length === size) { return buf; } - - return utils.typedOk() ? buf.subarray(0, size) : buf.slice(0, size); -} - /** * class Deflate * @@ -190,7 +183,7 @@ Deflate.prototype.push = function(data, mode) { strm.next_in = data; strm.next_in_index = 0; strm.avail_in = strm.next_in.length; - strm.next_out = utils.arrayCreate(chunkSize); + strm.next_out = new utils.Buf8(chunkSize); do { strm.avail_out = this.options.chunkSize; @@ -203,10 +196,10 @@ Deflate.prototype.push = function(data, mode) { return false; } if(strm.next_out_index) { - this.onData(sliceBuf(strm.next_out, strm.next_out_index)); + this.onData(utils.shrinkBuf(strm.next_out, strm.next_out_index)); // Allocate buffer for next chunk, if not last if (strm.avail_in > 0 || strm.avail_out === 0) { - strm.next_out = utils.arrayCreate(this.options.chunkSize); + strm.next_out = new utils.Buf8(this.options.chunkSize); } } } while (strm.avail_in > 0 || strm.avail_out === 0); @@ -252,7 +245,7 @@ Deflate.prototype.onEnd = function(status) { } this.chunks = []; this.err = status; - this.msg = msg[status]; + this.msg = this.strm.msg; }; @@ -288,7 +281,7 @@ function deflate(input, options) { deflator.push(input, true); // That will never happens, if you don't cheat with options :) - if (deflator.err) { throw msg[deflator.err]; } + if (deflator.err) { throw deflator.msg; } return deflator.result; } @@ -336,24 +329,27 @@ exports.gzip = gzip; // Small size is preferable. function adler32(adler, buf, len, pos) { - var s1 = adler & 0xffff - , s2 = (adler >>> 16) & 0xffff + var s1 = (adler & 0xffff) |0 + , s2 = ((adler >>> 16) & 0xffff) |0 , n = 0; while (len !== 0) { - n = len > 5552 ? 5552 : len; + // Set limit ~ twice less than 5552, to keep + // s2 in 31-bits, because we force signed ints. + // in other case %= will fail. + n = len > 2000 ? 2000 : len; len -= n; do { - s1 += buf[pos++]; - s2 += s1; + s1 = (s1 + buf[pos++]) |0; + s2 = (s2 + s1) |0; } while (--n); s1 %= 65521; s2 %= 65521; } - return (s1 | (s2 << 16)); + return (s1 | (s2 << 16)) |0; } @@ -407,6 +403,7 @@ var utils = _dereq_('./utils'); var trees = _dereq_('./trees'); var adler32 = _dereq_('./adler32'); var crc32 = _dereq_('./crc32'); +var msg = _dereq_('./messages'); /* Public constants ==========================================================*/ /* ===========================================================================*/ @@ -505,6 +502,10 @@ var BS_FINISH_DONE = 4; /* finish done, accept no more input or output */ var OS_CODE = 0x03; // Unix :) . Don't detect, use this default. +function err(strm, errorCode) { + strm.msg = msg[errorCode]; + return errorCode; +} function rank(f) { return ((f) << 1) - ((f) > 4 ? 9 : 0); @@ -1570,9 +1571,9 @@ function DeflateState() { // Use flat array of DOUBLE size, with interleaved fata, // because JS does not support effective - this.dyn_ltree = utils.array16Create(HEAP_SIZE * 2); - this.dyn_dtree = utils.array16Create((2*D_CODES+1) * 2); - this.bl_tree = utils.array16Create((2*BL_CODES+1) * 2); + this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2); + this.dyn_dtree = new utils.Buf16((2*D_CODES+1) * 2); + this.bl_tree = new utils.Buf16((2*BL_CODES+1) * 2); zero(this.dyn_ltree); zero(this.dyn_dtree); zero(this.bl_tree); @@ -1589,11 +1590,11 @@ function DeflateState() { this.bl_desc = null; /* desc. for bit length tree */ //ush bl_count[MAX_BITS+1]; - this.bl_count = utils.array16Create(MAX_BITS+1); + this.bl_count = new utils.Buf16(MAX_BITS+1); /* number of codes at each bit length for an optimal tree */ //int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ - this.heap = utils.array16Create(2*L_CODES+1); /* heap used to build the Huffman trees */ + this.heap = new utils.Buf16(2*L_CODES+1); /* heap used to build the Huffman trees */ zero(this.heap); this.heap_len = 0; /* number of elements in the heap */ @@ -1602,7 +1603,7 @@ function DeflateState() { * The same heap array is used to build all trees. */ - this.depth = utils.array16Create(2*L_CODES+1); //uch depth[2*L_CODES+1]; + this.depth = new utils.Buf16(2*L_CODES+1); //uch depth[2*L_CODES+1]; zero(this.depth); /* Depth of each subtree used as tie breaker for trees of equal frequency */ @@ -1664,7 +1665,7 @@ function deflateResetKeep(strm) { var s; if (!strm || !strm.state) { - return Z_STREAM_ERROR; + return err(strm, Z_STREAM_ERROR); } strm.total_in = strm.total_out = 0; @@ -1698,7 +1699,7 @@ function deflateReset(strm) { function deflateInit2(strm, level, method, windowBits, memLevel, strategy) { if (!strm) { // === Z_NULL - return Z_STREAM_ERROR; + return err(strm, Z_STREAM_ERROR); } var wrap = 1; @@ -1720,7 +1721,7 @@ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) { if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED || windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; + return err(strm, Z_STREAM_ERROR); } @@ -1745,16 +1746,16 @@ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) { s.hash_mask = s.hash_size - 1; s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH); - s.window = utils.arrayCreate(s.w_size * 2); - s.head = utils.array16Create(s.hash_size); - s.prev = utils.array16Create(s.w_size); + s.window = new utils.Buf8(s.w_size * 2); + s.head = new utils.Buf16(s.hash_size); + s.prev = new utils.Buf16(s.w_size); s.high_water = 0; /* nothing written to s->window yet */ s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ s.pending_buf_size = s.lit_bufsize * 4; - s.pending_buf = utils.arrayCreate(s.pending_buf_size); + s.pending_buf = new utils.Buf8(s.pending_buf_size); s.d_buf = s.lit_bufsize >> 1; s.l_buf = (1 + 2) * s.lit_bufsize; @@ -1776,7 +1777,7 @@ function deflate(strm, flush) { if (!strm || !strm.state || flush > Z_BLOCK || flush < 0) { - return Z_STREAM_ERROR; + return err(strm, Z_STREAM_ERROR); } s = strm.state; @@ -1784,7 +1785,7 @@ function deflate(strm, flush) { if (!strm.next_out || (!strm.next_in && strm.avail_in !== 0) || (s.status === FINISH_STATE && flush !== Z_FINISH)) { - return (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR; + return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR); } s.strm = strm; /* just in case */ @@ -1865,12 +1866,12 @@ function deflate(strm, flush) { */ } else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) && flush !== Z_FINISH) { - return Z_BUF_ERROR; + return err(strm, Z_BUF_ERROR); } /* User must not provide more input after the first FINISH: */ if (s.status === FINISH_STATE && strm.avail_in !== 0) { - return Z_BUF_ERROR; + return err(strm, Z_BUF_ERROR); } /* Start a new block or continue the current one. @@ -1968,12 +1969,12 @@ function deflateEnd(strm) { status !== BUSY_STATE && status !== FINISH_STATE ) { - return Z_STREAM_ERROR; + return err(strm, Z_STREAM_ERROR); } strm.state = null; - return status === BUSY_STATE ? Z_DATA_ERROR : Z_OK; + return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK; } /* ========================================================================= @@ -1988,7 +1989,7 @@ exports.deflateInit2 = deflateInit2; exports.deflateReset = deflateReset; exports.deflate = deflate; exports.deflateEnd = deflateEnd; -exports.deflate_info = 'pako deflate'; +exports.deflateInfo = 'pako deflate (from Nodeca project)'; /* Not implemented exports.deflateSetDictionary = deflateSetDictionary; @@ -1997,7 +1998,7 @@ exports.deflateSetHeader = deflateSetHeader; exports.deflateBound = deflateBound; exports.deflatePending = deflatePending; */ -},{"./adler32":2,"./crc32":3,"./trees":6,"./utils":7}],5:[function(_dereq_,module,exports){ +},{"./adler32":2,"./crc32":3,"./messages":5,"./trees":6,"./utils":7}],5:[function(_dereq_,module,exports){ 'use strict'; module.exports = { @@ -3212,19 +3213,7 @@ exports._tr_align = _tr_align; var TYPED_OK = (typeof Uint8Array !== 'undefined') && (typeof Uint16Array !== 'undefined') && - (typeof Uint32Array !== 'undefined'); - -var _toString = Function.prototype.call.bind(Object.prototype.toString); -var isArray = Array.isArray || function (obj) { return _toString(obj) === '[object Array]'; }; - -// For debug/testing. Set true to force use untyped arrays -exports.forceUntyped = false; - -function typedOk() { - return TYPED_OK && !exports.forceUntyped; -} - -exports.typedOk = typedOk; + (typeof Int32Array !== 'undefined'); exports.assign = function (obj /*from1, from2, from3, ...*/) { @@ -3248,58 +3237,32 @@ exports.assign = function (obj /*from1, from2, from3, ...*/) { }; -exports.arraySet = function (dest, src, src_offs, len, dest_offs) { - - // Suppose, that with typed array support destination is - // always typed - don't check it - if (typedOk() && (!isArray(src))) { - - // optimize full copy - //if ((src_offs === 0) && (src.length === len)) { - // dest.set(src, dest_offs); - // return; - //} - - dest.set(src.subarray(src_offs, src_offs+len), dest_offs); - return; - } - - // Fallback to ordinary array - for(var i=0; i0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new o;var a=_.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(a!==f)throw new Error(h[a])};b.prototype.push=function(t,e){var a,n,i=this.strm,s=this.options.chunkSize;if(this.ended)return!1;n=e===~~e?e:e===!0?u:d,i.next_in=t,i.next_in_index=0,i.avail_in=i.next_in.length,i.next_out=l.arrayCreate(s);do{if(i.avail_out=this.options.chunkSize,i.next_out_index=0,a=_.deflate(i,n),a!==c&&a!==f)return this.onEnd(a),this.ended=!0,!1;i.next_out_index&&(this.onData(r(i.next_out,i.next_out_index)),(i.avail_in>0||0===i.avail_out)&&(i.next_out=l.arrayCreate(this.options.chunkSize)))}while(i.avail_in>0||0===i.avail_out);return n===u?(a=_.deflateEnd(this.strm),this.onEnd(a),this.ended=!0,a===f):!0},b.prototype.onData=function(t){this.chunks.push(t)},b.prototype.onEnd=function(t){t===f&&(this.result=l.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=h[t]},a.Deflate=b,a.deflate=n,a.deflateRaw=i,a.gzip=s},{"./zlib/deflate.js":4,"./zlib/messages":5,"./zlib/utils":7,"./zlib/zstream":8}],2:[function(t,e){"use strict";function a(t,e,a,r){for(var n=65535&t,i=t>>>16&65535,s=0;0!==a;){s=a>5552?5552:a,a-=s;do n+=e[r++],i+=n;while(--s);n%=65521,i%=65521}return n|i<<16}e.exports=a},{}],3:[function(t,e){"use strict";function a(){for(var t,e=[],a=0;256>a;a++){t=a;for(var r=0;8>r;r++)t=1&t?3988292384^t>>>1:t>>>1;e[a]=t}return e}function r(t,e,a,r){var i=n,s=r+a;t=-1^t;for(var _=r;s>_;_++)t=t>>>8^i[255&(t^e[_])];return-1^t}var n=a();e.exports=r},{}],4:[function(t,e,a){"use strict";function r(t){return(t<<1)-(t>4?9:0)}function n(t){for(var e=t.length;--e;)t[e]=0}function i(t){var e=t.state,a=e.pending;a>t.avail_out&&(a=t.avail_out),0!==a&&(C.arraySet(t.next_out,e.pending_buf,e.pending_out,a,t.next_out_index),t.next_out_index+=a,e.pending_out+=a,t.total_out+=a,t.avail_out-=a,e.pending-=a,0===e.pending&&(e.pending_out=0))}function s(t,e){S._tr_flush_block(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,i(t.strm)}function _(t,e){t.pending_buf[t.pending++]=e}function l(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e}function h(t,e,a,r){var n=t.avail_in;return n>r&&(n=r),0===n?0:(t.avail_in-=n,C.arraySet(e,t.next_in,t.next_in_index,n,a),1===t.state.wrap?t.adler=E(t.adler,e,n,a):2===t.state.wrap&&(t.adler=B(t.adler,e,n,a)),t.next_in_index+=n,t.total_in+=n,n)}function o(t,e){var a,r,n=t.max_chain_length,i=t.strstart,s=t.prev_length,_=t.nice_match,l=t.strstart>t.w_size-se?t.strstart-(t.w_size-se):0,h=t.window,o=t.w_mask,d=t.prev,u=t.strstart+ie,f=h[i+s-1],c=h[i+s];t.prev_length>=t.good_match&&(n>>=2),_>t.lookahead&&(_=t.lookahead);do if(a=e,h[a+s]===c&&h[a+s-1]===f&&h[a]===h[i]&&h[++a]===h[i+1]){i+=2,a++;do;while(h[++i]===h[++a]&&h[++i]===h[++a]&&h[++i]===h[++a]&&h[++i]===h[++a]&&h[++i]===h[++a]&&h[++i]===h[++a]&&h[++i]===h[++a]&&h[++i]===h[++a]&&u>i);if(r=ie-(u-i),i=u-ie,r>s){if(t.match_start=e,s=r,r>=_)break;f=h[i+s-1],c=h[i+s]}}while((e=d[e&o])>l&&0!==--n);return s<=t.lookahead?s:t.lookahead}function d(t){var e,a,r,n,i,s=t.w_size;do{if(n=t.window_size-t.lookahead-t.strstart,t.strstart>=s+(s-se)){C.arraySet(t.window,t.window,s,s,0),t.match_start-=s,t.strstart-=s,t.block_start-=s,a=t.hash_size,e=a;do r=t.head[--e],t.head[e]=r>=s?r-s:0;while(--a);a=s,e=a;do r=t.prev[--e],t.prev[e]=r>=s?r-s:0;while(--a);n+=s}if(0===t.strm.avail_in)break;if(a=h(t.strm,t.window,t.strstart+t.lookahead,n),t.lookahead+=a,t.lookahead+t.insert>=ne)for(i=t.strstart-t.insert,t.ins_h=t.window[i],t.ins_h=(t.ins_h<t.pending_buf_size-5&&(a=t.pending_buf_size-5);;){if(t.lookahead<=1){if(d(t),0===t.lookahead&&e===U)return pe;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var r=t.block_start+a;if((0===t.strstart||t.strstart>=r)&&(t.lookahead=t.strstart-r,t.strstart=r,s(t,!1),0===t.strm.avail_out))return pe;if(t.strstart-t.block_start>=t.w_size-se&&(s(t,!1),0===t.strm.avail_out))return pe}return t.insert=0,e===I?(s(t,!0),0===t.strm.avail_out?we:be):t.strstart>t.block_start&&(s(t,!1),0===t.strm.avail_out)?pe:pe}function f(t,e){for(var a,r;;){if(t.lookahead=ne&&(t.ins_h=(t.ins_h<=ne)if(r=S._tr_tally(t,t.strstart-t.match_start,t.match_length-ne),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=ne){t.match_length--;do t.strstart++,t.ins_h=(t.ins_h<=ne&&(t.ins_h=(t.ins_h<4096)&&(t.match_length=ne-1)),t.prev_length>=ne&&t.match_length<=t.prev_length){n=t.strstart+t.lookahead-ne,r=S._tr_tally(t,t.strstart-1-t.match_start,t.prev_length-ne),t.lookahead-=t.prev_length-1,t.prev_length-=2;do++t.strstart<=n&&(t.ins_h=(t.ins_h<=ne&&t.strstart>0&&(n=t.strstart-1,r=_[n],r===_[++n]&&r===_[++n]&&r===_[++n])){i=t.strstart+ie;do;while(r===_[++n]&&r===_[++n]&&r===_[++n]&&r===_[++n]&&r===_[++n]&&r===_[++n]&&r===_[++n]&&r===_[++n]&&i>n);t.match_length=ie-(i-n),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=ne?(a=S._tr_tally(t,1,t.match_length-ne),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(a=S._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),a&&(s(t,!1),0===t.strm.avail_out))return pe}return t.insert=0,e===I?(s(t,!0),0===t.strm.avail_out?we:be):t.last_lit&&(s(t,!1),0===t.strm.avail_out)?pe:ve}function v(t,e){for(var a;;){if(0===t.lookahead&&(d(t),0===t.lookahead)){if(e===U)return pe;break}if(t.match_length=0,a=S._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,a&&(s(t,!1),0===t.strm.avail_out))return pe}return t.insert=0,e===I?(s(t,!0),0===t.strm.avail_out?we:be):t.last_lit&&(s(t,!1),0===t.strm.avail_out)?pe:ve}function w(t){t.window_size=2*t.w_size,n(t.head),t.max_lazy_match=A[t.level].max_lazy,t.good_match=A[t.level].good_length,t.nice_match=A[t.level].nice_length,t.max_chain_length=A[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=ne-1,t.match_available=0,t.ins_h=0}function b(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=N,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=C.array16Create(2*ae),this.dyn_dtree=C.array16Create(2*(2*te+1)),this.bl_tree=C.array16Create(2*(2*ee+1)),n(this.dyn_ltree),n(this.dyn_dtree),n(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=C.array16Create(re+1),this.heap=C.array16Create(2*$+1),n(this.heap),this.heap_len=0,this.heap_max=0,this.depth=C.array16Create(2*$+1),n(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0,this.high_water=0}function m(t){var e;return t&&t.state?(t.total_in=t.total_out=0,t.data_type=M,e=t.state,e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?le:fe,t.adler=2===e.wrap?0:1,e.last_flush=U,S._tr_init(e),D):P}function g(t){var e=m(t);return e===D&&w(t.state),e}function y(t,e,a,r,n,i){if(!t)return P;var s=1;if(e===G&&(e=6),0>r?(s=0,r=-r):r>15&&(s=2,r-=16),1>n||n>Q||a!==N||8>r||r>15||0>e||e>9||0>i||i>J)return P;8===r&&(r=9);var _=new b;return t.state=_,_.strm=t,_.wrap=s,_.gzhead=null,_.w_bits=r,_.w_size=1<<_.w_bits,_.w_mask=_.w_size-1,_.hash_bits=n+7,_.hash_size=1<<_.hash_bits,_.hash_mask=_.hash_size-1,_.hash_shift=~~((_.hash_bits+ne-1)/ne),_.window=C.arrayCreate(2*_.w_size),_.head=C.array16Create(_.hash_size),_.prev=C.array16Create(_.w_size),_.high_water=0,_.lit_bufsize=1<>1,_.l_buf=3*_.lit_bufsize,_.level=e,_.strategy=i,_.method=a,g(t)}function k(t,e){return y(t,e,N,V,W,K)}function x(t,e){var a,s;if(!t||!t.state||e>O||0>e)return P;if(s=t.state,!t.next_out||!t.next_in&&0!==t.avail_in||s.status===ce&&e!==I)return 0===t.avail_out?F:P;if(s.strm=t,a=s.last_flush,s.last_flush=e,s.status===le)if(2===s.wrap){if(t.adler=0,_(s,31),_(s,139),_(s,8),s.gzhead)throw new Error("Custom GZIP headers not supported");_(s,0),_(s,0),_(s,0),_(s,0),_(s,0),_(s,9===s.level?2:s.strategy>=Z||s.level<2?4:0),_(s,me),s.status=fe}else{var h=N+(s.w_bits-8<<4)<<8,o=-1;o=s.strategy>=Z||s.level<2?0:s.level<6?1:6===s.level?2:3,h|=o<<6,0!==s.strstart&&(h|=_e),h+=31-h%31,s.status=fe,l(s,h),0!==s.strstart&&(l(s,t.adler>>>16),l(s,65535&t.adler)),t.adler=1}if(0!==s.pending){if(i(t),0===t.avail_out)return s.last_flush=-1,D}else if(0===t.avail_in&&r(e)<=r(a)&&e!==I)return F;if(s.status===ce&&0!==t.avail_in)return F;if(0!==t.avail_in||0!==s.lookahead||e!==U&&s.status!==ce){var d=s.strategy===Z?v(s,e):s.strategy===H?p(s,e):A[s.level].func(s,e);if((d===we||d===be)&&(s.status=ce),d===pe||d===we)return 0===t.avail_out&&(s.last_flush=-1),D;if(d===ve&&(e===j?S._tr_align(s):e!==O&&(S._tr_stored_block(s,0,0,!1),e===q&&(n(s.head),0===s.lookahead&&(s.strstart=0,s.block_start=0,s.insert=0))),i(t),0===t.avail_out))return s.last_flush=-1,D}return e!==I?D:s.wrap<=0?L:(2===s.wrap?(_(s,255&t.adler),_(s,t.adler>>8&255),_(s,t.adler>>16&255),_(s,t.adler>>24&255),_(s,255&t.total_in),_(s,t.total_in>>8&255),_(s,t.total_in>>16&255),_(s,t.total_in>>24&255)):(l(s,t.adler>>>16),l(s,65535&t.adler)),i(t),s.wrap>0&&(s.wrap=-s.wrap),0!==s.pending?D:L)}function z(t){var e=t.state.status;return e!==le&&e!==he&&e!==oe&&e!==de&&e!==ue&&e!==fe&&e!==ce?P:(t.state=null,e===fe?R:D)}var A,C=t("./utils"),S=t("./trees"),E=t("./adler32"),B=t("./crc32"),U=0,j=1,q=3,I=4,O=5,D=0,L=1,P=-2,R=-3,F=-5,G=-1,T=1,Z=2,H=3,J=4,K=0,M=2,N=8,Q=9,V=15,W=8,X=29,Y=256,$=Y+1+X,te=30,ee=19,ae=2*$+1,re=15,ne=3,ie=258,se=ie+ne+1,_e=32,le=42,he=69,oe=73,de=91,ue=103,fe=113,ce=666,pe=1,ve=2,we=3,be=4,me=3,ge=function(t,e,a,r,n){this.good_length=t,this.max_lazy=e,this.nice_length=a,this.max_chain=r,this.func=n};A=[new ge(0,0,0,0,u),new ge(4,4,8,4,f),new ge(4,5,16,8,f),new ge(4,6,32,32,f),new ge(4,4,16,16,c),new ge(8,16,32,32,c),new ge(8,16,128,128,c),new ge(8,32,128,256,c),new ge(32,128,258,1024,c),new ge(32,258,258,4096,c)],a.deflateInit=k,a.deflateInit2=y,a.deflateReset=g,a.deflate=x,a.deflateEnd=z,a.deflate_info="pako deflate"},{"./adler32":2,"./crc32":3,"./trees":6,"./utils":7}],5:[function(t,e){"use strict";e.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],6:[function(t,e,a){"use strict";function r(t){for(var e=t.length;--e;)t[e]=0}function n(t){return 256>t?se[t]:se[256+(t>>>7)]}function i(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255}function s(t,e,a){t.bi_valid>N-a?(t.bi_buf|=e<>N-t.bi_valid,t.bi_valid+=a-N):(t.bi_buf|=e<>>=1,a<<=1;while(--e>0);return a>>>1}function h(t){16===t.bi_valid?(i(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}function o(t,e){var a,r,n,i,s,_,l=e.dyn_tree,h=e.max_code,o=e.stat_desc.static_tree,d=e.stat_desc.has_stree,u=e.stat_desc.extra_bits,f=e.stat_desc.extra_base,c=e.stat_desc.max_length,p=0;for(i=0;M>=i;i++)t.bl_count[i]=0;for(l[2*t.heap[t.heap_max]+1]=0,a=t.heap_max+1;K>a;a++)r=t.heap[a],i=l[2*l[2*r+1]+1]+1,i>c&&(i=c,p++),l[2*r+1]=i,r>h||(t.bl_count[i]++,s=0,r>=f&&(s=u[r-f]),_=l[2*r],t.opt_len+=_*(i+s),d&&(t.static_len+=_*(o[2*r+1]+s)));if(0!==p){do{for(i=c-1;0===t.bl_count[i];)i--;t.bl_count[i]--,t.bl_count[i+1]+=2,t.bl_count[c]--,p-=2}while(p>0);for(i=c;0!==i;i--)for(r=t.bl_count[i];0!==r;)n=t.heap[--a],n>h||(l[2*n+1]!==i&&(t.opt_len+=(i-l[2*n+1])*l[2*n],l[2*n+1]=i),r--)}}function d(t,e,a){var r,n,i=new Array(M+1),s=0;for(r=1;M>=r;r++)i[r]=s=s+a[r-1]<<1;for(n=0;e>=n;n++){var _=t[2*n+1];0!==_&&(t[2*n]=l(i[_]++,_))}}function u(){var t,e,a,r,n,i=new Array(M+1);for(a=0,r=0;G-1>r;r++)for(le[r]=a,t=0;t<1<<$[r];t++)_e[a++]=r;for(_e[a-1]=r,n=0,r=0;16>r;r++)for(he[r]=n,t=0;t<1<>=7;H>r;r++)for(he[r]=n<<7,t=0;t<1<=e;e++)i[e]=0;for(t=0;143>=t;)ne[2*t+1]=8,t++,i[8]++;for(;255>=t;)ne[2*t+1]=9,t++,i[9]++;for(;279>=t;)ne[2*t+1]=7,t++,i[7]++;for(;287>=t;)ne[2*t+1]=8,t++,i[8]++;for(d(ne,Z+1,i),t=0;H>t;t++)ie[2*t+1]=5,ie[2*t]=l(t,5);oe=new fe(ne,$,T+1,Z,M),de=new fe(ie,te,0,H,M),ue=new fe(new Array(0),ee,0,J,Q)}function f(t){var e;for(e=0;Z>e;e++)t.dyn_ltree[2*e]=0;for(e=0;H>e;e++)t.dyn_dtree[2*e]=0;for(e=0;J>e;e++)t.bl_tree[2*e]=0;t.dyn_ltree[2*V]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0}function c(t){t.bi_valid>8?i(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0}function p(t,e,a,r){c(t),r&&(i(t,a),i(t,~a)),U.arraySet(t.pending_buf,t.window,e,a,t.pending),t.pending+=a}function v(t,e,a,r){var n=2*e,i=2*a;return t[n]a;a++)0!==i[2*a]?(t.heap[++t.heap_len]=h=a,t.depth[a]=0):i[2*a+1]=0;for(;t.heap_len<2;)n=t.heap[++t.heap_len]=2>h?++h:0,i[2*n]=1,t.depth[n]=0,t.opt_len--,_&&(t.static_len-=s[2*n+1]);for(e.max_code=h,a=t.heap_len>>1;a>=1;a--)w(t,i,a);n=l;do a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],w(t,i,1),r=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=r,i[2*n]=i[2*a]+i[2*r],t.depth[n]=(t.depth[a]>=t.depth[r]?t.depth[a]:t.depth[r])+1,i[2*a+1]=i[2*r+1]=n,t.heap[1]=n++,w(t,i,1);while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],o(t,e),d(i,h,t.bl_count)}function g(t,e,a){var r,n,i=-1,s=e[1],_=0,l=7,h=4;for(0===s&&(l=138,h=3),e[2*(a+1)+1]=65535,r=0;a>=r;r++)n=s,s=e[2*(r+1)+1],++__?t.bl_tree[2*n]+=_:0!==n?(n!==i&&t.bl_tree[2*n]++,t.bl_tree[2*W]++):10>=_?t.bl_tree[2*X]++:t.bl_tree[2*Y]++,_=0,i=n,0===s?(l=138,h=3):n===s?(l=6,h=3):(l=7,h=4))}function y(t,e,a){var r,n,i=-1,l=e[1],h=0,o=7,d=4;for(0===l&&(o=138,d=3),r=0;a>=r;r++)if(n=l,l=e[2*(r+1)+1],!(++hh){do _(t,n,t.bl_tree);while(0!==--h)}else 0!==n?(n!==i&&(_(t,n,t.bl_tree),h--),_(t,W,t.bl_tree),s(t,h-3,2)):10>=h?(_(t,X,t.bl_tree),s(t,h-3,3)):(_(t,Y,t.bl_tree),s(t,h-11,7));h=0,i=n,0===l?(o=138,d=3):n===l?(o=6,d=3):(o=7,d=4)}}function k(t){var e;for(g(t,t.dyn_ltree,t.l_desc.max_code),g(t,t.dyn_dtree,t.d_desc.max_code),m(t,t.bl_desc),e=J-1;e>=3&&0===t.bl_tree[2*ae[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}function x(t,e,a,r){var n;for(s(t,e-257,5),s(t,a-1,5),s(t,r-4,4),n=0;r>n;n++)s(t,t.bl_tree[2*ae[n]+1],3);y(t,t.dyn_ltree,e-1),y(t,t.dyn_dtree,a-1)}function z(t){var e,a=4093624447;for(e=0;31>=e;e++,a>>>=1)if(1&a&&0!==t.dyn_ltree[2*e])return q;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return I;for(e=32;T>e;e++)if(0!==t.dyn_ltree[2*e])return I;return q}function A(t){pe||(u(),pe=!0),t.l_desc=new ce(t.dyn_ltree,oe),t.d_desc=new ce(t.dyn_dtree,de),t.bl_desc=new ce(t.bl_tree,ue),t.bi_buf=0,t.bi_valid=0,f(t)}function C(t,e,a,r){s(t,(D<<1)+(r?1:0),3),p(t,e,a,!0)}function S(t){s(t,L<<1,3),_(t,V,ne),h(t)}function E(t,e,a,r){var n,i,_=0;t.level>0?(t.strm.data_type===O&&(t.strm.data_type=z(t)),m(t,t.l_desc),m(t,t.d_desc),_=k(t),n=t.opt_len+3+7>>>3,i=t.static_len+3+7>>>3,n>=i&&(n=i)):n=i=a+5,n>=a+4&&-1!==e?C(t,e,a,r):t.strategy===j||i===n?(s(t,(L<<1)+(r?1:0),3),b(t,ne,ie)):(s(t,(P<<1)+(r?1:0),3),x(t,t.l_desc.max_code+1,t.d_desc.max_code+1,_+1),b(t,t.dyn_ltree,t.dyn_dtree)),f(t),r&&c(t)}function B(t,e,a){var r,i,s;if(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&a,t.last_lit++,0===e?t.dyn_ltree[2*a]++:(t.matches++,e--,t.dyn_ltree[2*(_e[a]+T+1)]++,t.dyn_dtree[2*n(e)]++),0===(8191&t.last_lit)&&t.level>2){for(r=8*t.last_lit,i=t.strstart-t.block_start,s=0;H>s;s++)r+=t.dyn_dtree[2*s]*(5+te[s]);if(r>>>=3,t.matches>1&&i>>1>r)return!0}return t.last_lit===t.lit_bufsize-1}var U=t("./utils"),j=4,q=0,I=1,O=2,D=0,L=1,P=2,R=3,F=258,G=29,T=256,Z=T+1+G,H=30,J=19,K=2*Z+1,M=15,N=16,Q=7,V=256,W=16,X=17,Y=18,$=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],te=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],ee=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],ae=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],re=512,ne=new Array(2*(Z+2));r(ne);var ie=new Array(2*H);r(ie);var se=new Array(re);r(se);var _e=new Array(F-R+1);r(_e);var le=new Array(G);r(le);var he=new Array(H);r(he);var oe,de,ue,fe=function(t,e,a,r,n){this.static_tree=t,this.extra_bits=e,this.extra_base=a,this.elems=r,this.max_length=n,this.has_stree=t&&t.length},ce=function(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e},pe=!1;a._tr_init=A,a._tr_stored_block=C,a._tr_flush_block=E,a._tr_tally=B,a._tr_align=S},{"./utils":7}],7:[function(t,e,a){"use strict";function r(){return n&&!a.forceUntyped}var n="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,i=Function.prototype.call.bind(Object.prototype.toString),s=Array.isArray||function(t){return"[object Array]"===i(t)};a.forceUntyped=!1,a.typedOk=r,a.assign=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var a=e.shift();if(a){if("object"!=typeof a)throw new TypeError(a+"must be non-object");for(var r in a)a.hasOwnProperty(r)&&(t[r]=a[r])}}return t},a.arraySet=function(t,e,a,n,i){if(r()&&!s(e))return void t.set(e.subarray(a,a+n),i);for(var _=0;n>_;_++)t[i+_]=e[a+_]},a.arrayCreate=function(t){return r()?new Uint8Array(t):new Array(t)},a.array16Create=function(t){return r()?new Uint16Array(t):new Array(t)},a.flattenChunks=function(t){var e,a,n,i,s,_;if(r()){for(n=0,e=0,a=t.length;a>e;e++)n+=t[e].length;for(_=new Uint8Array(n),i=0,e=0,a=t.length;a>e;e++)s=t[e],_.set(s,i),i+=s.length;return _}return[].concat.apply([],t)}},{}],8:[function(t,e){"use strict";function a(){this.next_in=null,this.avail_in=0,this.total_in=0,this.next_out=null,this.avail_out=0,this.total_out=0,this.state=null,this.data_type=2,this.adler=0}e.exports=a},{}]},{},[1])(1)}); \ No newline at end of file +!function(t){if("object"==typeof exports)module.exports=t();else if("function"==typeof define&&define.amd)define(t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.pako=t()}}(function(){return function t(e,a,r){function n(s,_){if(!a[s]){if(!e[s]){var l="function"==typeof require&&require;if(!_&&l)return l(s,!0);if(i)return i(s,!0);throw new Error("Cannot find module '"+s+"'")}var h=a[s]={exports:{}};e[s][0].call(h.exports,function(t){var a=e[s][1][t];return n(a?a:t)},h,h.exports,t,e,a,r)}return a[s].exports}for(var i="function"==typeof require&&require,s=0;s0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new h;var a=s.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(a!==d)throw new Error(l[a])};v.prototype.push=function(t,e){var a,r,n=this.strm,i=this.options.chunkSize;if(this.ended)return!1;r=e===~~e?e:e===!0?u:o,n.next_in=t,n.next_in_index=0,n.avail_in=n.next_in.length,n.next_out=new _.Buf8(i);do{if(n.avail_out=this.options.chunkSize,n.next_out_index=0,a=s.deflate(n,r),a!==f&&a!==d)return this.onEnd(a),this.ended=!0,!1;n.next_out_index&&(this.onData(_.shrinkBuf(n.next_out,n.next_out_index)),(n.avail_in>0||0===n.avail_out)&&(n.next_out=new _.Buf8(this.options.chunkSize)))}while(n.avail_in>0||0===n.avail_out);return r===u?(a=s.deflateEnd(this.strm),this.onEnd(a),this.ended=!0,a===d):!0},v.prototype.onData=function(t){this.chunks.push(t)},v.prototype.onEnd=function(t){t===d&&(this.result=_.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},a.Deflate=v,a.deflate=r,a.deflateRaw=n,a.gzip=i},{"./zlib/deflate.js":4,"./zlib/messages":5,"./zlib/utils":7,"./zlib/zstream":8}],2:[function(t,e){"use strict";function a(t,e,a,r){for(var n=65535&t|0,i=t>>>16&65535|0,s=0;0!==a;){s=a>2e3?2e3:a,a-=s;do n=n+e[r++]|0,i=i+n|0;while(--s);n%=65521,i%=65521}return n|i<<16|0}e.exports=a},{}],3:[function(t,e){"use strict";function a(){for(var t,e=[],a=0;256>a;a++){t=a;for(var r=0;8>r;r++)t=1&t?3988292384^t>>>1:t>>>1;e[a]=t}return e}function r(t,e,a,r){var i=n,s=r+a;t=-1^t;for(var _=r;s>_;_++)t=t>>>8^i[255&(t^e[_])];return-1^t}var n=a();e.exports=r},{}],4:[function(t,e,a){"use strict";function r(t,e){return t.msg=C[e],e}function n(t){return(t<<1)-(t>4?9:0)}function i(t){for(var e=t.length;--e;)t[e]=0}function s(t){var e=t.state,a=e.pending;a>t.avail_out&&(a=t.avail_out),0!==a&&(S.arraySet(t.next_out,e.pending_buf,e.pending_out,a,t.next_out_index),t.next_out_index+=a,e.pending_out+=a,t.total_out+=a,t.avail_out-=a,e.pending-=a,0===e.pending&&(e.pending_out=0))}function _(t,e){E._tr_flush_block(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,s(t.strm)}function l(t,e){t.pending_buf[t.pending++]=e}function h(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e}function o(t,e,a,r){var n=t.avail_in;return n>r&&(n=r),0===n?0:(t.avail_in-=n,S.arraySet(e,t.next_in,t.next_in_index,n,a),1===t.state.wrap?t.adler=I(t.adler,e,n,a):2===t.state.wrap&&(t.adler=j(t.adler,e,n,a)),t.next_in_index+=n,t.total_in+=n,n)}function u(t,e){var a,r,n=t.max_chain_length,i=t.strstart,s=t.prev_length,_=t.nice_match,l=t.strstart>t.w_size-le?t.strstart-(t.w_size-le):0,h=t.window,o=t.w_mask,u=t.prev,d=t.strstart+_e,f=h[i+s-1],c=h[i+s];t.prev_length>=t.good_match&&(n>>=2),_>t.lookahead&&(_=t.lookahead);do if(a=e,h[a+s]===c&&h[a+s-1]===f&&h[a]===h[i]&&h[++a]===h[i+1]){i+=2,a++;do;while(h[++i]===h[++a]&&h[++i]===h[++a]&&h[++i]===h[++a]&&h[++i]===h[++a]&&h[++i]===h[++a]&&h[++i]===h[++a]&&h[++i]===h[++a]&&h[++i]===h[++a]&&d>i);if(r=_e-(d-i),i=d-_e,r>s){if(t.match_start=e,s=r,r>=_)break;f=h[i+s-1],c=h[i+s]}}while((e=u[e&o])>l&&0!==--n);return s<=t.lookahead?s:t.lookahead}function d(t){var e,a,r,n,i,s=t.w_size;do{if(n=t.window_size-t.lookahead-t.strstart,t.strstart>=s+(s-le)){S.arraySet(t.window,t.window,s,s,0),t.match_start-=s,t.strstart-=s,t.block_start-=s,a=t.hash_size,e=a;do r=t.head[--e],t.head[e]=r>=s?r-s:0;while(--a);a=s,e=a;do r=t.prev[--e],t.prev[e]=r>=s?r-s:0;while(--a);n+=s}if(0===t.strm.avail_in)break;if(a=o(t.strm,t.window,t.strstart+t.lookahead,n),t.lookahead+=a,t.lookahead+t.insert>=se)for(i=t.strstart-t.insert,t.ins_h=t.window[i],t.ins_h=(t.ins_h<t.pending_buf_size-5&&(a=t.pending_buf_size-5);;){if(t.lookahead<=1){if(d(t),0===t.lookahead&&e===U)return ve;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var r=t.block_start+a;if((0===t.strstart||t.strstart>=r)&&(t.lookahead=t.strstart-r,t.strstart=r,_(t,!1),0===t.strm.avail_out))return ve;if(t.strstart-t.block_start>=t.w_size-le&&(_(t,!1),0===t.strm.avail_out))return ve}return t.insert=0,e===T?(_(t,!0),0===t.strm.avail_out?me:ge):t.strstart>t.block_start&&(_(t,!1),0===t.strm.avail_out)?ve:ve}function c(t,e){for(var a,r;;){if(t.lookahead=se&&(t.ins_h=(t.ins_h<=se)if(r=E._tr_tally(t,t.strstart-t.match_start,t.match_length-se),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=se){t.match_length--;do t.strstart++,t.ins_h=(t.ins_h<=se&&(t.ins_h=(t.ins_h<4096)&&(t.match_length=se-1)),t.prev_length>=se&&t.match_length<=t.prev_length){n=t.strstart+t.lookahead-se,r=E._tr_tally(t,t.strstart-1-t.match_start,t.prev_length-se),t.lookahead-=t.prev_length-1,t.prev_length-=2;do++t.strstart<=n&&(t.ins_h=(t.ins_h<=se&&t.strstart>0&&(n=t.strstart-1,r=s[n],r===s[++n]&&r===s[++n]&&r===s[++n])){i=t.strstart+_e;do;while(r===s[++n]&&r===s[++n]&&r===s[++n]&&r===s[++n]&&r===s[++n]&&r===s[++n]&&r===s[++n]&&r===s[++n]&&i>n);t.match_length=_e-(i-n),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=se?(a=E._tr_tally(t,1,t.match_length-se),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(a=E._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),a&&(_(t,!1),0===t.strm.avail_out))return ve}return t.insert=0,e===T?(_(t,!0),0===t.strm.avail_out?me:ge):t.last_lit&&(_(t,!1),0===t.strm.avail_out)?ve:be}function v(t,e){for(var a;;){if(0===t.lookahead&&(d(t),0===t.lookahead)){if(e===U)return ve;break}if(t.match_length=0,a=E._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,a&&(_(t,!1),0===t.strm.avail_out))return ve}return t.insert=0,e===T?(_(t,!0),0===t.strm.avail_out?me:ge):t.last_lit&&(_(t,!1),0===t.strm.avail_out)?ve:be}function b(t){t.window_size=2*t.w_size,i(t.head),t.max_lazy_match=A[t.level].max_lazy,t.good_match=A[t.level].good_length,t.nice_match=A[t.level].nice_length,t.max_chain_length=A[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=se-1,t.match_available=0,t.ins_h=0}function m(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=V,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new S.Buf16(2*ne),this.dyn_dtree=new S.Buf16(2*(2*ae+1)),this.bl_tree=new S.Buf16(2*(2*re+1)),i(this.dyn_ltree),i(this.dyn_dtree),i(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new S.Buf16(ie+1),this.heap=new S.Buf16(2*ee+1),i(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new S.Buf16(2*ee+1),i(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0,this.high_water=0}function g(t){var e;return t&&t.state?(t.total_in=t.total_out=0,t.data_type=Q,e=t.state,e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?oe:pe,t.adler=2===e.wrap?0:1,e.last_flush=U,E._tr_init(e),P):r(t,G)}function y(t){var e=g(t);return e===P&&b(t.state),e}function k(t,e,a,n,i,s){if(!t)return r(t,G);var _=1;if(e===Z&&(e=6),0>n?(_=0,n=-n):n>15&&(_=2,n-=16),1>i||i>W||a!==V||8>n||n>15||0>e||e>9||0>s||s>K)return r(t,G);8===n&&(n=9);var l=new m;return t.state=l,l.strm=t,l.wrap=_,l.gzhead=null,l.w_bits=n,l.w_size=1<>1,l.l_buf=3*l.lit_bufsize,l.level=e,l.strategy=s,l.method=a,y(t)}function x(t,e){return k(t,e,V,X,Y,M)}function z(t,e){var a,_;if(!t||!t.state||e>L||0>e)return r(t,G);if(_=t.state,!t.next_out||!t.next_in&&0!==t.avail_in||_.status===we&&e!==T)return r(t,0===t.avail_out?O:G);if(_.strm=t,a=_.last_flush,_.last_flush=e,_.status===oe)if(2===_.wrap){if(t.adler=0,l(_,31),l(_,139),l(_,8),_.gzhead)throw new Error("Custom GZIP headers not supported");l(_,0),l(_,0),l(_,0),l(_,0),l(_,0),l(_,9===_.level?2:_.strategy>=H||_.level<2?4:0),l(_,ye),_.status=pe}else{var o=V+(_.w_bits-8<<4)<<8,u=-1;u=_.strategy>=H||_.level<2?0:_.level<6?1:6===_.level?2:3,o|=u<<6,0!==_.strstart&&(o|=he),o+=31-o%31,_.status=pe,h(_,o),0!==_.strstart&&(h(_,t.adler>>>16),h(_,65535&t.adler)),t.adler=1}if(0!==_.pending){if(s(t),0===t.avail_out)return _.last_flush=-1,P}else if(0===t.avail_in&&n(e)<=n(a)&&e!==T)return r(t,O);if(_.status===we&&0!==t.avail_in)return r(t,O);if(0!==t.avail_in||0!==_.lookahead||e!==U&&_.status!==we){var d=_.strategy===H?v(_,e):_.strategy===J?w(_,e):A[_.level].func(_,e);if((d===me||d===ge)&&(_.status=we),d===ve||d===me)return 0===t.avail_out&&(_.last_flush=-1),P;if(d===be&&(e===q?E._tr_align(_):e!==L&&(E._tr_stored_block(_,0,0,!1),e===D&&(i(_.head),0===_.lookahead&&(_.strstart=0,_.block_start=0,_.insert=0))),s(t),0===t.avail_out))return _.last_flush=-1,P}return e!==T?P:_.wrap<=0?R:(2===_.wrap?(l(_,255&t.adler),l(_,t.adler>>8&255),l(_,t.adler>>16&255),l(_,t.adler>>24&255),l(_,255&t.total_in),l(_,t.total_in>>8&255),l(_,t.total_in>>16&255),l(_,t.total_in>>24&255)):(h(_,t.adler>>>16),h(_,65535&t.adler)),s(t),_.wrap>0&&(_.wrap=-_.wrap),0!==_.pending?P:R)}function B(t){var e=t.state.status;return e!==oe&&e!==ue&&e!==de&&e!==fe&&e!==ce&&e!==pe&&e!==we?r(t,G):(t.state=null,e===pe?r(t,N):P)}var A,S=t("./utils"),E=t("./trees"),I=t("./adler32"),j=t("./crc32"),C=t("./messages"),U=0,q=1,D=3,T=4,L=5,P=0,R=1,G=-2,N=-3,O=-5,Z=-1,F=1,H=2,J=3,K=4,M=0,Q=2,V=8,W=9,X=15,Y=8,$=29,te=256,ee=te+1+$,ae=30,re=19,ne=2*ee+1,ie=15,se=3,_e=258,le=_e+se+1,he=32,oe=42,ue=69,de=73,fe=91,ce=103,pe=113,we=666,ve=1,be=2,me=3,ge=4,ye=3,ke=function(t,e,a,r,n){this.good_length=t,this.max_lazy=e,this.nice_length=a,this.max_chain=r,this.func=n};A=[new ke(0,0,0,0,f),new ke(4,4,8,4,c),new ke(4,5,16,8,c),new ke(4,6,32,32,c),new ke(4,4,16,16,p),new ke(8,16,32,32,p),new ke(8,16,128,128,p),new ke(8,32,128,256,p),new ke(32,128,258,1024,p),new ke(32,258,258,4096,p)],a.deflateInit=x,a.deflateInit2=k,a.deflateReset=y,a.deflate=z,a.deflateEnd=B,a.deflateInfo="pako deflate (from Nodeca project)"},{"./adler32":2,"./crc32":3,"./messages":5,"./trees":6,"./utils":7}],5:[function(t,e){"use strict";e.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],6:[function(t,e,a){"use strict";function r(t){for(var e=t.length;--e;)t[e]=0}function n(t){return 256>t?se[t]:se[256+(t>>>7)]}function i(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255}function s(t,e,a){t.bi_valid>M-a?(t.bi_buf|=e<>M-t.bi_valid,t.bi_valid+=a-M):(t.bi_buf|=e<>>=1,a<<=1;while(--e>0);return a>>>1}function h(t){16===t.bi_valid?(i(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}function o(t,e){var a,r,n,i,s,_,l=e.dyn_tree,h=e.max_code,o=e.stat_desc.static_tree,u=e.stat_desc.has_stree,d=e.stat_desc.extra_bits,f=e.stat_desc.extra_base,c=e.stat_desc.max_length,p=0;for(i=0;K>=i;i++)t.bl_count[i]=0;for(l[2*t.heap[t.heap_max]+1]=0,a=t.heap_max+1;J>a;a++)r=t.heap[a],i=l[2*l[2*r+1]+1]+1,i>c&&(i=c,p++),l[2*r+1]=i,r>h||(t.bl_count[i]++,s=0,r>=f&&(s=d[r-f]),_=l[2*r],t.opt_len+=_*(i+s),u&&(t.static_len+=_*(o[2*r+1]+s)));if(0!==p){do{for(i=c-1;0===t.bl_count[i];)i--;t.bl_count[i]--,t.bl_count[i+1]+=2,t.bl_count[c]--,p-=2}while(p>0);for(i=c;0!==i;i--)for(r=t.bl_count[i];0!==r;)n=t.heap[--a],n>h||(l[2*n+1]!==i&&(t.opt_len+=(i-l[2*n+1])*l[2*n],l[2*n+1]=i),r--)}}function u(t,e,a){var r,n,i=new Array(K+1),s=0;for(r=1;K>=r;r++)i[r]=s=s+a[r-1]<<1;for(n=0;e>=n;n++){var _=t[2*n+1];0!==_&&(t[2*n]=l(i[_]++,_))}}function d(){var t,e,a,r,n,i=new Array(K+1);for(a=0,r=0;N-1>r;r++)for(le[r]=a,t=0;t<1<<$[r];t++)_e[a++]=r;for(_e[a-1]=r,n=0,r=0;16>r;r++)for(he[r]=n,t=0;t<1<>=7;F>r;r++)for(he[r]=n<<7,t=0;t<1<=e;e++)i[e]=0;for(t=0;143>=t;)ne[2*t+1]=8,t++,i[8]++;for(;255>=t;)ne[2*t+1]=9,t++,i[9]++;for(;279>=t;)ne[2*t+1]=7,t++,i[7]++;for(;287>=t;)ne[2*t+1]=8,t++,i[8]++;for(u(ne,Z+1,i),t=0;F>t;t++)ie[2*t+1]=5,ie[2*t]=l(t,5);oe=new fe(ne,$,O+1,Z,K),ue=new fe(ie,te,0,F,K),de=new fe(new Array(0),ee,0,H,Q)}function f(t){var e;for(e=0;Z>e;e++)t.dyn_ltree[2*e]=0;for(e=0;F>e;e++)t.dyn_dtree[2*e]=0;for(e=0;H>e;e++)t.bl_tree[2*e]=0;t.dyn_ltree[2*V]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0}function c(t){t.bi_valid>8?i(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0}function p(t,e,a,r){c(t),r&&(i(t,a),i(t,~a)),j.arraySet(t.pending_buf,t.window,e,a,t.pending),t.pending+=a}function w(t,e,a,r){var n=2*e,i=2*a;return t[n]a;a++)0!==i[2*a]?(t.heap[++t.heap_len]=h=a,t.depth[a]=0):i[2*a+1]=0;for(;t.heap_len<2;)n=t.heap[++t.heap_len]=2>h?++h:0,i[2*n]=1,t.depth[n]=0,t.opt_len--,_&&(t.static_len-=s[2*n+1]);for(e.max_code=h,a=t.heap_len>>1;a>=1;a--)v(t,i,a);n=l;do a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],v(t,i,1),r=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=r,i[2*n]=i[2*a]+i[2*r],t.depth[n]=(t.depth[a]>=t.depth[r]?t.depth[a]:t.depth[r])+1,i[2*a+1]=i[2*r+1]=n,t.heap[1]=n++,v(t,i,1);while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],o(t,e),u(i,h,t.bl_count)}function g(t,e,a){var r,n,i=-1,s=e[1],_=0,l=7,h=4;for(0===s&&(l=138,h=3),e[2*(a+1)+1]=65535,r=0;a>=r;r++)n=s,s=e[2*(r+1)+1],++__?t.bl_tree[2*n]+=_:0!==n?(n!==i&&t.bl_tree[2*n]++,t.bl_tree[2*W]++):10>=_?t.bl_tree[2*X]++:t.bl_tree[2*Y]++,_=0,i=n,0===s?(l=138,h=3):n===s?(l=6,h=3):(l=7,h=4))}function y(t,e,a){var r,n,i=-1,l=e[1],h=0,o=7,u=4;for(0===l&&(o=138,u=3),r=0;a>=r;r++)if(n=l,l=e[2*(r+1)+1],!(++hh){do _(t,n,t.bl_tree);while(0!==--h)}else 0!==n?(n!==i&&(_(t,n,t.bl_tree),h--),_(t,W,t.bl_tree),s(t,h-3,2)):10>=h?(_(t,X,t.bl_tree),s(t,h-3,3)):(_(t,Y,t.bl_tree),s(t,h-11,7));h=0,i=n,0===l?(o=138,u=3):n===l?(o=6,u=3):(o=7,u=4)}}function k(t){var e;for(g(t,t.dyn_ltree,t.l_desc.max_code),g(t,t.dyn_dtree,t.d_desc.max_code),m(t,t.bl_desc),e=H-1;e>=3&&0===t.bl_tree[2*ae[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}function x(t,e,a,r){var n;for(s(t,e-257,5),s(t,a-1,5),s(t,r-4,4),n=0;r>n;n++)s(t,t.bl_tree[2*ae[n]+1],3);y(t,t.dyn_ltree,e-1),y(t,t.dyn_dtree,a-1)}function z(t){var e,a=4093624447;for(e=0;31>=e;e++,a>>>=1)if(1&a&&0!==t.dyn_ltree[2*e])return U;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return q;for(e=32;O>e;e++)if(0!==t.dyn_ltree[2*e])return q;return U}function B(t){pe||(d(),pe=!0),t.l_desc=new ce(t.dyn_ltree,oe),t.d_desc=new ce(t.dyn_dtree,ue),t.bl_desc=new ce(t.bl_tree,de),t.bi_buf=0,t.bi_valid=0,f(t)}function A(t,e,a,r){s(t,(T<<1)+(r?1:0),3),p(t,e,a,!0)}function S(t){s(t,L<<1,3),_(t,V,ne),h(t)}function E(t,e,a,r){var n,i,_=0;t.level>0?(t.strm.data_type===D&&(t.strm.data_type=z(t)),m(t,t.l_desc),m(t,t.d_desc),_=k(t),n=t.opt_len+3+7>>>3,i=t.static_len+3+7>>>3,n>=i&&(n=i)):n=i=a+5,n>=a+4&&-1!==e?A(t,e,a,r):t.strategy===C||i===n?(s(t,(L<<1)+(r?1:0),3),b(t,ne,ie)):(s(t,(P<<1)+(r?1:0),3),x(t,t.l_desc.max_code+1,t.d_desc.max_code+1,_+1),b(t,t.dyn_ltree,t.dyn_dtree)),f(t),r&&c(t)}function I(t,e,a){var r,i,s;if(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&a,t.last_lit++,0===e?t.dyn_ltree[2*a]++:(t.matches++,e--,t.dyn_ltree[2*(_e[a]+O+1)]++,t.dyn_dtree[2*n(e)]++),0===(8191&t.last_lit)&&t.level>2){for(r=8*t.last_lit,i=t.strstart-t.block_start,s=0;F>s;s++)r+=t.dyn_dtree[2*s]*(5+te[s]);if(r>>>=3,t.matches>1&&i>>1>r)return!0}return t.last_lit===t.lit_bufsize-1}var j=t("./utils"),C=4,U=0,q=1,D=2,T=0,L=1,P=2,R=3,G=258,N=29,O=256,Z=O+1+N,F=30,H=19,J=2*Z+1,K=15,M=16,Q=7,V=256,W=16,X=17,Y=18,$=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],te=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],ee=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],ae=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],re=512,ne=new Array(2*(Z+2));r(ne);var ie=new Array(2*F);r(ie);var se=new Array(re);r(se);var _e=new Array(G-R+1);r(_e);var le=new Array(N);r(le);var he=new Array(F);r(he);var oe,ue,de,fe=function(t,e,a,r,n){this.static_tree=t,this.extra_bits=e,this.extra_base=a,this.elems=r,this.max_length=n,this.has_stree=t&&t.length},ce=function(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e},pe=!1;a._tr_init=B,a._tr_stored_block=A,a._tr_flush_block=E,a._tr_tally=I,a._tr_align=S},{"./utils":7}],7:[function(t,e,a){"use strict";var r="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;a.assign=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var a=e.shift();if(a){if("object"!=typeof a)throw new TypeError(a+"must be non-object");for(var r in a)a.hasOwnProperty(r)&&(t[r]=a[r])}}return t},a.shrinkBuf=function(t,e){return t.length===e?t:t.subarray?t.subarray(0,e):(t.length=e,t)};var n={arraySet:function(t,e,a,r,n){if(e.subarray)return void t.set(e.subarray(a,a+r),n);for(var i=0;r>i;i++)t[n+i]=e[a+i]},flattenChunks:function(t){var e,a,r,n,i,s;for(r=0,e=0,a=t.length;a>e;e++)r+=t[e].length;for(s=new Uint8Array(r),n=0,e=0,a=t.length;a>e;e++)i=t[e],s.set(i,n),n+=i.length;return s}},i={arraySet:function(t,e,a,r,n){for(var i=0;r>i;i++)t[n+i]=e[a+i]},flattenChunks:function(t){return[].concat.apply([],t)}};a.setTyped=function(t){t?(a.Buf8=Uint8Array,a.Buf16=Uint16Array,a.Buf32=Int32Array,a.assign(a,n)):(a.Buf8=Array,a.Buf16=Array,a.Buf32=Array,a.assign(a,i))},a.setTyped(r)},{}],8:[function(t,e){"use strict";function a(){this.next_in=null,this.next_in_index=0,this.avail_in=0,this.total_in=0,this.next_out=null,this.next_out_index=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}e.exports=a},{}]},{},[1])(1)}); \ No newline at end of file diff --git a/dist/pako_inflate.js b/dist/pako_inflate.js index 73ad145..ecd80d3 100644 --- a/dist/pako_inflate.js +++ b/dist/pako_inflate.js @@ -8,12 +8,6 @@ var c = _dereq_('./zlib/constants'); var msg = _dereq_('./zlib/messages'); var zstream = _dereq_('./zlib/zstream'); -// return sliced buffer, trying to avoid new objects creation and mem copy -function sliceBuf(buf, size) { - if (buf.length === size) { return buf; } - - return utils.typedOk() ? buf.subarray(0, size) : buf.slice(0, size); -} /** * class Inflate @@ -68,6 +62,9 @@ function sliceBuf(buf, size) { * - `chunkSize` - size of generated data chunks (16K by default) * - `raw` (boolean) - do raw inflate * + * By default, when no options set, autodetect deflate/gzip data format via + * wrapper header. + * * ##### Example: * * ```javascript @@ -89,13 +86,32 @@ var Inflate = function(options) { this.options = utils.assign({ chunkSize: 16384, - windowBits: 15 + 32 // By default - autodetect deflate/gzip + windowBits: 0 }, options || {}); var opt = this.options; - if (opt.raw && (opt.windowBits > 0)) { + // Force window size for `raw` data, if not set directly, + // because we have no header for autodetect. + if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) { opt.windowBits = -opt.windowBits; + if (opt.windowBits === 0) { opt.windowBits = -15; } + } + + // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate + if ((opt.windowBits >= 0) && (opt.windowBits < 16) && + !(options && options.windowBits)) { + opt.windowBits += 32; + } + + // Gzip header has no info about windows size, we can do autodetect only + // for deflate. So, if window size not set, force it to max when gzip possible + if ((opt.windowBits > 15) && (opt.windowBits < 48)) { + // bit 3 (16) -> gzipped data + // bit 4 (32) -> autodetect gzip/deflate + if ((opt.windowBits & 15) === 0) { + opt.windowBits |= 15; + } } this.err = 0; // error code, if happens (0 = Z_OK) @@ -148,13 +164,12 @@ Inflate.prototype.push = function(data, mode) { var status, _mode; if (this.ended) { return false; } - - _mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH); + _mode = c.Z_NO_FLUSH; strm.next_in = data; strm.next_in_index = 0; strm.avail_in = strm.next_in.length; - strm.next_out = utils.arrayCreate(chunkSize); + strm.next_out = new utils.Buf8(chunkSize); do { strm.avail_out = this.options.chunkSize; @@ -167,14 +182,15 @@ Inflate.prototype.push = function(data, mode) { return false; } if(strm.next_out_index) { - this.onData(sliceBuf(strm.next_out, strm.next_out_index)); + this.onData(utils.shrinkBuf(strm.next_out, strm.next_out_index)); // Allocate buffer for next chunk, if not last if (strm.avail_in > 0 || strm.avail_out === 0) { - strm.next_out = utils.arrayCreate(this.options.chunkSize); + strm.next_out = new utils.Buf8(this.options.chunkSize); } } } while (strm.avail_in > 0 || strm.avail_out === 0); + _mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH); // Finalize on the last chunk. if (_mode === c.Z_FINISH) { status = zlib_inflate.inflateEnd(this.strm); @@ -216,7 +232,7 @@ Inflate.prototype.onEnd = function(status) { } this.chunks = []; this.err = status; - this.msg = msg[status]; + this.msg = this.strm.msg; }; @@ -225,25 +241,35 @@ Inflate.prototype.onEnd = function(status) { * - data (Uint8Array|Array): input data to compress. * - options (Object): zlib inflate options. * - * Decompress `data` with inflate alrorythm and `options`. + * Decompress `data` with inflate/ungzip and `options`. Autodetect + * format via wrapper header by default. That's why we don't provide + * separate `ungzip` method. * * Supported options are: * * - windowBits * * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced) - * for more information on these. + * for more information. + * + * Sugar (options): + * + * - raw (Boolean) - say that we work with raw stream, if you don't wish to specify + * negative windowBits implicitly. + * * * ##### Example: * * ```javascript * var pako = require('pako') - * , in = Uint8Array([1,2,3,4,5,6,7,8,9]) - * , out; + * , input = pako.deflate([1,2,3,4,5,6,7,8,9]) + * , output; * - * out = pako.inflate(data); - * if (out.err) { throw new Error(out.err); } - * console.log(pako.inflate(out.result)); + * try { + * output = pako.inflate(input); + * } catch (err) + * console.log(err); + * } * ``` **/ function inflate(input, options) { @@ -252,7 +278,7 @@ function inflate(input, options) { inflator.push(input, true); // That will never happens, if you don't cheat with options :) - if (inflator.err) { throw msg[inflator.err]; } + if (inflator.err) { throw inflator.msg; } return inflator.result; } @@ -277,7 +303,40 @@ exports.Inflate = Inflate; exports.inflate = inflate; exports.inflateRaw = inflateRaw; -},{"./zlib/constants":2,"./zlib/inflate.js":3,"./zlib/messages":4,"./zlib/utils":5,"./zlib/zstream":6}],2:[function(_dereq_,module,exports){ +},{"./zlib/constants":3,"./zlib/inflate.js":6,"./zlib/messages":8,"./zlib/utils":9,"./zlib/zstream":10}],2:[function(_dereq_,module,exports){ +'use strict'; + +// Note: adler32 takes 12% for level 0 and 2% for level 6. +// It doesn't worth to make additional optimizationa as in original. +// Small size is preferable. + +function adler32(adler, buf, len, pos) { + var s1 = (adler & 0xffff) |0 + , s2 = ((adler >>> 16) & 0xffff) |0 + , n = 0; + + while (len !== 0) { + // Set limit ~ twice less than 5552, to keep + // s2 in 31-bits, because we force signed ints. + // in other case %= will fail. + n = len > 2000 ? 2000 : len; + len -= n; + + do { + s1 = (s1 + buf[pos++]) |0; + s2 = (s2 + s1) |0; + } while (--n); + + s1 %= 65521; + s2 %= 65521; + } + + return (s1 | (s2 << 16)) |0; +} + + +module.exports = adler32; +},{}],3:[function(_dereq_,module,exports){ module.exports = { /* Allowed flush values; see deflate() and inflate() below for details */ @@ -298,9 +357,9 @@ module.exports = { Z_ERRNO: (-1), Z_STREAM_ERROR: (-2), Z_DATA_ERROR: (-3), - Z_MEM_ERROR: (-4), + //Z_MEM_ERROR: (-4), Z_BUF_ERROR: (-5), - Z_VERSION_ERROR: (-6), + //Z_VERSION_ERROR: (-6), /* compression levels */ Z_NO_COMPRESSION: 0, @@ -322,93 +381,660 @@ module.exports = { Z_UNKNOWN: 2, /* The deflate compression method */ - Z_DEFLATED: 8, + Z_DEFLATED: 8 //Z_NULL: null // Use -1 or null, depending on var type }; -},{}],3:[function(_dereq_,module,exports){ +},{}],4:[function(_dereq_,module,exports){ 'use strict'; -//var utils = require('utils'); +// Note: we can't get significant speed boost here. +// So write code to minimize size - no pregenerated tables +// and array tools dependencies. + + +// Use ordinary array, since untyped makes no boost here +function makeTable() { + var c, table = []; + + for(var n =0; n < 256; n++){ + c = n; + for(var k =0; k < 8; k++){ + c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1)); + } + table[n] = c; + } + + return table; +} + +// Create table on load. Just 255 signed longs. Not a problem. +var crcTable = makeTable(); + + +function crc32(crc, buf, len, pos) { + var t = crcTable + , end = pos + len; + + crc = crc ^ (-1); + + for (var i = pos; i < end; i++ ) { + crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF]; + } + + return (crc ^ (-1)); // >>> 0; +} + + +module.exports = crc32; +},{}],5:[function(_dereq_,module,exports){ +'use strict'; + +// See state defs from inflate.js +var BAD = 30; /* got a data error -- remain here until reset */ +var TYPE = 12; /* i: waiting for type bits, including last-flag bit */ + +/* + Decode literal, length, and distance codes and write out the resulting + literal and match bytes until either not enough input or output is + available, an end-of-block is encountered, or a data error is encountered. + When large enough input and output buffers are supplied to inflate(), for + example, a 16K input buffer and a 64K output buffer, more than 95% of the + inflate execution time is spent in this routine. + + Entry assumptions: + + state.mode === LEN + strm.avail_in >= 6 + strm.avail_out >= 258 + start >= strm.avail_out + state.bits < 8 + + On return, state.mode is one of: + + LEN -- ran out of enough output space or enough available input + TYPE -- reached end of block code, inflate() to interpret next block + BAD -- error in block data + + Notes: + + - The maximum input bits used by a length/distance pair is 15 bits for the + length code, 5 bits for the length extra, 15 bits for the distance code, + and 13 bits for the distance extra. This totals 48 bits, or six bytes. + Therefore if strm.avail_in >= 6, then there is enough input to avoid + checking for available input while decoding. + + - The maximum bytes that a single length/distance pair can output is 258 + bytes, which is the maximum length that can be coded. inflate_fast() + requires strm.avail_out >= 258 for each loop to avoid checking for + output space. + */ +module.exports = function inflate_fast(strm, start) { + var state; + var _in; /* local strm.next_in */ + var last; /* have enough input while in < last */ + var _out; /* local strm.next_out */ + var beg; /* inflate()'s initial strm.next_out */ + var end; /* while out < end, enough space available */ +//#ifdef INFLATE_STRICT + var dmax; /* maximum distance from zlib header */ +//#endif + var wsize; /* window size or zero if not using window */ + var whave; /* valid bytes in the window */ + var wnext; /* window write index */ + var window; /* allocated sliding window, if wsize != 0 */ + var hold; /* local strm.hold */ + var bits; /* local strm.bits */ + var lcode; /* local strm.lencode */ + var dcode; /* local strm.distcode */ + var lmask; /* mask for first level of length codes */ + var dmask; /* mask for first level of distance codes */ + var here; /* retrieved table entry */ + var op; /* code bits, operation, extra bits, or */ + /* window position, window bytes to copy */ + var len; /* match length, unused bytes */ + var dist; /* match distance */ + var from; /* where to copy match from */ + var from_source; + + + var input, output; // JS specific, because we have no pointers + + /* copy state to local variables */ + state = strm.state; + //here = state.here; + _in = strm.next_in_index; + input = strm.next_in; + last = _in + (strm.avail_in - 5); + _out = strm.next_out_index; + output = strm.next_out; + beg = _out - (start - strm.avail_out); + end = _out + (strm.avail_out - 257); +//#ifdef INFLATE_STRICT + dmax = state.dmax; +//#endif + wsize = state.wsize; + whave = state.whave; + wnext = state.wnext; + window = state.window; + hold = state.hold; + bits = state.bits; + lcode = state.lencode; + dcode = state.distcode; + lmask = (1 << state.lenbits) - 1; + dmask = (1 << state.distbits) - 1; + + + /* decode literals and length/distances until end-of-block or not enough + input data or output space */ + + top: + do { + if (bits < 15) { + hold += input[_in++] << bits; + bits += 8; + hold += input[_in++] << bits; + bits += 8; + } + + here = lcode[hold & lmask]; + + dolen: + for (;;) { // Goto emulation + op = here >>> 24/*here.bits*/; + hold >>>= op; + bits -= op; + op = (here >>> 16) & 0xff/*here.op*/; + if (op === 0) { /* literal */ + //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + // "inflate: literal '%c'\n" : + // "inflate: literal 0x%02x\n", here.val)); + output[_out++] = here & 0xffff/*here.val*/; + } + else if (op & 16) { /* length base */ + len = here & 0xffff/*here.val*/; + op &= 15; /* number of extra bits */ + if (op) { + if (bits < op) { + hold += input[_in++] << bits; + bits += 8; + } + len += hold & ((1 << op) - 1); + hold >>>= op; + bits -= op; + } + //Tracevv((stderr, "inflate: length %u\n", len)); + if (bits < 15) { + hold += input[_in++] << bits; + bits += 8; + hold += input[_in++] << bits; + bits += 8; + } + here = dcode[hold & dmask]; + + dodist: + for (;;) { // goto emulation + op = here >>> 24/*here.bits*/; + hold >>>= op; + bits -= op; + op = (here >>> 16) & 0xff/*here.op*/; + + if (op & 16) { /* distance base */ + dist = here & 0xffff/*here.val*/; + op &= 15; /* number of extra bits */ + if (bits < op) { + hold += input[_in++] << bits; + bits += 8; + if (bits < op) { + hold += input[_in++] << bits; + bits += 8; + } + } + dist += hold & ((1 << op) - 1); +//#ifdef INFLATE_STRICT + if (dist > dmax) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break top; + } +//#endif + hold >>>= op; + bits -= op; + //Tracevv((stderr, "inflate: distance %u\n", dist)); + op = _out - beg; /* max distance in output */ + if (dist > op) { /* see if copy from window */ + op = dist - op; /* distance back in window */ + if (op > whave) { + if (state.sane) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break top; + } +//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR +// if (len <= op - whave) { +// do { +// output[_out++] = 0; +// } while (--len); +// continue top; +// } +// len -= op - whave; +// do { +// output[_out++] = 0; +// } while (--op > whave); +// if (op === 0) { +// from = _out - dist; +// do { +// output[_out++] = output[from++]; +// } while (--len); +// continue top; +// } +//#endif + } + from = 0; // window index + from_source = window; + if (wnext === 0) { /* very common case */ + from += wsize - op; + if (op < len) { /* some from window */ + len -= op; + do { + output[_out++] = window[from++]; + } while (--op); + from = _out - dist; /* rest from output */ + from_source = output; + } + } + else if (wnext < op) { /* wrap around window */ + from += wsize + wnext - op; + op -= wnext; + if (op < len) { /* some from end of window */ + len -= op; + do { + output[_out++] = window[from++]; + } while (--op); + from = 0; + if (wnext < len) { /* some from start of window */ + op = wnext; + len -= op; + do { + output[_out++] = window[from++]; + } while (--op); + from = _out - dist; /* rest from output */ + from_source = output; + } + } + } + else { /* contiguous in window */ + from += wnext - op; + if (op < len) { /* some from window */ + len -= op; + do { + output[_out++] = window[from++]; + } while (--op); + from = _out - dist; /* rest from output */ + from_source = output; + } + } + while (len > 2) { + output[_out++] = from_source[from++]; + output[_out++] = from_source[from++]; + output[_out++] = from_source[from++]; + len -= 3; + } + if (len) { + output[_out++] = from_source[from++]; + if (len > 1) { + output[_out++] = from_source[from++]; + } + } + } + else { + from = _out - dist; /* copy direct from output */ + do { /* minimum length is three */ + output[_out++] = output[from++]; + output[_out++] = output[from++]; + output[_out++] = output[from++]; + len -= 3; + } while (len > 2); + if (len) { + output[_out++] = output[from++]; + if (len > 1) { + output[_out++] = output[from++]; + } + } + } + } + else if ((op & 64) === 0) { /* 2nd level distance code */ + here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))]; + continue dodist; + } + else { + strm.msg = 'invalid distance code'; + state.mode = BAD; + break top; + } + + break; // need to emulate goto via "continue" + } + } + else if ((op & 64) === 0) { /* 2nd level length code */ + here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))]; + continue dolen; + } + else if (op & 32) { /* end-of-block */ + //Tracevv((stderr, "inflate: end of block\n")); + state.mode = TYPE; + break top; + } + else { + strm.msg = 'invalid literal/length code'; + state.mode = BAD; + break top; + } + + break; // need to emulate goto via "continue" + } + } while (_in < last && _out < end); + + /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ + len = bits >> 3; + _in -= len; + bits -= len << 3; + hold &= (1 << bits) - 1; + + /* update state and return */ + strm.next_in_index = _in; + strm.next_out_index = _out; + strm.avail_in = (_in < last ? 5 + (last - _in) : 5 - (_in - last)); + strm.avail_out = (_out < end ? 257 + (end - _out) : 257 - (_out - end)); + state.hold = hold; + state.bits = bits; + return; +}; + +},{}],6:[function(_dereq_,module,exports){ +'use strict'; + + +var utils = _dereq_('./utils'); +var adler32 = _dereq_('./adler32'); +var crc32 = _dereq_('./crc32'); +var inflate_fast = _dereq_('./inffast'); +var inflate_table = _dereq_('./inftrees'); + +var CODES = 0; +var LENS = 1; +var DISTS = 2; + +/* Public constants ==========================================================*/ +/* ===========================================================================*/ + + +/* Allowed flush values; see deflate() and inflate() below for details */ +//var Z_NO_FLUSH = 0; +//var Z_PARTIAL_FLUSH = 1; +//var Z_SYNC_FLUSH = 2; +//var Z_FULL_FLUSH = 3; +var Z_FINISH = 4; +var Z_BLOCK = 5; +var Z_TREES = 6; + + +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ +var Z_OK = 0; +var Z_STREAM_END = 1; +var Z_NEED_DICT = 2; +//var Z_ERRNO = -1; +var Z_STREAM_ERROR = -2; +var Z_DATA_ERROR = -3; +var Z_MEM_ERROR = -4; +var Z_BUF_ERROR = -5; +//var Z_VERSION_ERROR = -6; + +/* The deflate compression method */ +var Z_DEFLATED = 8; + + +/* STATES ====================================================================*/ +/* ===========================================================================*/ + + +var HEAD = 1; /* i: waiting for magic header */ +var FLAGS = 2; /* i: waiting for method and flags (gzip) */ +var TIME = 3; /* i: waiting for modification time (gzip) */ +var OS = 4; /* i: waiting for extra flags and operating system (gzip) */ +var EXLEN = 5; /* i: waiting for extra length (gzip) */ +var EXTRA = 6; /* i: waiting for extra bytes (gzip) */ +var NAME = 7; /* i: waiting for end of file name (gzip) */ +var COMMENT = 8; /* i: waiting for end of comment (gzip) */ +var HCRC = 9; /* i: waiting for header crc (gzip) */ +var DICTID = 10; /* i: waiting for dictionary check value */ +var DICT = 11; /* waiting for inflateSetDictionary() call */ +var TYPE = 12; /* i: waiting for type bits, including last-flag bit */ +var TYPEDO = 13; /* i: same, but skip check to exit inflate on new block */ +var STORED = 14; /* i: waiting for stored size (length and complement) */ +var COPY_ = 15; /* i/o: same as COPY below, but only first time in */ +var COPY = 16; /* i/o: waiting for input or output to copy stored block */ +var TABLE = 17; /* i: waiting for dynamic block table lengths */ +var LENLENS = 18; /* i: waiting for code length code lengths */ +var CODELENS = 19; /* i: waiting for length/lit and distance code lengths */ +var LEN_ = 20; /* i: same as LEN below, but only first time in */ +var LEN = 21; /* i: waiting for length/lit/eob code */ +var LENEXT = 22; /* i: waiting for length extra bits */ +var DIST = 23; /* i: waiting for distance code */ +var DISTEXT = 24; /* i: waiting for distance extra bits */ +var MATCH = 25; /* o: waiting for output space to copy string */ +var LIT = 26; /* o: waiting for output space to write literal */ +var CHECK = 27; /* i: waiting for 32-bit check value */ +var LENGTH = 28; /* i: waiting for 32-bit length (gzip) */ +var DONE = 29; /* finished check, done -- remain here until reset */ +var BAD = 30; /* got a data error -- remain here until reset */ +var MEM = 31; /* got an inflate() memory error -- remain here until reset */ +var SYNC = 32; /* looking for synchronization bytes to restart inflate() */ + +/* ===========================================================================*/ + + var ENOUGH_LENS = 852; var ENOUGH_DISTS = 592; var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS); -//function Code() { -// this.op = 0; /* operation, extra bits, table bits */ -// this.bits = 0; /* bits in this part of the code */ -// this.val = 0; /* offset in table or code value */ -//} +var MAX_WBITS = 15; +/* 32K LZ77 window */ +var DEF_WBITS = MAX_WBITS; + + +function ZSWAP32(q) { + return (((q >>> 24) & 0xff) + + ((q >>> 8) & 0xff00) + + ((q & 0xff00) << 8) + + ((q & 0xff) << 24)); +} + function InflateState() { - this.mode = -1; /* current inflate mode */ - this.last = 0; /* true if processing last block */ + this.mode = 0; /* current inflate mode */ + this.last = false; /* true if processing last block */ this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */ - this.havedict = 0; /* true if dictionary provided */ + this.havedict = false; /* true if dictionary provided */ this.flags = 0; /* gzip header method and flags (0 if zlib) */ this.dmax = 0; /* zlib header max distance (INFLATE_STRICT) */ this.check = 0; /* protected copy of check value */ this.total = 0; /* protected copy of output count */ - this.head = 0; /* where to save gzip header information */ + // TODO: may be {} + this.head = null; /* where to save gzip header information */ + /* sliding window */ this.wbits = 0; /* log base 2 of requested window size */ this.wsize = 0; /* window size or zero if not using window */ this.whave = 0; /* valid bytes in the window */ this.wnext = 0; /* window write index */ - this.window = -1; /* allocated sliding window, if needed */ + this.window = null; /* allocated sliding window, if needed */ + /* bit accumulator */ this.hold = 0; /* input bit accumulator */ this.bits = 0; /* number of bits in "in" */ + /* for string and stored block copying */ this.length = 0; /* literal or length of data to copy */ this.offset = 0; /* distance back to copy string from */ + /* for table and code decoding */ this.extra = 0; /* extra bits needed */ + /* fixed and dynamic code tables */ - this.lencode = -1; /* starting table for length/literal codes */ - this.distcode = -1; /* starting table for distance codes */ + this.lencode = null; /* starting table for length/literal codes */ + this.distcode = null; /* starting table for distance codes */ this.lenbits = 0; /* index bits for lencode */ this.distbits = 0; /* index bits for distcode */ + /* dynamic table building */ this.ncode = 0; /* number of code length code lengths */ this.nlen = 0; /* number of length code lengths */ this.ndist = 0; /* number of distance code lengths */ this.have = 0; /* number of code lengths in lens[] */ - this.next = 0; /* next available space in codes[] */ + this.next = null; /* next available space in codes[] */ + this.next_index = 0; //unsigned short array //todo: test later with Uint16Array - this.lens = new Array(320); /* temporary storage for code lengths */ - this.work = new Array(280); /* work area for code table building */ + this.lens = new utils.Buf16(320); /* temporary storage for code lengths */ + this.work = new utils.Buf16(280); /* work area for code table building */ - this.codes = new Array(ENOUGH); /* space for code tables */ + // TODO: 8 or 16 bits? + this.codes = new utils.Buf32(ENOUGH); /* space for code tables */ this.sane = 0; /* if false, allow invalid distance too far */ this.back = 0; /* bits back of last unprocessed length/lit */ this.was = 0; /* initial length of match */ } -function inflateResetKeep(/*strm*/) { +function InfTableOptions(type, lens, lens_index, codes, table, table_index, bits, work) { + this.type = type; + this.lens = lens; + this.lens_index = lens_index; + this.codes = codes; + this.table = table; + this.table_index = table_index; + this.bits = bits; + this.work = work; +} + +function inflateResetKeep(strm) { + var state; + + if (!strm || !strm.state) { return Z_STREAM_ERROR; } + state = strm.state; + strm.total_in = strm.total_out = state.total = 0; + //strm.msg = Z_NULL; + if (state.wrap) { /* to support ill-conceived Java test suite */ + strm.adler = state.wrap & 1; + } + state.mode = HEAD; + state.last = 0; + state.havedict = 0; + state.dmax = 32768; + // TODO: may be {} + state.head = null/*Z_NULL*/; + state.hold = 0; + state.bits = 0; + //state.lencode = state.distcode = state.next = state.codes; + //utils.arraySet(state.lencode,state.codes,0,state.codes.length,0); + //utils.arraySet(state.distcode,state.codes,0,state.codes.length,0); + state.lencode = new utils.Buf32(ENOUGH); + state.distcode = new utils.Buf32(ENOUGH); + + state.sane = 1; + state.back = -1; + //Tracev((stderr, "inflate: reset\n")); + return Z_OK; +} + +function inflateReset(strm) { + var state; + + if (!strm || !strm.state) { return Z_STREAM_ERROR; } + state = strm.state; + state.wsize = 0; + state.whave = 0; + state.wnext = 0; + return inflateResetKeep(strm); } -function inflateReset(/*strm*/) { +function inflateReset2(strm, windowBits) { + var wrap; + var state; + /* get the state */ + if (!strm || !strm.state) { return Z_STREAM_ERROR; } + state = strm.state; + + /* extract wrap request from windowBits parameter */ + if (windowBits < 0) { + wrap = 0; + windowBits = -windowBits; + } + else { + wrap = (windowBits >> 4) + 1; + if (windowBits < 48) { + windowBits &= 15; + } + } + + /* set number of window bits, free window if different */ + if (windowBits && (windowBits < 8 || windowBits > 15)) { + return Z_STREAM_ERROR; + } + if (state.window !== null && state.wbits !== windowBits) { + state.window = null; + } + + /* update state and reset the rest of it */ + state.wrap = wrap; + state.wbits = windowBits; + return inflateReset(strm); } -function inflateReset2(/*strm, windowBits*/) { +function inflateInit2(strm, windowBits) { + var ret; + var state; + if (!strm) { return Z_STREAM_ERROR; } + //strm.msg = Z_NULL; /* in case we return an error */ + + state = new InflateState(); + + //if (state === Z_NULL) return Z_MEM_ERROR; + //Tracev((stderr, "inflate: allocated\n")); + strm.state = state; + state.window = null/*Z_NULL*/; + ret = inflateReset2(strm, windowBits); + if (ret !== Z_OK) { + strm.state = null/*Z_NULL*/; + } + return ret; } -function inflateInit2(strm/*, windowBits, version, stream_size*/) { - strm.state = new InflateState(); +function inflateInit(strm) { + return inflateInit2(strm, DEF_WBITS); } -function inflateInit(/*strm, version, stream_size*/) { - -} - -function inflatePrime(/*strm, bits, value*/) { +function inflatePrime(strm, bits, value) { + var state; + if (!strm || !strm.state) { return Z_STREAM_ERROR; } + state = strm.state; + if (bits < 0) { + state.hold = 0; + state.bits = 0; + return Z_OK; + } + if (bits > 16 || state.bits + bits > 32) { return Z_STREAM_ERROR; } + value &= (1 << bits) - 1; + state.hold += value << state.bits; + state.bits += bits; + return Z_OK; } /* @@ -421,31 +1047,47 @@ function inflatePrime(/*strm, bits, value*/) { used for threaded applications, since the rewriting of the tables and virgin may not be thread-safe. */ -//function fixedtables(state) { -// -//} +var virgin = true; -/* - Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also - defines BUILDFIXED, so the tables are built on the fly. makefixed() writes - those tables to stdout, which would be piped to inffixed.h. A small program - can simply call makefixed to do this: +// TODO: check if we can use single array forbetter CPU cache use +// That will require to pass offset, when operating with distance tables. +var lenfix, distfix; // We have no pointers in JS, so keep tables separate - void makefixed(void); +function fixedtables(state) { + /* build fixed huffman tables if first call (may not be thread safe) */ + if (virgin) { + var sym, bits; - int main(void) - { - makefixed(); - return 0; - } + lenfix = new utils.Buf32(512); + distfix = new utils.Buf32(32); - Then that can be linked with zlib built with MAKEFIXED defined and run: + /* literal/length table */ + sym = 0; + while (sym < 144) { state.lens[sym++] = 8; } + while (sym < 256) { state.lens[sym++] = 9; } + while (sym < 280) { state.lens[sym++] = 7; } + while (sym < 288) { state.lens[sym++] = 8; } + + bits = 9; + inflate_table(new InfTableOptions(LENS, state.lens, 0, 288, lenfix, 0, bits, state.work)); + + /* distance table */ + sym = 0; + while (sym < 32) { state.lens[sym++] = 5; } + bits = 5; + + inflate_table(new InfTableOptions(DISTS, state.lens, 0, 32, distfix, 0, bits, state.work)); + + /* do this just once */ + virgin = false; + } + + state.lencode = lenfix; + state.lenbits = 9; + state.distcode = distfix; + state.distbits = 5; +} - a.out > inffixed.h - */ -//function makefixed() { -// -//} /* Update the window with the last wsize (normally 32K) bytes written before @@ -461,97 +1103,1487 @@ function inflatePrime(/*strm, bits, value*/) { output will fall in the output data, making match copies simpler and faster. The advantage may be dependent on the size of the processor's data caches. */ -//function updatewindow(strm, end, copy) { -// -//} +function updatewindow(strm, src, end, copy) { + var dist; + var state = strm.state; -function inflate(/*strm, flush*/) { + /* if it hasn't been done already, allocate space for the window */ + if (state.window === null) { + state.wsize = 1 << state.wbits; + state.wnext = 0; + state.whave = 0; + state.window = new utils.Buf8(state.wsize); + } + + /* copy state->wsize or less output bytes into the circular window */ + if (copy >= state.wsize) { + utils.arraySet(state.window,src, end - state.wsize, state.wsize, 0); + state.wnext = 0; + state.whave = state.wsize; + } + else { + dist = state.wsize - state.wnext; + if (dist > copy) { + dist = copy; + } + //zmemcpy(state->window + state->wnext, end - copy, dist); + utils.arraySet(state.window,src, end - copy, dist, state.wnext); + copy -= dist; + if (copy) { + //zmemcpy(state->window, end - copy, copy); + utils.arraySet(state.window,src, end - copy, copy, 0); + state.wnext = copy; + state.whave = state.wsize; + } + else { + state.wnext += dist; + if (state.wnext === state.wsize) { state.wnext = 0; } + if (state.whave < state.wsize) { state.whave += dist; } + } + } + return 0; } -function inflateEnd(/*strm*/) { +function inflate(strm, flush) { + var state; + var input, output; // input/output buffers + var next; /* next input INDEX */ + var put; /* next output INDEX */ + var have, left; /* available input and output */ + var hold; /* bit buffer */ + var bits; /* bits in bit buffer */ + var _in, _out; /* save starting available input and output */ + var copy; /* number of stored or match bytes to copy */ + var from; /* where to copy match bytes from */ + var from_source; + var here = 0; /* current decoding table entry */ + var here_bits, here_op, here_val; + //var last; /* parent table entry */ + var last_bits, last_op, last_val; // paked "last" denormalized + var len; /* length to copy for repeats, bits to drop */ + var ret; /* return code */ + var hbuf = new utils.Buf8(4); /* buffer for gzip header crc calculation */ + var opts; + var n; // temporary var for NEED_BITS + + var order = /* permutation of code lengths */ + [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; + + + // TODO: check if needed and don't affect speed + //if (strm === Z_NULL || strm.state === Z_NULL || strm.next_out === Z_NULL || + // (strm.next_in === Z_NULL && strm.avail_in !== 0)) + // return Z_STREAM_ERROR; + + state = strm.state; + if (state.mode === TYPE) { state.mode = TYPEDO; } /* skip check */ + + + //--- LOAD() --- + put = strm.next_out_index; + output = strm.next_out; + left = strm.avail_out; + next = strm.next_in_index; + input = strm.next_in; + have = strm.avail_in; + hold = state.hold; + bits = state.bits; + //--- + + _in = have; + _out = left; + ret = Z_OK; + + inf_leave: // goto emulation + for (;;) { + switch (state.mode) { + case HEAD: + if (state.wrap === 0) { + state.mode = TYPEDO; + break; + } + //=== NEEDBITS(16); + while (bits < 16) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if ((state.wrap & 2) && hold === 0x8b1f) { /* gzip header */ + state.check = 0/*crc32(0L, Z_NULL, 0)*/; + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = FLAGS; + break; + } + state.flags = 0; /* expect zlib header */ + if (state.head) { + state.head.done = -1; + } + if (!(state.wrap & 1) || /* check if zlib header allowed */ + (((hold & 0xff)/*BITS(8)*/ << 8) + (hold >> 8)) % 31) { + strm.msg = 'incorrect header check'; + state.mode = BAD; + break; + } + if ((hold & 0x0f)/*BITS(4)*/ !== Z_DEFLATED) { + strm.msg = 'unknown compression method'; + state.mode = BAD; + break; + } + //--- DROPBITS(4) ---// + hold >>>= 4; + bits -= 4; + //---// + len = (hold & 0x0f)/*BITS(4)*/ + 8; + if (state.wbits === 0) { + state.wbits = len; + } + else if (len > state.wbits) { + strm.msg = 'invalid window size'; + state.mode = BAD; + break; + } + state.dmax = 1 << len; + //Tracev((stderr, "inflate: zlib header ok\n")); + strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/; + state.mode = hold & 0x200 ? DICTID : TYPE; + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + break; + case FLAGS: + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.flags = hold; + if ((state.flags & 0xff) !== Z_DEFLATED) { + strm.msg = 'unknown compression method'; + state.mode = BAD; + break; + } + if (state.flags & 0xe000) { + strm.msg = 'unknown header flags set'; + state.mode = BAD; + break; + } + if (state.head) { + state.head.text = ((hold >> 8) & 1); + } + if (state.flags & 0x0200) { + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = TIME; + /* falls through */ + case TIME: + //=== NEEDBITS(32); */ + while (bits < 32) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (state.head) { + state.head.time = hold; + } + if (state.flags & 0x0200) { + //=== CRC4(state.check, hold) + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + hbuf[2] = (hold >>> 16) & 0xff; + hbuf[3] = (hold >>> 24) & 0xff; + state.check = crc32(state.check, hbuf, 4, 0); + //=== + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = OS; + /* falls through */ + case OS: + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (state.head) { + state.head.xflags = (hold & 0xff); + state.head.os = (hold >> 8); + } + if (state.flags & 0x0200) { + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = EXLEN; + /* falls through */ + case EXLEN: + if (state.flags & 0x0400) { + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.length = hold; + if (state.head) { + state.head.extra_len = hold; + } + if (state.flags & 0x0200) { + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + } + else if (state.head) { + state.head.extra = null/*Z_NULL*/; + } + state.mode = EXTRA; + /* falls through */ + case EXTRA: + if (state.flags & 0x0400) { + copy = state.length; + if (copy > have) { copy = have; } + if (copy) { + if (state.head && + state.head.extra) { + len = state.head.extra_len - state.length; + //zmemcpy(state.head.extra + len, next, + // len + copy > state.head.extra_max ? + // state.head.extra_max - len : copy); + throw 'Review & implement right'; + } + if (state.flags & 0x0200) { + state.check = crc32(state.check, input, copy, next); + } + have -= copy; + next += copy; + state.length -= copy; + } + if (state.length) { break inf_leave; } + } + state.length = 0; + state.mode = NAME; + /* falls through */ + case NAME: + if (state.flags & 0x0800) { + if (have === 0) { break inf_leave; } + copy = 0; + do { + // TODO: 2 or 1 bytes? + len = input[next + copy++]; + if (state.head && state.head.name && + (state.length < state.head.name_max)) { + state.head.name[state.length++] = len; + } + } while (len && copy < have); + if (state.flags & 0x0200) { + state.check = crc32(state.check, input, copy, next); + } + have -= copy; + next += copy; + if (len) { break inf_leave; } + } + else if (state.head) { + state.head.name = null; + } + state.length = 0; + state.mode = COMMENT; + /* falls through */ + case COMMENT: + if (state.flags & 0x1000) { + if (have === 0) { break inf_leave; } + copy = 0; + do { + len = input[next + copy++]; + if (state.head && state.head.comment && + (state.length < state.head.comm_max)) { + state.head.comment[state.length++] = len; + } + } while (len && copy < have); + if (state.flags & 0x0200) { + state.check = crc32(state.check, input, copy, next); + } + have -= copy; + next += copy; + if (len) { break inf_leave; } + } + else if (state.head) { + state.head.comment = null; + } + state.mode = HCRC; + /* falls through */ + case HCRC: + if (state.flags & 0x0200) { + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (hold !== (state.check & 0xffff)) { + strm.msg = 'header crc mismatch'; + state.mode = BAD; + break; + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + } + if (state.head) { + state.head.hcrc = ((state.flags >> 9) & 1); + state.head.done = 1; + } + strm.adler = state.check = 0 /*crc32(0L, Z_NULL, 0)*/; + state.mode = TYPE; + break; + case DICTID: + //=== NEEDBITS(32); */ + while (bits < 32) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + strm.adler = state.check = ZSWAP32(hold); + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = DICT; + /* falls through */ + case DICT: + if (state.havedict === 0) { + //--- RESTORE() --- + strm.next_out_index = put; + strm.avail_out = left; + strm.next_in_index = next; + strm.avail_in = have; + state.hold = hold; + state.bits = bits; + //--- + return Z_NEED_DICT; + } + strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/; + state.mode = TYPE; + /* falls through */ + case TYPE: + if (flush === Z_BLOCK || flush === Z_TREES) { break inf_leave; } + /* falls through */ + case TYPEDO: + if (state.last) { + //--- BYTEBITS() ---// + hold >>>= bits & 7; + bits -= bits & 7; + //---// + state.mode = CHECK; + break; + } + //=== NEEDBITS(3); */ + while (bits < 3) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.last = (hold & 0x01)/*BITS(1)*/; + //--- DROPBITS(1) ---// + hold >>>= 1; + bits -= 1; + //---// + + switch ((hold & 0x03)/*BITS(2)*/) { + case 0: /* stored block */ + //Tracev((stderr, "inflate: stored block%s\n", + // state.last ? " (last)" : "")); + state.mode = STORED; + break; + case 1: /* fixed block */ + fixedtables(state); + //Tracev((stderr, "inflate: fixed codes block%s\n", + // state.last ? " (last)" : "")); + state.mode = LEN_; /* decode codes */ + if (flush === Z_TREES) { + //--- DROPBITS(2) ---// + hold >>>= 2; + bits -= 2; + //---// + break inf_leave; + } + break; + case 2: /* dynamic block */ + //Tracev((stderr, "inflate: dynamic codes block%s\n", + // state.last ? " (last)" : "")); + state.mode = TABLE; + break; + case 3: + strm.msg = 'invalid block type'; + state.mode = BAD; + } + //--- DROPBITS(2) ---// + hold >>>= 2; + bits -= 2; + //---// + break; + case STORED: + //--- BYTEBITS() ---// /* go to byte boundary */ + hold >>>= bits & 7; + bits -= bits & 7; + //---// + //=== NEEDBITS(32); */ + while (bits < 32) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if ((hold & 0xffff) !== ((hold >>> 16) ^ 0xffff)) { + strm.msg = 'invalid stored block lengths'; + state.mode = BAD; + break; + } + state.length = hold & 0xffff; + //Tracev((stderr, "inflate: stored length %u\n", + // state.length)); + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = COPY_; + if (flush === Z_TREES) { break inf_leave; } + /* falls through */ + case COPY_: + state.mode = COPY; + /* falls through */ + case COPY: + copy = state.length; + if (copy) { + if (copy > have) { copy = have; } + if (copy > left) { copy = left; } + if (copy === 0) { break inf_leave; } + //--- zmemcpy(put, next, copy); --- + utils.arraySet(output, input, next, copy, put); + //---// + have -= copy; + next += copy; + left -= copy; + put += copy; + state.length -= copy; + break; + } + //Tracev((stderr, "inflate: stored end\n")); + state.mode = TYPE; + break; + case TABLE: + //=== NEEDBITS(14); */ + while (bits < 14) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.nlen = (hold & 0x1f)/*BITS(5)*/ + 257; + //--- DROPBITS(5) ---// + hold >>>= 5; + bits -= 5; + //---// + state.ndist = (hold & 0x1f)/*BITS(5)*/ + 1; + //--- DROPBITS(5) ---// + hold >>>= 5; + bits -= 5; + //---// + state.ncode = (hold & 0x0f)/*BITS(4)*/ + 4; + //--- DROPBITS(4) ---// + hold >>>= 4; + bits -= 4; + //---// +//#ifndef PKZIP_BUG_WORKAROUND + if (state.nlen > 286 || state.ndist > 30) { + strm.msg = 'too many length or distance symbols'; + state.mode = BAD; + break; + } +//#endif + //Tracev((stderr, "inflate: table sizes ok\n")); + state.have = 0; + state.mode = LENLENS; + /* falls through */ + case LENLENS: + while (state.have < state.ncode) { + //=== NEEDBITS(3); + while (bits < 3) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.lens[order[state.have++]] = (hold & 0x07);//BITS(3); + //--- DROPBITS(3) ---// + hold >>>= 3; + bits -= 3; + //---// + } + while (state.have < 19) { + state.lens[order[state.have++]] = 0; + } + //state.next = state.codes; + // TODO: + //state.lencode = state.next; + //state.lencode.copy(state.codes); + utils.arraySet(state.lencode, state.codes, 0, state.codes.length, 0); + state.lenbits = 7; + + opts = new InfTableOptions(CODES, state.lens, 0, 19, state.lencode, 0, state.lenbits, state.work); + ret = inflate_table(opts); + state.lenbits = opts.bits; + + if (ret) { + strm.msg = 'invalid code lengths set'; + state.mode = BAD; + break; + } + //Tracev((stderr, "inflate: code lengths ok\n")); + state.have = 0; + state.mode = CODELENS; + /* falls through */ + case CODELENS: + while (state.have < state.nlen + state.ndist) { + for (;;) { + here = state.lencode[hold & ((1 << state.lenbits) - 1)];/*BITS(state.lenbits)*/ + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if ((here_bits) <= bits) { break; } + //--- PULLBYTE() ---// + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + if (here_val < 16) { + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + state.lens[state.have++] = here_val; + } + else { + if (here_val === 16) { + //=== NEEDBITS(here.bits + 2); + n = here_bits + 2; + while (bits < n) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + if (state.have === 0) { + strm.msg = 'invalid bit length repeat'; + state.mode = BAD; + break; + } + len = state.lens[state.have - 1]; + copy = 3 + (hold & 0x03);//BITS(2); + //--- DROPBITS(2) ---// + hold >>>= 2; + bits -= 2; + //---// + } + else if (here_val === 17) { + //=== NEEDBITS(here.bits + 3); + n = here_bits + 3; + while (bits < n) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + len = 0; + copy = 3 + (hold & 0x07);//BITS(3); + //--- DROPBITS(3) ---// + hold >>>= 3; + bits -= 3; + //---// + } + else { + //=== NEEDBITS(here.bits + 7); + n = here_bits + 7; + while (bits < n) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + len = 0; + copy = 11 + (hold & 0x7f);//BITS(7); + //--- DROPBITS(7) ---// + hold >>>= 7; + bits -= 7; + //---// + } + if (state.have + copy > state.nlen + state.ndist) { + strm.msg = 'invalid bit length repeat'; + state.mode = BAD; + break; + } + while (copy--) { + state.lens[state.have++] = len; + } + } + } + + /* handle error breaks in while */ + if (state.mode === BAD) { break; } + + /* check for end-of-block code (better have one) */ + if (state.lens[256] === 0) { + strm.msg = 'invalid code -- missing end-of-block'; + state.mode = BAD; + break; + } + + /* build code tables -- note: do not change the lenbits or distbits + values here (9 and 6) without reading the comments in inftrees.h + concerning the ENOUGH constants, which depend on those values */ + //state.lencode.copy(state.codes); + utils.arraySet(state.lencode, state.codes, 0, state.codes.length, 0); + state.lenbits = 9; + + opts = new InfTableOptions(LENS, state.lens, 0, state.nlen,state.lencode,0, state.lenbits, state.work); + ret = inflate_table(opts); +// state.next_index = opts.table_index; + state.lenbits = opts.bits; +// state.lencode = state.next; + + if (ret) { + strm.msg = 'invalid literal/lengths set'; + state.mode = BAD; + break; + } + + state.distbits = 6; + //state.distcode.copy(state.codes); + utils.arraySet(state.distcode, state.codes, 0, state.codes.length, 0); + opts = new InfTableOptions(DISTS, state.lens, state.nlen, state.ndist, state.distcode,0, state.distbits, state.work); + ret = inflate_table(opts); +// state.next_index = opts.table_index; + state.distbits = opts.bits; +// state.distcode = state.next; + + if (ret) { + strm.msg = 'invalid distances set'; + state.mode = BAD; + break; + } + //Tracev((stderr, 'inflate: codes ok\n')); + state.mode = LEN_; + if (flush === Z_TREES) { break inf_leave; } + /* falls through */ + case LEN_: + state.mode = LEN; + /* falls through */ + case LEN: + if (have >= 6 && left >= 258) { + //--- RESTORE() --- + strm.next_out_index = put; + strm.avail_out = left; + strm.next_in_index = next; + strm.avail_in = have; + state.hold = hold; + state.bits = bits; + //--- + inflate_fast(strm, _out); + //--- LOAD() --- + put = strm.next_out_index; + output = strm.next_out; + left = strm.avail_out; + next = strm.next_in_index; + input = strm.next_in; + have = strm.avail_in; + hold = state.hold; + bits = state.bits; + //--- + + if (state.mode === TYPE) { + state.back = -1; + } + break; + } + state.back = 0; + for (;;) { + here = state.lencode[hold & ((1 << state.lenbits) -1)]; /*BITS(state.lenbits)*/ + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if (here_bits <= bits) { break; } + //--- PULLBYTE() ---// + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + if (here_op && (here_op & 0xf0) === 0) { + last_bits = here_bits; + last_op = here_op; + last_val = here_val; + for (;;) { + here = state.lencode[last_val + + ((hold & ((1 << (last_bits + last_op)) -1))/*BITS(last.bits + last.op)*/ >> last_bits)]; + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if ((last_bits + here_bits) <= bits) { break; } + //--- PULLBYTE() ---// + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + //--- DROPBITS(last.bits) ---// + hold >>>= last_bits; + bits -= last_bits; + //---// + state.back += last_bits; + } + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + state.back += here_bits; + state.length = here_val; + if (here_op === 0) { + //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + // "inflate: literal '%c'\n" : + // "inflate: literal 0x%02x\n", here.val)); + state.mode = LIT; + break; + } + if (here_op & 32) { + //Tracevv((stderr, "inflate: end of block\n")); + state.back = -1; + state.mode = TYPE; + break; + } + if (here_op & 64) { + strm.msg = 'invalid literal/length code'; + state.mode = BAD; + break; + } + state.extra = here_op & 15; + state.mode = LENEXT; + /* falls through */ + case LENEXT: + if (state.extra) { + //=== NEEDBITS(state.extra); + n = state.extra; + while (bits < n) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.length += hold & ((1 << state.extra) -1)/*BITS(state.extra)*/; + //--- DROPBITS(state.extra) ---// + hold >>>= state.extra; + bits -= state.extra; + //---// + state.back += state.extra; + } + //Tracevv((stderr, "inflate: length %u\n", state.length)); + state.was = state.length; + state.mode = DIST; + /* falls through */ + case DIST: + for (;;) { + here = state.distcode[hold & ((1 << state.distbits) -1)];/*BITS(state.distbits)*/ + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if ((here_bits) <= bits) { break; } + //--- PULLBYTE() ---// + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + if ((here_op & 0xf0) === 0) { + last_bits = here_bits; + last_op = here_op; + last_val = here_val; + for (;;) { + here = state.distcode[last_val + + ((hold & ((1 << (last_bits + last_op)) -1))/*BITS(last.bits + last.op)*/ >> last_bits)]; + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if ((last_bits + here_bits) <= bits) { break; } + //--- PULLBYTE() ---// + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + //--- DROPBITS(last.bits) ---// + hold >>>= last_bits; + bits -= last_bits; + //---// + state.back += last_bits; + } + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + state.back += here_bits; + if (here_op & 64) { + strm.msg = 'invalid distance code'; + state.mode = BAD; + break; + } + state.offset = here_val; + state.extra = (here_op) & 15; + state.mode = DISTEXT; + /* falls through */ + case DISTEXT: + if (state.extra) { + //=== NEEDBITS(state.extra); + n = state.extra; + while (bits < n) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.offset += hold & ((1 << state.extra) -1)/*BITS(state.extra)*/; + //--- DROPBITS(state.extra) ---// + hold >>>= state.extra; + bits -= state.extra; + //---// + state.back += state.extra; + } +//#ifdef INFLATE_STRICT + if (state.offset > state.dmax) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break; + } +//#endif + //Tracevv((stderr, "inflate: distance %u\n", state.offset)); + state.mode = MATCH; + /* falls through */ + case MATCH: + if (left === 0) { break inf_leave; } + copy = _out - left; + if (state.offset > copy) { /* copy from window */ + copy = state.offset - copy; + if (copy > state.whave) { + if (state.sane) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break; + } +//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR + //Trace((stderr, "inflate.c too far\n")); +// copy -= state.whave; +// if (copy > state.length) { copy = state.length; } +// if (copy > left) { copy = left; } +// left -= copy; +// state.length -= copy; +// do { +// output[put++] = 0; +// } while (--copy); +// if (state.length === 0) { state.mode = LEN; } +// break; +//#endif + } + if (copy > state.wnext) { + copy -= state.wnext; + from = state.wsize - copy; + } + else { + from = state.wnext - copy; + } + if (copy > state.length) { copy = state.length; } + from_source = state.window; + } + else { /* copy from output */ + from_source = output; + from = put - state.offset; + copy = state.length; + } + if (copy > left) { copy = left; } + left -= copy; + state.length -= copy; + do { + output[put++] = from_source[from++]; + } while (--copy); + if (state.length === 0) { state.mode = LEN; } + break; + case LIT: + if (left === 0) { break inf_leave; } + output[put++] = state.length; + left--; + state.mode = LEN; + break; + case CHECK: + if (state.wrap) { + //=== NEEDBITS(32); + while (bits < 32) { + if (have === 0) { break inf_leave; } + have--; + // Use '|' insdead of '+' to make sure that result is signed + hold |= input[next++] << bits; + bits += 8; + } + //===// + _out -= left; + strm.total_out += _out; + state.total += _out; + if (_out) { + strm.adler = state.check = + /*UPDATE(state.check, put - _out, _out);*/ + (state.flags ? crc32(state.check, output, _out, put - _out) : adler32(state.check, output, _out, put - _out)); + + } + _out = left; + // NB: crc32 stored as signed 32-bit int, ZSWAP32 returns signed too + if ((state.flags ? hold : ZSWAP32(hold)) !== state.check) { + strm.msg = 'incorrect data check'; + state.mode = BAD; + break; + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + //Tracev((stderr, "inflate: check matches trailer\n")); + } + state.mode = LENGTH; + /* falls through */ + case LENGTH: + if (state.wrap && state.flags) { + //=== NEEDBITS(32); + while (bits < 32) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (hold !== (state.total & 0xffffffff)) { + strm.msg = 'incorrect length check'; + state.mode = BAD; + break; + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + //Tracev((stderr, "inflate: length matches trailer\n")); + } + state.mode = DONE; + /* falls through */ + case DONE: + ret = Z_STREAM_END; + break inf_leave; + case BAD: + ret = Z_DATA_ERROR; + break inf_leave; + case MEM: + return Z_MEM_ERROR; + case SYNC: + /* falls through */ + default: + return Z_STREAM_ERROR; + } + } + + // inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave" + + /* + Return from inflate(), updating the total counts and the check value. + If there was no progress during the inflate() call, return a buffer + error. Call updatewindow() to create and/or update the window state. + Note: a memory error from inflate() is non-recoverable. + */ + + //--- RESTORE() --- + strm.next_out_index = put; + strm.avail_out = left; + strm.next_in_index = next; + strm.avail_in = have; + state.hold = hold; + state.bits = bits; + //--- + + if (state.wsize || (_out !== strm.avail_out && state.mode < BAD && + (state.mode < CHECK || flush !== Z_FINISH))) { + if (updatewindow(strm, strm.next_out, strm.next_out_index, _out - strm.avail_out)) { + state.mode = MEM; + return Z_MEM_ERROR; + } + } + _in -= strm.avail_in; + _out -= strm.avail_out; + strm.total_in += _in; + strm.total_out += _out; + state.total += _out; + if (state.wrap && _out) { + strm.adler = state.check = /*UPDATE(state.check, strm.next_out_index - _out, _out);*/ + (state.flags ? crc32(state.check, output, _out, strm.next_out_index - _out) : adler32(state.check, output, _out, strm.next_out_index - _out)); + } + strm.data_type = state.bits + (state.last ? 64 : 0) + + (state.mode === TYPE ? 128 : 0) + + (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0); + if (((_in === 0 && _out === 0) || flush === Z_FINISH) && ret === Z_OK) { + ret = Z_BUF_ERROR; + } + return ret; } -function inflateGetDictionary(/*strm, dictionary, dictLength*/) { - +function inflateEnd(strm) { +// if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) +// return Z_STREAM_ERROR; + var state = strm.state; + if (state.window) { + state.window = null; + } + strm.state = null; + return Z_OK; } -function inflateSetDictionary(/*strm, dictionary, dictLength*/) { - -} - -function inflateGetHeader(/*strm, head*/) { - -} - -/* - Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found - or when out of input. When called, *have is the number of pattern bytes - found in order so far, in 0..3. On return *have is updated to the new - state. If on return *have equals four, then the pattern was found and the - return value is how many bytes were read including the last byte of the - pattern. If *have is less than four, then the pattern has not been found - yet and the return value is len. In the latter case, syncsearch() can be - called again with more data and the *have state. *have is initialized to - zero for the first call. - */ -//function syncsearch(/*have, buf, len*/) { -// -//} - -function inflateSync(/*strm*/) { - -} - -function inflateSyncPoint(/*strm*/) { - -} - -function inflateCopy(/*dest, source*/) { - -} - -function inflateUndermine(/*strm, subvert*/) { - -} - -function inflateMark(/*strm*/) { - -} - -exports.inflateResetKeep = inflateResetKeep; exports.inflateReset = inflateReset; - exports.inflateReset2 = inflateReset2; - -exports.inflateInit2 = inflateInit2; - +exports.inflateResetKeep = inflateResetKeep; exports.inflateInit = inflateInit; - +exports.inflateInit2 = inflateInit2; exports.inflatePrime = inflatePrime; - exports.inflate = inflate; - exports.inflateEnd = inflateEnd; +exports.inflateInfo = 'pako inflate (from Nodeca project)'; +/* Not implemented exports.inflateGetDictionary = inflateGetDictionary; - exports.inflateGetHeader = inflateGetHeader; - exports.inflateSetDictionary = inflateSetDictionary; - exports.inflateSync = inflateSync; - exports.inflateSyncPoint = inflateSyncPoint; - exports.inflateCopy = inflateCopy; - exports.inflateUndermine = inflateUndermine; - exports.inflateMark = inflateMark; -},{}],4:[function(_dereq_,module,exports){ +*/ +},{"./adler32":2,"./crc32":4,"./inffast":5,"./inftrees":7,"./utils":9}],7:[function(_dereq_,module,exports){ +'use strict'; + + +var utils = _dereq_('./utils'); + +var MAXBITS = 15; +var ENOUGH_LENS = 852; +var ENOUGH_DISTS = 592; +//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS); + +var CODES = 0; +var LENS = 1; +var DISTS = 2; + +var lbase = [ /* Length codes 257..285 base */ + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 +]; + +var lext = [ /* Length codes 257..285 extra */ + 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78 +]; + +var dbase = [ /* Distance codes 0..29 base */ + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, + 8193, 12289, 16385, 24577, 0, 0 +]; + +var dext = [ /* Distance codes 0..29 extra */ + 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, + 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, + 28, 28, 29, 29, 64, 64 +]; + +module.exports = function inflate_table(opts) +{ + var type = opts.type, + lens = opts.lens, + codes = opts.codes, + table = opts.table, + bits = opts.bits, + work = opts.work; + //here = opts.here; /* table entry for duplication */ + + var len = 0; /* a code's length in bits */ + var sym = 0; /* index of code symbols */ + var min = 0, max = 0; /* minimum and maximum code lengths */ + var root = 0; /* number of index bits for root table */ + var curr = 0; /* number of index bits for current table */ + var drop = 0; /* code bits to drop for sub-table */ + var left = 0; /* number of prefix codes available */ + var used = 0; /* code entries in table used */ + var huff = 0; /* Huffman code */ + var incr; /* for incrementing code, index */ + var fill; /* index for replicating entries */ + var low; /* low bits for current root entry */ + var mask; /* mask for low root bits */ + var next; /* next available space in table */ + var base = null; /* base value table to use */ + var base_index = 0; +// var shoextra; /* extra bits table to use */ + var end; /* use base and extra for symbol > end */ + var count = new utils.Buf16(MAXBITS+1); //[MAXBITS+1]; /* number of codes of each length */ + var offs = new utils.Buf16(MAXBITS+1); //[MAXBITS+1]; /* offsets in table for each length */ + var extra = null; + var extra_index = 0; + + var here_bits, here_op, here_val; + + /* + Process a set of code lengths to create a canonical Huffman code. The + code lengths are lens[0..codes-1]. Each length corresponds to the + symbols 0..codes-1. The Huffman code is generated by first sorting the + symbols by length from short to long, and retaining the symbol order + for codes with equal lengths. Then the code starts with all zero bits + for the first code of the shortest length, and the codes are integer + increments for the same length, and zeros are appended as the length + increases. For the deflate format, these bits are stored backwards + from their more natural integer increment ordering, and so when the + decoding tables are built in the large loop below, the integer codes + are incremented backwards. + + This routine assumes, but does not check, that all of the entries in + lens[] are in the range 0..MAXBITS. The caller must assure this. + 1..MAXBITS is interpreted as that code length. zero means that that + symbol does not occur in this code. + + The codes are sorted by computing a count of codes for each length, + creating from that a table of starting indices for each length in the + sorted table, and then entering the symbols in order in the sorted + table. The sorted table is work[], with that space being provided by + the caller. + + The length counts are used for other purposes as well, i.e. finding + the minimum and maximum length codes, determining if there are any + codes at all, checking for a valid set of lengths, and looking ahead + at length counts to determine sub-table sizes when building the + decoding tables. + */ + + /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ + for (len = 0; len <= MAXBITS; len++) { + count[len] = 0; + } + for (sym = 0; sym < codes; sym++) { + count[lens[opts.lens_index + sym]]++; + } + + /* bound code lengths, force root to be within code lengths */ + root = bits; + for (max = MAXBITS; max >= 1; max--) { + if (count[max] !== 0) { break; } + } + if (root > max) { + root = max; + } + if (max === 0) { /* no symbols to code at all */ + //table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */ + //table.bits[opts.table_index] = 1; //here.bits = (var char)1; + //table.val[opts.table_index++] = 0; //here.val = (var short)0; + table[opts.table_index++] = (1 << 24) | (64 << 16) | 0; + + + //table.op[opts.table_index] = 64; + //table.bits[opts.table_index] = 1; + //table.val[opts.table_index++] = 0; + table[opts.table_index++] = (1 << 24) | (64 << 16) | 0; + + opts.bits = 1; + return 0; /* no symbols, but wait for decoding to report error */ + } + for (min = 1; min < max; min++) { + if (count[min] !== 0) { break; } + } + if (root < min) { + root = min; + } + + /* check for an over-subscribed or incomplete set of lengths */ + left = 1; + for (len = 1; len <= MAXBITS; len++) { + left <<= 1; + left -= count[len]; + if (left < 0) { + return -1; + } /* over-subscribed */ + } + if (left > 0 && (type === CODES || max !== 1)) { + return -1; /* incomplete set */ + } + + /* generate offsets into symbol table for each length for sorting */ + offs[1] = 0; + for (len = 1; len < MAXBITS; len++) { + offs[len + 1] = offs[len] + count[len]; + } + + /* sort symbols by length, by symbol order within each length */ + for (sym = 0; sym < codes; sym++) { + if (lens[opts.lens_index + sym] !== 0) { + work[offs[lens[opts.lens_index + sym]]++] = sym; + } + } + + /* + Create and fill in decoding tables. In this loop, the table being + filled is at next and has curr index bits. The code being used is huff + with length len. That code is converted to an index by dropping drop + bits off of the bottom. For codes where len is less than drop + curr, + those top drop + curr - len bits are incremented through all values to + fill the table with replicated entries. + + root is the number of index bits for the root table. When len exceeds + root, sub-tables are created pointed to by the root entry with an index + of the low root bits of huff. This is saved in low to check for when a + new sub-table should be started. drop is zero when the root table is + being filled, and drop is root when sub-tables are being filled. + + When a new sub-table is needed, it is necessary to look ahead in the + code lengths to determine what size sub-table is needed. The length + counts are used for this, and so count[] is decremented as codes are + entered in the tables. + + used keeps track of how many table entries have been allocated from the + provided *table space. It is checked for LENS and DIST tables against + the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in + the initial root table size constants. See the comments in inftrees.h + for more information. + + sym increments through all symbols, and the loop terminates when + all codes of length max, i.e. all codes, have been processed. This + routine permits incomplete codes, so another loop after this one fills + in the rest of the decoding tables with invalid code markers. + */ + + /* set up for code type */ + switch (type) { + case CODES: + base = extra = work; /* dummy value--not used */ + end = 19; + break; + case LENS: + base = lbase; + base_index -= 257; + extra = lext; + extra_index -= 257; + end = 256; + break; + default: /* DISTS */ + base = dbase; + extra = dext; + end = -1; + } + + /* initialize opts for loop */ + huff = 0; /* starting code */ + sym = 0; /* starting code symbol */ + len = min; /* starting code length */ + next = opts.table_index; /* current table to fill in */ + curr = root; /* current table index bits */ + drop = 0; /* current bits to drop from code for index */ + low = -1; /* trigger new sub-table when len > root */ + used = 1 << root; /* use root table entries */ + mask = used - 1; /* mask for comparing low */ + + /* check available table space */ + if ((type === LENS && used > ENOUGH_LENS) || + (type === DISTS && used > ENOUGH_DISTS)) { + return 1; + } + + var i=0; + /* process all codes and make table entries */ + for (;;) { + i++; + /* create table entry */ + here_bits = len - drop; + if (work[sym] < end) { + here_op = 0; + here_val = work[sym]; + } + else if (work[sym] > end) { + here_op = extra[extra_index + work[sym]]; + here_val = base[base_index + work[sym]]; + } + else { + here_op = 32 + 64; /* end of block */ + here_val = 0; + } + + /* replicate for those indices with low len bits equal to huff */ + incr = 1 << (len - drop); + fill = 1 << curr; + min = fill; /* save offset to next table */ + do { + fill -= incr; + table[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val |0; + } while (fill !== 0); + + /* backwards increment the len-bit code huff */ + incr = 1 << (len - 1); + while (huff & incr) { + incr >>= 1; + } + if (incr !== 0) { + huff &= incr - 1; + huff += incr; + } else { + huff = 0; + } + + /* go to next symbol, update count, len */ + sym++; + if (--(count[len]) === 0) { + if (len === max) { break; } + len = lens[opts.lens_index + work[sym]]; + } + + /* create new sub-table if needed */ + if (len > root && (huff & mask) !== low) { + /* if first time, transition to sub-tables */ + if (drop === 0) { + drop = root; + } + + /* increment past last table */ + next += min; /* here min is 1 << curr */ + + /* determine length of next table */ + curr = len - drop; + left = 1 << curr; + while (curr + drop < max) { + left -= count[curr + drop]; + if (left <= 0) { break; } + curr++; + left <<= 1; + } + + /* check for enough space */ + used += 1 << curr; + if ((type === LENS && used > ENOUGH_LENS) || + (type === DISTS && used > ENOUGH_DISTS)) { + return 1; + } + + /* point entry in root table to sub-table */ + low = huff & mask; + /*table.op[low] = curr; + table.bits[low] = root; + table.val[low] = next - opts.table_index;*/ + table[low] = (root << 24) | (curr << 16) | (next - opts.table_index); + } + } + + /* fill in remaining table entry if code is incomplete (guaranteed to have + at most one remaining entry, since if the code is incomplete, the + maximum code length that was allowed to get this far is one bit) */ + if (huff !== 0) { + //table.op[next + huff] = 64; /* invalid code marker */ + //table.bits[next + huff] = len - drop; + //table.val[next + huff] = 0; + table[next + huff] = ((len - drop) << 24) | (64 << 16) | 0; + } + + /* set return parameters */ + opts.table_index += used; + opts.bits = root; + return 0; +}; +},{"./utils":9}],8:[function(_dereq_,module,exports){ 'use strict'; module.exports = { @@ -565,25 +2597,13 @@ module.exports = { '-5': 'buffer error', /* Z_BUF_ERROR (-5) */ '-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */ }; -},{}],5:[function(_dereq_,module,exports){ +},{}],9:[function(_dereq_,module,exports){ 'use strict'; var TYPED_OK = (typeof Uint8Array !== 'undefined') && (typeof Uint16Array !== 'undefined') && - (typeof Uint32Array !== 'undefined'); - -var _toString = Function.prototype.call.bind(Object.prototype.toString); -var isArray = Array.isArray || function (obj) { return _toString(obj) === '[object Array]'; }; - -// For debug/testing. Set true to force use untyped arrays -exports.forceUntyped = false; - -function typedOk() { - return TYPED_OK && !exports.forceUntyped; -} - -exports.typedOk = typedOk; + (typeof Int32Array !== 'undefined'); exports.assign = function (obj /*from1, from2, from3, ...*/) { @@ -607,58 +2627,32 @@ exports.assign = function (obj /*from1, from2, from3, ...*/) { }; -exports.arraySet = function (dest, src, src_offs, len, dest_offs) { - - // Suppose, that with typed array support destination is - // always typed - don't check it - if (typedOk() && (!isArray(src))) { - - // optimize full copy - //if ((src_offs === 0) && (src.length === len)) { - // dest.set(src, dest_offs); - // return; - //} - - dest.set(src.subarray(src_offs, src_offs+len), dest_offs); - return; - } - - // Fallback to ordinary array - for(var i=0; i0&&(n.windowBits=-n.windowBits),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new h;var i=o.inflateInit2(this.strm,n.windowBits);if(i!==f.Z_OK)throw new Error(u[i])};l.prototype.push=function(t,n){var i,r,s=this.strm,u=this.options.chunkSize;if(this.ended)return!1;r=n===~~n?n:n===!0?f.Z_FINISH:f.Z_NO_FLUSH,s.next_in=t,s.next_in_index=0,s.avail_in=s.next_in.length,s.next_out=a.arrayCreate(u);do{if(s.avail_out=this.options.chunkSize,s.next_out_index=0,i=o.inflate(s,r),i!==f.Z_STREAM_END&&i!==f.Z_OK)return this.onEnd(i),this.ended=!0,!1;s.next_out_index&&(this.onData(e(s.next_out,s.next_out_index)),(s.avail_in>0||0===s.avail_out)&&(s.next_out=a.arrayCreate(this.options.chunkSize)))}while(s.avail_in>0||0===s.avail_out);return r===f.Z_FINISH?(i=o.inflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===f.Z_OK):!0},l.prototype.onData=function(t){this.chunks.push(t)},l.prototype.onEnd=function(t){t===f.Z_OK&&(this.result=a.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=u[t]},i.Inflate=l,i.inflate=r,i.inflateRaw=s},{"./zlib/constants":2,"./zlib/inflate.js":3,"./zlib/messages":4,"./zlib/utils":5,"./zlib/zstream":6}],2:[function(t,n){n.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],3:[function(t,n,i){"use strict";function e(){this.mode=-1,this.last=0,this.wrap=0,this.havedict=0,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=0,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=-1,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=-1,this.distcode=-1,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=0,this.lens=new Array(320),this.work=new Array(280),this.codes=new Array(v),this.sane=0,this.back=0,this.was=0}function r(){}function s(){}function o(){}function a(t){t.state=new e}function f(){}function u(){}function h(){}function l(){}function c(){}function _(){}function d(){}function p(){}function y(){}function w(){}function E(){}function Z(){}var R=852,S=592,v=R+S;i.inflateResetKeep=r,i.inflateReset=s,i.inflateReset2=o,i.inflateInit2=a,i.inflateInit=f,i.inflatePrime=u,i.inflate=h,i.inflateEnd=l,i.inflateGetDictionary=c,i.inflateGetHeader=d,i.inflateSetDictionary=_,i.inflateSync=p,i.inflateSyncPoint=y,i.inflateCopy=w,i.inflateUndermine=E,i.inflateMark=Z},{}],4:[function(t,n){"use strict";n.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],5:[function(t,n,i){"use strict";function e(){return r&&!i.forceUntyped}var r="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,s=Function.prototype.call.bind(Object.prototype.toString),o=Array.isArray||function(t){return"[object Array]"===s(t)};i.forceUntyped=!1,i.typedOk=e,i.assign=function(t){for(var n=Array.prototype.slice.call(arguments,1);n.length;){var i=n.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(var e in i)i.hasOwnProperty(e)&&(t[e]=i[e])}}return t},i.arraySet=function(t,n,i,r,s){if(e()&&!o(n))return void t.set(n.subarray(i,i+r),s);for(var a=0;r>a;a++)t[s+a]=n[i+a]},i.arrayCreate=function(t){return e()?new Uint8Array(t):new Array(t)},i.array16Create=function(t){return e()?new Uint16Array(t):new Array(t)},i.flattenChunks=function(t){var n,i,r,s,o,a;if(e()){for(r=0,n=0,i=t.length;i>n;n++)r+=t[n].length;for(a=new Uint8Array(r),s=0,n=0,i=t.length;i>n;n++)o=t[n],a.set(o,s),s+=o.length;return a}return[].concat.apply([],t)}},{}],6:[function(t,n){"use strict";function i(){this.next_in=null,this.avail_in=0,this.total_in=0,this.next_out=null,this.avail_out=0,this.total_out=0,this.state=null,this.data_type=2,this.adler=0}n.exports=i},{}]},{},[1])(1)}); \ No newline at end of file +!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.pako=e()}}(function(){return function e(t,i,n){function a(r,o){if(!i[r]){if(!t[r]){var d="function"==typeof require&&require;if(!o&&d)return d(r,!0);if(s)return s(r,!0);throw new Error("Cannot find module '"+r+"'")}var f=i[r]={exports:{}};t[r][0].call(f.exports,function(e){var i=t[r][1][e];return a(i?i:e)},f,f.exports,e,t,i,n)}return i[r].exports}for(var s="function"==typeof require&&require,r=0;r=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0===(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new f;var i=s.inflateInit2(this.strm,t.windowBits);if(i!==o.Z_OK)throw new Error(d[i])};l.prototype.push=function(e,t){var i,n,a=this.strm,d=this.options.chunkSize;if(this.ended)return!1;n=o.Z_NO_FLUSH,a.next_in=e,a.next_in_index=0,a.avail_in=a.next_in.length,a.next_out=new r.Buf8(d);do{if(a.avail_out=this.options.chunkSize,a.next_out_index=0,i=s.inflate(a,n),i!==o.Z_STREAM_END&&i!==o.Z_OK)return this.onEnd(i),this.ended=!0,!1;a.next_out_index&&(this.onData(r.shrinkBuf(a.next_out,a.next_out_index)),(a.avail_in>0||0===a.avail_out)&&(a.next_out=new r.Buf8(this.options.chunkSize)))}while(a.avail_in>0||0===a.avail_out);return n=t===~~t?t:t===!0?o.Z_FINISH:o.Z_NO_FLUSH,n===o.Z_FINISH?(i=s.inflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===o.Z_OK):!0},l.prototype.onData=function(e){this.chunks.push(e)},l.prototype.onEnd=function(e){e===o.Z_OK&&(this.result=r.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg},i.Inflate=l,i.inflate=n,i.inflateRaw=a},{"./zlib/constants":3,"./zlib/inflate.js":6,"./zlib/messages":8,"./zlib/utils":9,"./zlib/zstream":10}],2:[function(e,t){"use strict";function i(e,t,i,n){for(var a=65535&e|0,s=e>>>16&65535|0,r=0;0!==i;){r=i>2e3?2e3:i,i-=r;do a=a+t[n++]|0,s=s+a|0;while(--r);a%=65521,s%=65521}return a|s<<16|0}t.exports=i},{}],3:[function(e,t){t.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],4:[function(e,t){"use strict";function i(){for(var e,t=[],i=0;256>i;i++){e=i;for(var n=0;8>n;n++)e=1&e?3988292384^e>>>1:e>>>1;t[i]=e}return t}function n(e,t,i,n){var s=a,r=n+i;e=-1^e;for(var o=n;r>o;o++)e=e>>>8^s[255&(e^t[o])];return-1^e}var a=i();t.exports=n},{}],5:[function(e,t){"use strict";var i=30,n=12;t.exports=function(e,t){var a,s,r,o,d,f,l,c,h,u,w,b,_,k,m,x,v,g,p,y,B,E,S,Z,z;a=e.state,s=e.next_in_index,Z=e.next_in,r=s+(e.avail_in-5),o=e.next_out_index,z=e.next_out,d=o-(t-e.avail_out),f=o+(e.avail_out-257),l=a.dmax,c=a.wsize,h=a.whave,u=a.wnext,w=a.window,b=a.hold,_=a.bits,k=a.lencode,m=a.distcode,x=(1<_&&(b+=Z[s++]<<_,_+=8,b+=Z[s++]<<_,_+=8),g=k[b&x];t:for(;;){if(p=g>>>24,b>>>=p,_-=p,p=g>>>16&255,0===p)z[o++]=65535&g;else{if(!(16&p)){if(0===(64&p)){g=k[(65535&g)+(b&(1<_&&(b+=Z[s++]<<_,_+=8),y+=b&(1<>>=p,_-=p),15>_&&(b+=Z[s++]<<_,_+=8,b+=Z[s++]<<_,_+=8),g=m[b&v];i:for(;;){if(p=g>>>24,b>>>=p,_-=p,p=g>>>16&255,!(16&p)){if(0===(64&p)){g=m[(65535&g)+(b&(1<_&&(b+=Z[s++]<<_,_+=8,p>_&&(b+=Z[s++]<<_,_+=8)),B+=b&(1<l){e.msg="invalid distance too far back",a.mode=i;break e}if(b>>>=p,_-=p,p=o-d,B>p){if(p=B-p,p>h&&a.sane){e.msg="invalid distance too far back",a.mode=i;break e}if(E=0,S=w,0===u){if(E+=c-p,y>p){y-=p;do z[o++]=w[E++];while(--p);E=o-B,S=z}}else if(p>u){if(E+=c+u-p,p-=u,y>p){y-=p;do z[o++]=w[E++];while(--p);if(E=0,y>u){p=u,y-=p;do z[o++]=w[E++];while(--p);E=o-B,S=z}}}else if(E+=u-p,y>p){y-=p;do z[o++]=w[E++];while(--p);E=o-B,S=z}for(;y>2;)z[o++]=S[E++],z[o++]=S[E++],z[o++]=S[E++],y-=3;y&&(z[o++]=S[E++],y>1&&(z[o++]=S[E++]))}else{E=o-B;do z[o++]=z[E++],z[o++]=z[E++],z[o++]=z[E++],y-=3;while(y>2);y&&(z[o++]=z[E++],y>1&&(z[o++]=z[E++]))}break}}break}}while(r>s&&f>o);y=_>>3,s-=y,_-=y<<3,b&=(1<<_)-1,e.next_in_index=s,e.next_out_index=o,e.avail_in=r>s?5+(r-s):5-(s-r),e.avail_out=f>o?257+(f-o):257-(o-f),a.hold=b,a.bits=_}},{}],6:[function(e,t,i){"use strict";function n(e){return(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function a(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.next_index=0,this.lens=new m.Buf16(320),this.work=new m.Buf16(280),this.codes=new m.Buf32(kt),this.sane=0,this.back=0,this.was=0}function s(e,t,i,n,a,s,r,o){this.type=e,this.lens=t,this.lens_index=i,this.codes=n,this.table=a,this.table_index=s,this.bits=r,this.work=o}function r(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,t.wrap&&(e.adler=1&t.wrap),t.mode=L,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=new m.Buf32(kt),t.distcode=new m.Buf32(kt),t.sane=1,t.back=-1,R):N}function o(e){var t;return e&&e.state?(t=e.state,t.wsize=0,t.whave=0,t.wnext=0,r(e)):N}function d(e,t){var i,n;return e&&e.state?(n=e.state,0>t?(i=0,t=-t):(i=(t>>4)+1,48>t&&(t&=15)),t&&(8>t||t>15)?N:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=i,n.wbits=t,o(e))):N}function f(e,t){var i,n;return e?(n=new a,e.state=n,n.window=null,i=d(e,t),i!==R&&(e.state=null),i):N}function l(e){return f(e,xt)}function c(e,t,i){var n;return e&&e.state?(n=e.state,0>t?(n.hold=0,n.bits=0,R):t>16||n.bits+t>32?N:(i&=(1<t;)e.lens[t++]=8;for(;256>t;)e.lens[t++]=9;for(;280>t;)e.lens[t++]=7;for(;288>t;)e.lens[t++]=8;for(i=9,p(new s(B,e.lens,0,288,_,0,i,e.work)),t=0;32>t;)e.lens[t++]=5;i=5,p(new s(E,e.lens,0,32,k,0,i,e.work)),vt=!1}e.lencode=_,e.lenbits=9,e.distcode=k,e.distbits=5}function u(e,t,i,n){var a,s=e.state;return null===s.window&&(s.wsize=1<=s.wsize?(m.arraySet(s.window,t,i-s.wsize,s.wsize,0),s.wnext=0,s.whave=s.wsize):(a=s.wsize-s.wnext,a>n&&(a=n),m.arraySet(s.window,t,i-n,a,s.wnext),n-=a,n?(m.arraySet(s.window,t,i-n,n,0),s.wnext=n,s.whave=s.wsize):(s.wnext+=a,s.wnext===s.wsize&&(s.wnext=0),s.whavew;){if(0===f)break e;f--,c+=a[o++]<>>8&255,i.check=v(i.check,zt,2,0),c=0,w=0,i.mode=D;break}if(i.flags=0,i.head&&(i.head.done=-1),!(1&i.wrap)||(((255&c)<<8)+(c>>8))%31){e.msg="incorrect header check",i.mode=ht;break}if((15&c)!==U){e.msg="unknown compression method",i.mode=ht;break}if(c>>>=4,w-=4,yt=(15&c)+8,0===i.wbits)i.wbits=yt;else if(yt>i.wbits){e.msg="invalid window size",i.mode=ht;break}i.dmax=1<w;){if(0===f)break e;f--,c+=a[o++]<>8&1),512&i.flags&&(zt[0]=255&c,zt[1]=c>>>8&255,i.check=v(i.check,zt,2,0)),c=0,w=0,i.mode=C;case C:for(;32>w;){if(0===f)break e;f--,c+=a[o++]<>>8&255,zt[2]=c>>>16&255,zt[3]=c>>>24&255,i.check=v(i.check,zt,4,0)),c=0,w=0,i.mode=H;case H:for(;16>w;){if(0===f)break e;f--,c+=a[o++]<>8),512&i.flags&&(zt[0]=255&c,zt[1]=c>>>8&255,i.check=v(i.check,zt,2,0)),c=0,w=0,i.mode=K;case K:if(1024&i.flags){for(;16>w;){if(0===f)break e;f--,c+=a[o++]<>>8&255,i.check=v(i.check,zt,2,0)),c=0,w=0}else i.head&&(i.head.extra=null);i.mode=M;case M:if(1024&i.flags){if(k=i.length,k>f&&(k=f),k){if(i.head&&i.head.extra)throw yt=i.head.extra_len-i.length,"Review & implement right";512&i.flags&&(i.check=v(i.check,a,k,o)),f-=k,o+=k,i.length-=k}if(i.length)break e}i.length=0,i.mode=P;case P:if(2048&i.flags){if(0===f)break e;k=0;do yt=a[o+k++],i.head&&i.head.name&&i.lengthk);if(512&i.flags&&(i.check=v(i.check,a,k,o)),f-=k,o+=k,yt)break e}else i.head&&(i.head.name=null);i.length=0,i.mode=j;case j:if(4096&i.flags){if(0===f)break e;k=0;do yt=a[o+k++],i.head&&i.head.comment&&i.lengthk);if(512&i.flags&&(i.check=v(i.check,a,k,o)),f-=k,o+=k,yt)break e}else i.head&&(i.head.comment=null);i.mode=q;case q:if(512&i.flags){for(;16>w;){if(0===f)break e;f--,c+=a[o++]<>9&1,i.head.done=1),e.adler=i.check=0,i.mode=G;break;case Y:for(;32>w;){if(0===f)break e;f--,c+=a[o++]<>>=7&w,w-=7&w,i.mode=ft;break}for(;3>w;){if(0===f)break e;f--,c+=a[o++]<>>=1,w-=1,3&c){case 0:i.mode=J;break;case 1:if(h(i),i.mode=it,t===z){c>>>=2,w-=2;break e}break;case 2:i.mode=$;break;case 3:e.msg="invalid block type",i.mode=ht}c>>>=2,w-=2;break;case J:for(c>>>=7&w,w-=7&w;32>w;){if(0===f)break e;f--,c+=a[o++]<>>16^65535)){e.msg="invalid stored block lengths",i.mode=ht;break}if(i.length=65535&c,c=0,w=0,i.mode=Q,t===z)break e;case Q:i.mode=V;case V:if(k=i.length){if(k>f&&(k=f),k>l&&(k=l),0===k)break e;m.arraySet(r,a,o,k,d),f-=k,o+=k,l-=k,d+=k,i.length-=k;break}i.mode=G;break;case $:for(;14>w;){if(0===f)break e;f--,c+=a[o++]<>>=5,w-=5,i.ndist=(31&c)+1,c>>>=5,w-=5,i.ncode=(15&c)+4,c>>>=4,w-=4,i.nlen>286||i.ndist>30){e.msg="too many length or distance symbols",i.mode=ht;break}i.have=0,i.mode=et;case et:for(;i.havew;){if(0===f)break e;f--,c+=a[o++]<>>=3,w-=3}for(;i.have<19;)i.lens[Rt[i.have++]]=0;if(m.arraySet(i.lencode,i.codes,0,i.codes.length,0),i.lenbits=7,Et=new s(y,i.lens,0,19,i.lencode,0,i.lenbits,i.work),Bt=p(Et),i.lenbits=Et.bits,Bt){e.msg="invalid code lengths set",i.mode=ht;break}i.have=0,i.mode=tt;case tt:for(;i.have>>24,mt=Zt>>>16&255,xt=65535&Zt,!(w>=kt);){if(0===f)break e;f--,c+=a[o++]<xt)c>>>=kt,w-=kt,i.lens[i.have++]=xt;else{if(16===xt){for(St=kt+2;St>w;){if(0===f)break e;f--,c+=a[o++]<>>=kt,w-=kt,0===i.have){e.msg="invalid bit length repeat",i.mode=ht;break}yt=i.lens[i.have-1],k=3+(3&c),c>>>=2,w-=2}else if(17===xt){for(St=kt+3;St>w;){if(0===f)break e;f--,c+=a[o++]<>>=kt,w-=kt,yt=0,k=3+(7&c),c>>>=3,w-=3}else{for(St=kt+7;St>w;){if(0===f)break e;f--,c+=a[o++]<>>=kt,w-=kt,yt=0,k=11+(127&c),c>>>=7,w-=7}if(i.have+k>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=ht;break}for(;k--;)i.lens[i.have++]=yt}}if(i.mode===ht)break;if(0===i.lens[256]){e.msg="invalid code -- missing end-of-block",i.mode=ht;break}if(m.arraySet(i.lencode,i.codes,0,i.codes.length,0),i.lenbits=9,Et=new s(B,i.lens,0,i.nlen,i.lencode,0,i.lenbits,i.work),Bt=p(Et),i.lenbits=Et.bits,Bt){e.msg="invalid literal/lengths set",i.mode=ht;break}if(i.distbits=6,m.arraySet(i.distcode,i.codes,0,i.codes.length,0),Et=new s(E,i.lens,i.nlen,i.ndist,i.distcode,0,i.distbits,i.work),Bt=p(Et),i.distbits=Et.bits,Bt){e.msg="invalid distances set",i.mode=ht;break}if(i.mode=it,t===z)break e;case it:i.mode=nt;case nt:if(f>=6&&l>=258){e.next_out_index=d,e.avail_out=l,e.next_in_index=o,e.avail_in=f,i.hold=c,i.bits=w,g(e,_),d=e.next_out_index,r=e.next_out,l=e.avail_out,o=e.next_in_index,a=e.next_in,f=e.avail_in,c=i.hold,w=i.bits,i.mode===G&&(i.back=-1);break}for(i.back=0;Zt=i.lencode[c&(1<>>24,mt=Zt>>>16&255,xt=65535&Zt,!(w>=kt);){if(0===f)break e;f--,c+=a[o++]<>vt)],kt=Zt>>>24,mt=Zt>>>16&255,xt=65535&Zt,!(w>=vt+kt);){if(0===f)break e;f--,c+=a[o++]<>>=vt,w-=vt,i.back+=vt}if(c>>>=kt,w-=kt,i.back+=kt,i.length=xt,0===mt){i.mode=dt;break}if(32&mt){i.back=-1,i.mode=G;break}if(64&mt){e.msg="invalid literal/length code",i.mode=ht;break}i.extra=15&mt,i.mode=at;case at:if(i.extra){for(St=i.extra;St>w;){if(0===f)break e;f--,c+=a[o++]<>>=i.extra,w-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=st;case st:for(;Zt=i.distcode[c&(1<>>24,mt=Zt>>>16&255,xt=65535&Zt,!(w>=kt);){if(0===f)break e;f--,c+=a[o++]<>vt)],kt=Zt>>>24,mt=Zt>>>16&255,xt=65535&Zt,!(w>=vt+kt);){if(0===f)break e;f--,c+=a[o++]<>>=vt,w-=vt,i.back+=vt}if(c>>>=kt,w-=kt,i.back+=kt,64&mt){e.msg="invalid distance code",i.mode=ht;break}i.offset=xt,i.extra=15&mt,i.mode=rt;case rt:if(i.extra){for(St=i.extra;St>w;){if(0===f)break e;f--,c+=a[o++]<>>=i.extra,w-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=ht;break}i.mode=ot;case ot:if(0===l)break e;if(k=_-l,i.offset>k){if(k=i.offset-k,k>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=ht;break}k>i.wnext?(k-=i.wnext,bt=i.wsize-k):bt=i.wnext-k,k>i.length&&(k=i.length),_t=i.window}else _t=r,bt=d-i.offset,k=i.length;k>l&&(k=l),l-=k,i.length-=k;do r[d++]=_t[bt++];while(--k);0===i.length&&(i.mode=nt);break;case dt:if(0===l)break e;r[d++]=i.length,l--,i.mode=nt;break;case ft:if(i.wrap){for(;32>w;){if(0===f)break e;f--,c|=a[o++]<w;){if(0===f)break e;f--,c+=a[o++]<=Z;Z++)C[Z]=0;for(z=0;y>z;z++)C[p[e.lens_index+z]]++;for(O=E,A=n;A>=1&&0===C[A];A--);if(O>A&&(O=A),0===A)return B[e.table_index++]=20971520,B[e.table_index++]=20971520,e.bits=1,0;for(R=1;A>R&&0===C[R];R++);for(R>O&&(O=R),T=1,Z=1;n>=Z;Z++)if(T<<=1,T-=C[Z],0>T)return-1;if(T>0&&(g===r||1!==A))return-1;for(H[1]=0,Z=1;n>Z;Z++)H[Z+1]=H[Z]+C[Z];for(z=0;y>z;z++)0!==p[e.lens_index+z]&&(S[H[p[e.lens_index+z]]++]=z);switch(g){case r:L=K=S,k=19;break;case o:L=f,D-=257,K=l,M-=257,k=256;break;default:L=c,K=h,k=-1}if(U=0,z=0,Z=R,_=e.table_index,N=O,I=0,w=-1,F=1<a||g===d&&F>s)return 1;for(var P=0;;){P++,m=Z-I,S[z]k?(x=K[M+S[z]],v=L[D+S[z]]):(x=96,v=0),t=1<>I)+u]=m<<24|x<<16|v|0;while(0!==u);for(t=1<>=1;if(0!==t?(U&=t-1,U+=t):U=0,z++,0===--C[Z]){if(Z===A)break;Z=p[e.lens_index+S[z]]}if(Z>O&&(U&b)!==w){for(0===I&&(I=O),_+=R,N=Z-I,T=1<N+I&&(T-=C[N+I],!(0>=T));)N++,T<<=1;if(F+=1<a||g===d&&F>s)return 1;w=U&b,B[w]=O<<24|N<<16|_-e.table_index}}return 0!==U&&(B[_+U]=Z-I<<24|64<<16|0),e.table_index+=F,e.bits=O,0}},{"./utils":9}],8:[function(e,t){"use strict";t.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],9:[function(e,t,i){"use strict";var n="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;i.assign=function(e){for(var t=Array.prototype.slice.call(arguments,1);t.length;){var i=t.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(var n in i)i.hasOwnProperty(n)&&(e[n]=i[n])}}return e},i.shrinkBuf=function(e,t){return e.length===t?e:e.subarray?e.subarray(0,t):(e.length=t,e)};var a={arraySet:function(e,t,i,n,a){if(t.subarray)return void e.set(t.subarray(i,i+n),a);for(var s=0;n>s;s++)e[a+s]=t[i+s]},flattenChunks:function(e){var t,i,n,a,s,r;for(n=0,t=0,i=e.length;i>t;t++)n+=e[t].length;for(r=new Uint8Array(n),a=0,t=0,i=e.length;i>t;t++)s=e[t],r.set(s,a),a+=s.length;return r}},s={arraySet:function(e,t,i,n,a){for(var s=0;n>s;s++)e[a+s]=t[i+s]},flattenChunks:function(e){return[].concat.apply([],e)}};i.setTyped=function(e){e?(i.Buf8=Uint8Array,i.Buf16=Uint16Array,i.Buf32=Int32Array,i.assign(i,a)):(i.Buf8=Array,i.Buf16=Array,i.Buf32=Array,i.assign(i,s))},i.setTyped(n)},{}],10:[function(e,t){"use strict";function i(){this.next_in=null,this.next_in_index=0,this.avail_in=0,this.total_in=0,this.next_out=null,this.next_out_index=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}t.exports=i},{}]},{},[1])(1)}); \ No newline at end of file