{“ast”:null,“code”:“'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adlern// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsinn//n// This software is provided 'as-is', without any express or impliedn// warranty. In no event will the authors be held liable for any damagesn// arising from the use of this software.n//n// Permission is granted to anyone to use this software for any purpose,n// including commercial applications, and to alter it and redistribute itn// freely, subject to the following restrictions:n//n// 1. The origin of this software must not be misrepresented; you must notn// claim that you wrote the original software. If you use this softwaren// in a product, an acknowledgment in the product documentation would ben// appreciated but is not required.n// 2. Altered source versions must be plainly marked as such, and must not ben// misrepresented as being the original software.n// 3. This notice may not be removed or altered from any source distribution.nnvar utils = require('../utils/common');nnvar trees = require('./trees');nnvar adler32 = require('./adler32');nnvar crc32 = require('./crc32');nnvar msg = require('./messages');n/* Public constants ==========================================================*/nn/* ===========================================================================*/nn/* Allowed flush values; see deflate() and inflate() below for details */nnnvar Z_NO_FLUSH = 0;nvar Z_PARTIAL_FLUSH = 1; //var Z_SYNC_FLUSH = 2;nnvar Z_FULL_FLUSH = 3;nvar Z_FINISH = 4;nvar Z_BLOCK = 5; //var Z_TREES = 6;nn/* Return codes for the compression/decompression functions. Negative valuesn * are errors, positive values are used for special but normal events.n */nnvar Z_OK = 0;nvar Z_STREAM_END = 1; //var Z_NEED_DICT = 2;n//var Z_ERRNO = -1;nnvar Z_STREAM_ERROR = -2;nvar Z_DATA_ERROR = -3; //var Z_MEM_ERROR = -4;nnvar Z_BUF_ERROR = -5; //var Z_VERSION_ERROR = -6;nn/* compression levels */n//var Z_NO_COMPRESSION = 0;n//var Z_BEST_SPEED = 1;n//var Z_BEST_COMPRESSION = 9;nnvar Z_DEFAULT_COMPRESSION = -1;nvar Z_FILTERED = 1;nvar Z_HUFFMAN_ONLY = 2;nvar Z_RLE = 3;nvar Z_FIXED = 4;nvar Z_DEFAULT_STRATEGY = 0;n/* Possible values of the data_type field (though see inflate()) */n//var Z_BINARY = 0;n//var Z_TEXT = 1;n//var Z_ASCII = 1; // = Z_TEXTnnvar Z_UNKNOWN = 2;n/* The deflate compression method */nnvar Z_DEFLATED = 8;n/*============================================================================*/nnvar MAX_MEM_LEVEL = 9;n/* Maximum value for memLevel in deflateInit2 */nnvar MAX_WBITS = 15;n/* 32K LZ77 window */nnvar DEF_MEM_LEVEL = 8;nvar LENGTH_CODES = 29;n/* number of length codes, not counting the special END_BLOCK code */nnvar LITERALS = 256;n/* number of literal bytes 0..255 */nnvar L_CODES = LITERALS + 1 + LENGTH_CODES;n/* number of Literal or Length codes, including the END_BLOCK code */nnvar D_CODES = 30;n/* number of distance codes */nnvar BL_CODES = 19;n/* number of codes used to transfer the bit lengths */nnvar HEAP_SIZE = 2 * L_CODES + 1;n/* maximum heap size */nnvar MAX_BITS = 15;n/* All codes must not exceed MAX_BITS bits */nnvar MIN_MATCH = 3;nvar MAX_MATCH = 258;nvar MIN_LOOKAHEAD = MAX_MATCH + MIN_MATCH + 1;nvar PRESET_DICT = 0x20;nvar INIT_STATE = 42;nvar EXTRA_STATE = 69;nvar NAME_STATE = 73;nvar COMMENT_STATE = 91;nvar HCRC_STATE = 103;nvar BUSY_STATE = 113;nvar FINISH_STATE = 666;nvar BS_NEED_MORE = 1;n/* block not completed, need more input or more output */nnvar BS_BLOCK_DONE = 2;n/* block flush performed */nnvar BS_FINISH_STARTED = 3;n/* finish started, need only more output at next deflate */nnvar BS_FINISH_DONE = 4;n/* finish done, accept no more input or output */nnvar OS_CODE = 0x03; // Unix :) . Don't detect, use this default.nnfunction err(strm, errorCode) {n strm.msg = msg;n return errorCode;n}nnfunction rank(f) {n return (f << 1) - (f > 4 ? 9 : 0);n}nnfunction zero(buf) {n var len = buf.length;nn while (–len >= 0) {n buf = 0;n }n}n/* =========================================================================n * Flush as much pending output as possible. All deflate() output goesn * through this function so some applications may wish to modify itn * to avoid allocating a large strm->output buffer and copying into it.n * (See also read_buf()).n */nnnfunction flush_pending(strm) {n var s = strm.state; //_tr_flush_bits(s);nn var len = s.pending;nn if (len > strm.avail_out) {n len = strm.avail_out;n }nn if (len === 0) {n return;n }nn utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out);n strm.next_out += len;n s.pending_out += len;n strm.total_out += len;n strm.avail_out -= len;n s.pending -= len;nn if (s.pending === 0) {n s.pending_out = 0;n }n}nnfunction flush_block_only(s, last) {n trees._tr_flush_block(s, s.block_start >= 0 ? s.block_start : -1, s.strstart - s.block_start, last);nn s.block_start = s.strstart;n flush_pending(s.strm);n}nnfunction put_byte(s, b) {n s.pending_buf = b;n}n/* =========================================================================n * Put a short in the pending buffer. The 16-bit value is put in MSB order.n * IN assertion: the stream state is correct and there is enough room inn * pending_buf.n */nnnfunction putShortMSB(s, b) {n // put_byte(s, (Byte)(b >> 8));n // put_byte(s, (Byte)(b & 0xff));n s.pending_buf = b >>> 8 & 0xff;n s.pending_buf = b & 0xff;n}n/* ===========================================================================n * Read a new buffer from the current input stream, update the adler32n * and total number of bytes read. All deflate() input goes throughn * this function so some applications may wish to modify it to avoidn * allocating a large strm->input buffer and copying from it.n * (See also flush_pending()).n */nnnfunction read_buf(strm, buf, start, size) {n var len = strm.avail_in;nn if (len > size) {n len = size;n }nn if (len === 0) {n return 0;n }nn strm.avail_in -= len; // zmemcpy(buf, strm->next_in, len);nn utils.arraySet(buf, strm.input, strm.next_in, len, start);nn if (strm.state.wrap === 1) {n strm.adler = adler32(strm.adler, buf, len, start);n } else if (strm.state.wrap === 2) {n strm.adler = crc32(strm.adler, buf, len, start);n }nn strm.next_in += len;n strm.total_in += len;n return len;n}n/* ===========================================================================n * Set match_start to the longest match starting at the given string andn * return its length. Matches shorter or equal to prev_length are discarded,n * in which case the result is equal to prev_length and match_start isn * garbage.n * IN assertions: cur_match is the head of the hash chain for the currentn * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1n * OUT assertion: the match length is not greater than s->lookahead.n */nnnfunction longest_match(s, cur_match) {n var chain_length = s.max_chain_length;n /* max hash chain length */nn var scan = s.strstart;n /* current string */nn var match;n /* matched string */nn var len;n /* length of current match */nn var best_len = s.prev_length;n /* best match length so far */nn var nice_match = s.nice_match;n /* stop if match long enough */nn var limit = s.strstart > s.w_size - MIN_LOOKAHEAD ? s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0n /NIL/n ;n var _win = s.window; // shortcutnn var wmask = s.w_mask;n var prev = s.prev;n /* Stop when cur_match becomes <= limit. To simplify the code,n * we prevent matches with the string of window index 0.n */nn var strend = s.strstart + MAX_MATCH;n var scan_end1 = _win[scan + best_len - 1];n var scan_end = _win[scan + best_len];n /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.n * It is easy to get rid of this optimization if necessary.n */n // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");nn /* Do not waste too much time if we already have a good match: */nn if (s.prev_length >= s.good_match) {n chain_length >>= 2;n }n /* Do not look for matches beyond the end of the input. This is necessaryn * to make deflate deterministic.n */nnn if (nice_match > s.lookahead) {n nice_match = s.lookahead;n } // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");nnn do {n // Assert(cur_match < s->strstart, "no future");n match = cur_match;n /* Skip to next match if the match length cannot increasen * or if the match length is less than 2. Note that the checks belown * for insufficient lookahead only occur occasionally for performancen * reasons. Therefore uninitialized memory will be accessed, andn * conditional jumps will be made that depend on those values.n * However the length of the match is limited to the lookahead, son * the output of deflate is not affected by the uninitialized values.n */nn if (_win[match + best_len] !== scan_end || _win[match + best_len - 1] !== scan_end1 || _win !== _win || _win !== _win[scan + 1]) {n continue;n }n /* The check at best_len-1 can be removed because it will be maden * again later. (This heuristic is not always a win.)n * It is not necessary to compare scan and match since theyn * are always equal when the other bytes match, given thatn * the hash keys are equal and that HASH_BITS >= 8.n */nnn scan += 2;n match++; // Assert(*scan == *match, "match[2]?");nn /* We check for insufficient lookahead only every 8th comparison;n * the 256th check will be made at strstart+258.n */nn do {n /*jshint noempty:false*/n } while (_win === _win && _win === _win && _win === _win && _win === _win && _win === _win && _win === _win && _win === _win && _win === _win && scan < strend); // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");nnn len = MAX_MATCH - (strend - scan);n scan = strend - MAX_MATCH;nn if (len > best_len) {n s.match_start = cur_match;n best_len = len;nn if (len >= nice_match) {n break;n }nn scan_end1 = _win[scan + best_len - 1];n scan_end = _win[scan + best_len];n }n } while ((cur_match = prev[cur_match & wmask]) > limit && –chain_length !== 0);nn if (best_len <= s.lookahead) {n return best_len;n }nn return s.lookahead;n}n/* ===========================================================================n * Fill the window when the lookahead becomes insufficient.n * Updates strstart and lookahead.n *n * IN assertion: lookahead < MIN_LOOKAHEADn * OUT assertions: strstart <= window_size-MIN_LOOKAHEADn * At least one byte has been read, or avail_in == 0; reads aren * performed for at least two bytes (required for the zip translate_eoln * option – not supported here).n */nnnfunction fill_window(s) {n var _w_size = s.w_size;n var p, n, m, more, str; //Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");nn do {n more = s.window_size - s.lookahead - s.strstart; // JS ints have 32 bit, block below not needednn /* Deal with !@#$% 64K limit: */n //if (sizeof(int) <= 2) {n // if (more == 0 && s->strstart == 0 && s->lookahead == 0) {n // more = wsize;n //n // } else if (more == (unsigned)(-1)) {n // /* Very unlikely, but possible on 16 bit machine ifn // * strstart == 0 && lookahead == 1 (input done a byte at time)n // */n // more–;n // }n //}nn /* If the window is almost full and there is insufficient lookahead,n * move the upper half to the lower one to make room in the upper half.n */nn if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {n utils.arraySet(s.window, s.window, _w_size, _w_size, 0);n s.match_start -= _w_size;n s.strstart -= _w_size;n /* we now have strstart >= MAX_DIST */nn s.block_start -= _w_size;n /* Slide the hash table (could be avoided with 32 bit valuesn at the expense of memory usage). We slide even when level == 0n to keep the hash table consistent if we switch back to level > 0n later. (Using level 0 permanently is not an optimal usage ofn zlib, so we don't care about this pathological case.)n */nn n = s.hash_size;n p = n;nn do {n m = s.head;n s.head = m >= _w_size ? m - _w_size : 0;n } while (–n);nn n = _w_size;n p = n;nn do {n m = s.prev;n s.prev = m >= _w_size ? m - _w_size : 0;n /* If n is not on any hash chain, prev is garbage butn * its value will never be used.n */n } while (–n);nn more += _w_size;n }nn if (s.strm.avail_in === 0) {n break;n }n /* If there was no sliding:n * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&n * more == window_size - lookahead - strstartn * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)n * => more >= window_size - 2*WSIZE + 2n * In the BIG_MEM or MMAP case (not yet supported),n * window_size == input_size + MIN_LOOKAHEAD &&n * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.n * Otherwise, window_size == 2*WSIZE so more >= 2.n * If there was sliding, more >= WSIZE. So in all cases, more >= 2.n */n //Assert(more >= 2, "more < 2");nnn n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more);n s.lookahead += n;n /* Initialize the hash value now that we have some input: */nn if (s.lookahead + s.insert >= MIN_MATCH) {n str = s.strstart - s.insert;n s.ins_h = s.window;n /* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */nn s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + 1]) & s.hash_mask; //#if MIN_MATCH != 3n // Call update_hash() MIN_MATCH-3 more timesn //#endifnn while (s.insert) {n /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */n s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;n s.prev[str & s.w_mask] = s.head;n s.head = str;n str++;n s.insert–;nn if (s.lookahead + s.insert < MIN_MATCH) {n break;n }n }n }n /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,n * but this is not important since only literal bytes will be emitted.n */nn } while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0);n /* If the WIN_INIT bytes after the end of the current data have never beenn * written, then zero those bytes in order to avoid memory check reports ofn * the use of uninitialized (or uninitialised as Julian writes) bytes byn * the longest match routines. Update the high water mark for the nextn * time through here. WIN_INIT is set to MAX_MATCH since the longest matchn * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.n */n // if (s.high_water < s.window_size) {n // var curr = s.strstart + s.lookahead;n // var init = 0;n //n // if (s.high_water < curr) {n // /* Previous high water mark below current data – zero WIN_INITn // * bytes or up to end of window, whichever is less.n // */n // init = s.window_size - curr;n // if (init > WIN_INIT)n // init = WIN_INIT;n // zmemzero(s->window + curr, (unsigned)init);n // s->high_water = curr + init;n // }n // else if (s->high_water < (ulg)curr + WIN_INIT) {n // /* High water mark at or above current data, but below current datan // * plus WIN_INIT – zero out to current data plus WIN_INIT, or upn // * to end of window, whichever is less.n // */n // init = (ulg)curr + WIN_INIT - s->high_water;n // if (init > s->window_size - s->high_water)n // init = s->window_size - s->high_water;n // zmemzero(s->window + s->high_water, (unsigned)init);n // s->high_water += init;n // }n // }n //n // Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,n // "not enough room for search");nn}n/* ===========================================================================n * Copy without compression as much as possible from the input stream, returnn * the current block state.n * This function does not insert new strings in the dictionary sincen * uncompressible data is probably not useful. This function is usedn * only for the level=0 compression option.n * NOTE: this function should be optimized to avoid extra copying fromn * window to pending_buf.n */nnnfunction deflate_stored(s, flush) {n /* Stored blocks are limited to 0xffff bytes, pending_buf is limitedn * to pending_buf_size, and each stored block has a 5 byte header:n */n var max_block_size = 0xffff;nn if (max_block_size > s.pending_buf_size - 5) {n max_block_size = s.pending_buf_size - 5;n }n /* Copy as much as possible from input to output: */nnn for (;;) {n /* Fill the window as much as possible: */n if (s.lookahead <= 1) {n //Assert(s->strstart < s->w_size+MAX_DIST(s) ||n // s->block_start >= (long)s->w_size, "slide too late");n // if (!(s.strstart < s.w_size + (s.w_size - MIN_LOOKAHEAD) ||n // s.block_start >= s.w_size)) {n // throw new Error("slide too late");n // }n fill_window(s);nn if (s.lookahead === 0 && flush === Z_NO_FLUSH) {n return BS_NEED_MORE;n }nn if (s.lookahead === 0) {n break;n }n /* flush the current block */nn } //Assert(s->block_start >= 0L, "block gone");n // if (s.block_start < 0) throw new Error("block gone");nnn s.strstart += s.lookahead;n s.lookahead = 0;n /* Emit a stored block if pending_buf will be full: */nn var max_start = s.block_start + max_block_size;nn if (s.strstart === 0 || s.strstart >= max_start) {n /* strstart == 0 is possible when wraparound on 16-bit machine */n s.lookahead = s.strstart - max_start;n s.strstart = max_start;n /*** FLUSH_BLOCK(s, 0); ***/nn flush_block_only(s, false);nn if (s.strm.avail_out === 0) {n return BS_NEED_MORE;n }n /***/nn }n /* Flush if we may have to slide, otherwise block_start may becomen * negative and the data will be gone:n */nnn if (s.strstart - s.block_start >= s.w_size - MIN_LOOKAHEAD) {n /*** FLUSH_BLOCK(s, 0); ***/n flush_block_only(s, false);nn if (s.strm.avail_out === 0) {n return BS_NEED_MORE;n }n /***/nn }n }nn s.insert = 0;nn if (flush === Z_FINISH) {n /*** FLUSH_BLOCK(s, 1); ***/n flush_block_only(s, true);nn if (s.strm.avail_out === 0) {n return BS_FINISH_STARTED;n }n /***/nnn return BS_FINISH_DONE;n }nn if (s.strstart > s.block_start) {n /*** FLUSH_BLOCK(s, 0); ***/n flush_block_only(s, false);nn if (s.strm.avail_out === 0) {n return BS_NEED_MORE;n }n /***/nn }nn return BS_NEED_MORE;n}n/* ===========================================================================n * Compress as much as possible from the input stream, return the currentn * block state.n * This function does not perform lazy evaluation of matches and insertsn * new strings in the dictionary only for unmatched strings or for shortn * matches. It is used only for the fast compression options.n */nnnfunction deflate_fast(s, flush) {n var hash_head;n /* head of the hash chain */nn var bflush;n /* set if current block must be flushed */nn for (;;) {n /* Make sure that we always have enough lookahead, exceptn * at the end of the input file. We need MAX_MATCH bytesn * for the next match, plus MIN_MATCH bytes to insert then * string following the next match.n */n if (s.lookahead < MIN_LOOKAHEAD) {n fill_window(s);nn if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {n return BS_NEED_MORE;n }nn if (s.lookahead === 0) {n break;n /* flush the current block */n }n }n /* Insert the string window[strstart .. strstart+2] in then * dictionary, and set hash_head to the head of the hash chain:n */nnn hash_head = 0n /NIL/n ;nn if (s.lookahead >= MIN_MATCH) {n /*** INSERT_STRING(s, s.strstart, hash_head); ***/n s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;n hash_head = s.prev[s.strstart & s.w_mask] = s.head;n s.head = s.strstart;n /***/n }n /* Find the longest match, discarding those <= prev_length.n * At this point we have always match_length < MIN_MATCHn */nnn if (hash_head !== 0n /NIL/n && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD) {n /* To simplify the code, we prevent matches with the stringn * of window index 0 (in particular we have to avoid a matchn * of the string with itself at the start of the input file).n */n s.match_length = longest_match(s, hash_head);n /* longest_match() sets match_start */n }nn if (s.match_length >= MIN_MATCH) {n // check_match(s, s.strstart, s.match_start, s.match_length); // for debug onlynn /*** _tr_tally_dist(s, s.strstart - s.match_start,n s.match_length - MIN_MATCH, bflush); ***/n bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);n s.lookahead -= s.match_length;n /* Insert new strings in the hash table only if the match lengthn * is not too large. This saves time but degrades compression.n */nn if (s.match_length <= s.max_lazy_matchn /max_insert_length/n && s.lookahead >= MIN_MATCH) {n s.match_length–;n /* string at strstart already in table */nn do {n s.strstart++;n /*** INSERT_STRING(s, s.strstart, hash_head); ***/nn s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;n hash_head = s.prev[s.strstart & s.w_mask] = s.head;n s.head = s.strstart;n /***/nn /* strstart never exceeds WSIZE-MAX_MATCH, so there aren * always MIN_MATCH bytes ahead.n */n } while (–s.match_length !== 0);nn s.strstart++;n } else {n s.strstart += s.match_length;n s.match_length = 0;n s.ins_h = s.window;n /* UPDATE_HASH(s, s.ins_h, s.window); */nn s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + 1]) & s.hash_mask; //#if MIN_MATCH != 3n // Call UPDATE_HASH() MIN_MATCH-3 more timesn //#endifnn /* If lookahead < MIN_MATCH, ins_h is garbage, but it does notn * matter since it will be recomputed at next deflate call.n */n }n } else {n /* No match, output a literal byte */n //Tracevv((stderr,"%c", s.window));nn /*** _tr_tally_lit(s, s.window, bflush); ***/n bflush = trees._tr_tally(s, 0, s.window);n s.lookahead–;n s.strstart++;n }nn if (bflush) {n /*** FLUSH_BLOCK(s, 0); ***/n flush_block_only(s, false);nn if (s.strm.avail_out === 0) {n return BS_NEED_MORE;n }n /***/nn }n }nn s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;nn if (flush === Z_FINISH) {n /*** FLUSH_BLOCK(s, 1); ***/n flush_block_only(s, true);nn if (s.strm.avail_out === 0) {n return BS_FINISH_STARTED;n }n /***/nnn return BS_FINISH_DONE;n }nn if (s.last_lit) {n /*** FLUSH_BLOCK(s, 0); ***/n flush_block_only(s, false);nn if (s.strm.avail_out === 0) {n return BS_NEED_MORE;n }n /***/nn }nn return BS_BLOCK_DONE;n}n/* ===========================================================================n * Same as above, but achieves better compression. We use a lazyn * evaluation for matches: a match is finally adopted only if there isn * no better match at the next window position.n */nnnfunction deflate_slow(s, flush) {n var hash_head;n /* head of hash chain */nn var bflush;n /* set if current block must be flushed */nn var max_insert;n /* Process the input block. */nn for (;;) {n /* Make sure that we always have enough lookahead, exceptn * at the end of the input file. We need MAX_MATCH bytesn * for the next match, plus MIN_MATCH bytes to insert then * string following the next match.n */n if (s.lookahead < MIN_LOOKAHEAD) {n fill_window(s);nn if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {n return BS_NEED_MORE;n }nn if (s.lookahead === 0) {n break;n }n /* flush the current block */nn }n /* Insert the string window[strstart .. strstart+2] in then * dictionary, and set hash_head to the head of the hash chain:n */nnn hash_head = 0n /NIL/n ;nn if (s.lookahead >= MIN_MATCH) {n /*** INSERT_STRING(s, s.strstart, hash_head); ***/n s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;n hash_head = s.prev[s.strstart & s.w_mask] = s.head;n s.head = s.strstart;n /***/n }n /* Find the longest match, discarding those <= prev_length.n */nnn s.prev_length = s.match_length;n s.prev_match = s.match_start;n s.match_length = MIN_MATCH - 1;nn if (hash_head !== 0n /NIL/n && s.prev_length < s.max_lazy_match && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEADn /*MAX_DIST(s)*/n ) {n /* To simplify the code, we prevent matches with the stringn * of window index 0 (in particular we have to avoid a matchn * of the string with itself at the start of the input file).n */n s.match_length = longest_match(s, hash_head);n /* longest_match() sets match_start */nn if (s.match_length <= 5 && (s.strategy === Z_FILTERED || s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096n /TOO_FAR/n )) {n /* If prev_match is also MIN_MATCH, match_start is garbagen * but we will ignore the current match anyway.n */n s.match_length = MIN_MATCH - 1;n }n }n /* If there was a match at the previous step and the currentn * match is not better, output the previous match:n */nnn if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) {n max_insert = s.strstart + s.lookahead - MIN_MATCH;n /* Do not insert strings in hash table beyond this. */n //check_match(s, s.strstart-1, s.prev_match, s.prev_length);nn /***_tr_tally_dist(s, s.strstart - 1 - s.prev_match,n s.prev_length - MIN_MATCH, bflush);***/nn bflush = trees._tr_tally(s, s.strstart - 1 - s.prev_match, s.prev_length - MIN_MATCH);n /* Insert in hash table all strings up to the end of the match.n * strstart-1 and strstart are already inserted. If there is notn * enough lookahead, the last two strings are not inserted inn * the hash table.n */nn s.lookahead -= s.prev_length - 1;n s.prev_length -= 2;nn do {n if (++s.strstart <= max_insert) {n /*** INSERT_STRING(s, s.strstart, hash_head); ***/n s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;n hash_head = s.prev[s.strstart & s.w_mask] = s.head;n s.head = s.strstart;n /***/n }n } while (–s.prev_length !== 0);nn s.match_available = 0;n s.match_length = MIN_MATCH - 1;n s.strstart++;nn if (bflush) {n /*** FLUSH_BLOCK(s, 0); ***/n flush_block_only(s, false);nn if (s.strm.avail_out === 0) {n return BS_NEED_MORE;n }n /***/nn }n } else if (s.match_available) {n /* If there was no match at the previous position, output an * single literal. If there was a match but the current matchn * is longer, truncate the previous match to a single literal.n */n //Tracevv((stderr,"%c", s.window, bflush); ***/n bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);nn if (bflush) {n /*** FLUSH_BLOCK_ONLY(s, 0) ***/n flush_block_only(s, false);n /***/n }nn s.strstart++;n s.lookahead–;nn if (s.strm.avail_out === 0) {n return BS_NEED_MORE;n }n } else {n /* There is no previous match to compare with, wait forn * the next step to decide.n */n s.match_available = 1;n s.strstart++;n s.lookahead–;n }n } //Assert (flush != Z_NO_FLUSH, "no flush?");nnn if (s.match_available) {n //Tracevv((stderr,"%c", s.window, bflush); ***/n bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);n s.match_available = 0;n }nn s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;nn if (flush === Z_FINISH) {n /*** FLUSH_BLOCK(s, 1); ***/n flush_block_only(s, true);nn if (s.strm.avail_out === 0) {n return BS_FINISH_STARTED;n }n /***/nnn return BS_FINISH_DONE;n }nn if (s.last_lit) {n /*** FLUSH_BLOCK(s, 0); ***/n flush_block_only(s, false);nn if (s.strm.avail_out === 0) {n return BS_NEED_MORE;n }n /***/nn }nn return BS_BLOCK_DONE;n}n/* ===========================================================================n * For Z_RLE, simply look for runs of bytes, generate matches only of distancen * one. Do not maintain a hash table. (It will be regenerated if this run ofn * deflate switches away from Z_RLE.)n */nnnfunction deflate_rle(s, flush) {n var bflush;n /* set if current block must be flushed */nn var prev;n /* byte at distance one to match */nn var scan, strend;n /* scan goes up to strend for length of run */nn var _win = s.window;nn for (;;) {n /* Make sure that we always have enough lookahead, exceptn * at the end of the input file. We need MAX_MATCH bytesn * for the longest run, plus one for the unrolled loop.n */n if (s.lookahead <= MAX_MATCH) {n fill_window(s);nn if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) {n return BS_NEED_MORE;n }nn if (s.lookahead === 0) {n break;n }n /* flush the current block */nn }n /* See how many times the previous byte repeats */nnn s.match_length = 0;nn if (s.lookahead >= MIN_MATCH && s.strstart > 0) {n scan = s.strstart - 1;n prev = _win;nn if (prev === _win && prev === _win && prev === _win) {n strend = s.strstart + MAX_MATCH;nn do {n /*jshint noempty:false*/n } while (prev === _win && prev === _win && prev === _win && prev === _win && prev === _win && prev === _win && prev === _win && prev === _win && scan < strend);nn s.match_length = MAX_MATCH - (strend - scan);nn if (s.match_length > s.lookahead) {n s.match_length = s.lookahead;n }n } //Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");nn }n /* Emit match if have run of MIN_MATCH or longer, else emit literal */nnn if (s.match_length >= MIN_MATCH) {n //check_match(s, s.strstart, s.strstart - 1, s.match_length);nn /*** _tr_tally_dist(s, 1, s.match_length - MIN_MATCH, bflush); ***/n bflush = trees._tr_tally(s, 1, s.match_length - MIN_MATCH);n s.lookahead -= s.match_length;n s.strstart += s.match_length;n s.match_length = 0;n } else {n /* No match, output a literal byte */n //Tracevv((stderr,"%c", s.window, bflush); ***/n bflush = trees._tr_tally(s, 0, s.window);n s.lookahead–;n s.strstart++;n }nn if (bflush) {n /*** FLUSH_BLOCK(s, 0); ***/n flush_block_only(s, false);nn if (s.strm.avail_out === 0) {n return BS_NEED_MORE;n }n /***/nn }n }nn s.insert = 0;nn if (flush === Z_FINISH) {n /*** FLUSH_BLOCK(s, 1); ***/n flush_block_only(s, true);nn if (s.strm.avail_out === 0) {n return BS_FINISH_STARTED;n }n /***/nnn return BS_FINISH_DONE;n }nn if (s.last_lit) {n /*** FLUSH_BLOCK(s, 0); ***/n flush_block_only(s, false);nn if (s.strm.avail_out === 0) {n return BS_NEED_MORE;n }n /***/nn }nn return BS_BLOCK_DONE;n}n/* ===========================================================================n * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.n * (It will be regenerated if this run of deflate switches away from Huffman.)n */nnnfunction deflate_huff(s, flush) {n var bflush;n /* set if current block must be flushed */nn for (;;) {n /* Make sure that we have a literal to write. */n if (s.lookahead === 0) {n fill_window(s);nn if (s.lookahead === 0) {n if (flush === Z_NO_FLUSH) {n return BS_NEED_MORE;n }nn break;n /* flush the current block */n }n }n /* Output a literal byte */nnn s.match_length = 0; //Tracevv((stderr,"%c", s.window, bflush); ***/nn bflush = trees._tr_tally(s, 0, s.window);n s.lookahead–;n s.strstart++;nn if (bflush) {n /*** FLUSH_BLOCK(s, 0); ***/n flush_block_only(s, false);nn if (s.strm.avail_out === 0) {n return BS_NEED_MORE;n }n /***/nn }n }nn s.insert = 0;nn if (flush === Z_FINISH) {n /*** FLUSH_BLOCK(s, 1); ***/n flush_block_only(s, true);nn if (s.strm.avail_out === 0) {n return BS_FINISH_STARTED;n }n /***/nnn return BS_FINISH_DONE;n }nn if (s.last_lit) {n /*** FLUSH_BLOCK(s, 0); ***/n flush_block_only(s, false);nn if (s.strm.avail_out === 0) {n return BS_NEED_MORE;n }n /***/nn }nn return BS_BLOCK_DONE;n}n/* Values for max_lazy_match, good_match and max_chain_length, depending onn * the desired pack level (0..9). The values given below have been tuned ton * exclude worst case performance for pathological files. Better values may ben * found for specific files.n */nnnfunction Config(good_length, max_lazy, nice_length, max_chain, func) {n this.good_length = good_length;n this.max_lazy = max_lazy;n this.nice_length = nice_length;n this.max_chain = max_chain;n this.func = func;n}nnvar configuration_table;nconfiguration_table = [n/* good lazy nice chain */nnew Config(0, 0, 0, 0, deflate_stored),n/* 0 store only */nnew Config(4, 4, 8, 4, deflate_fast),n/* 1 max speed, no lazy matches */nnew Config(4, 5, 16, 8, deflate_fast),n/* 2 */nnew Config(4, 6, 32, 32, deflate_fast),n/* 3 */nnew Config(4, 4, 16, 16, deflate_slow),n/* 4 lazy matches */nnew Config(8, 16, 32, 32, deflate_slow),n/* 5 */nnew Config(8, 16, 128, 128, deflate_slow),n/* 6 */nnew Config(8, 32, 128, 256, deflate_slow),n/* 7 */nnew Config(32, 128, 258, 1024, deflate_slow),n/* 8 */nnew Config(32, 258, 258, 4096, deflate_slow)n/* 9 max compression */n];n/* ===========================================================================n * Initialize the "longest match" routines for a new zlib streamn */nnfunction lm_init(s) {n s.window_size = 2 * s.w_size;n /*** CLEAR_HASH(s); ***/nn zero(s.head); // Fill with NIL (= 0);nn /* Set the default configuration parameters:n */nn s.max_lazy_match = configuration_table.max_lazy;n s.good_match = configuration_table.good_length;n s.nice_match = configuration_table.nice_length;n s.max_chain_length = configuration_table.max_chain;n s.strstart = 0;n s.block_start = 0;n s.lookahead = 0;n s.insert = 0;n s.match_length = s.prev_length = MIN_MATCH - 1;n s.match_available = 0;n s.ins_h = 0;n}nnfunction DeflateState() {n this.strm = null;n /* pointer back to this zlib stream */nn this.status = 0;n /* as the name implies */nn this.pending_buf = null;n /* output still pending */nn this.pending_buf_size = 0;n /* size of pending_buf */nn this.pending_out = 0;n /* next pending byte to output to the stream */nn this.pending = 0;n /* nb of bytes in the pending buffer */nn this.wrap = 0;n /* bit 0 true for zlib, bit 1 true for gzip */nn this.gzhead = null;n /* gzip header information to write */nn this.gzindex = 0;n /* where in extra, name, or comment */nn this.method = Z_DEFLATED;n /* can only be DEFLATED */nn this.last_flush = -1;n /* value of flush param for previous deflate call */nn this.w_size = 0;n /* LZ77 window size (32K by default) */nn this.w_bits = 0;n /* log2(w_size) (8..16) */nn this.w_mask = 0;n /* w_size - 1 */nn this.window = null;n /* Sliding window. Input bytes are read into the second half of the window,n * and move to the first half later to keep a dictionary of at least wSizen * bytes. With this organization, matches are limited to a distance ofn * wSize-MAX_MATCH bytes, but this ensures that IO is alwaysn * performed with a length multiple of the block size.n */nn this.window_size = 0;n /* Actual size of window: 2*wSize, except when the user input buffern * is directly used as sliding window.n */nn this.prev = null;n /* Link to older string with same hash index. To limit the size of thisn * array to 64K, this link is maintained only for the last 32K strings.n * An index in this array is thus a window index modulo 32K.n */nn this.head = null;n /* Heads of the hash chains or NIL. */nn this.ins_h = 0;n /* hash index of string to be inserted */nn this.hash_size = 0;n /* number of elements in hash table */nn this.hash_bits = 0;n /* log2(hash_size) */nn this.hash_mask = 0;n /* hash_size-1 */nn this.hash_shift = 0;n /* Number of bits by which ins_h must be shifted at each inputn * step. It must be such that after MIN_MATCH steps, the oldestn * byte no longer takes part in the hash key, that is:n * hash_shift * MIN_MATCH >= hash_bitsn */nn this.block_start = 0;n /* Window position at the beginning of the current output block. Getsn * negative when the window is moved backwards.n */nn this.match_length = 0;n /* length of best match */nn this.prev_match = 0;n /* previous match */nn this.match_available = 0;n /* set if previous match exists */nn this.strstart = 0;n /* start of string to insert */nn this.match_start = 0;n /* start of matching string */nn this.lookahead = 0;n /* number of valid bytes ahead in window */nn this.prev_length = 0;n /* Length of the best match at previous step. Matches not greater than thisn * are discarded. This is used in the lazy match evaluation.n */nn this.max_chain_length = 0;n /* To speed up deflation, hash chains are never searched beyond thisn * length. A higher limit improves compression ratio but degrades then * speed.n */nn this.max_lazy_match = 0;n /* Attempt to find a better match only when the current match is strictlyn * smaller than this value. This mechanism is used only for compressionn * levels >= 4.n */n // That's alias to max_lazy_match, don't use directlyn //this.max_insert_length = 0;nn /* Insert new strings in the hash table only if the match length is notn * greater than this length. This saves time but degrades compression.n * max_insert_length is used only for compression levels <= 3.n */nn this.level = 0;n /* compression level (1..9) */nn this.strategy = 0;n /* favor or force Huffman coding*/nn this.good_match = 0;n /* Use a faster search when the previous match is longer than this */nn this.nice_match = 0;n /* Stop searching when current match exceeds this */nn /* used by trees.c: */nn /* Didn't use ct_data typedef below to suppress compiler warning */n // struct ct_data_s dyn_ltree; /* literal and length tree */n // struct ct_data_s dyn_dtree; /* distance tree */n // struct ct_data_s bl_tree; /* Huffman tree for bit lengths */n // Use flat array of DOUBLE size, with interleaved fata,n // because JS does not support effectivenn this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2);n this.dyn_dtree = new utils.Buf16((2 * D_CODES + 1) * 2);n this.bl_tree = new utils.Buf16((2 * BL_CODES + 1) * 2);n zero(this.dyn_ltree);n zero(this.dyn_dtree);n zero(this.bl_tree);n this.l_desc = null;n /* desc. for literal tree */nn this.d_desc = null;n /* desc. for distance tree */nn this.bl_desc = null;n /* desc. for bit length tree */n //ush bl_count;nn this.bl_count = new utils.Buf16(MAX_BITS + 1);n /* number of codes at each bit length for an optimal tree */n //int heap; /* heap used to build the Huffman trees */nn this.heap = new utils.Buf16(2 * L_CODES + 1);n /* heap used to build the Huffman trees */nn zero(this.heap);n this.heap_len = 0;n /* number of elements in the heap */nn this.heap_max = 0;n /* element of largest frequency */nn /* The sons of heap are heap and heap. heap is not used.n * The same heap array is used to build all trees.n */nn this.depth = new utils.Buf16(2 * L_CODES + 1); //uch depth;nn zero(this.depth);n /* Depth of each subtree used as tie breaker for trees of equal frequencyn */nn this.l_buf = 0;n /* buffer index for literals or lengths */nn this.lit_bufsize = 0;n /* Size of match buffer for literals/lengths. There are 4 reasons forn * limiting lit_bufsize to 64K:n * - frequencies can be kept in 16 bit countersn * - if compression is not successful for the first block, all inputn * data is still in the window so we can still emit a stored block evenn * when input comes from standard input. (This can also be done forn * all blocks if lit_bufsize is not greater than 32K.)n * - if compression is not successful for a file smaller than 64K, we cann * even emit a stored file instead of a stored block (saving 5 bytes).n * This is applicable only for zip (not gzip or zlib).n * - creating new Huffman trees less frequently may not provide fastn * adaptation to changes in the input data statistics. (Take forn * example a binary file with poorly compressible code followed byn * a highly compressible string table.) Smaller buffer sizes given * fast adaptation but have of course the overhead of transmittingn * trees more frequently.n * - I can't count above 4n */nn this.last_lit = 0;n /* running index in l_buf */nn this.d_buf = 0;n /* Buffer index for distances. To simplify the code, d_buf and l_buf haven * the same number of elements. To use different lengths, an extra flagn * array would be necessary.n */nn this.opt_len = 0;n /* bit length of current block with optimal trees */nn this.static_len = 0;n /* bit length of current block with static trees */nn this.matches = 0;n /* number of string matches in current block */nn this.insert = 0;n /* bytes at end of window left to insert */nn this.bi_buf = 0;n /* Output buffer. bits are inserted starting at the bottom (leastn * significant bits).n */nn this.bi_valid = 0;n /* Number of valid bits in bi_buf. All bits above the last valid bitn * are always zero.n */n // Used for window memory init. We safely ignore it for JS. That makesn // sense only for pointers and memory check tools.n //this.high_water = 0;nn /* High water mark offset in window for initialized bytes – bytes aboven * this are set to zero in order to avoid memory check warnings whenn * longest match routines access bytes past the input. This is thenn * updated to the new high water mark.n */n}nnfunction deflateResetKeep(strm) {n var s;nn if (!strm || !strm.state) {n return err(strm, Z_STREAM_ERROR);n }nn strm.total_in = strm.total_out = 0;n strm.data_type = Z_UNKNOWN;n s = strm.state;n s.pending = 0;n s.pending_out = 0;nn if (s.wrap < 0) {n s.wrap = -s.wrap;n /* was made negative by deflate(…, Z_FINISH); */n }nn s.status = s.wrap ? INIT_STATE : BUSY_STATE;n strm.adler = s.wrap === 2 ? 0 // crc32(0, Z_NULL, 0)n : 1; // adler32(0, Z_NULL, 0)nn s.last_flush = Z_NO_FLUSH;nn trees._tr_init(s);nn return Z_OK;n}nnfunction deflateReset(strm) {n var ret = deflateResetKeep(strm);nn if (ret === Z_OK) {n lm_init(strm.state);n }nn return ret;n}nnfunction deflateSetHeader(strm, head) {n if (!strm || !strm.state) {n return Z_STREAM_ERROR;n }nn if (strm.state.wrap !== 2) {n return Z_STREAM_ERROR;n }nn strm.state.gzhead = head;n return Z_OK;n}nnfunction deflateInit2(strm, level, method, windowBits, memLevel, strategy) {n if (!strm) {n // === Z_NULLn return Z_STREAM_ERROR;n }nn var wrap = 1;nn if (level === Z_DEFAULT_COMPRESSION) {n level = 6;n }nn if (windowBits < 0) {n /* suppress zlib wrapper */n wrap = 0;n windowBits = -windowBits;n } else if (windowBits > 15) {n wrap = 2;n /* write gzip wrapper instead */nn windowBits -= 16;n }nn if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED || windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {n return err(strm, Z_STREAM_ERROR);n }nn if (windowBits === 8) {n windowBits = 9;n }n /* until 256-byte window bug fixed */nnn var s = new DeflateState();n strm.state = s;n s.strm = strm;n s.wrap = wrap;n s.gzhead = null;n s.w_bits = windowBits;n s.w_size = 1 << s.w_bits;n s.w_mask = s.w_size - 1;n s.hash_bits = memLevel + 7;n s.hash_size = 1 << s.hash_bits;n s.hash_mask = s.hash_size - 1;n s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH);n s.window = new utils.Buf8(s.w_size * 2);n s.head = new utils.Buf16(s.hash_size);n s.prev = new utils.Buf16(s.w_size); // Don't need mem init magic for JS.n //s.high_water = 0; /* nothing written to s->window yet */nn s.lit_bufsize = 1 << memLevel + 6;n /* 16K elements by default */nn s.pending_buf_size = s.lit_bufsize * 4; //overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);n //s->pending_buf = (uchf *) overlay;nn s.pending_buf = new utils.Buf8(s.pending_buf_size); // It is offset from `s.pending_buf` (size is `s.lit_bufsize * 2`)n //s->d_buf = overlay + s->lit_bufsize/sizeof(ush);nn s.d_buf = 1 * s.lit_bufsize; //s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;nn s.l_buf = (1 + 2) * s.lit_bufsize;n s.level = level;n s.strategy = strategy;n s.method = method;n return deflateReset(strm);n}nnfunction deflateInit(strm, level) {n return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);n}nnfunction deflate(strm, flush) {n var old_flush, s;n var beg, val; // for gzip header write onlynn if (!strm || !strm.state || flush > Z_BLOCK || flush < 0) {n return strm ? err(strm, Z_STREAM_ERROR) : Z_STREAM_ERROR;n }nn s = strm.state;nn if (!strm.output || !strm.input && strm.avail_in !== 0 || s.status === FINISH_STATE && flush !== Z_FINISH) {n return err(strm, strm.avail_out === 0 ? Z_BUF_ERROR : Z_STREAM_ERROR);n }nn s.strm = strm;n /* just in case */nn old_flush = s.last_flush;n s.last_flush = flush;n /* Write the header */nn if (s.status === INIT_STATE) {n if (s.wrap === 2) {n // GZIP headern strm.adler = 0; //crc32(0L, Z_NULL, 0);nn put_byte(s, 31);n put_byte(s, 139);n put_byte(s, 8);nn if (!s.gzhead) {n // s->gzhead == Z_NULLn put_byte(s, 0);n put_byte(s, 0);n put_byte(s, 0);n put_byte(s, 0);n put_byte(s, 0);n put_byte(s, s.level === 9 ? 2 : s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ? 4 : 0);n put_byte(s, OS_CODE);n s.status = BUSY_STATE;n } else {n put_byte(s, (s.gzhead.text ? 1 : 0) + (s.gzhead.hcrc ? 2 : 0) + (!s.gzhead.extra ? 0 : 4) + (!s.gzhead.name ? 0 : 8) + (!s.gzhead.comment ? 0 : 16));n put_byte(s, s.gzhead.time & 0xff);n put_byte(s, s.gzhead.time >> 8 & 0xff);n put_byte(s, s.gzhead.time >> 16 & 0xff);n put_byte(s, s.gzhead.time >> 24 & 0xff);n put_byte(s, s.level === 9 ? 2 : s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ? 4 : 0);n put_byte(s, s.gzhead.os & 0xff);nn if (s.gzhead.extra && s.gzhead.extra.length) {n put_byte(s, s.gzhead.extra.length & 0xff);n put_byte(s, s.gzhead.extra.length >> 8 & 0xff);n }nn if (s.gzhead.hcrc) {n strm.adler = crc32(strm.adler, s.pending_buf, s.pending, 0);n }nn s.gzindex = 0;n s.status = EXTRA_STATE;n }n } else // DEFLATE headern {n var header = Z_DEFLATED + (s.w_bits - 8 << 4) << 8;n var level_flags = -1;nn if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) {n level_flags = 0;n } else if (s.level < 6) {n level_flags = 1;n } else if (s.level === 6) {n level_flags = 2;n } else {n level_flags = 3;n }nn header |= level_flags << 6;nn if (s.strstart !== 0) {n header |= PRESET_DICT;n }nn header += 31 - header % 31;n s.status = BUSY_STATE;n putShortMSB(s, header);n /* Save the adler32 of the preset dictionary: */nn if (s.strstart !== 0) {n putShortMSB(s, strm.adler >>> 16);n putShortMSB(s, strm.adler & 0xffff);n }nn strm.adler = 1; // adler32(0L, Z_NULL, 0);n }n } //#ifdef GZIPnnn if (s.status === EXTRA_STATE) {n if (s.gzhead.extran /* != Z_NULL*/n ) {n beg = s.pending;n /* start of bytes to update crc */nn while (s.gzindex < (s.gzhead.extra.length & 0xffff)) {n if (s.pending === s.pending_buf_size) {n if (s.gzhead.hcrc && s.pending > beg) {n strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);n }nn flush_pending(strm);n beg = s.pending;nn if (s.pending === s.pending_buf_size) {n break;n }n }nn put_byte(s, s.gzhead.extra & 0xff);n s.gzindex++;n }nn if (s.gzhead.hcrc && s.pending > beg) {n strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);n }nn if (s.gzindex === s.gzhead.extra.length) {n s.gzindex = 0;n s.status = NAME_STATE;n }n } else {n s.status = NAME_STATE;n }n }nn if (s.status === NAME_STATE) {n if (s.gzhead.namen /* != Z_NULL*/n ) {n beg = s.pending;n /* start of bytes to update crc */n //int val;nn do {n if (s.pending === s.pending_buf_size) {n if (s.gzhead.hcrc && s.pending > beg) {n strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);n }nn flush_pending(strm);n beg = s.pending;nn if (s.pending === s.pending_buf_size) {n val = 1;n break;n }n } // JS specific: little magic to add zero terminator to end of stringnnn if (s.gzindex < s.gzhead.name.length) {n val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff;n } else {n val = 0;n }nn put_byte(s, val);n } while (val !== 0);nn if (s.gzhead.hcrc && s.pending > beg) {n strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);n }nn if (val === 0) {n s.gzindex = 0;n s.status = COMMENT_STATE;n }n } else {n s.status = COMMENT_STATE;n }n }nn if (s.status === COMMENT_STATE) {n if (s.gzhead.commentn /* != Z_NULL*/n ) {n beg = s.pending;n /* start of bytes to update crc */n //int val;nn do {n if (s.pending === s.pending_buf_size) {n if (s.gzhead.hcrc && s.pending > beg) {n strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);n }nn flush_pending(strm);n beg = s.pending;nn if (s.pending === s.pending_buf_size) {n val = 1;n break;n }n } // JS specific: little magic to add zero terminator to end of stringnnn if (s.gzindex < s.gzhead.comment.length) {n val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff;n } else {n val = 0;n }nn put_byte(s, val);n } while (val !== 0);nn if (s.gzhead.hcrc && s.pending > beg) {n strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);n }nn if (val === 0) {n s.status = HCRC_STATE;n }n } else {n s.status = HCRC_STATE;n }n }nn if (s.status === HCRC_STATE) {n if (s.gzhead.hcrc) {n if (s.pending + 2 > s.pending_buf_size) {n flush_pending(strm);n }nn if (s.pending + 2 <= s.pending_buf_size) {n put_byte(s, strm.adler & 0xff);n put_byte(s, strm.adler >> 8 & 0xff);n strm.adler = 0; //crc32(0L, Z_NULL, 0);nn s.status = BUSY_STATE;n }n } else {n s.status = BUSY_STATE;n }n } //#endifnn /* Flush as much pending output as possible */nnn if (s.pending !== 0) {n flush_pending(strm);nn if (strm.avail_out === 0) {n /* Since avail_out is 0, deflate will be called again withn * more output space, but possibly with both pending andn * avail_in equal to zero. There won't be anything to do,n * but this is not an error situation so make sure wen * return OK instead of BUF_ERROR at next call of deflate:n */n s.last_flush = -1;n return Z_OK;n }n /* Make sure there is something to do and avoid duplicate consecutiven * flushes. For repeated and useless calls with Z_FINISH, we keepn * returning Z_STREAM_END instead of Z_BUF_ERROR.n */nn } else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) && flush !== Z_FINISH) {n return err(strm, Z_BUF_ERROR);n }n /* User must not provide more input after the first FINISH: */nnn if (s.status === FINISH_STATE && strm.avail_in !== 0) {n return err(strm, Z_BUF_ERROR);n }n /* Start a new block or continue the current one.n */nnn if (strm.avail_in !== 0 || s.lookahead !== 0 || flush !== Z_NO_FLUSH && s.status !== FINISH_STATE) {n var bstate = s.strategy === Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : s.strategy === Z_RLE ? deflate_rle(s, flush) : configuration_table.func(s, flush);nn if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) {n s.status = FINISH_STATE;n }nn if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) {n if (strm.avail_out === 0) {n s.last_flush = -1;n /* avoid BUF_ERROR next call, see above */n }nn return Z_OK;n /* If flush != Z_NO_FLUSH && avail_out == 0, the next calln * of deflate should use the same flush parameter to make suren * that the flush is complete. So we don't have to output ann * empty block here, this will be done at next call. This alson * ensures that for a very small output buffer, we emit at mostn * one empty block.n */n }nn if (bstate === BS_BLOCK_DONE) {n if (flush === Z_PARTIAL_FLUSH) {n trees._tr_align(s);n } else if (flush !== Z_BLOCK) {n /* FULL_FLUSH or SYNC_FLUSH */n trees._tr_stored_block(s, 0, 0, false);n /* For a full flush, this empty block will be recognizedn * as a special marker by inflate_sync().n */nnn if (flush === Z_FULL_FLUSH) {n /*** CLEAR_HASH(s); ***/nn /* forget history */n zero(s.head); // Fill with NIL (= 0);nn if (s.lookahead === 0) {n s.strstart = 0;n s.block_start = 0;n s.insert = 0;n }n }n }nn flush_pending(strm);nn if (strm.avail_out === 0) {n s.last_flush = -1;n /* avoid BUF_ERROR at next call, see above */nn return Z_OK;n }n }n } //Assert(strm->avail_out > 0, "bug2");n //if (strm.avail_out <= 0) { throw new Error("bug2");}nnn if (flush !== Z_FINISH) {n return Z_OK;n }nn if (s.wrap <= 0) {n return Z_STREAM_END;n }n /* Write the trailer */nnn if (s.wrap === 2) {n put_byte(s, strm.adler & 0xff);n put_byte(s, strm.adler >> 8 & 0xff);n put_byte(s, strm.adler >> 16 & 0xff);n put_byte(s, strm.adler >> 24 & 0xff);n put_byte(s, strm.total_in & 0xff);n put_byte(s, strm.total_in >> 8 & 0xff);n put_byte(s, strm.total_in >> 16 & 0xff);n put_byte(s, strm.total_in >> 24 & 0xff);n } else {n putShortMSB(s, strm.adler >>> 16);n putShortMSB(s, strm.adler & 0xffff);n }nn flush_pending(strm);n /* If avail_out is zero, the application will call deflate againn * to flush the rest.n */nn if (s.wrap > 0) {n s.wrap = -s.wrap;n }n /* write the trailer only once! */nnn return s.pending !== 0 ? Z_OK : Z_STREAM_END;n}nnfunction deflateEnd(strm) {n var status;nn if (!strmn /*== Z_NULL*/n || !strm.staten /*== Z_NULL*/n ) {n return Z_STREAM_ERROR;n }nn status = strm.state.status;nn if (status !== INIT_STATE && status !== EXTRA_STATE && status !== NAME_STATE && status !== COMMENT_STATE && status !== HCRC_STATE && status !== BUSY_STATE && status !== FINISH_STATE) {n return err(strm, Z_STREAM_ERROR);n }nn strm.state = null;n return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK;n}n/* =========================================================================n * Initializes the compression dictionary from the given byten * sequence without producing any compressed output.n */nnnfunction deflateSetDictionary(strm, dictionary) {n var dictLength = dictionary.length;n var s;n var str, n;n var wrap;n var avail;n var next;n var input;n var tmpDict;nn if (!strmn /*== Z_NULL*/n || !strm.staten /*== Z_NULL*/n ) {n return Z_STREAM_ERROR;n }nn s = strm.state;n wrap = s.wrap;nn if (wrap === 2 || wrap === 1 && s.status !== INIT_STATE || s.lookahead) {n return Z_STREAM_ERROR;n }n /* when using zlib wrappers, compute Adler-32 for provided dictionary */nnn if (wrap === 1) {n /* adler32(strm->adler, dictionary, dictLength); */n strm.adler = adler32(strm.adler, dictionary, dictLength, 0);n }nn s.wrap = 0;n /* avoid computing Adler-32 in read_buf */nn /* if dictionary would fill window, just replace the history */nn if (dictLength >= s.w_size) {n if (wrap === 0) {n /* already empty otherwise */nn /*** CLEAR_HASH(s); ***/n zero(s.head); // Fill with NIL (= 0);nn s.strstart = 0;n s.block_start = 0;n s.insert = 0;n }n /* use the tail */n // dictionary = dictionary.slice(dictLength - s.w_size);nnn tmpDict = new utils.Buf8(s.w_size);n utils.arraySet(tmpDict, dictionary, dictLength - s.w_size, s.w_size, 0);n dictionary = tmpDict;n dictLength = s.w_size;n }n /* insert dictionary into window and hash */nnn avail = strm.avail_in;n next = strm.next_in;n input = strm.input;n strm.avail_in = dictLength;n strm.next_in = 0;n strm.input = dictionary;n fill_window(s);nn while (s.lookahead >= MIN_MATCH) {n str = s.strstart;n n = s.lookahead - (MIN_MATCH - 1);nn do {n /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */n s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;n s.prev[str & s.w_mask] = s.head;n s.head = str;n str++;n } while (–n);nn s.strstart = str;n s.lookahead = MIN_MATCH - 1;n fill_window(s);n }nn s.strstart += s.lookahead;n s.block_start = s.strstart;n s.insert = s.lookahead;n s.lookahead = 0;n s.match_length = s.prev_length = MIN_MATCH - 1;n s.match_available = 0;n strm.next_in = next;n strm.input = input;n strm.avail_in = avail;n s.wrap = wrap;n return Z_OK;n}nnexports.deflateInit = deflateInit;nexports.deflateInit2 = deflateInit2;nexports.deflateReset = deflateReset;nexports.deflateResetKeep = deflateResetKeep;nexports.deflateSetHeader = deflateSetHeader;nexports.deflate = deflate;nexports.deflateEnd = deflateEnd;nexports.deflateSetDictionary = deflateSetDictionary;nexports.deflateInfo = 'pako deflate (from Nodeca project)';n/* Not implementednexports.deflateBound = deflateBound;nexports.deflateCopy = deflateCopy;nexports.deflateParams = deflateParams;nexports.deflatePending = deflatePending;nexports.deflatePrime = deflatePrime;nexports.deflateTune = deflateTune;n*/”,“map”:null,“metadata”:{},“sourceType”:“module”}