react / wstein / node_modules / browserify / node_modules / browserify-zlib / node_modules / pako / dist / pako_deflate.js
80540 views/* pako 0.2.6 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){1'use strict';234var TYPED_OK = (typeof Uint8Array !== 'undefined') &&5(typeof Uint16Array !== 'undefined') &&6(typeof Int32Array !== 'undefined');789exports.assign = function (obj /*from1, from2, from3, ...*/) {10var sources = Array.prototype.slice.call(arguments, 1);11while (sources.length) {12var source = sources.shift();13if (!source) { continue; }1415if (typeof(source) !== 'object') {16throw new TypeError(source + 'must be non-object');17}1819for (var p in source) {20if (source.hasOwnProperty(p)) {21obj[p] = source[p];22}23}24}2526return obj;27};282930// reduce buffer size, avoiding mem copy31exports.shrinkBuf = function (buf, size) {32if (buf.length === size) { return buf; }33if (buf.subarray) { return buf.subarray(0, size); }34buf.length = size;35return buf;36};373839var fnTyped = {40arraySet: function (dest, src, src_offs, len, dest_offs) {41if (src.subarray && dest.subarray) {42dest.set(src.subarray(src_offs, src_offs+len), dest_offs);43return;44}45// Fallback to ordinary array46for(var i=0; i<len; i++) {47dest[dest_offs + i] = src[src_offs + i];48}49},50// Join array of chunks to single array.51flattenChunks: function(chunks) {52var i, l, len, pos, chunk, result;5354// calculate data length55len = 0;56for (i=0, l=chunks.length; i<l; i++) {57len += chunks[i].length;58}5960// join chunks61result = new Uint8Array(len);62pos = 0;63for (i=0, l=chunks.length; i<l; i++) {64chunk = chunks[i];65result.set(chunk, pos);66pos += chunk.length;67}6869return result;70}71};7273var fnUntyped = {74arraySet: function (dest, src, src_offs, len, dest_offs) {75for(var i=0; i<len; i++) {76dest[dest_offs + i] = src[src_offs + i];77}78},79// Join array of chunks to single array.80flattenChunks: function(chunks) {81return [].concat.apply([], chunks);82}83};848586// Enable/Disable typed arrays use, for testing87//88exports.setTyped = function (on) {89if (on) {90exports.Buf8 = Uint8Array;91exports.Buf16 = Uint16Array;92exports.Buf32 = Int32Array;93exports.assign(exports, fnTyped);94} else {95exports.Buf8 = Array;96exports.Buf16 = Array;97exports.Buf32 = Array;98exports.assign(exports, fnUntyped);99}100};101102exports.setTyped(TYPED_OK);103},{}],2:[function(require,module,exports){104// String encode/decode helpers105'use strict';106107108var utils = require('./common');109110111// Quick check if we can use fast array to bin string conversion112//113// - apply(Array) can fail on Android 2.2114// - apply(Uint8Array) can fail on iOS 5.1 Safary115//116var STR_APPLY_OK = true;117var STR_APPLY_UIA_OK = true;118119try { String.fromCharCode.apply(null, [0]); } catch(__) { STR_APPLY_OK = false; }120try { String.fromCharCode.apply(null, new Uint8Array(1)); } catch(__) { STR_APPLY_UIA_OK = false; }121122123// Table with utf8 lengths (calculated by first byte of sequence)124// Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,125// because max possible codepoint is 0x10ffff126var _utf8len = new utils.Buf8(256);127for (var i=0; i<256; i++) {128_utf8len[i] = (i >= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1);129}130_utf8len[254]=_utf8len[254]=1; // Invalid sequence start131132133// convert string to array (typed, when possible)134exports.string2buf = function (str) {135var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;136137// count binary size138for (m_pos = 0; m_pos < str_len; m_pos++) {139c = str.charCodeAt(m_pos);140if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {141c2 = str.charCodeAt(m_pos+1);142if ((c2 & 0xfc00) === 0xdc00) {143c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);144m_pos++;145}146}147buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;148}149150// allocate buffer151buf = new utils.Buf8(buf_len);152153// convert154for (i=0, m_pos = 0; i < buf_len; m_pos++) {155c = str.charCodeAt(m_pos);156if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {157c2 = str.charCodeAt(m_pos+1);158if ((c2 & 0xfc00) === 0xdc00) {159c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);160m_pos++;161}162}163if (c < 0x80) {164/* one byte */165buf[i++] = c;166} else if (c < 0x800) {167/* two bytes */168buf[i++] = 0xC0 | (c >>> 6);169buf[i++] = 0x80 | (c & 0x3f);170} else if (c < 0x10000) {171/* three bytes */172buf[i++] = 0xE0 | (c >>> 12);173buf[i++] = 0x80 | (c >>> 6 & 0x3f);174buf[i++] = 0x80 | (c & 0x3f);175} else {176/* four bytes */177buf[i++] = 0xf0 | (c >>> 18);178buf[i++] = 0x80 | (c >>> 12 & 0x3f);179buf[i++] = 0x80 | (c >>> 6 & 0x3f);180buf[i++] = 0x80 | (c & 0x3f);181}182}183184return buf;185};186187// Helper (used in 2 places)188function buf2binstring(buf, len) {189// use fallback for big arrays to avoid stack overflow190if (len < 65537) {191if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) {192return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len));193}194}195196var result = '';197for(var i=0; i < len; i++) {198result += String.fromCharCode(buf[i]);199}200return result;201}202203204// Convert byte array to binary string205exports.buf2binstring = function(buf) {206return buf2binstring(buf, buf.length);207};208209210// Convert binary string (typed, when possible)211exports.binstring2buf = function(str) {212var buf = new utils.Buf8(str.length);213for(var i=0, len=buf.length; i < len; i++) {214buf[i] = str.charCodeAt(i);215}216return buf;217};218219220// convert array to string221exports.buf2string = function (buf, max) {222var i, out, c, c_len;223var len = max || buf.length;224225// Reserve max possible length (2 words per char)226// NB: by unknown reasons, Array is significantly faster for227// String.fromCharCode.apply than Uint16Array.228var utf16buf = new Array(len*2);229230for (out=0, i=0; i<len;) {231c = buf[i++];232// quick process ascii233if (c < 0x80) { utf16buf[out++] = c; continue; }234235c_len = _utf8len[c];236// skip 5 & 6 byte codes237if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len-1; continue; }238239// apply mask on first byte240c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;241// join the rest242while (c_len > 1 && i < len) {243c = (c << 6) | (buf[i++] & 0x3f);244c_len--;245}246247// terminated by end of string?248if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }249250if (c < 0x10000) {251utf16buf[out++] = c;252} else {253c -= 0x10000;254utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);255utf16buf[out++] = 0xdc00 | (c & 0x3ff);256}257}258259return buf2binstring(utf16buf, out);260};261262263// Calculate max possible position in utf8 buffer,264// that will not break sequence. If that's not possible265// - (very small limits) return max size as is.266//267// buf[] - utf8 bytes array268// max - length limit (mandatory);269exports.utf8border = function(buf, max) {270var pos;271272max = max || buf.length;273if (max > buf.length) { max = buf.length; }274275// go back from last position, until start of sequence found276pos = max-1;277while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }278279// Fuckup - very small and broken sequence,280// return max, because we should return something anyway.281if (pos < 0) { return max; }282283// If we came to start of buffer - that means vuffer is too small,284// return max too.285if (pos === 0) { return max; }286287return (pos + _utf8len[buf[pos]] > max) ? pos : max;288};289290},{"./common":1}],3:[function(require,module,exports){291'use strict';292293// Note: adler32 takes 12% for level 0 and 2% for level 6.294// It doesn't worth to make additional optimizationa as in original.295// Small size is preferable.296297function adler32(adler, buf, len, pos) {298var s1 = (adler & 0xffff) |0299, s2 = ((adler >>> 16) & 0xffff) |0300, n = 0;301302while (len !== 0) {303// Set limit ~ twice less than 5552, to keep304// s2 in 31-bits, because we force signed ints.305// in other case %= will fail.306n = len > 2000 ? 2000 : len;307len -= n;308309do {310s1 = (s1 + buf[pos++]) |0;311s2 = (s2 + s1) |0;312} while (--n);313314s1 %= 65521;315s2 %= 65521;316}317318return (s1 | (s2 << 16)) |0;319}320321322module.exports = adler32;323},{}],4:[function(require,module,exports){324'use strict';325326// Note: we can't get significant speed boost here.327// So write code to minimize size - no pregenerated tables328// and array tools dependencies.329330331// Use ordinary array, since untyped makes no boost here332function makeTable() {333var c, table = [];334335for(var n =0; n < 256; n++){336c = n;337for(var k =0; k < 8; k++){338c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));339}340table[n] = c;341}342343return table;344}345346// Create table on load. Just 255 signed longs. Not a problem.347var crcTable = makeTable();348349350function crc32(crc, buf, len, pos) {351var t = crcTable352, end = pos + len;353354crc = crc ^ (-1);355356for (var i = pos; i < end; i++ ) {357crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];358}359360return (crc ^ (-1)); // >>> 0;361}362363364module.exports = crc32;365},{}],5:[function(require,module,exports){366'use strict';367368var utils = require('../utils/common');369var trees = require('./trees');370var adler32 = require('./adler32');371var crc32 = require('./crc32');372var msg = require('./messages');373374/* Public constants ==========================================================*/375/* ===========================================================================*/376377378/* Allowed flush values; see deflate() and inflate() below for details */379var Z_NO_FLUSH = 0;380var Z_PARTIAL_FLUSH = 1;381//var Z_SYNC_FLUSH = 2;382var Z_FULL_FLUSH = 3;383var Z_FINISH = 4;384var Z_BLOCK = 5;385//var Z_TREES = 6;386387388/* Return codes for the compression/decompression functions. Negative values389* are errors, positive values are used for special but normal events.390*/391var Z_OK = 0;392var Z_STREAM_END = 1;393//var Z_NEED_DICT = 2;394//var Z_ERRNO = -1;395var Z_STREAM_ERROR = -2;396var Z_DATA_ERROR = -3;397//var Z_MEM_ERROR = -4;398var Z_BUF_ERROR = -5;399//var Z_VERSION_ERROR = -6;400401402/* compression levels */403//var Z_NO_COMPRESSION = 0;404//var Z_BEST_SPEED = 1;405//var Z_BEST_COMPRESSION = 9;406var Z_DEFAULT_COMPRESSION = -1;407408409var Z_FILTERED = 1;410var Z_HUFFMAN_ONLY = 2;411var Z_RLE = 3;412var Z_FIXED = 4;413var Z_DEFAULT_STRATEGY = 0;414415/* Possible values of the data_type field (though see inflate()) */416//var Z_BINARY = 0;417//var Z_TEXT = 1;418//var Z_ASCII = 1; // = Z_TEXT419var Z_UNKNOWN = 2;420421422/* The deflate compression method */423var Z_DEFLATED = 8;424425/*============================================================================*/426427428var MAX_MEM_LEVEL = 9;429/* Maximum value for memLevel in deflateInit2 */430var MAX_WBITS = 15;431/* 32K LZ77 window */432var DEF_MEM_LEVEL = 8;433434435var LENGTH_CODES = 29;436/* number of length codes, not counting the special END_BLOCK code */437var LITERALS = 256;438/* number of literal bytes 0..255 */439var L_CODES = LITERALS + 1 + LENGTH_CODES;440/* number of Literal or Length codes, including the END_BLOCK code */441var D_CODES = 30;442/* number of distance codes */443var BL_CODES = 19;444/* number of codes used to transfer the bit lengths */445var HEAP_SIZE = 2*L_CODES + 1;446/* maximum heap size */447var MAX_BITS = 15;448/* All codes must not exceed MAX_BITS bits */449450var MIN_MATCH = 3;451var MAX_MATCH = 258;452var MIN_LOOKAHEAD = (MAX_MATCH + MIN_MATCH + 1);453454var PRESET_DICT = 0x20;455456var INIT_STATE = 42;457var EXTRA_STATE = 69;458var NAME_STATE = 73;459var COMMENT_STATE = 91;460var HCRC_STATE = 103;461var BUSY_STATE = 113;462var FINISH_STATE = 666;463464var BS_NEED_MORE = 1; /* block not completed, need more input or more output */465var BS_BLOCK_DONE = 2; /* block flush performed */466var BS_FINISH_STARTED = 3; /* finish started, need only more output at next deflate */467var BS_FINISH_DONE = 4; /* finish done, accept no more input or output */468469var OS_CODE = 0x03; // Unix :) . Don't detect, use this default.470471function err(strm, errorCode) {472strm.msg = msg[errorCode];473return errorCode;474}475476function rank(f) {477return ((f) << 1) - ((f) > 4 ? 9 : 0);478}479480function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }481482483/* =========================================================================484* Flush as much pending output as possible. All deflate() output goes485* through this function so some applications may wish to modify it486* to avoid allocating a large strm->output buffer and copying into it.487* (See also read_buf()).488*/489function flush_pending(strm) {490var s = strm.state;491492//_tr_flush_bits(s);493var len = s.pending;494if (len > strm.avail_out) {495len = strm.avail_out;496}497if (len === 0) { return; }498499utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out);500strm.next_out += len;501s.pending_out += len;502strm.total_out += len;503strm.avail_out -= len;504s.pending -= len;505if (s.pending === 0) {506s.pending_out = 0;507}508}509510511function flush_block_only (s, last) {512trees._tr_flush_block(s, (s.block_start >= 0 ? s.block_start : -1), s.strstart - s.block_start, last);513s.block_start = s.strstart;514flush_pending(s.strm);515}516517518function put_byte(s, b) {519s.pending_buf[s.pending++] = b;520}521522523/* =========================================================================524* Put a short in the pending buffer. The 16-bit value is put in MSB order.525* IN assertion: the stream state is correct and there is enough room in526* pending_buf.527*/528function putShortMSB(s, b) {529// put_byte(s, (Byte)(b >> 8));530// put_byte(s, (Byte)(b & 0xff));531s.pending_buf[s.pending++] = (b >>> 8) & 0xff;532s.pending_buf[s.pending++] = b & 0xff;533}534535536/* ===========================================================================537* Read a new buffer from the current input stream, update the adler32538* and total number of bytes read. All deflate() input goes through539* this function so some applications may wish to modify it to avoid540* allocating a large strm->input buffer and copying from it.541* (See also flush_pending()).542*/543function read_buf(strm, buf, start, size) {544var len = strm.avail_in;545546if (len > size) { len = size; }547if (len === 0) { return 0; }548549strm.avail_in -= len;550551utils.arraySet(buf, strm.input, strm.next_in, len, start);552if (strm.state.wrap === 1) {553strm.adler = adler32(strm.adler, buf, len, start);554}555556else if (strm.state.wrap === 2) {557strm.adler = crc32(strm.adler, buf, len, start);558}559560strm.next_in += len;561strm.total_in += len;562563return len;564}565566567/* ===========================================================================568* Set match_start to the longest match starting at the given string and569* return its length. Matches shorter or equal to prev_length are discarded,570* in which case the result is equal to prev_length and match_start is571* garbage.572* IN assertions: cur_match is the head of the hash chain for the current573* string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1574* OUT assertion: the match length is not greater than s->lookahead.575*/576function longest_match(s, cur_match) {577var chain_length = s.max_chain_length; /* max hash chain length */578var scan = s.strstart; /* current string */579var match; /* matched string */580var len; /* length of current match */581var best_len = s.prev_length; /* best match length so far */582var nice_match = s.nice_match; /* stop if match long enough */583var limit = (s.strstart > (s.w_size - MIN_LOOKAHEAD)) ?584s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0/*NIL*/;585586var _win = s.window; // shortcut587588var wmask = s.w_mask;589var prev = s.prev;590591/* Stop when cur_match becomes <= limit. To simplify the code,592* we prevent matches with the string of window index 0.593*/594595var strend = s.strstart + MAX_MATCH;596var scan_end1 = _win[scan + best_len - 1];597var scan_end = _win[scan + best_len];598599/* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.600* It is easy to get rid of this optimization if necessary.601*/602// Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");603604/* Do not waste too much time if we already have a good match: */605if (s.prev_length >= s.good_match) {606chain_length >>= 2;607}608/* Do not look for matches beyond the end of the input. This is necessary609* to make deflate deterministic.610*/611if (nice_match > s.lookahead) { nice_match = s.lookahead; }612613// Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");614615do {616// Assert(cur_match < s->strstart, "no future");617match = cur_match;618619/* Skip to next match if the match length cannot increase620* or if the match length is less than 2. Note that the checks below621* for insufficient lookahead only occur occasionally for performance622* reasons. Therefore uninitialized memory will be accessed, and623* conditional jumps will be made that depend on those values.624* However the length of the match is limited to the lookahead, so625* the output of deflate is not affected by the uninitialized values.626*/627628if (_win[match + best_len] !== scan_end ||629_win[match + best_len - 1] !== scan_end1 ||630_win[match] !== _win[scan] ||631_win[++match] !== _win[scan + 1]) {632continue;633}634635/* The check at best_len-1 can be removed because it will be made636* again later. (This heuristic is not always a win.)637* It is not necessary to compare scan[2] and match[2] since they638* are always equal when the other bytes match, given that639* the hash keys are equal and that HASH_BITS >= 8.640*/641scan += 2;642match++;643// Assert(*scan == *match, "match[2]?");644645/* We check for insufficient lookahead only every 8th comparison;646* the 256th check will be made at strstart+258.647*/648do {649/*jshint noempty:false*/650} while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&651_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&652_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&653_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&654scan < strend);655656// Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");657658len = MAX_MATCH - (strend - scan);659scan = strend - MAX_MATCH;660661if (len > best_len) {662s.match_start = cur_match;663best_len = len;664if (len >= nice_match) {665break;666}667scan_end1 = _win[scan + best_len - 1];668scan_end = _win[scan + best_len];669}670} while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0);671672if (best_len <= s.lookahead) {673return best_len;674}675return s.lookahead;676}677678679/* ===========================================================================680* Fill the window when the lookahead becomes insufficient.681* Updates strstart and lookahead.682*683* IN assertion: lookahead < MIN_LOOKAHEAD684* OUT assertions: strstart <= window_size-MIN_LOOKAHEAD685* At least one byte has been read, or avail_in == 0; reads are686* performed for at least two bytes (required for the zip translate_eol687* option -- not supported here).688*/689function fill_window(s) {690var _w_size = s.w_size;691var p, n, m, more, str;692693//Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");694695do {696more = s.window_size - s.lookahead - s.strstart;697698// JS ints have 32 bit, block below not needed699/* Deal with !@#$% 64K limit: */700//if (sizeof(int) <= 2) {701// if (more == 0 && s->strstart == 0 && s->lookahead == 0) {702// more = wsize;703//704// } else if (more == (unsigned)(-1)) {705// /* Very unlikely, but possible on 16 bit machine if706// * strstart == 0 && lookahead == 1 (input done a byte at time)707// */708// more--;709// }710//}711712713/* If the window is almost full and there is insufficient lookahead,714* move the upper half to the lower one to make room in the upper half.715*/716if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {717718utils.arraySet(s.window, s.window, _w_size, _w_size, 0);719s.match_start -= _w_size;720s.strstart -= _w_size;721/* we now have strstart >= MAX_DIST */722s.block_start -= _w_size;723724/* Slide the hash table (could be avoided with 32 bit values725at the expense of memory usage). We slide even when level == 0726to keep the hash table consistent if we switch back to level > 0727later. (Using level 0 permanently is not an optimal usage of728zlib, so we don't care about this pathological case.)729*/730731n = s.hash_size;732p = n;733do {734m = s.head[--p];735s.head[p] = (m >= _w_size ? m - _w_size : 0);736} while (--n);737738n = _w_size;739p = n;740do {741m = s.prev[--p];742s.prev[p] = (m >= _w_size ? m - _w_size : 0);743/* If n is not on any hash chain, prev[n] is garbage but744* its value will never be used.745*/746} while (--n);747748more += _w_size;749}750if (s.strm.avail_in === 0) {751break;752}753754/* If there was no sliding:755* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&756* more == window_size - lookahead - strstart757* => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)758* => more >= window_size - 2*WSIZE + 2759* In the BIG_MEM or MMAP case (not yet supported),760* window_size == input_size + MIN_LOOKAHEAD &&761* strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.762* Otherwise, window_size == 2*WSIZE so more >= 2.763* If there was sliding, more >= WSIZE. So in all cases, more >= 2.764*/765//Assert(more >= 2, "more < 2");766n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more);767s.lookahead += n;768769/* Initialize the hash value now that we have some input: */770if (s.lookahead + s.insert >= MIN_MATCH) {771str = s.strstart - s.insert;772s.ins_h = s.window[str];773774/* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */775s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + 1]) & s.hash_mask;776//#if MIN_MATCH != 3777// Call update_hash() MIN_MATCH-3 more times778//#endif779while (s.insert) {780/* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */781s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH-1]) & s.hash_mask;782783s.prev[str & s.w_mask] = s.head[s.ins_h];784s.head[s.ins_h] = str;785str++;786s.insert--;787if (s.lookahead + s.insert < MIN_MATCH) {788break;789}790}791}792/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,793* but this is not important since only literal bytes will be emitted.794*/795796} while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0);797798/* If the WIN_INIT bytes after the end of the current data have never been799* written, then zero those bytes in order to avoid memory check reports of800* the use of uninitialized (or uninitialised as Julian writes) bytes by801* the longest match routines. Update the high water mark for the next802* time through here. WIN_INIT is set to MAX_MATCH since the longest match803* routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.804*/805// if (s.high_water < s.window_size) {806// var curr = s.strstart + s.lookahead;807// var init = 0;808//809// if (s.high_water < curr) {810// /* Previous high water mark below current data -- zero WIN_INIT811// * bytes or up to end of window, whichever is less.812// */813// init = s.window_size - curr;814// if (init > WIN_INIT)815// init = WIN_INIT;816// zmemzero(s->window + curr, (unsigned)init);817// s->high_water = curr + init;818// }819// else if (s->high_water < (ulg)curr + WIN_INIT) {820// /* High water mark at or above current data, but below current data821// * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up822// * to end of window, whichever is less.823// */824// init = (ulg)curr + WIN_INIT - s->high_water;825// if (init > s->window_size - s->high_water)826// init = s->window_size - s->high_water;827// zmemzero(s->window + s->high_water, (unsigned)init);828// s->high_water += init;829// }830// }831//832// Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,833// "not enough room for search");834}835836/* ===========================================================================837* Copy without compression as much as possible from the input stream, return838* the current block state.839* This function does not insert new strings in the dictionary since840* uncompressible data is probably not useful. This function is used841* only for the level=0 compression option.842* NOTE: this function should be optimized to avoid extra copying from843* window to pending_buf.844*/845function deflate_stored(s, flush) {846/* Stored blocks are limited to 0xffff bytes, pending_buf is limited847* to pending_buf_size, and each stored block has a 5 byte header:848*/849var max_block_size = 0xffff;850851if (max_block_size > s.pending_buf_size - 5) {852max_block_size = s.pending_buf_size - 5;853}854855/* Copy as much as possible from input to output: */856for (;;) {857/* Fill the window as much as possible: */858if (s.lookahead <= 1) {859860//Assert(s->strstart < s->w_size+MAX_DIST(s) ||861// s->block_start >= (long)s->w_size, "slide too late");862// if (!(s.strstart < s.w_size + (s.w_size - MIN_LOOKAHEAD) ||863// s.block_start >= s.w_size)) {864// throw new Error("slide too late");865// }866867fill_window(s);868if (s.lookahead === 0 && flush === Z_NO_FLUSH) {869return BS_NEED_MORE;870}871872if (s.lookahead === 0) {873break;874}875/* flush the current block */876}877//Assert(s->block_start >= 0L, "block gone");878// if (s.block_start < 0) throw new Error("block gone");879880s.strstart += s.lookahead;881s.lookahead = 0;882883/* Emit a stored block if pending_buf will be full: */884var max_start = s.block_start + max_block_size;885886if (s.strstart === 0 || s.strstart >= max_start) {887/* strstart == 0 is possible when wraparound on 16-bit machine */888s.lookahead = s.strstart - max_start;889s.strstart = max_start;890/*** FLUSH_BLOCK(s, 0); ***/891flush_block_only(s, false);892if (s.strm.avail_out === 0) {893return BS_NEED_MORE;894}895/***/896897898}899/* Flush if we may have to slide, otherwise block_start may become900* negative and the data will be gone:901*/902if (s.strstart - s.block_start >= (s.w_size - MIN_LOOKAHEAD)) {903/*** FLUSH_BLOCK(s, 0); ***/904flush_block_only(s, false);905if (s.strm.avail_out === 0) {906return BS_NEED_MORE;907}908/***/909}910}911912s.insert = 0;913914if (flush === Z_FINISH) {915/*** FLUSH_BLOCK(s, 1); ***/916flush_block_only(s, true);917if (s.strm.avail_out === 0) {918return BS_FINISH_STARTED;919}920/***/921return BS_FINISH_DONE;922}923924if (s.strstart > s.block_start) {925/*** FLUSH_BLOCK(s, 0); ***/926flush_block_only(s, false);927if (s.strm.avail_out === 0) {928return BS_NEED_MORE;929}930/***/931}932933return BS_NEED_MORE;934}935936/* ===========================================================================937* Compress as much as possible from the input stream, return the current938* block state.939* This function does not perform lazy evaluation of matches and inserts940* new strings in the dictionary only for unmatched strings or for short941* matches. It is used only for the fast compression options.942*/943function deflate_fast(s, flush) {944var hash_head; /* head of the hash chain */945var bflush; /* set if current block must be flushed */946947for (;;) {948/* Make sure that we always have enough lookahead, except949* at the end of the input file. We need MAX_MATCH bytes950* for the next match, plus MIN_MATCH bytes to insert the951* string following the next match.952*/953if (s.lookahead < MIN_LOOKAHEAD) {954fill_window(s);955if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {956return BS_NEED_MORE;957}958if (s.lookahead === 0) {959break; /* flush the current block */960}961}962963/* Insert the string window[strstart .. strstart+2] in the964* dictionary, and set hash_head to the head of the hash chain:965*/966hash_head = 0/*NIL*/;967if (s.lookahead >= MIN_MATCH) {968/*** INSERT_STRING(s, s.strstart, hash_head); ***/969s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;970hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];971s.head[s.ins_h] = s.strstart;972/***/973}974975/* Find the longest match, discarding those <= prev_length.976* At this point we have always match_length < MIN_MATCH977*/978if (hash_head !== 0/*NIL*/ && ((s.strstart - hash_head) <= (s.w_size - MIN_LOOKAHEAD))) {979/* To simplify the code, we prevent matches with the string980* of window index 0 (in particular we have to avoid a match981* of the string with itself at the start of the input file).982*/983s.match_length = longest_match(s, hash_head);984/* longest_match() sets match_start */985}986if (s.match_length >= MIN_MATCH) {987// check_match(s, s.strstart, s.match_start, s.match_length); // for debug only988989/*** _tr_tally_dist(s, s.strstart - s.match_start,990s.match_length - MIN_MATCH, bflush); ***/991bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);992993s.lookahead -= s.match_length;994995/* Insert new strings in the hash table only if the match length996* is not too large. This saves time but degrades compression.997*/998if (s.match_length <= s.max_lazy_match/*max_insert_length*/ && s.lookahead >= MIN_MATCH) {999s.match_length--; /* string at strstart already in table */1000do {1001s.strstart++;1002/*** INSERT_STRING(s, s.strstart, hash_head); ***/1003s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;1004hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];1005s.head[s.ins_h] = s.strstart;1006/***/1007/* strstart never exceeds WSIZE-MAX_MATCH, so there are1008* always MIN_MATCH bytes ahead.1009*/1010} while (--s.match_length !== 0);1011s.strstart++;1012} else1013{1014s.strstart += s.match_length;1015s.match_length = 0;1016s.ins_h = s.window[s.strstart];1017/* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */1018s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + 1]) & s.hash_mask;10191020//#if MIN_MATCH != 31021// Call UPDATE_HASH() MIN_MATCH-3 more times1022//#endif1023/* If lookahead < MIN_MATCH, ins_h is garbage, but it does not1024* matter since it will be recomputed at next deflate call.1025*/1026}1027} else {1028/* No match, output a literal byte */1029//Tracevv((stderr,"%c", s.window[s.strstart]));1030/*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/1031bflush = trees._tr_tally(s, 0, s.window[s.strstart]);10321033s.lookahead--;1034s.strstart++;1035}1036if (bflush) {1037/*** FLUSH_BLOCK(s, 0); ***/1038flush_block_only(s, false);1039if (s.strm.avail_out === 0) {1040return BS_NEED_MORE;1041}1042/***/1043}1044}1045s.insert = ((s.strstart < (MIN_MATCH-1)) ? s.strstart : MIN_MATCH-1);1046if (flush === Z_FINISH) {1047/*** FLUSH_BLOCK(s, 1); ***/1048flush_block_only(s, true);1049if (s.strm.avail_out === 0) {1050return BS_FINISH_STARTED;1051}1052/***/1053return BS_FINISH_DONE;1054}1055if (s.last_lit) {1056/*** FLUSH_BLOCK(s, 0); ***/1057flush_block_only(s, false);1058if (s.strm.avail_out === 0) {1059return BS_NEED_MORE;1060}1061/***/1062}1063return BS_BLOCK_DONE;1064}10651066/* ===========================================================================1067* Same as above, but achieves better compression. We use a lazy1068* evaluation for matches: a match is finally adopted only if there is1069* no better match at the next window position.1070*/1071function deflate_slow(s, flush) {1072var hash_head; /* head of hash chain */1073var bflush; /* set if current block must be flushed */10741075var max_insert;10761077/* Process the input block. */1078for (;;) {1079/* Make sure that we always have enough lookahead, except1080* at the end of the input file. We need MAX_MATCH bytes1081* for the next match, plus MIN_MATCH bytes to insert the1082* string following the next match.1083*/1084if (s.lookahead < MIN_LOOKAHEAD) {1085fill_window(s);1086if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {1087return BS_NEED_MORE;1088}1089if (s.lookahead === 0) { break; } /* flush the current block */1090}10911092/* Insert the string window[strstart .. strstart+2] in the1093* dictionary, and set hash_head to the head of the hash chain:1094*/1095hash_head = 0/*NIL*/;1096if (s.lookahead >= MIN_MATCH) {1097/*** INSERT_STRING(s, s.strstart, hash_head); ***/1098s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;1099hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];1100s.head[s.ins_h] = s.strstart;1101/***/1102}11031104/* Find the longest match, discarding those <= prev_length.1105*/1106s.prev_length = s.match_length;1107s.prev_match = s.match_start;1108s.match_length = MIN_MATCH-1;11091110if (hash_head !== 0/*NIL*/ && s.prev_length < s.max_lazy_match &&1111s.strstart - hash_head <= (s.w_size-MIN_LOOKAHEAD)/*MAX_DIST(s)*/) {1112/* To simplify the code, we prevent matches with the string1113* of window index 0 (in particular we have to avoid a match1114* of the string with itself at the start of the input file).1115*/1116s.match_length = longest_match(s, hash_head);1117/* longest_match() sets match_start */11181119if (s.match_length <= 5 &&1120(s.strategy === Z_FILTERED || (s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096/*TOO_FAR*/))) {11211122/* If prev_match is also MIN_MATCH, match_start is garbage1123* but we will ignore the current match anyway.1124*/1125s.match_length = MIN_MATCH-1;1126}1127}1128/* If there was a match at the previous step and the current1129* match is not better, output the previous match:1130*/1131if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) {1132max_insert = s.strstart + s.lookahead - MIN_MATCH;1133/* Do not insert strings in hash table beyond this. */11341135//check_match(s, s.strstart-1, s.prev_match, s.prev_length);11361137/***_tr_tally_dist(s, s.strstart - 1 - s.prev_match,1138s.prev_length - MIN_MATCH, bflush);***/1139bflush = trees._tr_tally(s, s.strstart - 1- s.prev_match, s.prev_length - MIN_MATCH);1140/* Insert in hash table all strings up to the end of the match.1141* strstart-1 and strstart are already inserted. If there is not1142* enough lookahead, the last two strings are not inserted in1143* the hash table.1144*/1145s.lookahead -= s.prev_length-1;1146s.prev_length -= 2;1147do {1148if (++s.strstart <= max_insert) {1149/*** INSERT_STRING(s, s.strstart, hash_head); ***/1150s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;1151hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];1152s.head[s.ins_h] = s.strstart;1153/***/1154}1155} while (--s.prev_length !== 0);1156s.match_available = 0;1157s.match_length = MIN_MATCH-1;1158s.strstart++;11591160if (bflush) {1161/*** FLUSH_BLOCK(s, 0); ***/1162flush_block_only(s, false);1163if (s.strm.avail_out === 0) {1164return BS_NEED_MORE;1165}1166/***/1167}11681169} else if (s.match_available) {1170/* If there was no match at the previous position, output a1171* single literal. If there was a match but the current match1172* is longer, truncate the previous match to a single literal.1173*/1174//Tracevv((stderr,"%c", s->window[s->strstart-1]));1175/*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/1176bflush = trees._tr_tally(s, 0, s.window[s.strstart-1]);11771178if (bflush) {1179/*** FLUSH_BLOCK_ONLY(s, 0) ***/1180flush_block_only(s, false);1181/***/1182}1183s.strstart++;1184s.lookahead--;1185if (s.strm.avail_out === 0) {1186return BS_NEED_MORE;1187}1188} else {1189/* There is no previous match to compare with, wait for1190* the next step to decide.1191*/1192s.match_available = 1;1193s.strstart++;1194s.lookahead--;1195}1196}1197//Assert (flush != Z_NO_FLUSH, "no flush?");1198if (s.match_available) {1199//Tracevv((stderr,"%c", s->window[s->strstart-1]));1200/*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/1201bflush = trees._tr_tally(s, 0, s.window[s.strstart-1]);12021203s.match_available = 0;1204}1205s.insert = s.strstart < MIN_MATCH-1 ? s.strstart : MIN_MATCH-1;1206if (flush === Z_FINISH) {1207/*** FLUSH_BLOCK(s, 1); ***/1208flush_block_only(s, true);1209if (s.strm.avail_out === 0) {1210return BS_FINISH_STARTED;1211}1212/***/1213return BS_FINISH_DONE;1214}1215if (s.last_lit) {1216/*** FLUSH_BLOCK(s, 0); ***/1217flush_block_only(s, false);1218if (s.strm.avail_out === 0) {1219return BS_NEED_MORE;1220}1221/***/1222}12231224return BS_BLOCK_DONE;1225}122612271228/* ===========================================================================1229* For Z_RLE, simply look for runs of bytes, generate matches only of distance1230* one. Do not maintain a hash table. (It will be regenerated if this run of1231* deflate switches away from Z_RLE.)1232*/1233function deflate_rle(s, flush) {1234var bflush; /* set if current block must be flushed */1235var prev; /* byte at distance one to match */1236var scan, strend; /* scan goes up to strend for length of run */12371238var _win = s.window;12391240for (;;) {1241/* Make sure that we always have enough lookahead, except1242* at the end of the input file. We need MAX_MATCH bytes1243* for the longest run, plus one for the unrolled loop.1244*/1245if (s.lookahead <= MAX_MATCH) {1246fill_window(s);1247if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) {1248return BS_NEED_MORE;1249}1250if (s.lookahead === 0) { break; } /* flush the current block */1251}12521253/* See how many times the previous byte repeats */1254s.match_length = 0;1255if (s.lookahead >= MIN_MATCH && s.strstart > 0) {1256scan = s.strstart - 1;1257prev = _win[scan];1258if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) {1259strend = s.strstart + MAX_MATCH;1260do {1261/*jshint noempty:false*/1262} while (prev === _win[++scan] && prev === _win[++scan] &&1263prev === _win[++scan] && prev === _win[++scan] &&1264prev === _win[++scan] && prev === _win[++scan] &&1265prev === _win[++scan] && prev === _win[++scan] &&1266scan < strend);1267s.match_length = MAX_MATCH - (strend - scan);1268if (s.match_length > s.lookahead) {1269s.match_length = s.lookahead;1270}1271}1272//Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");1273}12741275/* Emit match if have run of MIN_MATCH or longer, else emit literal */1276if (s.match_length >= MIN_MATCH) {1277//check_match(s, s.strstart, s.strstart - 1, s.match_length);12781279/*** _tr_tally_dist(s, 1, s.match_length - MIN_MATCH, bflush); ***/1280bflush = trees._tr_tally(s, 1, s.match_length - MIN_MATCH);12811282s.lookahead -= s.match_length;1283s.strstart += s.match_length;1284s.match_length = 0;1285} else {1286/* No match, output a literal byte */1287//Tracevv((stderr,"%c", s->window[s->strstart]));1288/*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/1289bflush = trees._tr_tally(s, 0, s.window[s.strstart]);12901291s.lookahead--;1292s.strstart++;1293}1294if (bflush) {1295/*** FLUSH_BLOCK(s, 0); ***/1296flush_block_only(s, false);1297if (s.strm.avail_out === 0) {1298return BS_NEED_MORE;1299}1300/***/1301}1302}1303s.insert = 0;1304if (flush === Z_FINISH) {1305/*** FLUSH_BLOCK(s, 1); ***/1306flush_block_only(s, true);1307if (s.strm.avail_out === 0) {1308return BS_FINISH_STARTED;1309}1310/***/1311return BS_FINISH_DONE;1312}1313if (s.last_lit) {1314/*** FLUSH_BLOCK(s, 0); ***/1315flush_block_only(s, false);1316if (s.strm.avail_out === 0) {1317return BS_NEED_MORE;1318}1319/***/1320}1321return BS_BLOCK_DONE;1322}13231324/* ===========================================================================1325* For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.1326* (It will be regenerated if this run of deflate switches away from Huffman.)1327*/1328function deflate_huff(s, flush) {1329var bflush; /* set if current block must be flushed */13301331for (;;) {1332/* Make sure that we have a literal to write. */1333if (s.lookahead === 0) {1334fill_window(s);1335if (s.lookahead === 0) {1336if (flush === Z_NO_FLUSH) {1337return BS_NEED_MORE;1338}1339break; /* flush the current block */1340}1341}13421343/* Output a literal byte */1344s.match_length = 0;1345//Tracevv((stderr,"%c", s->window[s->strstart]));1346/*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/1347bflush = trees._tr_tally(s, 0, s.window[s.strstart]);1348s.lookahead--;1349s.strstart++;1350if (bflush) {1351/*** FLUSH_BLOCK(s, 0); ***/1352flush_block_only(s, false);1353if (s.strm.avail_out === 0) {1354return BS_NEED_MORE;1355}1356/***/1357}1358}1359s.insert = 0;1360if (flush === Z_FINISH) {1361/*** FLUSH_BLOCK(s, 1); ***/1362flush_block_only(s, true);1363if (s.strm.avail_out === 0) {1364return BS_FINISH_STARTED;1365}1366/***/1367return BS_FINISH_DONE;1368}1369if (s.last_lit) {1370/*** FLUSH_BLOCK(s, 0); ***/1371flush_block_only(s, false);1372if (s.strm.avail_out === 0) {1373return BS_NEED_MORE;1374}1375/***/1376}1377return BS_BLOCK_DONE;1378}13791380/* Values for max_lazy_match, good_match and max_chain_length, depending on1381* the desired pack level (0..9). The values given below have been tuned to1382* exclude worst case performance for pathological files. Better values may be1383* found for specific files.1384*/1385var Config = function (good_length, max_lazy, nice_length, max_chain, func) {1386this.good_length = good_length;1387this.max_lazy = max_lazy;1388this.nice_length = nice_length;1389this.max_chain = max_chain;1390this.func = func;1391};13921393var configuration_table;13941395configuration_table = [1396/* good lazy nice chain */1397new Config(0, 0, 0, 0, deflate_stored), /* 0 store only */1398new Config(4, 4, 8, 4, deflate_fast), /* 1 max speed, no lazy matches */1399new Config(4, 5, 16, 8, deflate_fast), /* 2 */1400new Config(4, 6, 32, 32, deflate_fast), /* 3 */14011402new Config(4, 4, 16, 16, deflate_slow), /* 4 lazy matches */1403new Config(8, 16, 32, 32, deflate_slow), /* 5 */1404new Config(8, 16, 128, 128, deflate_slow), /* 6 */1405new Config(8, 32, 128, 256, deflate_slow), /* 7 */1406new Config(32, 128, 258, 1024, deflate_slow), /* 8 */1407new Config(32, 258, 258, 4096, deflate_slow) /* 9 max compression */1408];140914101411/* ===========================================================================1412* Initialize the "longest match" routines for a new zlib stream1413*/1414function lm_init(s) {1415s.window_size = 2 * s.w_size;14161417/*** CLEAR_HASH(s); ***/1418zero(s.head); // Fill with NIL (= 0);14191420/* Set the default configuration parameters:1421*/1422s.max_lazy_match = configuration_table[s.level].max_lazy;1423s.good_match = configuration_table[s.level].good_length;1424s.nice_match = configuration_table[s.level].nice_length;1425s.max_chain_length = configuration_table[s.level].max_chain;14261427s.strstart = 0;1428s.block_start = 0;1429s.lookahead = 0;1430s.insert = 0;1431s.match_length = s.prev_length = MIN_MATCH - 1;1432s.match_available = 0;1433s.ins_h = 0;1434}143514361437function DeflateState() {1438this.strm = null; /* pointer back to this zlib stream */1439this.status = 0; /* as the name implies */1440this.pending_buf = null; /* output still pending */1441this.pending_buf_size = 0; /* size of pending_buf */1442this.pending_out = 0; /* next pending byte to output to the stream */1443this.pending = 0; /* nb of bytes in the pending buffer */1444this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */1445this.gzhead = null; /* gzip header information to write */1446this.gzindex = 0; /* where in extra, name, or comment */1447this.method = Z_DEFLATED; /* can only be DEFLATED */1448this.last_flush = -1; /* value of flush param for previous deflate call */14491450this.w_size = 0; /* LZ77 window size (32K by default) */1451this.w_bits = 0; /* log2(w_size) (8..16) */1452this.w_mask = 0; /* w_size - 1 */14531454this.window = null;1455/* Sliding window. Input bytes are read into the second half of the window,1456* and move to the first half later to keep a dictionary of at least wSize1457* bytes. With this organization, matches are limited to a distance of1458* wSize-MAX_MATCH bytes, but this ensures that IO is always1459* performed with a length multiple of the block size.1460*/14611462this.window_size = 0;1463/* Actual size of window: 2*wSize, except when the user input buffer1464* is directly used as sliding window.1465*/14661467this.prev = null;1468/* Link to older string with same hash index. To limit the size of this1469* array to 64K, this link is maintained only for the last 32K strings.1470* An index in this array is thus a window index modulo 32K.1471*/14721473this.head = null; /* Heads of the hash chains or NIL. */14741475this.ins_h = 0; /* hash index of string to be inserted */1476this.hash_size = 0; /* number of elements in hash table */1477this.hash_bits = 0; /* log2(hash_size) */1478this.hash_mask = 0; /* hash_size-1 */14791480this.hash_shift = 0;1481/* Number of bits by which ins_h must be shifted at each input1482* step. It must be such that after MIN_MATCH steps, the oldest1483* byte no longer takes part in the hash key, that is:1484* hash_shift * MIN_MATCH >= hash_bits1485*/14861487this.block_start = 0;1488/* Window position at the beginning of the current output block. Gets1489* negative when the window is moved backwards.1490*/14911492this.match_length = 0; /* length of best match */1493this.prev_match = 0; /* previous match */1494this.match_available = 0; /* set if previous match exists */1495this.strstart = 0; /* start of string to insert */1496this.match_start = 0; /* start of matching string */1497this.lookahead = 0; /* number of valid bytes ahead in window */14981499this.prev_length = 0;1500/* Length of the best match at previous step. Matches not greater than this1501* are discarded. This is used in the lazy match evaluation.1502*/15031504this.max_chain_length = 0;1505/* To speed up deflation, hash chains are never searched beyond this1506* length. A higher limit improves compression ratio but degrades the1507* speed.1508*/15091510this.max_lazy_match = 0;1511/* Attempt to find a better match only when the current match is strictly1512* smaller than this value. This mechanism is used only for compression1513* levels >= 4.1514*/1515// That's alias to max_lazy_match, don't use directly1516//this.max_insert_length = 0;1517/* Insert new strings in the hash table only if the match length is not1518* greater than this length. This saves time but degrades compression.1519* max_insert_length is used only for compression levels <= 3.1520*/15211522this.level = 0; /* compression level (1..9) */1523this.strategy = 0; /* favor or force Huffman coding*/15241525this.good_match = 0;1526/* Use a faster search when the previous match is longer than this */15271528this.nice_match = 0; /* Stop searching when current match exceeds this */15291530/* used by trees.c: */15311532/* Didn't use ct_data typedef below to suppress compiler warning */15331534// struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */1535// struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */1536// struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */15371538// Use flat array of DOUBLE size, with interleaved fata,1539// because JS does not support effective1540this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2);1541this.dyn_dtree = new utils.Buf16((2*D_CODES+1) * 2);1542this.bl_tree = new utils.Buf16((2*BL_CODES+1) * 2);1543zero(this.dyn_ltree);1544zero(this.dyn_dtree);1545zero(this.bl_tree);15461547this.l_desc = null; /* desc. for literal tree */1548this.d_desc = null; /* desc. for distance tree */1549this.bl_desc = null; /* desc. for bit length tree */15501551//ush bl_count[MAX_BITS+1];1552this.bl_count = new utils.Buf16(MAX_BITS+1);1553/* number of codes at each bit length for an optimal tree */15541555//int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */1556this.heap = new utils.Buf16(2*L_CODES+1); /* heap used to build the Huffman trees */1557zero(this.heap);15581559this.heap_len = 0; /* number of elements in the heap */1560this.heap_max = 0; /* element of largest frequency */1561/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.1562* The same heap array is used to build all trees.1563*/15641565this.depth = new utils.Buf16(2*L_CODES+1); //uch depth[2*L_CODES+1];1566zero(this.depth);1567/* Depth of each subtree used as tie breaker for trees of equal frequency1568*/15691570this.l_buf = 0; /* buffer index for literals or lengths */15711572this.lit_bufsize = 0;1573/* Size of match buffer for literals/lengths. There are 4 reasons for1574* limiting lit_bufsize to 64K:1575* - frequencies can be kept in 16 bit counters1576* - if compression is not successful for the first block, all input1577* data is still in the window so we can still emit a stored block even1578* when input comes from standard input. (This can also be done for1579* all blocks if lit_bufsize is not greater than 32K.)1580* - if compression is not successful for a file smaller than 64K, we can1581* even emit a stored file instead of a stored block (saving 5 bytes).1582* This is applicable only for zip (not gzip or zlib).1583* - creating new Huffman trees less frequently may not provide fast1584* adaptation to changes in the input data statistics. (Take for1585* example a binary file with poorly compressible code followed by1586* a highly compressible string table.) Smaller buffer sizes give1587* fast adaptation but have of course the overhead of transmitting1588* trees more frequently.1589* - I can't count above 41590*/15911592this.last_lit = 0; /* running index in l_buf */15931594this.d_buf = 0;1595/* Buffer index for distances. To simplify the code, d_buf and l_buf have1596* the same number of elements. To use different lengths, an extra flag1597* array would be necessary.1598*/15991600this.opt_len = 0; /* bit length of current block with optimal trees */1601this.static_len = 0; /* bit length of current block with static trees */1602this.matches = 0; /* number of string matches in current block */1603this.insert = 0; /* bytes at end of window left to insert */160416051606this.bi_buf = 0;1607/* Output buffer. bits are inserted starting at the bottom (least1608* significant bits).1609*/1610this.bi_valid = 0;1611/* Number of valid bits in bi_buf. All bits above the last valid bit1612* are always zero.1613*/16141615// Used for window memory init. We safely ignore it for JS. That makes1616// sense only for pointers and memory check tools.1617//this.high_water = 0;1618/* High water mark offset in window for initialized bytes -- bytes above1619* this are set to zero in order to avoid memory check warnings when1620* longest match routines access bytes past the input. This is then1621* updated to the new high water mark.1622*/1623}162416251626function deflateResetKeep(strm) {1627var s;16281629if (!strm || !strm.state) {1630return err(strm, Z_STREAM_ERROR);1631}16321633strm.total_in = strm.total_out = 0;1634strm.data_type = Z_UNKNOWN;16351636s = strm.state;1637s.pending = 0;1638s.pending_out = 0;16391640if (s.wrap < 0) {1641s.wrap = -s.wrap;1642/* was made negative by deflate(..., Z_FINISH); */1643}1644s.status = (s.wrap ? INIT_STATE : BUSY_STATE);1645strm.adler = (s.wrap === 2) ?16460 // crc32(0, Z_NULL, 0)1647:16481; // adler32(0, Z_NULL, 0)1649s.last_flush = Z_NO_FLUSH;1650trees._tr_init(s);1651return Z_OK;1652}165316541655function deflateReset(strm) {1656var ret = deflateResetKeep(strm);1657if (ret === Z_OK) {1658lm_init(strm.state);1659}1660return ret;1661}166216631664function deflateSetHeader(strm, head) {1665if (!strm || !strm.state) { return Z_STREAM_ERROR; }1666if (strm.state.wrap !== 2) { return Z_STREAM_ERROR; }1667strm.state.gzhead = head;1668return Z_OK;1669}167016711672function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {1673if (!strm) { // === Z_NULL1674return Z_STREAM_ERROR;1675}1676var wrap = 1;16771678if (level === Z_DEFAULT_COMPRESSION) {1679level = 6;1680}16811682if (windowBits < 0) { /* suppress zlib wrapper */1683wrap = 0;1684windowBits = -windowBits;1685}16861687else if (windowBits > 15) {1688wrap = 2; /* write gzip wrapper instead */1689windowBits -= 16;1690}169116921693if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED ||1694windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||1695strategy < 0 || strategy > Z_FIXED) {1696return err(strm, Z_STREAM_ERROR);1697}169816991700if (windowBits === 8) {1701windowBits = 9;1702}1703/* until 256-byte window bug fixed */17041705var s = new DeflateState();17061707strm.state = s;1708s.strm = strm;17091710s.wrap = wrap;1711s.gzhead = null;1712s.w_bits = windowBits;1713s.w_size = 1 << s.w_bits;1714s.w_mask = s.w_size - 1;17151716s.hash_bits = memLevel + 7;1717s.hash_size = 1 << s.hash_bits;1718s.hash_mask = s.hash_size - 1;1719s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH);17201721s.window = new utils.Buf8(s.w_size * 2);1722s.head = new utils.Buf16(s.hash_size);1723s.prev = new utils.Buf16(s.w_size);17241725// Don't need mem init magic for JS.1726//s.high_water = 0; /* nothing written to s->window yet */17271728s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */17291730s.pending_buf_size = s.lit_bufsize * 4;1731s.pending_buf = new utils.Buf8(s.pending_buf_size);17321733s.d_buf = s.lit_bufsize >> 1;1734s.l_buf = (1 + 2) * s.lit_bufsize;17351736s.level = level;1737s.strategy = strategy;1738s.method = method;17391740return deflateReset(strm);1741}17421743function deflateInit(strm, level) {1744return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);1745}174617471748function deflate(strm, flush) {1749var old_flush, s;1750var beg, val; // for gzip header write only17511752if (!strm || !strm.state ||1753flush > Z_BLOCK || flush < 0) {1754return strm ? err(strm, Z_STREAM_ERROR) : Z_STREAM_ERROR;1755}17561757s = strm.state;17581759if (!strm.output ||1760(!strm.input && strm.avail_in !== 0) ||1761(s.status === FINISH_STATE && flush !== Z_FINISH)) {1762return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR);1763}17641765s.strm = strm; /* just in case */1766old_flush = s.last_flush;1767s.last_flush = flush;17681769/* Write the header */1770if (s.status === INIT_STATE) {17711772if (s.wrap === 2) { // GZIP header1773strm.adler = 0; //crc32(0L, Z_NULL, 0);1774put_byte(s, 31);1775put_byte(s, 139);1776put_byte(s, 8);1777if (!s.gzhead) { // s->gzhead == Z_NULL1778put_byte(s, 0);1779put_byte(s, 0);1780put_byte(s, 0);1781put_byte(s, 0);1782put_byte(s, 0);1783put_byte(s, s.level === 9 ? 2 :1784(s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?17854 : 0));1786put_byte(s, OS_CODE);1787s.status = BUSY_STATE;1788}1789else {1790put_byte(s, (s.gzhead.text ? 1 : 0) +1791(s.gzhead.hcrc ? 2 : 0) +1792(!s.gzhead.extra ? 0 : 4) +1793(!s.gzhead.name ? 0 : 8) +1794(!s.gzhead.comment ? 0 : 16)1795);1796put_byte(s, s.gzhead.time & 0xff);1797put_byte(s, (s.gzhead.time >> 8) & 0xff);1798put_byte(s, (s.gzhead.time >> 16) & 0xff);1799put_byte(s, (s.gzhead.time >> 24) & 0xff);1800put_byte(s, s.level === 9 ? 2 :1801(s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?18024 : 0));1803put_byte(s, s.gzhead.os & 0xff);1804if (s.gzhead.extra && s.gzhead.extra.length) {1805put_byte(s, s.gzhead.extra.length & 0xff);1806put_byte(s, (s.gzhead.extra.length >> 8) & 0xff);1807}1808if (s.gzhead.hcrc) {1809strm.adler = crc32(strm.adler, s.pending_buf, s.pending, 0);1810}1811s.gzindex = 0;1812s.status = EXTRA_STATE;1813}1814}1815else // DEFLATE header1816{1817var header = (Z_DEFLATED + ((s.w_bits - 8) << 4)) << 8;1818var level_flags = -1;18191820if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) {1821level_flags = 0;1822} else if (s.level < 6) {1823level_flags = 1;1824} else if (s.level === 6) {1825level_flags = 2;1826} else {1827level_flags = 3;1828}1829header |= (level_flags << 6);1830if (s.strstart !== 0) { header |= PRESET_DICT; }1831header += 31 - (header % 31);18321833s.status = BUSY_STATE;1834putShortMSB(s, header);18351836/* Save the adler32 of the preset dictionary: */1837if (s.strstart !== 0) {1838putShortMSB(s, strm.adler >>> 16);1839putShortMSB(s, strm.adler & 0xffff);1840}1841strm.adler = 1; // adler32(0L, Z_NULL, 0);1842}1843}18441845//#ifdef GZIP1846if (s.status === EXTRA_STATE) {1847if (s.gzhead.extra/* != Z_NULL*/) {1848beg = s.pending; /* start of bytes to update crc */18491850while (s.gzindex < (s.gzhead.extra.length & 0xffff)) {1851if (s.pending === s.pending_buf_size) {1852if (s.gzhead.hcrc && s.pending > beg) {1853strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);1854}1855flush_pending(strm);1856beg = s.pending;1857if (s.pending === s.pending_buf_size) {1858break;1859}1860}1861put_byte(s, s.gzhead.extra[s.gzindex] & 0xff);1862s.gzindex++;1863}1864if (s.gzhead.hcrc && s.pending > beg) {1865strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);1866}1867if (s.gzindex === s.gzhead.extra.length) {1868s.gzindex = 0;1869s.status = NAME_STATE;1870}1871}1872else {1873s.status = NAME_STATE;1874}1875}1876if (s.status === NAME_STATE) {1877if (s.gzhead.name/* != Z_NULL*/) {1878beg = s.pending; /* start of bytes to update crc */1879//int val;18801881do {1882if (s.pending === s.pending_buf_size) {1883if (s.gzhead.hcrc && s.pending > beg) {1884strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);1885}1886flush_pending(strm);1887beg = s.pending;1888if (s.pending === s.pending_buf_size) {1889val = 1;1890break;1891}1892}1893// JS specific: little magic to add zero terminator to end of string1894if (s.gzindex < s.gzhead.name.length) {1895val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff;1896} else {1897val = 0;1898}1899put_byte(s, val);1900} while (val !== 0);19011902if (s.gzhead.hcrc && s.pending > beg){1903strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);1904}1905if (val === 0) {1906s.gzindex = 0;1907s.status = COMMENT_STATE;1908}1909}1910else {1911s.status = COMMENT_STATE;1912}1913}1914if (s.status === COMMENT_STATE) {1915if (s.gzhead.comment/* != Z_NULL*/) {1916beg = s.pending; /* start of bytes to update crc */1917//int val;19181919do {1920if (s.pending === s.pending_buf_size) {1921if (s.gzhead.hcrc && s.pending > beg) {1922strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);1923}1924flush_pending(strm);1925beg = s.pending;1926if (s.pending === s.pending_buf_size) {1927val = 1;1928break;1929}1930}1931// JS specific: little magic to add zero terminator to end of string1932if (s.gzindex < s.gzhead.comment.length) {1933val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff;1934} else {1935val = 0;1936}1937put_byte(s, val);1938} while (val !== 0);19391940if (s.gzhead.hcrc && s.pending > beg) {1941strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);1942}1943if (val === 0) {1944s.status = HCRC_STATE;1945}1946}1947else {1948s.status = HCRC_STATE;1949}1950}1951if (s.status === HCRC_STATE) {1952if (s.gzhead.hcrc) {1953if (s.pending + 2 > s.pending_buf_size) {1954flush_pending(strm);1955}1956if (s.pending + 2 <= s.pending_buf_size) {1957put_byte(s, strm.adler & 0xff);1958put_byte(s, (strm.adler >> 8) & 0xff);1959strm.adler = 0; //crc32(0L, Z_NULL, 0);1960s.status = BUSY_STATE;1961}1962}1963else {1964s.status = BUSY_STATE;1965}1966}1967//#endif19681969/* Flush as much pending output as possible */1970if (s.pending !== 0) {1971flush_pending(strm);1972if (strm.avail_out === 0) {1973/* Since avail_out is 0, deflate will be called again with1974* more output space, but possibly with both pending and1975* avail_in equal to zero. There won't be anything to do,1976* but this is not an error situation so make sure we1977* return OK instead of BUF_ERROR at next call of deflate:1978*/1979s.last_flush = -1;1980return Z_OK;1981}19821983/* Make sure there is something to do and avoid duplicate consecutive1984* flushes. For repeated and useless calls with Z_FINISH, we keep1985* returning Z_STREAM_END instead of Z_BUF_ERROR.1986*/1987} else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) &&1988flush !== Z_FINISH) {1989return err(strm, Z_BUF_ERROR);1990}19911992/* User must not provide more input after the first FINISH: */1993if (s.status === FINISH_STATE && strm.avail_in !== 0) {1994return err(strm, Z_BUF_ERROR);1995}19961997/* Start a new block or continue the current one.1998*/1999if (strm.avail_in !== 0 || s.lookahead !== 0 ||2000(flush !== Z_NO_FLUSH && s.status !== FINISH_STATE)) {2001var bstate = (s.strategy === Z_HUFFMAN_ONLY) ? deflate_huff(s, flush) :2002(s.strategy === Z_RLE ? deflate_rle(s, flush) :2003configuration_table[s.level].func(s, flush));20042005if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) {2006s.status = FINISH_STATE;2007}2008if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) {2009if (strm.avail_out === 0) {2010s.last_flush = -1;2011/* avoid BUF_ERROR next call, see above */2012}2013return Z_OK;2014/* If flush != Z_NO_FLUSH && avail_out == 0, the next call2015* of deflate should use the same flush parameter to make sure2016* that the flush is complete. So we don't have to output an2017* empty block here, this will be done at next call. This also2018* ensures that for a very small output buffer, we emit at most2019* one empty block.2020*/2021}2022if (bstate === BS_BLOCK_DONE) {2023if (flush === Z_PARTIAL_FLUSH) {2024trees._tr_align(s);2025}2026else if (flush !== Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */20272028trees._tr_stored_block(s, 0, 0, false);2029/* For a full flush, this empty block will be recognized2030* as a special marker by inflate_sync().2031*/2032if (flush === Z_FULL_FLUSH) {2033/*** CLEAR_HASH(s); ***/ /* forget history */2034zero(s.head); // Fill with NIL (= 0);20352036if (s.lookahead === 0) {2037s.strstart = 0;2038s.block_start = 0;2039s.insert = 0;2040}2041}2042}2043flush_pending(strm);2044if (strm.avail_out === 0) {2045s.last_flush = -1; /* avoid BUF_ERROR at next call, see above */2046return Z_OK;2047}2048}2049}2050//Assert(strm->avail_out > 0, "bug2");2051//if (strm.avail_out <= 0) { throw new Error("bug2");}20522053if (flush !== Z_FINISH) { return Z_OK; }2054if (s.wrap <= 0) { return Z_STREAM_END; }20552056/* Write the trailer */2057if (s.wrap === 2) {2058put_byte(s, strm.adler & 0xff);2059put_byte(s, (strm.adler >> 8) & 0xff);2060put_byte(s, (strm.adler >> 16) & 0xff);2061put_byte(s, (strm.adler >> 24) & 0xff);2062put_byte(s, strm.total_in & 0xff);2063put_byte(s, (strm.total_in >> 8) & 0xff);2064put_byte(s, (strm.total_in >> 16) & 0xff);2065put_byte(s, (strm.total_in >> 24) & 0xff);2066}2067else2068{2069putShortMSB(s, strm.adler >>> 16);2070putShortMSB(s, strm.adler & 0xffff);2071}20722073flush_pending(strm);2074/* If avail_out is zero, the application will call deflate again2075* to flush the rest.2076*/2077if (s.wrap > 0) { s.wrap = -s.wrap; }2078/* write the trailer only once! */2079return s.pending !== 0 ? Z_OK : Z_STREAM_END;2080}20812082function deflateEnd(strm) {2083var status;20842085if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {2086return Z_STREAM_ERROR;2087}20882089status = strm.state.status;2090if (status !== INIT_STATE &&2091status !== EXTRA_STATE &&2092status !== NAME_STATE &&2093status !== COMMENT_STATE &&2094status !== HCRC_STATE &&2095status !== BUSY_STATE &&2096status !== FINISH_STATE2097) {2098return err(strm, Z_STREAM_ERROR);2099}21002101strm.state = null;21022103return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK;2104}21052106/* =========================================================================2107* Copy the source state to the destination state2108*/2109//function deflateCopy(dest, source) {2110//2111//}21122113exports.deflateInit = deflateInit;2114exports.deflateInit2 = deflateInit2;2115exports.deflateReset = deflateReset;2116exports.deflateResetKeep = deflateResetKeep;2117exports.deflateSetHeader = deflateSetHeader;2118exports.deflate = deflate;2119exports.deflateEnd = deflateEnd;2120exports.deflateInfo = 'pako deflate (from Nodeca project)';21212122/* Not implemented2123exports.deflateBound = deflateBound;2124exports.deflateCopy = deflateCopy;2125exports.deflateSetDictionary = deflateSetDictionary;2126exports.deflateParams = deflateParams;2127exports.deflatePending = deflatePending;2128exports.deflatePrime = deflatePrime;2129exports.deflateTune = deflateTune;2130*/2131},{"../utils/common":1,"./adler32":3,"./crc32":4,"./messages":6,"./trees":7}],6:[function(require,module,exports){2132'use strict';21332134module.exports = {2135'2': 'need dictionary', /* Z_NEED_DICT 2 */2136'1': 'stream end', /* Z_STREAM_END 1 */2137'0': '', /* Z_OK 0 */2138'-1': 'file error', /* Z_ERRNO (-1) */2139'-2': 'stream error', /* Z_STREAM_ERROR (-2) */2140'-3': 'data error', /* Z_DATA_ERROR (-3) */2141'-4': 'insufficient memory', /* Z_MEM_ERROR (-4) */2142'-5': 'buffer error', /* Z_BUF_ERROR (-5) */2143'-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */2144};2145},{}],7:[function(require,module,exports){2146'use strict';214721482149var utils = require('../utils/common');21502151/* Public constants ==========================================================*/2152/* ===========================================================================*/215321542155//var Z_FILTERED = 1;2156//var Z_HUFFMAN_ONLY = 2;2157//var Z_RLE = 3;2158var Z_FIXED = 4;2159//var Z_DEFAULT_STRATEGY = 0;21602161/* Possible values of the data_type field (though see inflate()) */2162var Z_BINARY = 0;2163var Z_TEXT = 1;2164//var Z_ASCII = 1; // = Z_TEXT2165var Z_UNKNOWN = 2;21662167/*============================================================================*/216821692170function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }21712172// From zutil.h21732174var STORED_BLOCK = 0;2175var STATIC_TREES = 1;2176var DYN_TREES = 2;2177/* The three kinds of block type */21782179var MIN_MATCH = 3;2180var MAX_MATCH = 258;2181/* The minimum and maximum match lengths */21822183// From deflate.h2184/* ===========================================================================2185* Internal compression state.2186*/21872188var LENGTH_CODES = 29;2189/* number of length codes, not counting the special END_BLOCK code */21902191var LITERALS = 256;2192/* number of literal bytes 0..255 */21932194var L_CODES = LITERALS + 1 + LENGTH_CODES;2195/* number of Literal or Length codes, including the END_BLOCK code */21962197var D_CODES = 30;2198/* number of distance codes */21992200var BL_CODES = 19;2201/* number of codes used to transfer the bit lengths */22022203var HEAP_SIZE = 2*L_CODES + 1;2204/* maximum heap size */22052206var MAX_BITS = 15;2207/* All codes must not exceed MAX_BITS bits */22082209var Buf_size = 16;2210/* size of bit buffer in bi_buf */221122122213/* ===========================================================================2214* Constants2215*/22162217var MAX_BL_BITS = 7;2218/* Bit length codes must not exceed MAX_BL_BITS bits */22192220var END_BLOCK = 256;2221/* end of block literal code */22222223var REP_3_6 = 16;2224/* repeat previous bit length 3-6 times (2 bits of repeat count) */22252226var REPZ_3_10 = 17;2227/* repeat a zero length 3-10 times (3 bits of repeat count) */22282229var REPZ_11_138 = 18;2230/* repeat a zero length 11-138 times (7 bits of repeat count) */22312232var extra_lbits = /* extra bits for each length code */2233[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];22342235var extra_dbits = /* extra bits for each distance code */2236[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];22372238var extra_blbits = /* extra bits for each bit length code */2239[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7];22402241var bl_order =2242[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];2243/* The lengths of the bit length codes are sent in order of decreasing2244* probability, to avoid transmitting the lengths for unused bit length codes.2245*/22462247/* ===========================================================================2248* Local data. These are initialized only once.2249*/22502251// We pre-fill arrays with 0 to avoid uninitialized gaps22522253var DIST_CODE_LEN = 512; /* see definition of array dist_code below */22542255// !!!! Use flat array insdead of structure, Freq = i*2, Len = i*2+12256var static_ltree = new Array((L_CODES+2) * 2);2257zero(static_ltree);2258/* The static literal tree. Since the bit lengths are imposed, there is no2259* need for the L_CODES extra codes used during heap construction. However2260* The codes 286 and 287 are needed to build a canonical tree (see _tr_init2261* below).2262*/22632264var static_dtree = new Array(D_CODES * 2);2265zero(static_dtree);2266/* The static distance tree. (Actually a trivial tree since all codes use2267* 5 bits.)2268*/22692270var _dist_code = new Array(DIST_CODE_LEN);2271zero(_dist_code);2272/* Distance codes. The first 256 values correspond to the distances2273* 3 .. 258, the last 256 values correspond to the top 8 bits of2274* the 15 bit distances.2275*/22762277var _length_code = new Array(MAX_MATCH-MIN_MATCH+1);2278zero(_length_code);2279/* length code for each normalized match length (0 == MIN_MATCH) */22802281var base_length = new Array(LENGTH_CODES);2282zero(base_length);2283/* First normalized length for each code (0 = MIN_MATCH) */22842285var base_dist = new Array(D_CODES);2286zero(base_dist);2287/* First normalized distance for each code (0 = distance of 1) */228822892290var StaticTreeDesc = function (static_tree, extra_bits, extra_base, elems, max_length) {22912292this.static_tree = static_tree; /* static tree or NULL */2293this.extra_bits = extra_bits; /* extra bits for each code or NULL */2294this.extra_base = extra_base; /* base index for extra_bits */2295this.elems = elems; /* max number of elements in the tree */2296this.max_length = max_length; /* max bit length for the codes */22972298// show if `static_tree` has data or dummy - needed for monomorphic objects2299this.has_stree = static_tree && static_tree.length;2300};230123022303var static_l_desc;2304var static_d_desc;2305var static_bl_desc;230623072308var TreeDesc = function(dyn_tree, stat_desc) {2309this.dyn_tree = dyn_tree; /* the dynamic tree */2310this.max_code = 0; /* largest code with non zero frequency */2311this.stat_desc = stat_desc; /* the corresponding static tree */2312};2313231423152316function d_code(dist) {2317return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];2318}231923202321/* ===========================================================================2322* Output a short LSB first on the stream.2323* IN assertion: there is enough room in pendingBuf.2324*/2325function put_short (s, w) {2326// put_byte(s, (uch)((w) & 0xff));2327// put_byte(s, (uch)((ush)(w) >> 8));2328s.pending_buf[s.pending++] = (w) & 0xff;2329s.pending_buf[s.pending++] = (w >>> 8) & 0xff;2330}233123322333/* ===========================================================================2334* Send a value on a given number of bits.2335* IN assertion: length <= 16 and value fits in length bits.2336*/2337function send_bits(s, value, length) {2338if (s.bi_valid > (Buf_size - length)) {2339s.bi_buf |= (value << s.bi_valid) & 0xffff;2340put_short(s, s.bi_buf);2341s.bi_buf = value >> (Buf_size - s.bi_valid);2342s.bi_valid += length - Buf_size;2343} else {2344s.bi_buf |= (value << s.bi_valid) & 0xffff;2345s.bi_valid += length;2346}2347}234823492350function send_code(s, c, tree) {2351send_bits(s, tree[c*2]/*.Code*/, tree[c*2 + 1]/*.Len*/);2352}235323542355/* ===========================================================================2356* Reverse the first len bits of a code, using straightforward code (a faster2357* method would use a table)2358* IN assertion: 1 <= len <= 152359*/2360function bi_reverse(code, len) {2361var res = 0;2362do {2363res |= code & 1;2364code >>>= 1;2365res <<= 1;2366} while (--len > 0);2367return res >>> 1;2368}236923702371/* ===========================================================================2372* Flush the bit buffer, keeping at most 7 bits in it.2373*/2374function bi_flush(s) {2375if (s.bi_valid === 16) {2376put_short(s, s.bi_buf);2377s.bi_buf = 0;2378s.bi_valid = 0;23792380} else if (s.bi_valid >= 8) {2381s.pending_buf[s.pending++] = s.bi_buf & 0xff;2382s.bi_buf >>= 8;2383s.bi_valid -= 8;2384}2385}238623872388/* ===========================================================================2389* Compute the optimal bit lengths for a tree and update the total bit length2390* for the current block.2391* IN assertion: the fields freq and dad are set, heap[heap_max] and2392* above are the tree nodes sorted by increasing frequency.2393* OUT assertions: the field len is set to the optimal bit length, the2394* array bl_count contains the frequencies for each bit length.2395* The length opt_len is updated; static_len is also updated if stree is2396* not null.2397*/2398function gen_bitlen(s, desc)2399// deflate_state *s;2400// tree_desc *desc; /* the tree descriptor */2401{2402var tree = desc.dyn_tree;2403var max_code = desc.max_code;2404var stree = desc.stat_desc.static_tree;2405var has_stree = desc.stat_desc.has_stree;2406var extra = desc.stat_desc.extra_bits;2407var base = desc.stat_desc.extra_base;2408var max_length = desc.stat_desc.max_length;2409var h; /* heap index */2410var n, m; /* iterate over the tree elements */2411var bits; /* bit length */2412var xbits; /* extra bits */2413var f; /* frequency */2414var overflow = 0; /* number of elements with bit length too large */24152416for (bits = 0; bits <= MAX_BITS; bits++) {2417s.bl_count[bits] = 0;2418}24192420/* In a first pass, compute the optimal bit lengths (which may2421* overflow in the case of the bit length tree).2422*/2423tree[s.heap[s.heap_max]*2 + 1]/*.Len*/ = 0; /* root of the heap */24242425for (h = s.heap_max+1; h < HEAP_SIZE; h++) {2426n = s.heap[h];2427bits = tree[tree[n*2 +1]/*.Dad*/ * 2 + 1]/*.Len*/ + 1;2428if (bits > max_length) {2429bits = max_length;2430overflow++;2431}2432tree[n*2 + 1]/*.Len*/ = bits;2433/* We overwrite tree[n].Dad which is no longer needed */24342435if (n > max_code) { continue; } /* not a leaf node */24362437s.bl_count[bits]++;2438xbits = 0;2439if (n >= base) {2440xbits = extra[n-base];2441}2442f = tree[n * 2]/*.Freq*/;2443s.opt_len += f * (bits + xbits);2444if (has_stree) {2445s.static_len += f * (stree[n*2 + 1]/*.Len*/ + xbits);2446}2447}2448if (overflow === 0) { return; }24492450// Trace((stderr,"\nbit length overflow\n"));2451/* This happens for example on obj2 and pic of the Calgary corpus */24522453/* Find the first bit length which could increase: */2454do {2455bits = max_length-1;2456while (s.bl_count[bits] === 0) { bits--; }2457s.bl_count[bits]--; /* move one leaf down the tree */2458s.bl_count[bits+1] += 2; /* move one overflow item as its brother */2459s.bl_count[max_length]--;2460/* The brother of the overflow item also moves one step up,2461* but this does not affect bl_count[max_length]2462*/2463overflow -= 2;2464} while (overflow > 0);24652466/* Now recompute all bit lengths, scanning in increasing frequency.2467* h is still equal to HEAP_SIZE. (It is simpler to reconstruct all2468* lengths instead of fixing only the wrong ones. This idea is taken2469* from 'ar' written by Haruhiko Okumura.)2470*/2471for (bits = max_length; bits !== 0; bits--) {2472n = s.bl_count[bits];2473while (n !== 0) {2474m = s.heap[--h];2475if (m > max_code) { continue; }2476if (tree[m*2 + 1]/*.Len*/ !== bits) {2477// Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));2478s.opt_len += (bits - tree[m*2 + 1]/*.Len*/)*tree[m*2]/*.Freq*/;2479tree[m*2 + 1]/*.Len*/ = bits;2480}2481n--;2482}2483}2484}248524862487/* ===========================================================================2488* Generate the codes for a given tree and bit counts (which need not be2489* optimal).2490* IN assertion: the array bl_count contains the bit length statistics for2491* the given tree and the field len is set for all tree elements.2492* OUT assertion: the field code is set for all tree elements of non2493* zero code length.2494*/2495function gen_codes(tree, max_code, bl_count)2496// ct_data *tree; /* the tree to decorate */2497// int max_code; /* largest code with non zero frequency */2498// ushf *bl_count; /* number of codes at each bit length */2499{2500var next_code = new Array(MAX_BITS+1); /* next code value for each bit length */2501var code = 0; /* running code value */2502var bits; /* bit index */2503var n; /* code index */25042505/* The distribution counts are first used to generate the code values2506* without bit reversal.2507*/2508for (bits = 1; bits <= MAX_BITS; bits++) {2509next_code[bits] = code = (code + bl_count[bits-1]) << 1;2510}2511/* Check that the bit counts in bl_count are consistent. The last code2512* must be all ones.2513*/2514//Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,2515// "inconsistent bit counts");2516//Tracev((stderr,"\ngen_codes: max_code %d ", max_code));25172518for (n = 0; n <= max_code; n++) {2519var len = tree[n*2 + 1]/*.Len*/;2520if (len === 0) { continue; }2521/* Now reverse the bits */2522tree[n*2]/*.Code*/ = bi_reverse(next_code[len]++, len);25232524//Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",2525// n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));2526}2527}252825292530/* ===========================================================================2531* Initialize the various 'constant' tables.2532*/2533function tr_static_init() {2534var n; /* iterates over tree elements */2535var bits; /* bit counter */2536var length; /* length value */2537var code; /* code value */2538var dist; /* distance index */2539var bl_count = new Array(MAX_BITS+1);2540/* number of codes at each bit length for an optimal tree */25412542// do check in _tr_init()2543//if (static_init_done) return;25442545/* For some embedded targets, global variables are not initialized: */2546/*#ifdef NO_INIT_GLOBAL_POINTERS2547static_l_desc.static_tree = static_ltree;2548static_l_desc.extra_bits = extra_lbits;2549static_d_desc.static_tree = static_dtree;2550static_d_desc.extra_bits = extra_dbits;2551static_bl_desc.extra_bits = extra_blbits;2552#endif*/25532554/* Initialize the mapping length (0..255) -> length code (0..28) */2555length = 0;2556for (code = 0; code < LENGTH_CODES-1; code++) {2557base_length[code] = length;2558for (n = 0; n < (1<<extra_lbits[code]); n++) {2559_length_code[length++] = code;2560}2561}2562//Assert (length == 256, "tr_static_init: length != 256");2563/* Note that the length 255 (match length 258) can be represented2564* in two different ways: code 284 + 5 bits or code 285, so we2565* overwrite length_code[255] to use the best encoding:2566*/2567_length_code[length-1] = code;25682569/* Initialize the mapping dist (0..32K) -> dist code (0..29) */2570dist = 0;2571for (code = 0 ; code < 16; code++) {2572base_dist[code] = dist;2573for (n = 0; n < (1<<extra_dbits[code]); n++) {2574_dist_code[dist++] = code;2575}2576}2577//Assert (dist == 256, "tr_static_init: dist != 256");2578dist >>= 7; /* from now on, all distances are divided by 128 */2579for ( ; code < D_CODES; code++) {2580base_dist[code] = dist << 7;2581for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {2582_dist_code[256 + dist++] = code;2583}2584}2585//Assert (dist == 256, "tr_static_init: 256+dist != 512");25862587/* Construct the codes of the static literal tree */2588for (bits = 0; bits <= MAX_BITS; bits++) {2589bl_count[bits] = 0;2590}25912592n = 0;2593while (n <= 143) {2594static_ltree[n*2 + 1]/*.Len*/ = 8;2595n++;2596bl_count[8]++;2597}2598while (n <= 255) {2599static_ltree[n*2 + 1]/*.Len*/ = 9;2600n++;2601bl_count[9]++;2602}2603while (n <= 279) {2604static_ltree[n*2 + 1]/*.Len*/ = 7;2605n++;2606bl_count[7]++;2607}2608while (n <= 287) {2609static_ltree[n*2 + 1]/*.Len*/ = 8;2610n++;2611bl_count[8]++;2612}2613/* Codes 286 and 287 do not exist, but we must include them in the2614* tree construction to get a canonical Huffman tree (longest code2615* all ones)2616*/2617gen_codes(static_ltree, L_CODES+1, bl_count);26182619/* The static distance tree is trivial: */2620for (n = 0; n < D_CODES; n++) {2621static_dtree[n*2 + 1]/*.Len*/ = 5;2622static_dtree[n*2]/*.Code*/ = bi_reverse(n, 5);2623}26242625// Now data ready and we can init static trees2626static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS);2627static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS);2628static_bl_desc =new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS);26292630//static_init_done = true;2631}263226332634/* ===========================================================================2635* Initialize a new block.2636*/2637function init_block(s) {2638var n; /* iterates over tree elements */26392640/* Initialize the trees. */2641for (n = 0; n < L_CODES; n++) { s.dyn_ltree[n*2]/*.Freq*/ = 0; }2642for (n = 0; n < D_CODES; n++) { s.dyn_dtree[n*2]/*.Freq*/ = 0; }2643for (n = 0; n < BL_CODES; n++) { s.bl_tree[n*2]/*.Freq*/ = 0; }26442645s.dyn_ltree[END_BLOCK*2]/*.Freq*/ = 1;2646s.opt_len = s.static_len = 0;2647s.last_lit = s.matches = 0;2648}264926502651/* ===========================================================================2652* Flush the bit buffer and align the output on a byte boundary2653*/2654function bi_windup(s)2655{2656if (s.bi_valid > 8) {2657put_short(s, s.bi_buf);2658} else if (s.bi_valid > 0) {2659//put_byte(s, (Byte)s->bi_buf);2660s.pending_buf[s.pending++] = s.bi_buf;2661}2662s.bi_buf = 0;2663s.bi_valid = 0;2664}26652666/* ===========================================================================2667* Copy a stored block, storing first the length and its2668* one's complement if requested.2669*/2670function copy_block(s, buf, len, header)2671//DeflateState *s;2672//charf *buf; /* the input data */2673//unsigned len; /* its length */2674//int header; /* true if block header must be written */2675{2676bi_windup(s); /* align on byte boundary */26772678if (header) {2679put_short(s, len);2680put_short(s, ~len);2681}2682// while (len--) {2683// put_byte(s, *buf++);2684// }2685utils.arraySet(s.pending_buf, s.window, buf, len, s.pending);2686s.pending += len;2687}26882689/* ===========================================================================2690* Compares to subtrees, using the tree depth as tie breaker when2691* the subtrees have equal frequency. This minimizes the worst case length.2692*/2693function smaller(tree, n, m, depth) {2694var _n2 = n*2;2695var _m2 = m*2;2696return (tree[_n2]/*.Freq*/ < tree[_m2]/*.Freq*/ ||2697(tree[_n2]/*.Freq*/ === tree[_m2]/*.Freq*/ && depth[n] <= depth[m]));2698}26992700/* ===========================================================================2701* Restore the heap property by moving down the tree starting at node k,2702* exchanging a node with the smallest of its two sons if necessary, stopping2703* when the heap property is re-established (each father smaller than its2704* two sons).2705*/2706function pqdownheap(s, tree, k)2707// deflate_state *s;2708// ct_data *tree; /* the tree to restore */2709// int k; /* node to move down */2710{2711var v = s.heap[k];2712var j = k << 1; /* left son of k */2713while (j <= s.heap_len) {2714/* Set j to the smallest of the two sons: */2715if (j < s.heap_len &&2716smaller(tree, s.heap[j+1], s.heap[j], s.depth)) {2717j++;2718}2719/* Exit if v is smaller than both sons */2720if (smaller(tree, v, s.heap[j], s.depth)) { break; }27212722/* Exchange v with the smallest son */2723s.heap[k] = s.heap[j];2724k = j;27252726/* And continue down the tree, setting j to the left son of k */2727j <<= 1;2728}2729s.heap[k] = v;2730}273127322733// inlined manually2734// var SMALLEST = 1;27352736/* ===========================================================================2737* Send the block data compressed using the given Huffman trees2738*/2739function compress_block(s, ltree, dtree)2740// deflate_state *s;2741// const ct_data *ltree; /* literal tree */2742// const ct_data *dtree; /* distance tree */2743{2744var dist; /* distance of matched string */2745var lc; /* match length or unmatched char (if dist == 0) */2746var lx = 0; /* running index in l_buf */2747var code; /* the code to send */2748var extra; /* number of extra bits to send */27492750if (s.last_lit !== 0) {2751do {2752dist = (s.pending_buf[s.d_buf + lx*2] << 8) | (s.pending_buf[s.d_buf + lx*2 + 1]);2753lc = s.pending_buf[s.l_buf + lx];2754lx++;27552756if (dist === 0) {2757send_code(s, lc, ltree); /* send a literal byte */2758//Tracecv(isgraph(lc), (stderr," '%c' ", lc));2759} else {2760/* Here, lc is the match length - MIN_MATCH */2761code = _length_code[lc];2762send_code(s, code+LITERALS+1, ltree); /* send the length code */2763extra = extra_lbits[code];2764if (extra !== 0) {2765lc -= base_length[code];2766send_bits(s, lc, extra); /* send the extra length bits */2767}2768dist--; /* dist is now the match distance - 1 */2769code = d_code(dist);2770//Assert (code < D_CODES, "bad d_code");27712772send_code(s, code, dtree); /* send the distance code */2773extra = extra_dbits[code];2774if (extra !== 0) {2775dist -= base_dist[code];2776send_bits(s, dist, extra); /* send the extra distance bits */2777}2778} /* literal or match pair ? */27792780/* Check that the overlay between pending_buf and d_buf+l_buf is ok: */2781//Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,2782// "pendingBuf overflow");27832784} while (lx < s.last_lit);2785}27862787send_code(s, END_BLOCK, ltree);2788}278927902791/* ===========================================================================2792* Construct one Huffman tree and assigns the code bit strings and lengths.2793* Update the total bit length for the current block.2794* IN assertion: the field freq is set for all tree elements.2795* OUT assertions: the fields len and code are set to the optimal bit length2796* and corresponding code. The length opt_len is updated; static_len is2797* also updated if stree is not null. The field max_code is set.2798*/2799function build_tree(s, desc)2800// deflate_state *s;2801// tree_desc *desc; /* the tree descriptor */2802{2803var tree = desc.dyn_tree;2804var stree = desc.stat_desc.static_tree;2805var has_stree = desc.stat_desc.has_stree;2806var elems = desc.stat_desc.elems;2807var n, m; /* iterate over heap elements */2808var max_code = -1; /* largest code with non zero frequency */2809var node; /* new node being created */28102811/* Construct the initial heap, with least frequent element in2812* heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].2813* heap[0] is not used.2814*/2815s.heap_len = 0;2816s.heap_max = HEAP_SIZE;28172818for (n = 0; n < elems; n++) {2819if (tree[n * 2]/*.Freq*/ !== 0) {2820s.heap[++s.heap_len] = max_code = n;2821s.depth[n] = 0;28222823} else {2824tree[n*2 + 1]/*.Len*/ = 0;2825}2826}28272828/* The pkzip format requires that at least one distance code exists,2829* and that at least one bit should be sent even if there is only one2830* possible code. So to avoid special checks later on we force at least2831* two codes of non zero frequency.2832*/2833while (s.heap_len < 2) {2834node = s.heap[++s.heap_len] = (max_code < 2 ? ++max_code : 0);2835tree[node * 2]/*.Freq*/ = 1;2836s.depth[node] = 0;2837s.opt_len--;28382839if (has_stree) {2840s.static_len -= stree[node*2 + 1]/*.Len*/;2841}2842/* node is 0 or 1 so it does not have extra bits */2843}2844desc.max_code = max_code;28452846/* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,2847* establish sub-heaps of increasing lengths:2848*/2849for (n = (s.heap_len >> 1/*int /2*/); n >= 1; n--) { pqdownheap(s, tree, n); }28502851/* Construct the Huffman tree by repeatedly combining the least two2852* frequent nodes.2853*/2854node = elems; /* next internal node of the tree */2855do {2856//pqremove(s, tree, n); /* n = node of least frequency */2857/*** pqremove ***/2858n = s.heap[1/*SMALLEST*/];2859s.heap[1/*SMALLEST*/] = s.heap[s.heap_len--];2860pqdownheap(s, tree, 1/*SMALLEST*/);2861/***/28622863m = s.heap[1/*SMALLEST*/]; /* m = node of next least frequency */28642865s.heap[--s.heap_max] = n; /* keep the nodes sorted by frequency */2866s.heap[--s.heap_max] = m;28672868/* Create a new node father of n and m */2869tree[node * 2]/*.Freq*/ = tree[n * 2]/*.Freq*/ + tree[m * 2]/*.Freq*/;2870s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;2871tree[n*2 + 1]/*.Dad*/ = tree[m*2 + 1]/*.Dad*/ = node;28722873/* and insert the new node in the heap */2874s.heap[1/*SMALLEST*/] = node++;2875pqdownheap(s, tree, 1/*SMALLEST*/);28762877} while (s.heap_len >= 2);28782879s.heap[--s.heap_max] = s.heap[1/*SMALLEST*/];28802881/* At this point, the fields freq and dad are set. We can now2882* generate the bit lengths.2883*/2884gen_bitlen(s, desc);28852886/* The field len is now set, we can generate the bit codes */2887gen_codes(tree, max_code, s.bl_count);2888}288928902891/* ===========================================================================2892* Scan a literal or distance tree to determine the frequencies of the codes2893* in the bit length tree.2894*/2895function scan_tree(s, tree, max_code)2896// deflate_state *s;2897// ct_data *tree; /* the tree to be scanned */2898// int max_code; /* and its largest code of non zero frequency */2899{2900var n; /* iterates over all tree elements */2901var prevlen = -1; /* last emitted length */2902var curlen; /* length of current code */29032904var nextlen = tree[0*2 + 1]/*.Len*/; /* length of next code */29052906var count = 0; /* repeat count of the current code */2907var max_count = 7; /* max repeat count */2908var min_count = 4; /* min repeat count */29092910if (nextlen === 0) {2911max_count = 138;2912min_count = 3;2913}2914tree[(max_code+1)*2 + 1]/*.Len*/ = 0xffff; /* guard */29152916for (n = 0; n <= max_code; n++) {2917curlen = nextlen;2918nextlen = tree[(n+1)*2 + 1]/*.Len*/;29192920if (++count < max_count && curlen === nextlen) {2921continue;29222923} else if (count < min_count) {2924s.bl_tree[curlen * 2]/*.Freq*/ += count;29252926} else if (curlen !== 0) {29272928if (curlen !== prevlen) { s.bl_tree[curlen * 2]/*.Freq*/++; }2929s.bl_tree[REP_3_6*2]/*.Freq*/++;29302931} else if (count <= 10) {2932s.bl_tree[REPZ_3_10*2]/*.Freq*/++;29332934} else {2935s.bl_tree[REPZ_11_138*2]/*.Freq*/++;2936}29372938count = 0;2939prevlen = curlen;29402941if (nextlen === 0) {2942max_count = 138;2943min_count = 3;29442945} else if (curlen === nextlen) {2946max_count = 6;2947min_count = 3;29482949} else {2950max_count = 7;2951min_count = 4;2952}2953}2954}295529562957/* ===========================================================================2958* Send a literal or distance tree in compressed form, using the codes in2959* bl_tree.2960*/2961function send_tree(s, tree, max_code)2962// deflate_state *s;2963// ct_data *tree; /* the tree to be scanned */2964// int max_code; /* and its largest code of non zero frequency */2965{2966var n; /* iterates over all tree elements */2967var prevlen = -1; /* last emitted length */2968var curlen; /* length of current code */29692970var nextlen = tree[0*2 + 1]/*.Len*/; /* length of next code */29712972var count = 0; /* repeat count of the current code */2973var max_count = 7; /* max repeat count */2974var min_count = 4; /* min repeat count */29752976/* tree[max_code+1].Len = -1; */ /* guard already set */2977if (nextlen === 0) {2978max_count = 138;2979min_count = 3;2980}29812982for (n = 0; n <= max_code; n++) {2983curlen = nextlen;2984nextlen = tree[(n+1)*2 + 1]/*.Len*/;29852986if (++count < max_count && curlen === nextlen) {2987continue;29882989} else if (count < min_count) {2990do { send_code(s, curlen, s.bl_tree); } while (--count !== 0);29912992} else if (curlen !== 0) {2993if (curlen !== prevlen) {2994send_code(s, curlen, s.bl_tree);2995count--;2996}2997//Assert(count >= 3 && count <= 6, " 3_6?");2998send_code(s, REP_3_6, s.bl_tree);2999send_bits(s, count-3, 2);30003001} else if (count <= 10) {3002send_code(s, REPZ_3_10, s.bl_tree);3003send_bits(s, count-3, 3);30043005} else {3006send_code(s, REPZ_11_138, s.bl_tree);3007send_bits(s, count-11, 7);3008}30093010count = 0;3011prevlen = curlen;3012if (nextlen === 0) {3013max_count = 138;3014min_count = 3;30153016} else if (curlen === nextlen) {3017max_count = 6;3018min_count = 3;30193020} else {3021max_count = 7;3022min_count = 4;3023}3024}3025}302630273028/* ===========================================================================3029* Construct the Huffman tree for the bit lengths and return the index in3030* bl_order of the last bit length code to send.3031*/3032function build_bl_tree(s) {3033var max_blindex; /* index of last bit length code of non zero freq */30343035/* Determine the bit length frequencies for literal and distance trees */3036scan_tree(s, s.dyn_ltree, s.l_desc.max_code);3037scan_tree(s, s.dyn_dtree, s.d_desc.max_code);30383039/* Build the bit length tree: */3040build_tree(s, s.bl_desc);3041/* opt_len now includes the length of the tree representations, except3042* the lengths of the bit lengths codes and the 5+5+4 bits for the counts.3043*/30443045/* Determine the number of bit length codes to send. The pkzip format3046* requires that at least 4 bit length codes be sent. (appnote.txt says3047* 3 but the actual value used is 4.)3048*/3049for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {3050if (s.bl_tree[bl_order[max_blindex]*2 + 1]/*.Len*/ !== 0) {3051break;3052}3053}3054/* Update opt_len to include the bit length tree and counts */3055s.opt_len += 3*(max_blindex+1) + 5+5+4;3056//Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",3057// s->opt_len, s->static_len));30583059return max_blindex;3060}306130623063/* ===========================================================================3064* Send the header for a block using dynamic Huffman trees: the counts, the3065* lengths of the bit length codes, the literal tree and the distance tree.3066* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.3067*/3068function send_all_trees(s, lcodes, dcodes, blcodes)3069// deflate_state *s;3070// int lcodes, dcodes, blcodes; /* number of codes for each tree */3071{3072var rank; /* index in bl_order */30733074//Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");3075//Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,3076// "too many codes");3077//Tracev((stderr, "\nbl counts: "));3078send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */3079send_bits(s, dcodes-1, 5);3080send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */3081for (rank = 0; rank < blcodes; rank++) {3082//Tracev((stderr, "\nbl code %2d ", bl_order[rank]));3083send_bits(s, s.bl_tree[bl_order[rank]*2 + 1]/*.Len*/, 3);3084}3085//Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));30863087send_tree(s, s.dyn_ltree, lcodes-1); /* literal tree */3088//Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));30893090send_tree(s, s.dyn_dtree, dcodes-1); /* distance tree */3091//Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));3092}309330943095/* ===========================================================================3096* Check if the data type is TEXT or BINARY, using the following algorithm:3097* - TEXT if the two conditions below are satisfied:3098* a) There are no non-portable control characters belonging to the3099* "black list" (0..6, 14..25, 28..31).3100* b) There is at least one printable character belonging to the3101* "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).3102* - BINARY otherwise.3103* - The following partially-portable control characters form a3104* "gray list" that is ignored in this detection algorithm:3105* (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).3106* IN assertion: the fields Freq of dyn_ltree are set.3107*/3108function detect_data_type(s) {3109/* black_mask is the bit mask of black-listed bytes3110* set bits 0..6, 14..25, and 28..313111* 0xf3ffc07f = binary 111100111111111111000000011111113112*/3113var black_mask = 0xf3ffc07f;3114var n;31153116/* Check for non-textual ("black-listed") bytes. */3117for (n = 0; n <= 31; n++, black_mask >>>= 1) {3118if ((black_mask & 1) && (s.dyn_ltree[n*2]/*.Freq*/ !== 0)) {3119return Z_BINARY;3120}3121}31223123/* Check for textual ("white-listed") bytes. */3124if (s.dyn_ltree[9 * 2]/*.Freq*/ !== 0 || s.dyn_ltree[10 * 2]/*.Freq*/ !== 0 ||3125s.dyn_ltree[13 * 2]/*.Freq*/ !== 0) {3126return Z_TEXT;3127}3128for (n = 32; n < LITERALS; n++) {3129if (s.dyn_ltree[n * 2]/*.Freq*/ !== 0) {3130return Z_TEXT;3131}3132}31333134/* There are no "black-listed" or "white-listed" bytes:3135* this stream either is empty or has tolerated ("gray-listed") bytes only.3136*/3137return Z_BINARY;3138}313931403141var static_init_done = false;31423143/* ===========================================================================3144* Initialize the tree data structures for a new zlib stream.3145*/3146function _tr_init(s)3147{31483149if (!static_init_done) {3150tr_static_init();3151static_init_done = true;3152}31533154s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc);3155s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc);3156s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc);31573158s.bi_buf = 0;3159s.bi_valid = 0;31603161/* Initialize the first block of the first file: */3162init_block(s);3163}316431653166/* ===========================================================================3167* Send a stored block3168*/3169function _tr_stored_block(s, buf, stored_len, last)3170//DeflateState *s;3171//charf *buf; /* input block */3172//ulg stored_len; /* length of input block */3173//int last; /* one if this is the last block for a file */3174{3175send_bits(s, (STORED_BLOCK<<1)+(last ? 1 : 0), 3); /* send block type */3176copy_block(s, buf, stored_len, true); /* with header */3177}317831793180/* ===========================================================================3181* Send one empty static block to give enough lookahead for inflate.3182* This takes 10 bits, of which 7 may remain in the bit buffer.3183*/3184function _tr_align(s) {3185send_bits(s, STATIC_TREES<<1, 3);3186send_code(s, END_BLOCK, static_ltree);3187bi_flush(s);3188}318931903191/* ===========================================================================3192* Determine the best encoding for the current block: dynamic trees, static3193* trees or store, and output the encoded block to the zip file.3194*/3195function _tr_flush_block(s, buf, stored_len, last)3196//DeflateState *s;3197//charf *buf; /* input block, or NULL if too old */3198//ulg stored_len; /* length of input block */3199//int last; /* one if this is the last block for a file */3200{3201var opt_lenb, static_lenb; /* opt_len and static_len in bytes */3202var max_blindex = 0; /* index of last bit length code of non zero freq */32033204/* Build the Huffman trees unless a stored block is forced */3205if (s.level > 0) {32063207/* Check if the file is binary or text */3208if (s.strm.data_type === Z_UNKNOWN) {3209s.strm.data_type = detect_data_type(s);3210}32113212/* Construct the literal and distance trees */3213build_tree(s, s.l_desc);3214// Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,3215// s->static_len));32163217build_tree(s, s.d_desc);3218// Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,3219// s->static_len));3220/* At this point, opt_len and static_len are the total bit lengths of3221* the compressed block data, excluding the tree representations.3222*/32233224/* Build the bit length tree for the above two trees, and get the index3225* in bl_order of the last bit length code to send.3226*/3227max_blindex = build_bl_tree(s);32283229/* Determine the best encoding. Compute the block lengths in bytes. */3230opt_lenb = (s.opt_len+3+7) >>> 3;3231static_lenb = (s.static_len+3+7) >>> 3;32323233// Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",3234// opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,3235// s->last_lit));32363237if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }32383239} else {3240// Assert(buf != (char*)0, "lost buf");3241opt_lenb = static_lenb = stored_len + 5; /* force a stored block */3242}32433244if ((stored_len+4 <= opt_lenb) && (buf !== -1)) {3245/* 4: two words for the lengths */32463247/* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.3248* Otherwise we can't have processed more than WSIZE input bytes since3249* the last block flush, because compression would have been3250* successful. If LIT_BUFSIZE <= WSIZE, it is never too late to3251* transform a block into a stored block.3252*/3253_tr_stored_block(s, buf, stored_len, last);32543255} else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) {32563257send_bits(s, (STATIC_TREES<<1) + (last ? 1 : 0), 3);3258compress_block(s, static_ltree, static_dtree);32593260} else {3261send_bits(s, (DYN_TREES<<1) + (last ? 1 : 0), 3);3262send_all_trees(s, s.l_desc.max_code+1, s.d_desc.max_code+1, max_blindex+1);3263compress_block(s, s.dyn_ltree, s.dyn_dtree);3264}3265// Assert (s->compressed_len == s->bits_sent, "bad compressed size");3266/* The above check is made mod 2^32, for files larger than 512 MB3267* and uLong implemented on 32 bits.3268*/3269init_block(s);32703271if (last) {3272bi_windup(s);3273}3274// Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,3275// s->compressed_len-7*last));3276}32773278/* ===========================================================================3279* Save the match info and tally the frequency counts. Return true if3280* the current block must be flushed.3281*/3282function _tr_tally(s, dist, lc)3283// deflate_state *s;3284// unsigned dist; /* distance of matched string */3285// unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */3286{3287//var out_length, in_length, dcode;32883289s.pending_buf[s.d_buf + s.last_lit * 2] = (dist >>> 8) & 0xff;3290s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff;32913292s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff;3293s.last_lit++;32943295if (dist === 0) {3296/* lc is the unmatched char */3297s.dyn_ltree[lc*2]/*.Freq*/++;3298} else {3299s.matches++;3300/* Here, lc is the match length - MIN_MATCH */3301dist--; /* dist = match distance - 1 */3302//Assert((ush)dist < (ush)MAX_DIST(s) &&3303// (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&3304// (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");33053306s.dyn_ltree[(_length_code[lc]+LITERALS+1) * 2]/*.Freq*/++;3307s.dyn_dtree[d_code(dist) * 2]/*.Freq*/++;3308}33093310// (!) This block is disabled in zlib defailts,3311// don't enable it for binary compatibility33123313//#ifdef TRUNCATE_BLOCK3314// /* Try to guess if it is profitable to stop the current block here */3315// if ((s.last_lit & 0x1fff) === 0 && s.level > 2) {3316// /* Compute an upper bound for the compressed length */3317// out_length = s.last_lit*8;3318// in_length = s.strstart - s.block_start;3319//3320// for (dcode = 0; dcode < D_CODES; dcode++) {3321// out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]);3322// }3323// out_length >>>= 3;3324// //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",3325// // s->last_lit, in_length, out_length,3326// // 100L - out_length*100L/in_length));3327// if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) {3328// return true;3329// }3330// }3331//#endif33323333return (s.last_lit === s.lit_bufsize-1);3334/* We avoid equality with lit_bufsize because of wraparound at 64K3335* on 16 bit machines and because stored blocks are restricted to3336* 64K-1 bytes.3337*/3338}33393340exports._tr_init = _tr_init;3341exports._tr_stored_block = _tr_stored_block;3342exports._tr_flush_block = _tr_flush_block;3343exports._tr_tally = _tr_tally;3344exports._tr_align = _tr_align;3345},{"../utils/common":1}],8:[function(require,module,exports){3346'use strict';334733483349function ZStream() {3350/* next input byte */3351this.input = null; // JS specific, because we have no pointers3352this.next_in = 0;3353/* number of bytes available at input */3354this.avail_in = 0;3355/* total number of input bytes read so far */3356this.total_in = 0;3357/* next output byte should be put there */3358this.output = null; // JS specific, because we have no pointers3359this.next_out = 0;3360/* remaining free space at output */3361this.avail_out = 0;3362/* total number of bytes output so far */3363this.total_out = 0;3364/* last error message, NULL if no error */3365this.msg = ''/*Z_NULL*/;3366/* not visible by applications */3367this.state = null;3368/* best guess about the data type: binary or text */3369this.data_type = 2/*Z_UNKNOWN*/;3370/* adler32 value of the uncompressed data */3371this.adler = 0;3372}33733374module.exports = ZStream;3375},{}],"/lib/deflate.js":[function(require,module,exports){3376'use strict';337733783379var zlib_deflate = require('./zlib/deflate.js');3380var utils = require('./utils/common');3381var strings = require('./utils/strings');3382var msg = require('./zlib/messages');3383var zstream = require('./zlib/zstream');33843385var toString = Object.prototype.toString;33863387/* Public constants ==========================================================*/3388/* ===========================================================================*/33893390var Z_NO_FLUSH = 0;3391var Z_FINISH = 4;33923393var Z_OK = 0;3394var Z_STREAM_END = 1;33953396var Z_DEFAULT_COMPRESSION = -1;33973398var Z_DEFAULT_STRATEGY = 0;33993400var Z_DEFLATED = 8;34013402/* ===========================================================================*/340334043405/**3406* class Deflate3407*3408* Generic JS-style wrapper for zlib calls. If you don't need3409* streaming behaviour - use more simple functions: [[deflate]],3410* [[deflateRaw]] and [[gzip]].3411**/34123413/* internal3414* Deflate.chunks -> Array3415*3416* Chunks of output data, if [[Deflate#onData]] not overriden.3417**/34183419/**3420* Deflate.result -> Uint8Array|Array3421*3422* Compressed result, generated by default [[Deflate#onData]]3423* and [[Deflate#onEnd]] handlers. Filled after you push last chunk3424* (call [[Deflate#push]] with `Z_FINISH` / `true` param).3425**/34263427/**3428* Deflate.err -> Number3429*3430* Error code after deflate finished. 0 (Z_OK) on success.3431* You will not need it in real life, because deflate errors3432* are possible only on wrong options or bad `onData` / `onEnd`3433* custom handlers.3434**/34353436/**3437* Deflate.msg -> String3438*3439* Error message, if [[Deflate.err]] != 03440**/344134423443/**3444* new Deflate(options)3445* - options (Object): zlib deflate options.3446*3447* Creates new deflator instance with specified params. Throws exception3448* on bad params. Supported options:3449*3450* - `level`3451* - `windowBits`3452* - `memLevel`3453* - `strategy`3454*3455* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)3456* for more information on these.3457*3458* Additional options, for internal needs:3459*3460* - `chunkSize` - size of generated data chunks (16K by default)3461* - `raw` (Boolean) - do raw deflate3462* - `gzip` (Boolean) - create gzip wrapper3463* - `to` (String) - if equal to 'string', then result will be "binary string"3464* (each char code [0..255])3465* - `header` (Object) - custom header for gzip3466* - `text` (Boolean) - true if compressed data believed to be text3467* - `time` (Number) - modification time, unix timestamp3468* - `os` (Number) - operation system code3469* - `extra` (Array) - array of bytes with extra data (max 65536)3470* - `name` (String) - file name (binary string)3471* - `comment` (String) - comment (binary string)3472* - `hcrc` (Boolean) - true if header crc should be added3473*3474* ##### Example:3475*3476* ```javascript3477* var pako = require('pako')3478* , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])3479* , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);3480*3481* var deflate = new pako.Deflate({ level: 3});3482*3483* deflate.push(chunk1, false);3484* deflate.push(chunk2, true); // true -> last chunk3485*3486* if (deflate.err) { throw new Error(deflate.err); }3487*3488* console.log(deflate.result);3489* ```3490**/3491var Deflate = function(options) {34923493this.options = utils.assign({3494level: Z_DEFAULT_COMPRESSION,3495method: Z_DEFLATED,3496chunkSize: 16384,3497windowBits: 15,3498memLevel: 8,3499strategy: Z_DEFAULT_STRATEGY,3500to: ''3501}, options || {});35023503var opt = this.options;35043505if (opt.raw && (opt.windowBits > 0)) {3506opt.windowBits = -opt.windowBits;3507}35083509else if (opt.gzip && (opt.windowBits > 0) && (opt.windowBits < 16)) {3510opt.windowBits += 16;3511}35123513this.err = 0; // error code, if happens (0 = Z_OK)3514this.msg = ''; // error message3515this.ended = false; // used to avoid multiple onEnd() calls3516this.chunks = []; // chunks of compressed data35173518this.strm = new zstream();3519this.strm.avail_out = 0;35203521var status = zlib_deflate.deflateInit2(3522this.strm,3523opt.level,3524opt.method,3525opt.windowBits,3526opt.memLevel,3527opt.strategy3528);35293530if (status !== Z_OK) {3531throw new Error(msg[status]);3532}35333534if (opt.header) {3535zlib_deflate.deflateSetHeader(this.strm, opt.header);3536}3537};35383539/**3540* Deflate#push(data[, mode]) -> Boolean3541* - data (Uint8Array|Array|ArrayBuffer|String): input data. Strings will be3542* converted to utf8 byte sequence.3543* - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.3544* See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.3545*3546* Sends input data to deflate pipe, generating [[Deflate#onData]] calls with3547* new compressed chunks. Returns `true` on success. The last data block must have3548* mode Z_FINISH (or `true`). That flush internal pending buffers and call3549* [[Deflate#onEnd]].3550*3551* On fail call [[Deflate#onEnd]] with error code and return false.3552*3553* We strongly recommend to use `Uint8Array` on input for best speed (output3554* array format is detected automatically). Also, don't skip last param and always3555* use the same type in your code (boolean or number). That will improve JS speed.3556*3557* For regular `Array`-s make sure all elements are [0..255].3558*3559* ##### Example3560*3561* ```javascript3562* push(chunk, false); // push one of data chunks3563* ...3564* push(chunk, true); // push last chunk3565* ```3566**/3567Deflate.prototype.push = function(data, mode) {3568var strm = this.strm;3569var chunkSize = this.options.chunkSize;3570var status, _mode;35713572if (this.ended) { return false; }35733574_mode = (mode === ~~mode) ? mode : ((mode === true) ? Z_FINISH : Z_NO_FLUSH);35753576// Convert data if needed3577if (typeof data === 'string') {3578// If we need to compress text, change encoding to utf8.3579strm.input = strings.string2buf(data);3580} else if (toString.call(data) === '[object ArrayBuffer]') {3581strm.input = new Uint8Array(data);3582} else {3583strm.input = data;3584}35853586strm.next_in = 0;3587strm.avail_in = strm.input.length;35883589do {3590if (strm.avail_out === 0) {3591strm.output = new utils.Buf8(chunkSize);3592strm.next_out = 0;3593strm.avail_out = chunkSize;3594}3595status = zlib_deflate.deflate(strm, _mode); /* no bad return value */35963597if (status !== Z_STREAM_END && status !== Z_OK) {3598this.onEnd(status);3599this.ended = true;3600return false;3601}3602if (strm.avail_out === 0 || (strm.avail_in === 0 && _mode === Z_FINISH)) {3603if (this.options.to === 'string') {3604this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out)));3605} else {3606this.onData(utils.shrinkBuf(strm.output, strm.next_out));3607}3608}3609} while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END);36103611// Finalize on the last chunk.3612if (_mode === Z_FINISH) {3613status = zlib_deflate.deflateEnd(this.strm);3614this.onEnd(status);3615this.ended = true;3616return status === Z_OK;3617}36183619return true;3620};362136223623/**3624* Deflate#onData(chunk) -> Void3625* - chunk (Uint8Array|Array|String): ouput data. Type of array depends3626* on js engine support. When string output requested, each chunk3627* will be string.3628*3629* By default, stores data blocks in `chunks[]` property and glue3630* those in `onEnd`. Override this handler, if you need another behaviour.3631**/3632Deflate.prototype.onData = function(chunk) {3633this.chunks.push(chunk);3634};363536363637/**3638* Deflate#onEnd(status) -> Void3639* - status (Number): deflate status. 0 (Z_OK) on success,3640* other if not.3641*3642* Called once after you tell deflate that input stream complete3643* or error happenned. By default - join collected chunks,3644* free memory and fill `results` / `err` properties.3645**/3646Deflate.prototype.onEnd = function(status) {3647// On success - join3648if (status === Z_OK) {3649if (this.options.to === 'string') {3650this.result = this.chunks.join('');3651} else {3652this.result = utils.flattenChunks(this.chunks);3653}3654}3655this.chunks = [];3656this.err = status;3657this.msg = this.strm.msg;3658};365936603661/**3662* deflate(data[, options]) -> Uint8Array|Array|String3663* - data (Uint8Array|Array|String): input data to compress.3664* - options (Object): zlib deflate options.3665*3666* Compress `data` with deflate alrorythm and `options`.3667*3668* Supported options are:3669*3670* - level3671* - windowBits3672* - memLevel3673* - strategy3674*3675* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)3676* for more information on these.3677*3678* Sugar (options):3679*3680* - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify3681* negative windowBits implicitly.3682* - `to` (String) - if equal to 'string', then result will be "binary string"3683* (each char code [0..255])3684*3685* ##### Example:3686*3687* ```javascript3688* var pako = require('pako')3689* , data = Uint8Array([1,2,3,4,5,6,7,8,9]);3690*3691* console.log(pako.deflate(data));3692* ```3693**/3694function deflate(input, options) {3695var deflator = new Deflate(options);36963697deflator.push(input, true);36983699// That will never happens, if you don't cheat with options :)3700if (deflator.err) { throw deflator.msg; }37013702return deflator.result;3703}370437053706/**3707* deflateRaw(data[, options]) -> Uint8Array|Array|String3708* - data (Uint8Array|Array|String): input data to compress.3709* - options (Object): zlib deflate options.3710*3711* The same as [[deflate]], but creates raw data, without wrapper3712* (header and adler32 crc).3713**/3714function deflateRaw(input, options) {3715options = options || {};3716options.raw = true;3717return deflate(input, options);3718}371937203721/**3722* gzip(data[, options]) -> Uint8Array|Array|String3723* - data (Uint8Array|Array|String): input data to compress.3724* - options (Object): zlib deflate options.3725*3726* The same as [[deflate]], but create gzip wrapper instead of3727* deflate one.3728**/3729function gzip(input, options) {3730options = options || {};3731options.gzip = true;3732return deflate(input, options);3733}373437353736exports.Deflate = Deflate;3737exports.deflate = deflate;3738exports.deflateRaw = deflateRaw;3739exports.gzip = gzip;3740},{"./utils/common":1,"./utils/strings":2,"./zlib/deflate.js":5,"./zlib/messages":6,"./zlib/zstream":8}]},{},[])("/lib/deflate.js")3741});37423743