react / wstein / node_modules / browserify / node_modules / browserify-zlib / node_modules / pako / dist / pako.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 zlib_deflate = require('./zlib/deflate.js');5var utils = require('./utils/common');6var strings = require('./utils/strings');7var msg = require('./zlib/messages');8var zstream = require('./zlib/zstream');910var toString = Object.prototype.toString;1112/* Public constants ==========================================================*/13/* ===========================================================================*/1415var Z_NO_FLUSH = 0;16var Z_FINISH = 4;1718var Z_OK = 0;19var Z_STREAM_END = 1;2021var Z_DEFAULT_COMPRESSION = -1;2223var Z_DEFAULT_STRATEGY = 0;2425var Z_DEFLATED = 8;2627/* ===========================================================================*/282930/**31* class Deflate32*33* Generic JS-style wrapper for zlib calls. If you don't need34* streaming behaviour - use more simple functions: [[deflate]],35* [[deflateRaw]] and [[gzip]].36**/3738/* internal39* Deflate.chunks -> Array40*41* Chunks of output data, if [[Deflate#onData]] not overriden.42**/4344/**45* Deflate.result -> Uint8Array|Array46*47* Compressed result, generated by default [[Deflate#onData]]48* and [[Deflate#onEnd]] handlers. Filled after you push last chunk49* (call [[Deflate#push]] with `Z_FINISH` / `true` param).50**/5152/**53* Deflate.err -> Number54*55* Error code after deflate finished. 0 (Z_OK) on success.56* You will not need it in real life, because deflate errors57* are possible only on wrong options or bad `onData` / `onEnd`58* custom handlers.59**/6061/**62* Deflate.msg -> String63*64* Error message, if [[Deflate.err]] != 065**/666768/**69* new Deflate(options)70* - options (Object): zlib deflate options.71*72* Creates new deflator instance with specified params. Throws exception73* on bad params. Supported options:74*75* - `level`76* - `windowBits`77* - `memLevel`78* - `strategy`79*80* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)81* for more information on these.82*83* Additional options, for internal needs:84*85* - `chunkSize` - size of generated data chunks (16K by default)86* - `raw` (Boolean) - do raw deflate87* - `gzip` (Boolean) - create gzip wrapper88* - `to` (String) - if equal to 'string', then result will be "binary string"89* (each char code [0..255])90* - `header` (Object) - custom header for gzip91* - `text` (Boolean) - true if compressed data believed to be text92* - `time` (Number) - modification time, unix timestamp93* - `os` (Number) - operation system code94* - `extra` (Array) - array of bytes with extra data (max 65536)95* - `name` (String) - file name (binary string)96* - `comment` (String) - comment (binary string)97* - `hcrc` (Boolean) - true if header crc should be added98*99* ##### Example:100*101* ```javascript102* var pako = require('pako')103* , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])104* , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);105*106* var deflate = new pako.Deflate({ level: 3});107*108* deflate.push(chunk1, false);109* deflate.push(chunk2, true); // true -> last chunk110*111* if (deflate.err) { throw new Error(deflate.err); }112*113* console.log(deflate.result);114* ```115**/116var Deflate = function(options) {117118this.options = utils.assign({119level: Z_DEFAULT_COMPRESSION,120method: Z_DEFLATED,121chunkSize: 16384,122windowBits: 15,123memLevel: 8,124strategy: Z_DEFAULT_STRATEGY,125to: ''126}, options || {});127128var opt = this.options;129130if (opt.raw && (opt.windowBits > 0)) {131opt.windowBits = -opt.windowBits;132}133134else if (opt.gzip && (opt.windowBits > 0) && (opt.windowBits < 16)) {135opt.windowBits += 16;136}137138this.err = 0; // error code, if happens (0 = Z_OK)139this.msg = ''; // error message140this.ended = false; // used to avoid multiple onEnd() calls141this.chunks = []; // chunks of compressed data142143this.strm = new zstream();144this.strm.avail_out = 0;145146var status = zlib_deflate.deflateInit2(147this.strm,148opt.level,149opt.method,150opt.windowBits,151opt.memLevel,152opt.strategy153);154155if (status !== Z_OK) {156throw new Error(msg[status]);157}158159if (opt.header) {160zlib_deflate.deflateSetHeader(this.strm, opt.header);161}162};163164/**165* Deflate#push(data[, mode]) -> Boolean166* - data (Uint8Array|Array|ArrayBuffer|String): input data. Strings will be167* converted to utf8 byte sequence.168* - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.169* See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.170*171* Sends input data to deflate pipe, generating [[Deflate#onData]] calls with172* new compressed chunks. Returns `true` on success. The last data block must have173* mode Z_FINISH (or `true`). That flush internal pending buffers and call174* [[Deflate#onEnd]].175*176* On fail call [[Deflate#onEnd]] with error code and return false.177*178* We strongly recommend to use `Uint8Array` on input for best speed (output179* array format is detected automatically). Also, don't skip last param and always180* use the same type in your code (boolean or number). That will improve JS speed.181*182* For regular `Array`-s make sure all elements are [0..255].183*184* ##### Example185*186* ```javascript187* push(chunk, false); // push one of data chunks188* ...189* push(chunk, true); // push last chunk190* ```191**/192Deflate.prototype.push = function(data, mode) {193var strm = this.strm;194var chunkSize = this.options.chunkSize;195var status, _mode;196197if (this.ended) { return false; }198199_mode = (mode === ~~mode) ? mode : ((mode === true) ? Z_FINISH : Z_NO_FLUSH);200201// Convert data if needed202if (typeof data === 'string') {203// If we need to compress text, change encoding to utf8.204strm.input = strings.string2buf(data);205} else if (toString.call(data) === '[object ArrayBuffer]') {206strm.input = new Uint8Array(data);207} else {208strm.input = data;209}210211strm.next_in = 0;212strm.avail_in = strm.input.length;213214do {215if (strm.avail_out === 0) {216strm.output = new utils.Buf8(chunkSize);217strm.next_out = 0;218strm.avail_out = chunkSize;219}220status = zlib_deflate.deflate(strm, _mode); /* no bad return value */221222if (status !== Z_STREAM_END && status !== Z_OK) {223this.onEnd(status);224this.ended = true;225return false;226}227if (strm.avail_out === 0 || (strm.avail_in === 0 && _mode === Z_FINISH)) {228if (this.options.to === 'string') {229this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out)));230} else {231this.onData(utils.shrinkBuf(strm.output, strm.next_out));232}233}234} while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END);235236// Finalize on the last chunk.237if (_mode === Z_FINISH) {238status = zlib_deflate.deflateEnd(this.strm);239this.onEnd(status);240this.ended = true;241return status === Z_OK;242}243244return true;245};246247248/**249* Deflate#onData(chunk) -> Void250* - chunk (Uint8Array|Array|String): ouput data. Type of array depends251* on js engine support. When string output requested, each chunk252* will be string.253*254* By default, stores data blocks in `chunks[]` property and glue255* those in `onEnd`. Override this handler, if you need another behaviour.256**/257Deflate.prototype.onData = function(chunk) {258this.chunks.push(chunk);259};260261262/**263* Deflate#onEnd(status) -> Void264* - status (Number): deflate status. 0 (Z_OK) on success,265* other if not.266*267* Called once after you tell deflate that input stream complete268* or error happenned. By default - join collected chunks,269* free memory and fill `results` / `err` properties.270**/271Deflate.prototype.onEnd = function(status) {272// On success - join273if (status === Z_OK) {274if (this.options.to === 'string') {275this.result = this.chunks.join('');276} else {277this.result = utils.flattenChunks(this.chunks);278}279}280this.chunks = [];281this.err = status;282this.msg = this.strm.msg;283};284285286/**287* deflate(data[, options]) -> Uint8Array|Array|String288* - data (Uint8Array|Array|String): input data to compress.289* - options (Object): zlib deflate options.290*291* Compress `data` with deflate alrorythm and `options`.292*293* Supported options are:294*295* - level296* - windowBits297* - memLevel298* - strategy299*300* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)301* for more information on these.302*303* Sugar (options):304*305* - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify306* negative windowBits implicitly.307* - `to` (String) - if equal to 'string', then result will be "binary string"308* (each char code [0..255])309*310* ##### Example:311*312* ```javascript313* var pako = require('pako')314* , data = Uint8Array([1,2,3,4,5,6,7,8,9]);315*316* console.log(pako.deflate(data));317* ```318**/319function deflate(input, options) {320var deflator = new Deflate(options);321322deflator.push(input, true);323324// That will never happens, if you don't cheat with options :)325if (deflator.err) { throw deflator.msg; }326327return deflator.result;328}329330331/**332* deflateRaw(data[, options]) -> Uint8Array|Array|String333* - data (Uint8Array|Array|String): input data to compress.334* - options (Object): zlib deflate options.335*336* The same as [[deflate]], but creates raw data, without wrapper337* (header and adler32 crc).338**/339function deflateRaw(input, options) {340options = options || {};341options.raw = true;342return deflate(input, options);343}344345346/**347* gzip(data[, options]) -> Uint8Array|Array|String348* - data (Uint8Array|Array|String): input data to compress.349* - options (Object): zlib deflate options.350*351* The same as [[deflate]], but create gzip wrapper instead of352* deflate one.353**/354function gzip(input, options) {355options = options || {};356options.gzip = true;357return deflate(input, options);358}359360361exports.Deflate = Deflate;362exports.deflate = deflate;363exports.deflateRaw = deflateRaw;364exports.gzip = gzip;365},{"./utils/common":3,"./utils/strings":4,"./zlib/deflate.js":8,"./zlib/messages":13,"./zlib/zstream":15}],2:[function(require,module,exports){366'use strict';367368369var zlib_inflate = require('./zlib/inflate.js');370var utils = require('./utils/common');371var strings = require('./utils/strings');372var c = require('./zlib/constants');373var msg = require('./zlib/messages');374var zstream = require('./zlib/zstream');375var gzheader = require('./zlib/gzheader');376377var toString = Object.prototype.toString;378379/**380* class Inflate381*382* Generic JS-style wrapper for zlib calls. If you don't need383* streaming behaviour - use more simple functions: [[inflate]]384* and [[inflateRaw]].385**/386387/* internal388* inflate.chunks -> Array389*390* Chunks of output data, if [[Inflate#onData]] not overriden.391**/392393/**394* Inflate.result -> Uint8Array|Array|String395*396* Uncompressed result, generated by default [[Inflate#onData]]397* and [[Inflate#onEnd]] handlers. Filled after you push last chunk398* (call [[Inflate#push]] with `Z_FINISH` / `true` param).399**/400401/**402* Inflate.err -> Number403*404* Error code after inflate finished. 0 (Z_OK) on success.405* Should be checked if broken data possible.406**/407408/**409* Inflate.msg -> String410*411* Error message, if [[Inflate.err]] != 0412**/413414415/**416* new Inflate(options)417* - options (Object): zlib inflate options.418*419* Creates new inflator instance with specified params. Throws exception420* on bad params. Supported options:421*422* - `windowBits`423*424* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)425* for more information on these.426*427* Additional options, for internal needs:428*429* - `chunkSize` - size of generated data chunks (16K by default)430* - `raw` (Boolean) - do raw inflate431* - `to` (String) - if equal to 'string', then result will be converted432* from utf8 to utf16 (javascript) string. When string output requested,433* chunk length can differ from `chunkSize`, depending on content.434*435* By default, when no options set, autodetect deflate/gzip data format via436* wrapper header.437*438* ##### Example:439*440* ```javascript441* var pako = require('pako')442* , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])443* , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);444*445* var inflate = new pako.Inflate({ level: 3});446*447* inflate.push(chunk1, false);448* inflate.push(chunk2, true); // true -> last chunk449*450* if (inflate.err) { throw new Error(inflate.err); }451*452* console.log(inflate.result);453* ```454**/455var Inflate = function(options) {456457this.options = utils.assign({458chunkSize: 16384,459windowBits: 0,460to: ''461}, options || {});462463var opt = this.options;464465// Force window size for `raw` data, if not set directly,466// because we have no header for autodetect.467if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {468opt.windowBits = -opt.windowBits;469if (opt.windowBits === 0) { opt.windowBits = -15; }470}471472// If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate473if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&474!(options && options.windowBits)) {475opt.windowBits += 32;476}477478// Gzip header has no info about windows size, we can do autodetect only479// for deflate. So, if window size not set, force it to max when gzip possible480if ((opt.windowBits > 15) && (opt.windowBits < 48)) {481// bit 3 (16) -> gzipped data482// bit 4 (32) -> autodetect gzip/deflate483if ((opt.windowBits & 15) === 0) {484opt.windowBits |= 15;485}486}487488this.err = 0; // error code, if happens (0 = Z_OK)489this.msg = ''; // error message490this.ended = false; // used to avoid multiple onEnd() calls491this.chunks = []; // chunks of compressed data492493this.strm = new zstream();494this.strm.avail_out = 0;495496var status = zlib_inflate.inflateInit2(497this.strm,498opt.windowBits499);500501if (status !== c.Z_OK) {502throw new Error(msg[status]);503}504505this.header = new gzheader();506507zlib_inflate.inflateGetHeader(this.strm, this.header);508};509510/**511* Inflate#push(data[, mode]) -> Boolean512* - data (Uint8Array|Array|ArrayBuffer|String): input data513* - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.514* See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.515*516* Sends input data to inflate pipe, generating [[Inflate#onData]] calls with517* new output chunks. Returns `true` on success. The last data block must have518* mode Z_FINISH (or `true`). That flush internal pending buffers and call519* [[Inflate#onEnd]].520*521* On fail call [[Inflate#onEnd]] with error code and return false.522*523* We strongly recommend to use `Uint8Array` on input for best speed (output524* format is detected automatically). Also, don't skip last param and always525* use the same type in your code (boolean or number). That will improve JS speed.526*527* For regular `Array`-s make sure all elements are [0..255].528*529* ##### Example530*531* ```javascript532* push(chunk, false); // push one of data chunks533* ...534* push(chunk, true); // push last chunk535* ```536**/537Inflate.prototype.push = function(data, mode) {538var strm = this.strm;539var chunkSize = this.options.chunkSize;540var status, _mode;541var next_out_utf8, tail, utf8str;542543if (this.ended) { return false; }544_mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH);545546// Convert data if needed547if (typeof data === 'string') {548// Only binary strings can be decompressed on practice549strm.input = strings.binstring2buf(data);550} else if (toString.call(data) === '[object ArrayBuffer]') {551strm.input = new Uint8Array(data);552} else {553strm.input = data;554}555556strm.next_in = 0;557strm.avail_in = strm.input.length;558559do {560if (strm.avail_out === 0) {561strm.output = new utils.Buf8(chunkSize);562strm.next_out = 0;563strm.avail_out = chunkSize;564}565566status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH); /* no bad return value */567568if (status !== c.Z_STREAM_END && status !== c.Z_OK) {569this.onEnd(status);570this.ended = true;571return false;572}573574if (strm.next_out) {575if (strm.avail_out === 0 || status === c.Z_STREAM_END || (strm.avail_in === 0 && _mode === c.Z_FINISH)) {576577if (this.options.to === 'string') {578579next_out_utf8 = strings.utf8border(strm.output, strm.next_out);580581tail = strm.next_out - next_out_utf8;582utf8str = strings.buf2string(strm.output, next_out_utf8);583584// move tail585strm.next_out = tail;586strm.avail_out = chunkSize - tail;587if (tail) { utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0); }588589this.onData(utf8str);590591} else {592this.onData(utils.shrinkBuf(strm.output, strm.next_out));593}594}595}596} while ((strm.avail_in > 0) && status !== c.Z_STREAM_END);597598if (status === c.Z_STREAM_END) {599_mode = c.Z_FINISH;600}601// Finalize on the last chunk.602if (_mode === c.Z_FINISH) {603status = zlib_inflate.inflateEnd(this.strm);604this.onEnd(status);605this.ended = true;606return status === c.Z_OK;607}608609return true;610};611612613/**614* Inflate#onData(chunk) -> Void615* - chunk (Uint8Array|Array|String): ouput data. Type of array depends616* on js engine support. When string output requested, each chunk617* will be string.618*619* By default, stores data blocks in `chunks[]` property and glue620* those in `onEnd`. Override this handler, if you need another behaviour.621**/622Inflate.prototype.onData = function(chunk) {623this.chunks.push(chunk);624};625626627/**628* Inflate#onEnd(status) -> Void629* - status (Number): inflate status. 0 (Z_OK) on success,630* other if not.631*632* Called once after you tell inflate that input stream complete633* or error happenned. By default - join collected chunks,634* free memory and fill `results` / `err` properties.635**/636Inflate.prototype.onEnd = function(status) {637// On success - join638if (status === c.Z_OK) {639if (this.options.to === 'string') {640// Glue & convert here, until we teach pako to send641// utf8 alligned strings to onData642this.result = this.chunks.join('');643} else {644this.result = utils.flattenChunks(this.chunks);645}646}647this.chunks = [];648this.err = status;649this.msg = this.strm.msg;650};651652653/**654* inflate(data[, options]) -> Uint8Array|Array|String655* - data (Uint8Array|Array|String): input data to decompress.656* - options (Object): zlib inflate options.657*658* Decompress `data` with inflate/ungzip and `options`. Autodetect659* format via wrapper header by default. That's why we don't provide660* separate `ungzip` method.661*662* Supported options are:663*664* - windowBits665*666* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)667* for more information.668*669* Sugar (options):670*671* - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify672* negative windowBits implicitly.673* - `to` (String) - if equal to 'string', then result will be converted674* from utf8 to utf16 (javascript) string. When string output requested,675* chunk length can differ from `chunkSize`, depending on content.676*677*678* ##### Example:679*680* ```javascript681* var pako = require('pako')682* , input = pako.deflate([1,2,3,4,5,6,7,8,9])683* , output;684*685* try {686* output = pako.inflate(input);687* } catch (err)688* console.log(err);689* }690* ```691**/692function inflate(input, options) {693var inflator = new Inflate(options);694695inflator.push(input, true);696697// That will never happens, if you don't cheat with options :)698if (inflator.err) { throw inflator.msg; }699700return inflator.result;701}702703704/**705* inflateRaw(data[, options]) -> Uint8Array|Array|String706* - data (Uint8Array|Array|String): input data to decompress.707* - options (Object): zlib inflate options.708*709* The same as [[inflate]], but creates raw data, without wrapper710* (header and adler32 crc).711**/712function inflateRaw(input, options) {713options = options || {};714options.raw = true;715return inflate(input, options);716}717718719/**720* ungzip(data[, options]) -> Uint8Array|Array|String721* - data (Uint8Array|Array|String): input data to decompress.722* - options (Object): zlib inflate options.723*724* Just shortcut to [[inflate]], because it autodetects format725* by header.content. Done for convenience.726**/727728729exports.Inflate = Inflate;730exports.inflate = inflate;731exports.inflateRaw = inflateRaw;732exports.ungzip = inflate;733734},{"./utils/common":3,"./utils/strings":4,"./zlib/constants":6,"./zlib/gzheader":9,"./zlib/inflate.js":11,"./zlib/messages":13,"./zlib/zstream":15}],3:[function(require,module,exports){735'use strict';736737738var TYPED_OK = (typeof Uint8Array !== 'undefined') &&739(typeof Uint16Array !== 'undefined') &&740(typeof Int32Array !== 'undefined');741742743exports.assign = function (obj /*from1, from2, from3, ...*/) {744var sources = Array.prototype.slice.call(arguments, 1);745while (sources.length) {746var source = sources.shift();747if (!source) { continue; }748749if (typeof(source) !== 'object') {750throw new TypeError(source + 'must be non-object');751}752753for (var p in source) {754if (source.hasOwnProperty(p)) {755obj[p] = source[p];756}757}758}759760return obj;761};762763764// reduce buffer size, avoiding mem copy765exports.shrinkBuf = function (buf, size) {766if (buf.length === size) { return buf; }767if (buf.subarray) { return buf.subarray(0, size); }768buf.length = size;769return buf;770};771772773var fnTyped = {774arraySet: function (dest, src, src_offs, len, dest_offs) {775if (src.subarray && dest.subarray) {776dest.set(src.subarray(src_offs, src_offs+len), dest_offs);777return;778}779// Fallback to ordinary array780for(var i=0; i<len; i++) {781dest[dest_offs + i] = src[src_offs + i];782}783},784// Join array of chunks to single array.785flattenChunks: function(chunks) {786var i, l, len, pos, chunk, result;787788// calculate data length789len = 0;790for (i=0, l=chunks.length; i<l; i++) {791len += chunks[i].length;792}793794// join chunks795result = new Uint8Array(len);796pos = 0;797for (i=0, l=chunks.length; i<l; i++) {798chunk = chunks[i];799result.set(chunk, pos);800pos += chunk.length;801}802803return result;804}805};806807var fnUntyped = {808arraySet: function (dest, src, src_offs, len, dest_offs) {809for(var i=0; i<len; i++) {810dest[dest_offs + i] = src[src_offs + i];811}812},813// Join array of chunks to single array.814flattenChunks: function(chunks) {815return [].concat.apply([], chunks);816}817};818819820// Enable/Disable typed arrays use, for testing821//822exports.setTyped = function (on) {823if (on) {824exports.Buf8 = Uint8Array;825exports.Buf16 = Uint16Array;826exports.Buf32 = Int32Array;827exports.assign(exports, fnTyped);828} else {829exports.Buf8 = Array;830exports.Buf16 = Array;831exports.Buf32 = Array;832exports.assign(exports, fnUntyped);833}834};835836exports.setTyped(TYPED_OK);837},{}],4:[function(require,module,exports){838// String encode/decode helpers839'use strict';840841842var utils = require('./common');843844845// Quick check if we can use fast array to bin string conversion846//847// - apply(Array) can fail on Android 2.2848// - apply(Uint8Array) can fail on iOS 5.1 Safary849//850var STR_APPLY_OK = true;851var STR_APPLY_UIA_OK = true;852853try { String.fromCharCode.apply(null, [0]); } catch(__) { STR_APPLY_OK = false; }854try { String.fromCharCode.apply(null, new Uint8Array(1)); } catch(__) { STR_APPLY_UIA_OK = false; }855856857// Table with utf8 lengths (calculated by first byte of sequence)858// Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,859// because max possible codepoint is 0x10ffff860var _utf8len = new utils.Buf8(256);861for (var i=0; i<256; i++) {862_utf8len[i] = (i >= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1);863}864_utf8len[254]=_utf8len[254]=1; // Invalid sequence start865866867// convert string to array (typed, when possible)868exports.string2buf = function (str) {869var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;870871// count binary size872for (m_pos = 0; m_pos < str_len; m_pos++) {873c = str.charCodeAt(m_pos);874if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {875c2 = str.charCodeAt(m_pos+1);876if ((c2 & 0xfc00) === 0xdc00) {877c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);878m_pos++;879}880}881buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;882}883884// allocate buffer885buf = new utils.Buf8(buf_len);886887// convert888for (i=0, m_pos = 0; i < buf_len; m_pos++) {889c = str.charCodeAt(m_pos);890if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {891c2 = str.charCodeAt(m_pos+1);892if ((c2 & 0xfc00) === 0xdc00) {893c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);894m_pos++;895}896}897if (c < 0x80) {898/* one byte */899buf[i++] = c;900} else if (c < 0x800) {901/* two bytes */902buf[i++] = 0xC0 | (c >>> 6);903buf[i++] = 0x80 | (c & 0x3f);904} else if (c < 0x10000) {905/* three bytes */906buf[i++] = 0xE0 | (c >>> 12);907buf[i++] = 0x80 | (c >>> 6 & 0x3f);908buf[i++] = 0x80 | (c & 0x3f);909} else {910/* four bytes */911buf[i++] = 0xf0 | (c >>> 18);912buf[i++] = 0x80 | (c >>> 12 & 0x3f);913buf[i++] = 0x80 | (c >>> 6 & 0x3f);914buf[i++] = 0x80 | (c & 0x3f);915}916}917918return buf;919};920921// Helper (used in 2 places)922function buf2binstring(buf, len) {923// use fallback for big arrays to avoid stack overflow924if (len < 65537) {925if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) {926return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len));927}928}929930var result = '';931for(var i=0; i < len; i++) {932result += String.fromCharCode(buf[i]);933}934return result;935}936937938// Convert byte array to binary string939exports.buf2binstring = function(buf) {940return buf2binstring(buf, buf.length);941};942943944// Convert binary string (typed, when possible)945exports.binstring2buf = function(str) {946var buf = new utils.Buf8(str.length);947for(var i=0, len=buf.length; i < len; i++) {948buf[i] = str.charCodeAt(i);949}950return buf;951};952953954// convert array to string955exports.buf2string = function (buf, max) {956var i, out, c, c_len;957var len = max || buf.length;958959// Reserve max possible length (2 words per char)960// NB: by unknown reasons, Array is significantly faster for961// String.fromCharCode.apply than Uint16Array.962var utf16buf = new Array(len*2);963964for (out=0, i=0; i<len;) {965c = buf[i++];966// quick process ascii967if (c < 0x80) { utf16buf[out++] = c; continue; }968969c_len = _utf8len[c];970// skip 5 & 6 byte codes971if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len-1; continue; }972973// apply mask on first byte974c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;975// join the rest976while (c_len > 1 && i < len) {977c = (c << 6) | (buf[i++] & 0x3f);978c_len--;979}980981// terminated by end of string?982if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }983984if (c < 0x10000) {985utf16buf[out++] = c;986} else {987c -= 0x10000;988utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);989utf16buf[out++] = 0xdc00 | (c & 0x3ff);990}991}992993return buf2binstring(utf16buf, out);994};995996997// Calculate max possible position in utf8 buffer,998// that will not break sequence. If that's not possible999// - (very small limits) return max size as is.1000//1001// buf[] - utf8 bytes array1002// max - length limit (mandatory);1003exports.utf8border = function(buf, max) {1004var pos;10051006max = max || buf.length;1007if (max > buf.length) { max = buf.length; }10081009// go back from last position, until start of sequence found1010pos = max-1;1011while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }10121013// Fuckup - very small and broken sequence,1014// return max, because we should return something anyway.1015if (pos < 0) { return max; }10161017// If we came to start of buffer - that means vuffer is too small,1018// return max too.1019if (pos === 0) { return max; }10201021return (pos + _utf8len[buf[pos]] > max) ? pos : max;1022};10231024},{"./common":3}],5:[function(require,module,exports){1025'use strict';10261027// Note: adler32 takes 12% for level 0 and 2% for level 6.1028// It doesn't worth to make additional optimizationa as in original.1029// Small size is preferable.10301031function adler32(adler, buf, len, pos) {1032var s1 = (adler & 0xffff) |01033, s2 = ((adler >>> 16) & 0xffff) |01034, n = 0;10351036while (len !== 0) {1037// Set limit ~ twice less than 5552, to keep1038// s2 in 31-bits, because we force signed ints.1039// in other case %= will fail.1040n = len > 2000 ? 2000 : len;1041len -= n;10421043do {1044s1 = (s1 + buf[pos++]) |0;1045s2 = (s2 + s1) |0;1046} while (--n);10471048s1 %= 65521;1049s2 %= 65521;1050}10511052return (s1 | (s2 << 16)) |0;1053}105410551056module.exports = adler32;1057},{}],6:[function(require,module,exports){1058module.exports = {10591060/* Allowed flush values; see deflate() and inflate() below for details */1061Z_NO_FLUSH: 0,1062Z_PARTIAL_FLUSH: 1,1063Z_SYNC_FLUSH: 2,1064Z_FULL_FLUSH: 3,1065Z_FINISH: 4,1066Z_BLOCK: 5,1067Z_TREES: 6,10681069/* Return codes for the compression/decompression functions. Negative values1070* are errors, positive values are used for special but normal events.1071*/1072Z_OK: 0,1073Z_STREAM_END: 1,1074Z_NEED_DICT: 2,1075Z_ERRNO: -1,1076Z_STREAM_ERROR: -2,1077Z_DATA_ERROR: -3,1078//Z_MEM_ERROR: -4,1079Z_BUF_ERROR: -5,1080//Z_VERSION_ERROR: -6,10811082/* compression levels */1083Z_NO_COMPRESSION: 0,1084Z_BEST_SPEED: 1,1085Z_BEST_COMPRESSION: 9,1086Z_DEFAULT_COMPRESSION: -1,108710881089Z_FILTERED: 1,1090Z_HUFFMAN_ONLY: 2,1091Z_RLE: 3,1092Z_FIXED: 4,1093Z_DEFAULT_STRATEGY: 0,10941095/* Possible values of the data_type field (though see inflate()) */1096Z_BINARY: 0,1097Z_TEXT: 1,1098//Z_ASCII: 1, // = Z_TEXT (deprecated)1099Z_UNKNOWN: 2,11001101/* The deflate compression method */1102Z_DEFLATED: 81103//Z_NULL: null // Use -1 or null inline, depending on var type1104};1105},{}],7:[function(require,module,exports){1106'use strict';11071108// Note: we can't get significant speed boost here.1109// So write code to minimize size - no pregenerated tables1110// and array tools dependencies.111111121113// Use ordinary array, since untyped makes no boost here1114function makeTable() {1115var c, table = [];11161117for(var n =0; n < 256; n++){1118c = n;1119for(var k =0; k < 8; k++){1120c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));1121}1122table[n] = c;1123}11241125return table;1126}11271128// Create table on load. Just 255 signed longs. Not a problem.1129var crcTable = makeTable();113011311132function crc32(crc, buf, len, pos) {1133var t = crcTable1134, end = pos + len;11351136crc = crc ^ (-1);11371138for (var i = pos; i < end; i++ ) {1139crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];1140}11411142return (crc ^ (-1)); // >>> 0;1143}114411451146module.exports = crc32;1147},{}],8:[function(require,module,exports){1148'use strict';11491150var utils = require('../utils/common');1151var trees = require('./trees');1152var adler32 = require('./adler32');1153var crc32 = require('./crc32');1154var msg = require('./messages');11551156/* Public constants ==========================================================*/1157/* ===========================================================================*/115811591160/* Allowed flush values; see deflate() and inflate() below for details */1161var Z_NO_FLUSH = 0;1162var Z_PARTIAL_FLUSH = 1;1163//var Z_SYNC_FLUSH = 2;1164var Z_FULL_FLUSH = 3;1165var Z_FINISH = 4;1166var Z_BLOCK = 5;1167//var Z_TREES = 6;116811691170/* Return codes for the compression/decompression functions. Negative values1171* are errors, positive values are used for special but normal events.1172*/1173var Z_OK = 0;1174var Z_STREAM_END = 1;1175//var Z_NEED_DICT = 2;1176//var Z_ERRNO = -1;1177var Z_STREAM_ERROR = -2;1178var Z_DATA_ERROR = -3;1179//var Z_MEM_ERROR = -4;1180var Z_BUF_ERROR = -5;1181//var Z_VERSION_ERROR = -6;118211831184/* compression levels */1185//var Z_NO_COMPRESSION = 0;1186//var Z_BEST_SPEED = 1;1187//var Z_BEST_COMPRESSION = 9;1188var Z_DEFAULT_COMPRESSION = -1;118911901191var Z_FILTERED = 1;1192var Z_HUFFMAN_ONLY = 2;1193var Z_RLE = 3;1194var Z_FIXED = 4;1195var Z_DEFAULT_STRATEGY = 0;11961197/* Possible values of the data_type field (though see inflate()) */1198//var Z_BINARY = 0;1199//var Z_TEXT = 1;1200//var Z_ASCII = 1; // = Z_TEXT1201var Z_UNKNOWN = 2;120212031204/* The deflate compression method */1205var Z_DEFLATED = 8;12061207/*============================================================================*/120812091210var MAX_MEM_LEVEL = 9;1211/* Maximum value for memLevel in deflateInit2 */1212var MAX_WBITS = 15;1213/* 32K LZ77 window */1214var DEF_MEM_LEVEL = 8;121512161217var LENGTH_CODES = 29;1218/* number of length codes, not counting the special END_BLOCK code */1219var LITERALS = 256;1220/* number of literal bytes 0..255 */1221var L_CODES = LITERALS + 1 + LENGTH_CODES;1222/* number of Literal or Length codes, including the END_BLOCK code */1223var D_CODES = 30;1224/* number of distance codes */1225var BL_CODES = 19;1226/* number of codes used to transfer the bit lengths */1227var HEAP_SIZE = 2*L_CODES + 1;1228/* maximum heap size */1229var MAX_BITS = 15;1230/* All codes must not exceed MAX_BITS bits */12311232var MIN_MATCH = 3;1233var MAX_MATCH = 258;1234var MIN_LOOKAHEAD = (MAX_MATCH + MIN_MATCH + 1);12351236var PRESET_DICT = 0x20;12371238var INIT_STATE = 42;1239var EXTRA_STATE = 69;1240var NAME_STATE = 73;1241var COMMENT_STATE = 91;1242var HCRC_STATE = 103;1243var BUSY_STATE = 113;1244var FINISH_STATE = 666;12451246var BS_NEED_MORE = 1; /* block not completed, need more input or more output */1247var BS_BLOCK_DONE = 2; /* block flush performed */1248var BS_FINISH_STARTED = 3; /* finish started, need only more output at next deflate */1249var BS_FINISH_DONE = 4; /* finish done, accept no more input or output */12501251var OS_CODE = 0x03; // Unix :) . Don't detect, use this default.12521253function err(strm, errorCode) {1254strm.msg = msg[errorCode];1255return errorCode;1256}12571258function rank(f) {1259return ((f) << 1) - ((f) > 4 ? 9 : 0);1260}12611262function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }126312641265/* =========================================================================1266* Flush as much pending output as possible. All deflate() output goes1267* through this function so some applications may wish to modify it1268* to avoid allocating a large strm->output buffer and copying into it.1269* (See also read_buf()).1270*/1271function flush_pending(strm) {1272var s = strm.state;12731274//_tr_flush_bits(s);1275var len = s.pending;1276if (len > strm.avail_out) {1277len = strm.avail_out;1278}1279if (len === 0) { return; }12801281utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out);1282strm.next_out += len;1283s.pending_out += len;1284strm.total_out += len;1285strm.avail_out -= len;1286s.pending -= len;1287if (s.pending === 0) {1288s.pending_out = 0;1289}1290}129112921293function flush_block_only (s, last) {1294trees._tr_flush_block(s, (s.block_start >= 0 ? s.block_start : -1), s.strstart - s.block_start, last);1295s.block_start = s.strstart;1296flush_pending(s.strm);1297}129812991300function put_byte(s, b) {1301s.pending_buf[s.pending++] = b;1302}130313041305/* =========================================================================1306* Put a short in the pending buffer. The 16-bit value is put in MSB order.1307* IN assertion: the stream state is correct and there is enough room in1308* pending_buf.1309*/1310function putShortMSB(s, b) {1311// put_byte(s, (Byte)(b >> 8));1312// put_byte(s, (Byte)(b & 0xff));1313s.pending_buf[s.pending++] = (b >>> 8) & 0xff;1314s.pending_buf[s.pending++] = b & 0xff;1315}131613171318/* ===========================================================================1319* Read a new buffer from the current input stream, update the adler321320* and total number of bytes read. All deflate() input goes through1321* this function so some applications may wish to modify it to avoid1322* allocating a large strm->input buffer and copying from it.1323* (See also flush_pending()).1324*/1325function read_buf(strm, buf, start, size) {1326var len = strm.avail_in;13271328if (len > size) { len = size; }1329if (len === 0) { return 0; }13301331strm.avail_in -= len;13321333utils.arraySet(buf, strm.input, strm.next_in, len, start);1334if (strm.state.wrap === 1) {1335strm.adler = adler32(strm.adler, buf, len, start);1336}13371338else if (strm.state.wrap === 2) {1339strm.adler = crc32(strm.adler, buf, len, start);1340}13411342strm.next_in += len;1343strm.total_in += len;13441345return len;1346}134713481349/* ===========================================================================1350* Set match_start to the longest match starting at the given string and1351* return its length. Matches shorter or equal to prev_length are discarded,1352* in which case the result is equal to prev_length and match_start is1353* garbage.1354* IN assertions: cur_match is the head of the hash chain for the current1355* string (strstart) and its distance is <= MAX_DIST, and prev_length >= 11356* OUT assertion: the match length is not greater than s->lookahead.1357*/1358function longest_match(s, cur_match) {1359var chain_length = s.max_chain_length; /* max hash chain length */1360var scan = s.strstart; /* current string */1361var match; /* matched string */1362var len; /* length of current match */1363var best_len = s.prev_length; /* best match length so far */1364var nice_match = s.nice_match; /* stop if match long enough */1365var limit = (s.strstart > (s.w_size - MIN_LOOKAHEAD)) ?1366s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0/*NIL*/;13671368var _win = s.window; // shortcut13691370var wmask = s.w_mask;1371var prev = s.prev;13721373/* Stop when cur_match becomes <= limit. To simplify the code,1374* we prevent matches with the string of window index 0.1375*/13761377var strend = s.strstart + MAX_MATCH;1378var scan_end1 = _win[scan + best_len - 1];1379var scan_end = _win[scan + best_len];13801381/* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.1382* It is easy to get rid of this optimization if necessary.1383*/1384// Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");13851386/* Do not waste too much time if we already have a good match: */1387if (s.prev_length >= s.good_match) {1388chain_length >>= 2;1389}1390/* Do not look for matches beyond the end of the input. This is necessary1391* to make deflate deterministic.1392*/1393if (nice_match > s.lookahead) { nice_match = s.lookahead; }13941395// Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");13961397do {1398// Assert(cur_match < s->strstart, "no future");1399match = cur_match;14001401/* Skip to next match if the match length cannot increase1402* or if the match length is less than 2. Note that the checks below1403* for insufficient lookahead only occur occasionally for performance1404* reasons. Therefore uninitialized memory will be accessed, and1405* conditional jumps will be made that depend on those values.1406* However the length of the match is limited to the lookahead, so1407* the output of deflate is not affected by the uninitialized values.1408*/14091410if (_win[match + best_len] !== scan_end ||1411_win[match + best_len - 1] !== scan_end1 ||1412_win[match] !== _win[scan] ||1413_win[++match] !== _win[scan + 1]) {1414continue;1415}14161417/* The check at best_len-1 can be removed because it will be made1418* again later. (This heuristic is not always a win.)1419* It is not necessary to compare scan[2] and match[2] since they1420* are always equal when the other bytes match, given that1421* the hash keys are equal and that HASH_BITS >= 8.1422*/1423scan += 2;1424match++;1425// Assert(*scan == *match, "match[2]?");14261427/* We check for insufficient lookahead only every 8th comparison;1428* the 256th check will be made at strstart+258.1429*/1430do {1431/*jshint noempty:false*/1432} while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&1433_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&1434_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&1435_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&1436scan < strend);14371438// Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");14391440len = MAX_MATCH - (strend - scan);1441scan = strend - MAX_MATCH;14421443if (len > best_len) {1444s.match_start = cur_match;1445best_len = len;1446if (len >= nice_match) {1447break;1448}1449scan_end1 = _win[scan + best_len - 1];1450scan_end = _win[scan + best_len];1451}1452} while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0);14531454if (best_len <= s.lookahead) {1455return best_len;1456}1457return s.lookahead;1458}145914601461/* ===========================================================================1462* Fill the window when the lookahead becomes insufficient.1463* Updates strstart and lookahead.1464*1465* IN assertion: lookahead < MIN_LOOKAHEAD1466* OUT assertions: strstart <= window_size-MIN_LOOKAHEAD1467* At least one byte has been read, or avail_in == 0; reads are1468* performed for at least two bytes (required for the zip translate_eol1469* option -- not supported here).1470*/1471function fill_window(s) {1472var _w_size = s.w_size;1473var p, n, m, more, str;14741475//Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");14761477do {1478more = s.window_size - s.lookahead - s.strstart;14791480// JS ints have 32 bit, block below not needed1481/* Deal with !@#$% 64K limit: */1482//if (sizeof(int) <= 2) {1483// if (more == 0 && s->strstart == 0 && s->lookahead == 0) {1484// more = wsize;1485//1486// } else if (more == (unsigned)(-1)) {1487// /* Very unlikely, but possible on 16 bit machine if1488// * strstart == 0 && lookahead == 1 (input done a byte at time)1489// */1490// more--;1491// }1492//}149314941495/* If the window is almost full and there is insufficient lookahead,1496* move the upper half to the lower one to make room in the upper half.1497*/1498if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {14991500utils.arraySet(s.window, s.window, _w_size, _w_size, 0);1501s.match_start -= _w_size;1502s.strstart -= _w_size;1503/* we now have strstart >= MAX_DIST */1504s.block_start -= _w_size;15051506/* Slide the hash table (could be avoided with 32 bit values1507at the expense of memory usage). We slide even when level == 01508to keep the hash table consistent if we switch back to level > 01509later. (Using level 0 permanently is not an optimal usage of1510zlib, so we don't care about this pathological case.)1511*/15121513n = s.hash_size;1514p = n;1515do {1516m = s.head[--p];1517s.head[p] = (m >= _w_size ? m - _w_size : 0);1518} while (--n);15191520n = _w_size;1521p = n;1522do {1523m = s.prev[--p];1524s.prev[p] = (m >= _w_size ? m - _w_size : 0);1525/* If n is not on any hash chain, prev[n] is garbage but1526* its value will never be used.1527*/1528} while (--n);15291530more += _w_size;1531}1532if (s.strm.avail_in === 0) {1533break;1534}15351536/* If there was no sliding:1537* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&1538* more == window_size - lookahead - strstart1539* => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)1540* => more >= window_size - 2*WSIZE + 21541* In the BIG_MEM or MMAP case (not yet supported),1542* window_size == input_size + MIN_LOOKAHEAD &&1543* strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.1544* Otherwise, window_size == 2*WSIZE so more >= 2.1545* If there was sliding, more >= WSIZE. So in all cases, more >= 2.1546*/1547//Assert(more >= 2, "more < 2");1548n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more);1549s.lookahead += n;15501551/* Initialize the hash value now that we have some input: */1552if (s.lookahead + s.insert >= MIN_MATCH) {1553str = s.strstart - s.insert;1554s.ins_h = s.window[str];15551556/* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */1557s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + 1]) & s.hash_mask;1558//#if MIN_MATCH != 31559// Call update_hash() MIN_MATCH-3 more times1560//#endif1561while (s.insert) {1562/* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */1563s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH-1]) & s.hash_mask;15641565s.prev[str & s.w_mask] = s.head[s.ins_h];1566s.head[s.ins_h] = str;1567str++;1568s.insert--;1569if (s.lookahead + s.insert < MIN_MATCH) {1570break;1571}1572}1573}1574/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,1575* but this is not important since only literal bytes will be emitted.1576*/15771578} while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0);15791580/* If the WIN_INIT bytes after the end of the current data have never been1581* written, then zero those bytes in order to avoid memory check reports of1582* the use of uninitialized (or uninitialised as Julian writes) bytes by1583* the longest match routines. Update the high water mark for the next1584* time through here. WIN_INIT is set to MAX_MATCH since the longest match1585* routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.1586*/1587// if (s.high_water < s.window_size) {1588// var curr = s.strstart + s.lookahead;1589// var init = 0;1590//1591// if (s.high_water < curr) {1592// /* Previous high water mark below current data -- zero WIN_INIT1593// * bytes or up to end of window, whichever is less.1594// */1595// init = s.window_size - curr;1596// if (init > WIN_INIT)1597// init = WIN_INIT;1598// zmemzero(s->window + curr, (unsigned)init);1599// s->high_water = curr + init;1600// }1601// else if (s->high_water < (ulg)curr + WIN_INIT) {1602// /* High water mark at or above current data, but below current data1603// * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up1604// * to end of window, whichever is less.1605// */1606// init = (ulg)curr + WIN_INIT - s->high_water;1607// if (init > s->window_size - s->high_water)1608// init = s->window_size - s->high_water;1609// zmemzero(s->window + s->high_water, (unsigned)init);1610// s->high_water += init;1611// }1612// }1613//1614// Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,1615// "not enough room for search");1616}16171618/* ===========================================================================1619* Copy without compression as much as possible from the input stream, return1620* the current block state.1621* This function does not insert new strings in the dictionary since1622* uncompressible data is probably not useful. This function is used1623* only for the level=0 compression option.1624* NOTE: this function should be optimized to avoid extra copying from1625* window to pending_buf.1626*/1627function deflate_stored(s, flush) {1628/* Stored blocks are limited to 0xffff bytes, pending_buf is limited1629* to pending_buf_size, and each stored block has a 5 byte header:1630*/1631var max_block_size = 0xffff;16321633if (max_block_size > s.pending_buf_size - 5) {1634max_block_size = s.pending_buf_size - 5;1635}16361637/* Copy as much as possible from input to output: */1638for (;;) {1639/* Fill the window as much as possible: */1640if (s.lookahead <= 1) {16411642//Assert(s->strstart < s->w_size+MAX_DIST(s) ||1643// s->block_start >= (long)s->w_size, "slide too late");1644// if (!(s.strstart < s.w_size + (s.w_size - MIN_LOOKAHEAD) ||1645// s.block_start >= s.w_size)) {1646// throw new Error("slide too late");1647// }16481649fill_window(s);1650if (s.lookahead === 0 && flush === Z_NO_FLUSH) {1651return BS_NEED_MORE;1652}16531654if (s.lookahead === 0) {1655break;1656}1657/* flush the current block */1658}1659//Assert(s->block_start >= 0L, "block gone");1660// if (s.block_start < 0) throw new Error("block gone");16611662s.strstart += s.lookahead;1663s.lookahead = 0;16641665/* Emit a stored block if pending_buf will be full: */1666var max_start = s.block_start + max_block_size;16671668if (s.strstart === 0 || s.strstart >= max_start) {1669/* strstart == 0 is possible when wraparound on 16-bit machine */1670s.lookahead = s.strstart - max_start;1671s.strstart = max_start;1672/*** FLUSH_BLOCK(s, 0); ***/1673flush_block_only(s, false);1674if (s.strm.avail_out === 0) {1675return BS_NEED_MORE;1676}1677/***/167816791680}1681/* Flush if we may have to slide, otherwise block_start may become1682* negative and the data will be gone:1683*/1684if (s.strstart - s.block_start >= (s.w_size - MIN_LOOKAHEAD)) {1685/*** FLUSH_BLOCK(s, 0); ***/1686flush_block_only(s, false);1687if (s.strm.avail_out === 0) {1688return BS_NEED_MORE;1689}1690/***/1691}1692}16931694s.insert = 0;16951696if (flush === Z_FINISH) {1697/*** FLUSH_BLOCK(s, 1); ***/1698flush_block_only(s, true);1699if (s.strm.avail_out === 0) {1700return BS_FINISH_STARTED;1701}1702/***/1703return BS_FINISH_DONE;1704}17051706if (s.strstart > s.block_start) {1707/*** FLUSH_BLOCK(s, 0); ***/1708flush_block_only(s, false);1709if (s.strm.avail_out === 0) {1710return BS_NEED_MORE;1711}1712/***/1713}17141715return BS_NEED_MORE;1716}17171718/* ===========================================================================1719* Compress as much as possible from the input stream, return the current1720* block state.1721* This function does not perform lazy evaluation of matches and inserts1722* new strings in the dictionary only for unmatched strings or for short1723* matches. It is used only for the fast compression options.1724*/1725function deflate_fast(s, flush) {1726var hash_head; /* head of the hash chain */1727var bflush; /* set if current block must be flushed */17281729for (;;) {1730/* Make sure that we always have enough lookahead, except1731* at the end of the input file. We need MAX_MATCH bytes1732* for the next match, plus MIN_MATCH bytes to insert the1733* string following the next match.1734*/1735if (s.lookahead < MIN_LOOKAHEAD) {1736fill_window(s);1737if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {1738return BS_NEED_MORE;1739}1740if (s.lookahead === 0) {1741break; /* flush the current block */1742}1743}17441745/* Insert the string window[strstart .. strstart+2] in the1746* dictionary, and set hash_head to the head of the hash chain:1747*/1748hash_head = 0/*NIL*/;1749if (s.lookahead >= MIN_MATCH) {1750/*** INSERT_STRING(s, s.strstart, hash_head); ***/1751s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;1752hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];1753s.head[s.ins_h] = s.strstart;1754/***/1755}17561757/* Find the longest match, discarding those <= prev_length.1758* At this point we have always match_length < MIN_MATCH1759*/1760if (hash_head !== 0/*NIL*/ && ((s.strstart - hash_head) <= (s.w_size - MIN_LOOKAHEAD))) {1761/* To simplify the code, we prevent matches with the string1762* of window index 0 (in particular we have to avoid a match1763* of the string with itself at the start of the input file).1764*/1765s.match_length = longest_match(s, hash_head);1766/* longest_match() sets match_start */1767}1768if (s.match_length >= MIN_MATCH) {1769// check_match(s, s.strstart, s.match_start, s.match_length); // for debug only17701771/*** _tr_tally_dist(s, s.strstart - s.match_start,1772s.match_length - MIN_MATCH, bflush); ***/1773bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);17741775s.lookahead -= s.match_length;17761777/* Insert new strings in the hash table only if the match length1778* is not too large. This saves time but degrades compression.1779*/1780if (s.match_length <= s.max_lazy_match/*max_insert_length*/ && s.lookahead >= MIN_MATCH) {1781s.match_length--; /* string at strstart already in table */1782do {1783s.strstart++;1784/*** INSERT_STRING(s, s.strstart, hash_head); ***/1785s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;1786hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];1787s.head[s.ins_h] = s.strstart;1788/***/1789/* strstart never exceeds WSIZE-MAX_MATCH, so there are1790* always MIN_MATCH bytes ahead.1791*/1792} while (--s.match_length !== 0);1793s.strstart++;1794} else1795{1796s.strstart += s.match_length;1797s.match_length = 0;1798s.ins_h = s.window[s.strstart];1799/* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */1800s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + 1]) & s.hash_mask;18011802//#if MIN_MATCH != 31803// Call UPDATE_HASH() MIN_MATCH-3 more times1804//#endif1805/* If lookahead < MIN_MATCH, ins_h is garbage, but it does not1806* matter since it will be recomputed at next deflate call.1807*/1808}1809} else {1810/* No match, output a literal byte */1811//Tracevv((stderr,"%c", s.window[s.strstart]));1812/*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/1813bflush = trees._tr_tally(s, 0, s.window[s.strstart]);18141815s.lookahead--;1816s.strstart++;1817}1818if (bflush) {1819/*** FLUSH_BLOCK(s, 0); ***/1820flush_block_only(s, false);1821if (s.strm.avail_out === 0) {1822return BS_NEED_MORE;1823}1824/***/1825}1826}1827s.insert = ((s.strstart < (MIN_MATCH-1)) ? s.strstart : MIN_MATCH-1);1828if (flush === Z_FINISH) {1829/*** FLUSH_BLOCK(s, 1); ***/1830flush_block_only(s, true);1831if (s.strm.avail_out === 0) {1832return BS_FINISH_STARTED;1833}1834/***/1835return BS_FINISH_DONE;1836}1837if (s.last_lit) {1838/*** FLUSH_BLOCK(s, 0); ***/1839flush_block_only(s, false);1840if (s.strm.avail_out === 0) {1841return BS_NEED_MORE;1842}1843/***/1844}1845return BS_BLOCK_DONE;1846}18471848/* ===========================================================================1849* Same as above, but achieves better compression. We use a lazy1850* evaluation for matches: a match is finally adopted only if there is1851* no better match at the next window position.1852*/1853function deflate_slow(s, flush) {1854var hash_head; /* head of hash chain */1855var bflush; /* set if current block must be flushed */18561857var max_insert;18581859/* Process the input block. */1860for (;;) {1861/* Make sure that we always have enough lookahead, except1862* at the end of the input file. We need MAX_MATCH bytes1863* for the next match, plus MIN_MATCH bytes to insert the1864* string following the next match.1865*/1866if (s.lookahead < MIN_LOOKAHEAD) {1867fill_window(s);1868if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {1869return BS_NEED_MORE;1870}1871if (s.lookahead === 0) { break; } /* flush the current block */1872}18731874/* Insert the string window[strstart .. strstart+2] in the1875* dictionary, and set hash_head to the head of the hash chain:1876*/1877hash_head = 0/*NIL*/;1878if (s.lookahead >= MIN_MATCH) {1879/*** INSERT_STRING(s, s.strstart, hash_head); ***/1880s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;1881hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];1882s.head[s.ins_h] = s.strstart;1883/***/1884}18851886/* Find the longest match, discarding those <= prev_length.1887*/1888s.prev_length = s.match_length;1889s.prev_match = s.match_start;1890s.match_length = MIN_MATCH-1;18911892if (hash_head !== 0/*NIL*/ && s.prev_length < s.max_lazy_match &&1893s.strstart - hash_head <= (s.w_size-MIN_LOOKAHEAD)/*MAX_DIST(s)*/) {1894/* To simplify the code, we prevent matches with the string1895* of window index 0 (in particular we have to avoid a match1896* of the string with itself at the start of the input file).1897*/1898s.match_length = longest_match(s, hash_head);1899/* longest_match() sets match_start */19001901if (s.match_length <= 5 &&1902(s.strategy === Z_FILTERED || (s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096/*TOO_FAR*/))) {19031904/* If prev_match is also MIN_MATCH, match_start is garbage1905* but we will ignore the current match anyway.1906*/1907s.match_length = MIN_MATCH-1;1908}1909}1910/* If there was a match at the previous step and the current1911* match is not better, output the previous match:1912*/1913if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) {1914max_insert = s.strstart + s.lookahead - MIN_MATCH;1915/* Do not insert strings in hash table beyond this. */19161917//check_match(s, s.strstart-1, s.prev_match, s.prev_length);19181919/***_tr_tally_dist(s, s.strstart - 1 - s.prev_match,1920s.prev_length - MIN_MATCH, bflush);***/1921bflush = trees._tr_tally(s, s.strstart - 1- s.prev_match, s.prev_length - MIN_MATCH);1922/* Insert in hash table all strings up to the end of the match.1923* strstart-1 and strstart are already inserted. If there is not1924* enough lookahead, the last two strings are not inserted in1925* the hash table.1926*/1927s.lookahead -= s.prev_length-1;1928s.prev_length -= 2;1929do {1930if (++s.strstart <= max_insert) {1931/*** INSERT_STRING(s, s.strstart, hash_head); ***/1932s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;1933hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];1934s.head[s.ins_h] = s.strstart;1935/***/1936}1937} while (--s.prev_length !== 0);1938s.match_available = 0;1939s.match_length = MIN_MATCH-1;1940s.strstart++;19411942if (bflush) {1943/*** FLUSH_BLOCK(s, 0); ***/1944flush_block_only(s, false);1945if (s.strm.avail_out === 0) {1946return BS_NEED_MORE;1947}1948/***/1949}19501951} else if (s.match_available) {1952/* If there was no match at the previous position, output a1953* single literal. If there was a match but the current match1954* is longer, truncate the previous match to a single literal.1955*/1956//Tracevv((stderr,"%c", s->window[s->strstart-1]));1957/*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/1958bflush = trees._tr_tally(s, 0, s.window[s.strstart-1]);19591960if (bflush) {1961/*** FLUSH_BLOCK_ONLY(s, 0) ***/1962flush_block_only(s, false);1963/***/1964}1965s.strstart++;1966s.lookahead--;1967if (s.strm.avail_out === 0) {1968return BS_NEED_MORE;1969}1970} else {1971/* There is no previous match to compare with, wait for1972* the next step to decide.1973*/1974s.match_available = 1;1975s.strstart++;1976s.lookahead--;1977}1978}1979//Assert (flush != Z_NO_FLUSH, "no flush?");1980if (s.match_available) {1981//Tracevv((stderr,"%c", s->window[s->strstart-1]));1982/*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/1983bflush = trees._tr_tally(s, 0, s.window[s.strstart-1]);19841985s.match_available = 0;1986}1987s.insert = s.strstart < MIN_MATCH-1 ? s.strstart : MIN_MATCH-1;1988if (flush === Z_FINISH) {1989/*** FLUSH_BLOCK(s, 1); ***/1990flush_block_only(s, true);1991if (s.strm.avail_out === 0) {1992return BS_FINISH_STARTED;1993}1994/***/1995return BS_FINISH_DONE;1996}1997if (s.last_lit) {1998/*** FLUSH_BLOCK(s, 0); ***/1999flush_block_only(s, false);2000if (s.strm.avail_out === 0) {2001return BS_NEED_MORE;2002}2003/***/2004}20052006return BS_BLOCK_DONE;2007}200820092010/* ===========================================================================2011* For Z_RLE, simply look for runs of bytes, generate matches only of distance2012* one. Do not maintain a hash table. (It will be regenerated if this run of2013* deflate switches away from Z_RLE.)2014*/2015function deflate_rle(s, flush) {2016var bflush; /* set if current block must be flushed */2017var prev; /* byte at distance one to match */2018var scan, strend; /* scan goes up to strend for length of run */20192020var _win = s.window;20212022for (;;) {2023/* Make sure that we always have enough lookahead, except2024* at the end of the input file. We need MAX_MATCH bytes2025* for the longest run, plus one for the unrolled loop.2026*/2027if (s.lookahead <= MAX_MATCH) {2028fill_window(s);2029if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) {2030return BS_NEED_MORE;2031}2032if (s.lookahead === 0) { break; } /* flush the current block */2033}20342035/* See how many times the previous byte repeats */2036s.match_length = 0;2037if (s.lookahead >= MIN_MATCH && s.strstart > 0) {2038scan = s.strstart - 1;2039prev = _win[scan];2040if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) {2041strend = s.strstart + MAX_MATCH;2042do {2043/*jshint noempty:false*/2044} while (prev === _win[++scan] && prev === _win[++scan] &&2045prev === _win[++scan] && prev === _win[++scan] &&2046prev === _win[++scan] && prev === _win[++scan] &&2047prev === _win[++scan] && prev === _win[++scan] &&2048scan < strend);2049s.match_length = MAX_MATCH - (strend - scan);2050if (s.match_length > s.lookahead) {2051s.match_length = s.lookahead;2052}2053}2054//Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");2055}20562057/* Emit match if have run of MIN_MATCH or longer, else emit literal */2058if (s.match_length >= MIN_MATCH) {2059//check_match(s, s.strstart, s.strstart - 1, s.match_length);20602061/*** _tr_tally_dist(s, 1, s.match_length - MIN_MATCH, bflush); ***/2062bflush = trees._tr_tally(s, 1, s.match_length - MIN_MATCH);20632064s.lookahead -= s.match_length;2065s.strstart += s.match_length;2066s.match_length = 0;2067} else {2068/* No match, output a literal byte */2069//Tracevv((stderr,"%c", s->window[s->strstart]));2070/*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/2071bflush = trees._tr_tally(s, 0, s.window[s.strstart]);20722073s.lookahead--;2074s.strstart++;2075}2076if (bflush) {2077/*** FLUSH_BLOCK(s, 0); ***/2078flush_block_only(s, false);2079if (s.strm.avail_out === 0) {2080return BS_NEED_MORE;2081}2082/***/2083}2084}2085s.insert = 0;2086if (flush === Z_FINISH) {2087/*** FLUSH_BLOCK(s, 1); ***/2088flush_block_only(s, true);2089if (s.strm.avail_out === 0) {2090return BS_FINISH_STARTED;2091}2092/***/2093return BS_FINISH_DONE;2094}2095if (s.last_lit) {2096/*** FLUSH_BLOCK(s, 0); ***/2097flush_block_only(s, false);2098if (s.strm.avail_out === 0) {2099return BS_NEED_MORE;2100}2101/***/2102}2103return BS_BLOCK_DONE;2104}21052106/* ===========================================================================2107* For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.2108* (It will be regenerated if this run of deflate switches away from Huffman.)2109*/2110function deflate_huff(s, flush) {2111var bflush; /* set if current block must be flushed */21122113for (;;) {2114/* Make sure that we have a literal to write. */2115if (s.lookahead === 0) {2116fill_window(s);2117if (s.lookahead === 0) {2118if (flush === Z_NO_FLUSH) {2119return BS_NEED_MORE;2120}2121break; /* flush the current block */2122}2123}21242125/* Output a literal byte */2126s.match_length = 0;2127//Tracevv((stderr,"%c", s->window[s->strstart]));2128/*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/2129bflush = trees._tr_tally(s, 0, s.window[s.strstart]);2130s.lookahead--;2131s.strstart++;2132if (bflush) {2133/*** FLUSH_BLOCK(s, 0); ***/2134flush_block_only(s, false);2135if (s.strm.avail_out === 0) {2136return BS_NEED_MORE;2137}2138/***/2139}2140}2141s.insert = 0;2142if (flush === Z_FINISH) {2143/*** FLUSH_BLOCK(s, 1); ***/2144flush_block_only(s, true);2145if (s.strm.avail_out === 0) {2146return BS_FINISH_STARTED;2147}2148/***/2149return BS_FINISH_DONE;2150}2151if (s.last_lit) {2152/*** FLUSH_BLOCK(s, 0); ***/2153flush_block_only(s, false);2154if (s.strm.avail_out === 0) {2155return BS_NEED_MORE;2156}2157/***/2158}2159return BS_BLOCK_DONE;2160}21612162/* Values for max_lazy_match, good_match and max_chain_length, depending on2163* the desired pack level (0..9). The values given below have been tuned to2164* exclude worst case performance for pathological files. Better values may be2165* found for specific files.2166*/2167var Config = function (good_length, max_lazy, nice_length, max_chain, func) {2168this.good_length = good_length;2169this.max_lazy = max_lazy;2170this.nice_length = nice_length;2171this.max_chain = max_chain;2172this.func = func;2173};21742175var configuration_table;21762177configuration_table = [2178/* good lazy nice chain */2179new Config(0, 0, 0, 0, deflate_stored), /* 0 store only */2180new Config(4, 4, 8, 4, deflate_fast), /* 1 max speed, no lazy matches */2181new Config(4, 5, 16, 8, deflate_fast), /* 2 */2182new Config(4, 6, 32, 32, deflate_fast), /* 3 */21832184new Config(4, 4, 16, 16, deflate_slow), /* 4 lazy matches */2185new Config(8, 16, 32, 32, deflate_slow), /* 5 */2186new Config(8, 16, 128, 128, deflate_slow), /* 6 */2187new Config(8, 32, 128, 256, deflate_slow), /* 7 */2188new Config(32, 128, 258, 1024, deflate_slow), /* 8 */2189new Config(32, 258, 258, 4096, deflate_slow) /* 9 max compression */2190];219121922193/* ===========================================================================2194* Initialize the "longest match" routines for a new zlib stream2195*/2196function lm_init(s) {2197s.window_size = 2 * s.w_size;21982199/*** CLEAR_HASH(s); ***/2200zero(s.head); // Fill with NIL (= 0);22012202/* Set the default configuration parameters:2203*/2204s.max_lazy_match = configuration_table[s.level].max_lazy;2205s.good_match = configuration_table[s.level].good_length;2206s.nice_match = configuration_table[s.level].nice_length;2207s.max_chain_length = configuration_table[s.level].max_chain;22082209s.strstart = 0;2210s.block_start = 0;2211s.lookahead = 0;2212s.insert = 0;2213s.match_length = s.prev_length = MIN_MATCH - 1;2214s.match_available = 0;2215s.ins_h = 0;2216}221722182219function DeflateState() {2220this.strm = null; /* pointer back to this zlib stream */2221this.status = 0; /* as the name implies */2222this.pending_buf = null; /* output still pending */2223this.pending_buf_size = 0; /* size of pending_buf */2224this.pending_out = 0; /* next pending byte to output to the stream */2225this.pending = 0; /* nb of bytes in the pending buffer */2226this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */2227this.gzhead = null; /* gzip header information to write */2228this.gzindex = 0; /* where in extra, name, or comment */2229this.method = Z_DEFLATED; /* can only be DEFLATED */2230this.last_flush = -1; /* value of flush param for previous deflate call */22312232this.w_size = 0; /* LZ77 window size (32K by default) */2233this.w_bits = 0; /* log2(w_size) (8..16) */2234this.w_mask = 0; /* w_size - 1 */22352236this.window = null;2237/* Sliding window. Input bytes are read into the second half of the window,2238* and move to the first half later to keep a dictionary of at least wSize2239* bytes. With this organization, matches are limited to a distance of2240* wSize-MAX_MATCH bytes, but this ensures that IO is always2241* performed with a length multiple of the block size.2242*/22432244this.window_size = 0;2245/* Actual size of window: 2*wSize, except when the user input buffer2246* is directly used as sliding window.2247*/22482249this.prev = null;2250/* Link to older string with same hash index. To limit the size of this2251* array to 64K, this link is maintained only for the last 32K strings.2252* An index in this array is thus a window index modulo 32K.2253*/22542255this.head = null; /* Heads of the hash chains or NIL. */22562257this.ins_h = 0; /* hash index of string to be inserted */2258this.hash_size = 0; /* number of elements in hash table */2259this.hash_bits = 0; /* log2(hash_size) */2260this.hash_mask = 0; /* hash_size-1 */22612262this.hash_shift = 0;2263/* Number of bits by which ins_h must be shifted at each input2264* step. It must be such that after MIN_MATCH steps, the oldest2265* byte no longer takes part in the hash key, that is:2266* hash_shift * MIN_MATCH >= hash_bits2267*/22682269this.block_start = 0;2270/* Window position at the beginning of the current output block. Gets2271* negative when the window is moved backwards.2272*/22732274this.match_length = 0; /* length of best match */2275this.prev_match = 0; /* previous match */2276this.match_available = 0; /* set if previous match exists */2277this.strstart = 0; /* start of string to insert */2278this.match_start = 0; /* start of matching string */2279this.lookahead = 0; /* number of valid bytes ahead in window */22802281this.prev_length = 0;2282/* Length of the best match at previous step. Matches not greater than this2283* are discarded. This is used in the lazy match evaluation.2284*/22852286this.max_chain_length = 0;2287/* To speed up deflation, hash chains are never searched beyond this2288* length. A higher limit improves compression ratio but degrades the2289* speed.2290*/22912292this.max_lazy_match = 0;2293/* Attempt to find a better match only when the current match is strictly2294* smaller than this value. This mechanism is used only for compression2295* levels >= 4.2296*/2297// That's alias to max_lazy_match, don't use directly2298//this.max_insert_length = 0;2299/* Insert new strings in the hash table only if the match length is not2300* greater than this length. This saves time but degrades compression.2301* max_insert_length is used only for compression levels <= 3.2302*/23032304this.level = 0; /* compression level (1..9) */2305this.strategy = 0; /* favor or force Huffman coding*/23062307this.good_match = 0;2308/* Use a faster search when the previous match is longer than this */23092310this.nice_match = 0; /* Stop searching when current match exceeds this */23112312/* used by trees.c: */23132314/* Didn't use ct_data typedef below to suppress compiler warning */23152316// struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */2317// struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */2318// struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */23192320// Use flat array of DOUBLE size, with interleaved fata,2321// because JS does not support effective2322this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2);2323this.dyn_dtree = new utils.Buf16((2*D_CODES+1) * 2);2324this.bl_tree = new utils.Buf16((2*BL_CODES+1) * 2);2325zero(this.dyn_ltree);2326zero(this.dyn_dtree);2327zero(this.bl_tree);23282329this.l_desc = null; /* desc. for literal tree */2330this.d_desc = null; /* desc. for distance tree */2331this.bl_desc = null; /* desc. for bit length tree */23322333//ush bl_count[MAX_BITS+1];2334this.bl_count = new utils.Buf16(MAX_BITS+1);2335/* number of codes at each bit length for an optimal tree */23362337//int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */2338this.heap = new utils.Buf16(2*L_CODES+1); /* heap used to build the Huffman trees */2339zero(this.heap);23402341this.heap_len = 0; /* number of elements in the heap */2342this.heap_max = 0; /* element of largest frequency */2343/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.2344* The same heap array is used to build all trees.2345*/23462347this.depth = new utils.Buf16(2*L_CODES+1); //uch depth[2*L_CODES+1];2348zero(this.depth);2349/* Depth of each subtree used as tie breaker for trees of equal frequency2350*/23512352this.l_buf = 0; /* buffer index for literals or lengths */23532354this.lit_bufsize = 0;2355/* Size of match buffer for literals/lengths. There are 4 reasons for2356* limiting lit_bufsize to 64K:2357* - frequencies can be kept in 16 bit counters2358* - if compression is not successful for the first block, all input2359* data is still in the window so we can still emit a stored block even2360* when input comes from standard input. (This can also be done for2361* all blocks if lit_bufsize is not greater than 32K.)2362* - if compression is not successful for a file smaller than 64K, we can2363* even emit a stored file instead of a stored block (saving 5 bytes).2364* This is applicable only for zip (not gzip or zlib).2365* - creating new Huffman trees less frequently may not provide fast2366* adaptation to changes in the input data statistics. (Take for2367* example a binary file with poorly compressible code followed by2368* a highly compressible string table.) Smaller buffer sizes give2369* fast adaptation but have of course the overhead of transmitting2370* trees more frequently.2371* - I can't count above 42372*/23732374this.last_lit = 0; /* running index in l_buf */23752376this.d_buf = 0;2377/* Buffer index for distances. To simplify the code, d_buf and l_buf have2378* the same number of elements. To use different lengths, an extra flag2379* array would be necessary.2380*/23812382this.opt_len = 0; /* bit length of current block with optimal trees */2383this.static_len = 0; /* bit length of current block with static trees */2384this.matches = 0; /* number of string matches in current block */2385this.insert = 0; /* bytes at end of window left to insert */238623872388this.bi_buf = 0;2389/* Output buffer. bits are inserted starting at the bottom (least2390* significant bits).2391*/2392this.bi_valid = 0;2393/* Number of valid bits in bi_buf. All bits above the last valid bit2394* are always zero.2395*/23962397// Used for window memory init. We safely ignore it for JS. That makes2398// sense only for pointers and memory check tools.2399//this.high_water = 0;2400/* High water mark offset in window for initialized bytes -- bytes above2401* this are set to zero in order to avoid memory check warnings when2402* longest match routines access bytes past the input. This is then2403* updated to the new high water mark.2404*/2405}240624072408function deflateResetKeep(strm) {2409var s;24102411if (!strm || !strm.state) {2412return err(strm, Z_STREAM_ERROR);2413}24142415strm.total_in = strm.total_out = 0;2416strm.data_type = Z_UNKNOWN;24172418s = strm.state;2419s.pending = 0;2420s.pending_out = 0;24212422if (s.wrap < 0) {2423s.wrap = -s.wrap;2424/* was made negative by deflate(..., Z_FINISH); */2425}2426s.status = (s.wrap ? INIT_STATE : BUSY_STATE);2427strm.adler = (s.wrap === 2) ?24280 // crc32(0, Z_NULL, 0)2429:24301; // adler32(0, Z_NULL, 0)2431s.last_flush = Z_NO_FLUSH;2432trees._tr_init(s);2433return Z_OK;2434}243524362437function deflateReset(strm) {2438var ret = deflateResetKeep(strm);2439if (ret === Z_OK) {2440lm_init(strm.state);2441}2442return ret;2443}244424452446function deflateSetHeader(strm, head) {2447if (!strm || !strm.state) { return Z_STREAM_ERROR; }2448if (strm.state.wrap !== 2) { return Z_STREAM_ERROR; }2449strm.state.gzhead = head;2450return Z_OK;2451}245224532454function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {2455if (!strm) { // === Z_NULL2456return Z_STREAM_ERROR;2457}2458var wrap = 1;24592460if (level === Z_DEFAULT_COMPRESSION) {2461level = 6;2462}24632464if (windowBits < 0) { /* suppress zlib wrapper */2465wrap = 0;2466windowBits = -windowBits;2467}24682469else if (windowBits > 15) {2470wrap = 2; /* write gzip wrapper instead */2471windowBits -= 16;2472}247324742475if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED ||2476windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||2477strategy < 0 || strategy > Z_FIXED) {2478return err(strm, Z_STREAM_ERROR);2479}248024812482if (windowBits === 8) {2483windowBits = 9;2484}2485/* until 256-byte window bug fixed */24862487var s = new DeflateState();24882489strm.state = s;2490s.strm = strm;24912492s.wrap = wrap;2493s.gzhead = null;2494s.w_bits = windowBits;2495s.w_size = 1 << s.w_bits;2496s.w_mask = s.w_size - 1;24972498s.hash_bits = memLevel + 7;2499s.hash_size = 1 << s.hash_bits;2500s.hash_mask = s.hash_size - 1;2501s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH);25022503s.window = new utils.Buf8(s.w_size * 2);2504s.head = new utils.Buf16(s.hash_size);2505s.prev = new utils.Buf16(s.w_size);25062507// Don't need mem init magic for JS.2508//s.high_water = 0; /* nothing written to s->window yet */25092510s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */25112512s.pending_buf_size = s.lit_bufsize * 4;2513s.pending_buf = new utils.Buf8(s.pending_buf_size);25142515s.d_buf = s.lit_bufsize >> 1;2516s.l_buf = (1 + 2) * s.lit_bufsize;25172518s.level = level;2519s.strategy = strategy;2520s.method = method;25212522return deflateReset(strm);2523}25242525function deflateInit(strm, level) {2526return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);2527}252825292530function deflate(strm, flush) {2531var old_flush, s;2532var beg, val; // for gzip header write only25332534if (!strm || !strm.state ||2535flush > Z_BLOCK || flush < 0) {2536return strm ? err(strm, Z_STREAM_ERROR) : Z_STREAM_ERROR;2537}25382539s = strm.state;25402541if (!strm.output ||2542(!strm.input && strm.avail_in !== 0) ||2543(s.status === FINISH_STATE && flush !== Z_FINISH)) {2544return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR);2545}25462547s.strm = strm; /* just in case */2548old_flush = s.last_flush;2549s.last_flush = flush;25502551/* Write the header */2552if (s.status === INIT_STATE) {25532554if (s.wrap === 2) { // GZIP header2555strm.adler = 0; //crc32(0L, Z_NULL, 0);2556put_byte(s, 31);2557put_byte(s, 139);2558put_byte(s, 8);2559if (!s.gzhead) { // s->gzhead == Z_NULL2560put_byte(s, 0);2561put_byte(s, 0);2562put_byte(s, 0);2563put_byte(s, 0);2564put_byte(s, 0);2565put_byte(s, s.level === 9 ? 2 :2566(s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?25674 : 0));2568put_byte(s, OS_CODE);2569s.status = BUSY_STATE;2570}2571else {2572put_byte(s, (s.gzhead.text ? 1 : 0) +2573(s.gzhead.hcrc ? 2 : 0) +2574(!s.gzhead.extra ? 0 : 4) +2575(!s.gzhead.name ? 0 : 8) +2576(!s.gzhead.comment ? 0 : 16)2577);2578put_byte(s, s.gzhead.time & 0xff);2579put_byte(s, (s.gzhead.time >> 8) & 0xff);2580put_byte(s, (s.gzhead.time >> 16) & 0xff);2581put_byte(s, (s.gzhead.time >> 24) & 0xff);2582put_byte(s, s.level === 9 ? 2 :2583(s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?25844 : 0));2585put_byte(s, s.gzhead.os & 0xff);2586if (s.gzhead.extra && s.gzhead.extra.length) {2587put_byte(s, s.gzhead.extra.length & 0xff);2588put_byte(s, (s.gzhead.extra.length >> 8) & 0xff);2589}2590if (s.gzhead.hcrc) {2591strm.adler = crc32(strm.adler, s.pending_buf, s.pending, 0);2592}2593s.gzindex = 0;2594s.status = EXTRA_STATE;2595}2596}2597else // DEFLATE header2598{2599var header = (Z_DEFLATED + ((s.w_bits - 8) << 4)) << 8;2600var level_flags = -1;26012602if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) {2603level_flags = 0;2604} else if (s.level < 6) {2605level_flags = 1;2606} else if (s.level === 6) {2607level_flags = 2;2608} else {2609level_flags = 3;2610}2611header |= (level_flags << 6);2612if (s.strstart !== 0) { header |= PRESET_DICT; }2613header += 31 - (header % 31);26142615s.status = BUSY_STATE;2616putShortMSB(s, header);26172618/* Save the adler32 of the preset dictionary: */2619if (s.strstart !== 0) {2620putShortMSB(s, strm.adler >>> 16);2621putShortMSB(s, strm.adler & 0xffff);2622}2623strm.adler = 1; // adler32(0L, Z_NULL, 0);2624}2625}26262627//#ifdef GZIP2628if (s.status === EXTRA_STATE) {2629if (s.gzhead.extra/* != Z_NULL*/) {2630beg = s.pending; /* start of bytes to update crc */26312632while (s.gzindex < (s.gzhead.extra.length & 0xffff)) {2633if (s.pending === s.pending_buf_size) {2634if (s.gzhead.hcrc && s.pending > beg) {2635strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);2636}2637flush_pending(strm);2638beg = s.pending;2639if (s.pending === s.pending_buf_size) {2640break;2641}2642}2643put_byte(s, s.gzhead.extra[s.gzindex] & 0xff);2644s.gzindex++;2645}2646if (s.gzhead.hcrc && s.pending > beg) {2647strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);2648}2649if (s.gzindex === s.gzhead.extra.length) {2650s.gzindex = 0;2651s.status = NAME_STATE;2652}2653}2654else {2655s.status = NAME_STATE;2656}2657}2658if (s.status === NAME_STATE) {2659if (s.gzhead.name/* != Z_NULL*/) {2660beg = s.pending; /* start of bytes to update crc */2661//int val;26622663do {2664if (s.pending === s.pending_buf_size) {2665if (s.gzhead.hcrc && s.pending > beg) {2666strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);2667}2668flush_pending(strm);2669beg = s.pending;2670if (s.pending === s.pending_buf_size) {2671val = 1;2672break;2673}2674}2675// JS specific: little magic to add zero terminator to end of string2676if (s.gzindex < s.gzhead.name.length) {2677val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff;2678} else {2679val = 0;2680}2681put_byte(s, val);2682} while (val !== 0);26832684if (s.gzhead.hcrc && s.pending > beg){2685strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);2686}2687if (val === 0) {2688s.gzindex = 0;2689s.status = COMMENT_STATE;2690}2691}2692else {2693s.status = COMMENT_STATE;2694}2695}2696if (s.status === COMMENT_STATE) {2697if (s.gzhead.comment/* != Z_NULL*/) {2698beg = s.pending; /* start of bytes to update crc */2699//int val;27002701do {2702if (s.pending === s.pending_buf_size) {2703if (s.gzhead.hcrc && s.pending > beg) {2704strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);2705}2706flush_pending(strm);2707beg = s.pending;2708if (s.pending === s.pending_buf_size) {2709val = 1;2710break;2711}2712}2713// JS specific: little magic to add zero terminator to end of string2714if (s.gzindex < s.gzhead.comment.length) {2715val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff;2716} else {2717val = 0;2718}2719put_byte(s, val);2720} while (val !== 0);27212722if (s.gzhead.hcrc && s.pending > beg) {2723strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);2724}2725if (val === 0) {2726s.status = HCRC_STATE;2727}2728}2729else {2730s.status = HCRC_STATE;2731}2732}2733if (s.status === HCRC_STATE) {2734if (s.gzhead.hcrc) {2735if (s.pending + 2 > s.pending_buf_size) {2736flush_pending(strm);2737}2738if (s.pending + 2 <= s.pending_buf_size) {2739put_byte(s, strm.adler & 0xff);2740put_byte(s, (strm.adler >> 8) & 0xff);2741strm.adler = 0; //crc32(0L, Z_NULL, 0);2742s.status = BUSY_STATE;2743}2744}2745else {2746s.status = BUSY_STATE;2747}2748}2749//#endif27502751/* Flush as much pending output as possible */2752if (s.pending !== 0) {2753flush_pending(strm);2754if (strm.avail_out === 0) {2755/* Since avail_out is 0, deflate will be called again with2756* more output space, but possibly with both pending and2757* avail_in equal to zero. There won't be anything to do,2758* but this is not an error situation so make sure we2759* return OK instead of BUF_ERROR at next call of deflate:2760*/2761s.last_flush = -1;2762return Z_OK;2763}27642765/* Make sure there is something to do and avoid duplicate consecutive2766* flushes. For repeated and useless calls with Z_FINISH, we keep2767* returning Z_STREAM_END instead of Z_BUF_ERROR.2768*/2769} else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) &&2770flush !== Z_FINISH) {2771return err(strm, Z_BUF_ERROR);2772}27732774/* User must not provide more input after the first FINISH: */2775if (s.status === FINISH_STATE && strm.avail_in !== 0) {2776return err(strm, Z_BUF_ERROR);2777}27782779/* Start a new block or continue the current one.2780*/2781if (strm.avail_in !== 0 || s.lookahead !== 0 ||2782(flush !== Z_NO_FLUSH && s.status !== FINISH_STATE)) {2783var bstate = (s.strategy === Z_HUFFMAN_ONLY) ? deflate_huff(s, flush) :2784(s.strategy === Z_RLE ? deflate_rle(s, flush) :2785configuration_table[s.level].func(s, flush));27862787if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) {2788s.status = FINISH_STATE;2789}2790if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) {2791if (strm.avail_out === 0) {2792s.last_flush = -1;2793/* avoid BUF_ERROR next call, see above */2794}2795return Z_OK;2796/* If flush != Z_NO_FLUSH && avail_out == 0, the next call2797* of deflate should use the same flush parameter to make sure2798* that the flush is complete. So we don't have to output an2799* empty block here, this will be done at next call. This also2800* ensures that for a very small output buffer, we emit at most2801* one empty block.2802*/2803}2804if (bstate === BS_BLOCK_DONE) {2805if (flush === Z_PARTIAL_FLUSH) {2806trees._tr_align(s);2807}2808else if (flush !== Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */28092810trees._tr_stored_block(s, 0, 0, false);2811/* For a full flush, this empty block will be recognized2812* as a special marker by inflate_sync().2813*/2814if (flush === Z_FULL_FLUSH) {2815/*** CLEAR_HASH(s); ***/ /* forget history */2816zero(s.head); // Fill with NIL (= 0);28172818if (s.lookahead === 0) {2819s.strstart = 0;2820s.block_start = 0;2821s.insert = 0;2822}2823}2824}2825flush_pending(strm);2826if (strm.avail_out === 0) {2827s.last_flush = -1; /* avoid BUF_ERROR at next call, see above */2828return Z_OK;2829}2830}2831}2832//Assert(strm->avail_out > 0, "bug2");2833//if (strm.avail_out <= 0) { throw new Error("bug2");}28342835if (flush !== Z_FINISH) { return Z_OK; }2836if (s.wrap <= 0) { return Z_STREAM_END; }28372838/* Write the trailer */2839if (s.wrap === 2) {2840put_byte(s, strm.adler & 0xff);2841put_byte(s, (strm.adler >> 8) & 0xff);2842put_byte(s, (strm.adler >> 16) & 0xff);2843put_byte(s, (strm.adler >> 24) & 0xff);2844put_byte(s, strm.total_in & 0xff);2845put_byte(s, (strm.total_in >> 8) & 0xff);2846put_byte(s, (strm.total_in >> 16) & 0xff);2847put_byte(s, (strm.total_in >> 24) & 0xff);2848}2849else2850{2851putShortMSB(s, strm.adler >>> 16);2852putShortMSB(s, strm.adler & 0xffff);2853}28542855flush_pending(strm);2856/* If avail_out is zero, the application will call deflate again2857* to flush the rest.2858*/2859if (s.wrap > 0) { s.wrap = -s.wrap; }2860/* write the trailer only once! */2861return s.pending !== 0 ? Z_OK : Z_STREAM_END;2862}28632864function deflateEnd(strm) {2865var status;28662867if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {2868return Z_STREAM_ERROR;2869}28702871status = strm.state.status;2872if (status !== INIT_STATE &&2873status !== EXTRA_STATE &&2874status !== NAME_STATE &&2875status !== COMMENT_STATE &&2876status !== HCRC_STATE &&2877status !== BUSY_STATE &&2878status !== FINISH_STATE2879) {2880return err(strm, Z_STREAM_ERROR);2881}28822883strm.state = null;28842885return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK;2886}28872888/* =========================================================================2889* Copy the source state to the destination state2890*/2891//function deflateCopy(dest, source) {2892//2893//}28942895exports.deflateInit = deflateInit;2896exports.deflateInit2 = deflateInit2;2897exports.deflateReset = deflateReset;2898exports.deflateResetKeep = deflateResetKeep;2899exports.deflateSetHeader = deflateSetHeader;2900exports.deflate = deflate;2901exports.deflateEnd = deflateEnd;2902exports.deflateInfo = 'pako deflate (from Nodeca project)';29032904/* Not implemented2905exports.deflateBound = deflateBound;2906exports.deflateCopy = deflateCopy;2907exports.deflateSetDictionary = deflateSetDictionary;2908exports.deflateParams = deflateParams;2909exports.deflatePending = deflatePending;2910exports.deflatePrime = deflatePrime;2911exports.deflateTune = deflateTune;2912*/2913},{"../utils/common":3,"./adler32":5,"./crc32":7,"./messages":13,"./trees":14}],9:[function(require,module,exports){2914'use strict';291529162917function GZheader() {2918/* true if compressed data believed to be text */2919this.text = 0;2920/* modification time */2921this.time = 0;2922/* extra flags (not used when writing a gzip file) */2923this.xflags = 0;2924/* operating system */2925this.os = 0;2926/* pointer to extra field or Z_NULL if none */2927this.extra = null;2928/* extra field length (valid if extra != Z_NULL) */2929this.extra_len = 0; // Actually, we don't need it in JS,2930// but leave for few code modifications29312932//2933// Setup limits is not necessary because in js we should not preallocate memory2934// for inflate use constant limit in 65536 bytes2935//29362937/* space at extra (only when reading header) */2938// this.extra_max = 0;2939/* pointer to zero-terminated file name or Z_NULL */2940this.name = '';2941/* space at name (only when reading header) */2942// this.name_max = 0;2943/* pointer to zero-terminated comment or Z_NULL */2944this.comment = '';2945/* space at comment (only when reading header) */2946// this.comm_max = 0;2947/* true if there was or will be a header crc */2948this.hcrc = 0;2949/* true when done reading gzip header (not used when writing a gzip file) */2950this.done = false;2951}29522953module.exports = GZheader;2954},{}],10:[function(require,module,exports){2955'use strict';29562957// See state defs from inflate.js2958var BAD = 30; /* got a data error -- remain here until reset */2959var TYPE = 12; /* i: waiting for type bits, including last-flag bit */29602961/*2962Decode literal, length, and distance codes and write out the resulting2963literal and match bytes until either not enough input or output is2964available, an end-of-block is encountered, or a data error is encountered.2965When large enough input and output buffers are supplied to inflate(), for2966example, a 16K input buffer and a 64K output buffer, more than 95% of the2967inflate execution time is spent in this routine.29682969Entry assumptions:29702971state.mode === LEN2972strm.avail_in >= 62973strm.avail_out >= 2582974start >= strm.avail_out2975state.bits < 829762977On return, state.mode is one of:29782979LEN -- ran out of enough output space or enough available input2980TYPE -- reached end of block code, inflate() to interpret next block2981BAD -- error in block data29822983Notes:29842985- The maximum input bits used by a length/distance pair is 15 bits for the2986length code, 5 bits for the length extra, 15 bits for the distance code,2987and 13 bits for the distance extra. This totals 48 bits, or six bytes.2988Therefore if strm.avail_in >= 6, then there is enough input to avoid2989checking for available input while decoding.29902991- The maximum bytes that a single length/distance pair can output is 2582992bytes, which is the maximum length that can be coded. inflate_fast()2993requires strm.avail_out >= 258 for each loop to avoid checking for2994output space.2995*/2996module.exports = function inflate_fast(strm, start) {2997var state;2998var _in; /* local strm.input */2999var last; /* have enough input while in < last */3000var _out; /* local strm.output */3001var beg; /* inflate()'s initial strm.output */3002var end; /* while out < end, enough space available */3003//#ifdef INFLATE_STRICT3004var dmax; /* maximum distance from zlib header */3005//#endif3006var wsize; /* window size or zero if not using window */3007var whave; /* valid bytes in the window */3008var wnext; /* window write index */3009var window; /* allocated sliding window, if wsize != 0 */3010var hold; /* local strm.hold */3011var bits; /* local strm.bits */3012var lcode; /* local strm.lencode */3013var dcode; /* local strm.distcode */3014var lmask; /* mask for first level of length codes */3015var dmask; /* mask for first level of distance codes */3016var here; /* retrieved table entry */3017var op; /* code bits, operation, extra bits, or */3018/* window position, window bytes to copy */3019var len; /* match length, unused bytes */3020var dist; /* match distance */3021var from; /* where to copy match from */3022var from_source;302330243025var input, output; // JS specific, because we have no pointers30263027/* copy state to local variables */3028state = strm.state;3029//here = state.here;3030_in = strm.next_in;3031input = strm.input;3032last = _in + (strm.avail_in - 5);3033_out = strm.next_out;3034output = strm.output;3035beg = _out - (start - strm.avail_out);3036end = _out + (strm.avail_out - 257);3037//#ifdef INFLATE_STRICT3038dmax = state.dmax;3039//#endif3040wsize = state.wsize;3041whave = state.whave;3042wnext = state.wnext;3043window = state.window;3044hold = state.hold;3045bits = state.bits;3046lcode = state.lencode;3047dcode = state.distcode;3048lmask = (1 << state.lenbits) - 1;3049dmask = (1 << state.distbits) - 1;305030513052/* decode literals and length/distances until end-of-block or not enough3053input data or output space */30543055top:3056do {3057if (bits < 15) {3058hold += input[_in++] << bits;3059bits += 8;3060hold += input[_in++] << bits;3061bits += 8;3062}30633064here = lcode[hold & lmask];30653066dolen:3067for (;;) { // Goto emulation3068op = here >>> 24/*here.bits*/;3069hold >>>= op;3070bits -= op;3071op = (here >>> 16) & 0xff/*here.op*/;3072if (op === 0) { /* literal */3073//Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?3074// "inflate: literal '%c'\n" :3075// "inflate: literal 0x%02x\n", here.val));3076output[_out++] = here & 0xffff/*here.val*/;3077}3078else if (op & 16) { /* length base */3079len = here & 0xffff/*here.val*/;3080op &= 15; /* number of extra bits */3081if (op) {3082if (bits < op) {3083hold += input[_in++] << bits;3084bits += 8;3085}3086len += hold & ((1 << op) - 1);3087hold >>>= op;3088bits -= op;3089}3090//Tracevv((stderr, "inflate: length %u\n", len));3091if (bits < 15) {3092hold += input[_in++] << bits;3093bits += 8;3094hold += input[_in++] << bits;3095bits += 8;3096}3097here = dcode[hold & dmask];30983099dodist:3100for (;;) { // goto emulation3101op = here >>> 24/*here.bits*/;3102hold >>>= op;3103bits -= op;3104op = (here >>> 16) & 0xff/*here.op*/;31053106if (op & 16) { /* distance base */3107dist = here & 0xffff/*here.val*/;3108op &= 15; /* number of extra bits */3109if (bits < op) {3110hold += input[_in++] << bits;3111bits += 8;3112if (bits < op) {3113hold += input[_in++] << bits;3114bits += 8;3115}3116}3117dist += hold & ((1 << op) - 1);3118//#ifdef INFLATE_STRICT3119if (dist > dmax) {3120strm.msg = 'invalid distance too far back';3121state.mode = BAD;3122break top;3123}3124//#endif3125hold >>>= op;3126bits -= op;3127//Tracevv((stderr, "inflate: distance %u\n", dist));3128op = _out - beg; /* max distance in output */3129if (dist > op) { /* see if copy from window */3130op = dist - op; /* distance back in window */3131if (op > whave) {3132if (state.sane) {3133strm.msg = 'invalid distance too far back';3134state.mode = BAD;3135break top;3136}31373138// (!) This block is disabled in zlib defailts,3139// don't enable it for binary compatibility3140//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR3141// if (len <= op - whave) {3142// do {3143// output[_out++] = 0;3144// } while (--len);3145// continue top;3146// }3147// len -= op - whave;3148// do {3149// output[_out++] = 0;3150// } while (--op > whave);3151// if (op === 0) {3152// from = _out - dist;3153// do {3154// output[_out++] = output[from++];3155// } while (--len);3156// continue top;3157// }3158//#endif3159}3160from = 0; // window index3161from_source = window;3162if (wnext === 0) { /* very common case */3163from += wsize - op;3164if (op < len) { /* some from window */3165len -= op;3166do {3167output[_out++] = window[from++];3168} while (--op);3169from = _out - dist; /* rest from output */3170from_source = output;3171}3172}3173else if (wnext < op) { /* wrap around window */3174from += wsize + wnext - op;3175op -= wnext;3176if (op < len) { /* some from end of window */3177len -= op;3178do {3179output[_out++] = window[from++];3180} while (--op);3181from = 0;3182if (wnext < len) { /* some from start of window */3183op = wnext;3184len -= op;3185do {3186output[_out++] = window[from++];3187} while (--op);3188from = _out - dist; /* rest from output */3189from_source = output;3190}3191}3192}3193else { /* contiguous in window */3194from += wnext - op;3195if (op < len) { /* some from window */3196len -= op;3197do {3198output[_out++] = window[from++];3199} while (--op);3200from = _out - dist; /* rest from output */3201from_source = output;3202}3203}3204while (len > 2) {3205output[_out++] = from_source[from++];3206output[_out++] = from_source[from++];3207output[_out++] = from_source[from++];3208len -= 3;3209}3210if (len) {3211output[_out++] = from_source[from++];3212if (len > 1) {3213output[_out++] = from_source[from++];3214}3215}3216}3217else {3218from = _out - dist; /* copy direct from output */3219do { /* minimum length is three */3220output[_out++] = output[from++];3221output[_out++] = output[from++];3222output[_out++] = output[from++];3223len -= 3;3224} while (len > 2);3225if (len) {3226output[_out++] = output[from++];3227if (len > 1) {3228output[_out++] = output[from++];3229}3230}3231}3232}3233else if ((op & 64) === 0) { /* 2nd level distance code */3234here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];3235continue dodist;3236}3237else {3238strm.msg = 'invalid distance code';3239state.mode = BAD;3240break top;3241}32423243break; // need to emulate goto via "continue"3244}3245}3246else if ((op & 64) === 0) { /* 2nd level length code */3247here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];3248continue dolen;3249}3250else if (op & 32) { /* end-of-block */3251//Tracevv((stderr, "inflate: end of block\n"));3252state.mode = TYPE;3253break top;3254}3255else {3256strm.msg = 'invalid literal/length code';3257state.mode = BAD;3258break top;3259}32603261break; // need to emulate goto via "continue"3262}3263} while (_in < last && _out < end);32643265/* return unused bytes (on entry, bits < 8, so in won't go too far back) */3266len = bits >> 3;3267_in -= len;3268bits -= len << 3;3269hold &= (1 << bits) - 1;32703271/* update state and return */3272strm.next_in = _in;3273strm.next_out = _out;3274strm.avail_in = (_in < last ? 5 + (last - _in) : 5 - (_in - last));3275strm.avail_out = (_out < end ? 257 + (end - _out) : 257 - (_out - end));3276state.hold = hold;3277state.bits = bits;3278return;3279};32803281},{}],11:[function(require,module,exports){3282'use strict';328332843285var utils = require('../utils/common');3286var adler32 = require('./adler32');3287var crc32 = require('./crc32');3288var inflate_fast = require('./inffast');3289var inflate_table = require('./inftrees');32903291var CODES = 0;3292var LENS = 1;3293var DISTS = 2;32943295/* Public constants ==========================================================*/3296/* ===========================================================================*/329732983299/* Allowed flush values; see deflate() and inflate() below for details */3300//var Z_NO_FLUSH = 0;3301//var Z_PARTIAL_FLUSH = 1;3302//var Z_SYNC_FLUSH = 2;3303//var Z_FULL_FLUSH = 3;3304var Z_FINISH = 4;3305var Z_BLOCK = 5;3306var Z_TREES = 6;330733083309/* Return codes for the compression/decompression functions. Negative values3310* are errors, positive values are used for special but normal events.3311*/3312var Z_OK = 0;3313var Z_STREAM_END = 1;3314var Z_NEED_DICT = 2;3315//var Z_ERRNO = -1;3316var Z_STREAM_ERROR = -2;3317var Z_DATA_ERROR = -3;3318var Z_MEM_ERROR = -4;3319var Z_BUF_ERROR = -5;3320//var Z_VERSION_ERROR = -6;33213322/* The deflate compression method */3323var Z_DEFLATED = 8;332433253326/* STATES ====================================================================*/3327/* ===========================================================================*/332833293330var HEAD = 1; /* i: waiting for magic header */3331var FLAGS = 2; /* i: waiting for method and flags (gzip) */3332var TIME = 3; /* i: waiting for modification time (gzip) */3333var OS = 4; /* i: waiting for extra flags and operating system (gzip) */3334var EXLEN = 5; /* i: waiting for extra length (gzip) */3335var EXTRA = 6; /* i: waiting for extra bytes (gzip) */3336var NAME = 7; /* i: waiting for end of file name (gzip) */3337var COMMENT = 8; /* i: waiting for end of comment (gzip) */3338var HCRC = 9; /* i: waiting for header crc (gzip) */3339var DICTID = 10; /* i: waiting for dictionary check value */3340var DICT = 11; /* waiting for inflateSetDictionary() call */3341var TYPE = 12; /* i: waiting for type bits, including last-flag bit */3342var TYPEDO = 13; /* i: same, but skip check to exit inflate on new block */3343var STORED = 14; /* i: waiting for stored size (length and complement) */3344var COPY_ = 15; /* i/o: same as COPY below, but only first time in */3345var COPY = 16; /* i/o: waiting for input or output to copy stored block */3346var TABLE = 17; /* i: waiting for dynamic block table lengths */3347var LENLENS = 18; /* i: waiting for code length code lengths */3348var CODELENS = 19; /* i: waiting for length/lit and distance code lengths */3349var LEN_ = 20; /* i: same as LEN below, but only first time in */3350var LEN = 21; /* i: waiting for length/lit/eob code */3351var LENEXT = 22; /* i: waiting for length extra bits */3352var DIST = 23; /* i: waiting for distance code */3353var DISTEXT = 24; /* i: waiting for distance extra bits */3354var MATCH = 25; /* o: waiting for output space to copy string */3355var LIT = 26; /* o: waiting for output space to write literal */3356var CHECK = 27; /* i: waiting for 32-bit check value */3357var LENGTH = 28; /* i: waiting for 32-bit length (gzip) */3358var DONE = 29; /* finished check, done -- remain here until reset */3359var BAD = 30; /* got a data error -- remain here until reset */3360var MEM = 31; /* got an inflate() memory error -- remain here until reset */3361var SYNC = 32; /* looking for synchronization bytes to restart inflate() */33623363/* ===========================================================================*/3364336533663367var ENOUGH_LENS = 852;3368var ENOUGH_DISTS = 592;3369//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);33703371var MAX_WBITS = 15;3372/* 32K LZ77 window */3373var DEF_WBITS = MAX_WBITS;337433753376function ZSWAP32(q) {3377return (((q >>> 24) & 0xff) +3378((q >>> 8) & 0xff00) +3379((q & 0xff00) << 8) +3380((q & 0xff) << 24));3381}338233833384function InflateState() {3385this.mode = 0; /* current inflate mode */3386this.last = false; /* true if processing last block */3387this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */3388this.havedict = false; /* true if dictionary provided */3389this.flags = 0; /* gzip header method and flags (0 if zlib) */3390this.dmax = 0; /* zlib header max distance (INFLATE_STRICT) */3391this.check = 0; /* protected copy of check value */3392this.total = 0; /* protected copy of output count */3393// TODO: may be {}3394this.head = null; /* where to save gzip header information */33953396/* sliding window */3397this.wbits = 0; /* log base 2 of requested window size */3398this.wsize = 0; /* window size or zero if not using window */3399this.whave = 0; /* valid bytes in the window */3400this.wnext = 0; /* window write index */3401this.window = null; /* allocated sliding window, if needed */34023403/* bit accumulator */3404this.hold = 0; /* input bit accumulator */3405this.bits = 0; /* number of bits in "in" */34063407/* for string and stored block copying */3408this.length = 0; /* literal or length of data to copy */3409this.offset = 0; /* distance back to copy string from */34103411/* for table and code decoding */3412this.extra = 0; /* extra bits needed */34133414/* fixed and dynamic code tables */3415this.lencode = null; /* starting table for length/literal codes */3416this.distcode = null; /* starting table for distance codes */3417this.lenbits = 0; /* index bits for lencode */3418this.distbits = 0; /* index bits for distcode */34193420/* dynamic table building */3421this.ncode = 0; /* number of code length code lengths */3422this.nlen = 0; /* number of length code lengths */3423this.ndist = 0; /* number of distance code lengths */3424this.have = 0; /* number of code lengths in lens[] */3425this.next = null; /* next available space in codes[] */34263427this.lens = new utils.Buf16(320); /* temporary storage for code lengths */3428this.work = new utils.Buf16(288); /* work area for code table building */34293430/*3431because we don't have pointers in js, we use lencode and distcode directly3432as buffers so we don't need codes3433*/3434//this.codes = new utils.Buf32(ENOUGH); /* space for code tables */3435this.lendyn = null; /* dynamic table for length/literal codes (JS specific) */3436this.distdyn = null; /* dynamic table for distance codes (JS specific) */3437this.sane = 0; /* if false, allow invalid distance too far */3438this.back = 0; /* bits back of last unprocessed length/lit */3439this.was = 0; /* initial length of match */3440}34413442function inflateResetKeep(strm) {3443var state;34443445if (!strm || !strm.state) { return Z_STREAM_ERROR; }3446state = strm.state;3447strm.total_in = strm.total_out = state.total = 0;3448strm.msg = ''; /*Z_NULL*/3449if (state.wrap) { /* to support ill-conceived Java test suite */3450strm.adler = state.wrap & 1;3451}3452state.mode = HEAD;3453state.last = 0;3454state.havedict = 0;3455state.dmax = 32768;3456state.head = null/*Z_NULL*/;3457state.hold = 0;3458state.bits = 0;3459//state.lencode = state.distcode = state.next = state.codes;3460state.lencode = state.lendyn = new utils.Buf32(ENOUGH_LENS);3461state.distcode = state.distdyn = new utils.Buf32(ENOUGH_DISTS);34623463state.sane = 1;3464state.back = -1;3465//Tracev((stderr, "inflate: reset\n"));3466return Z_OK;3467}34683469function inflateReset(strm) {3470var state;34713472if (!strm || !strm.state) { return Z_STREAM_ERROR; }3473state = strm.state;3474state.wsize = 0;3475state.whave = 0;3476state.wnext = 0;3477return inflateResetKeep(strm);34783479}34803481function inflateReset2(strm, windowBits) {3482var wrap;3483var state;34843485/* get the state */3486if (!strm || !strm.state) { return Z_STREAM_ERROR; }3487state = strm.state;34883489/* extract wrap request from windowBits parameter */3490if (windowBits < 0) {3491wrap = 0;3492windowBits = -windowBits;3493}3494else {3495wrap = (windowBits >> 4) + 1;3496if (windowBits < 48) {3497windowBits &= 15;3498}3499}35003501/* set number of window bits, free window if different */3502if (windowBits && (windowBits < 8 || windowBits > 15)) {3503return Z_STREAM_ERROR;3504}3505if (state.window !== null && state.wbits !== windowBits) {3506state.window = null;3507}35083509/* update state and reset the rest of it */3510state.wrap = wrap;3511state.wbits = windowBits;3512return inflateReset(strm);3513}35143515function inflateInit2(strm, windowBits) {3516var ret;3517var state;35183519if (!strm) { return Z_STREAM_ERROR; }3520//strm.msg = Z_NULL; /* in case we return an error */35213522state = new InflateState();35233524//if (state === Z_NULL) return Z_MEM_ERROR;3525//Tracev((stderr, "inflate: allocated\n"));3526strm.state = state;3527state.window = null/*Z_NULL*/;3528ret = inflateReset2(strm, windowBits);3529if (ret !== Z_OK) {3530strm.state = null/*Z_NULL*/;3531}3532return ret;3533}35343535function inflateInit(strm) {3536return inflateInit2(strm, DEF_WBITS);3537}353835393540/*3541Return state with length and distance decoding tables and index sizes set to3542fixed code decoding. Normally this returns fixed tables from inffixed.h.3543If BUILDFIXED is defined, then instead this routine builds the tables the3544first time it's called, and returns those tables the first time and3545thereafter. This reduces the size of the code by about 2K bytes, in3546exchange for a little execution time. However, BUILDFIXED should not be3547used for threaded applications, since the rewriting of the tables and virgin3548may not be thread-safe.3549*/3550var virgin = true;35513552var lenfix, distfix; // We have no pointers in JS, so keep tables separate35533554function fixedtables(state) {3555/* build fixed huffman tables if first call (may not be thread safe) */3556if (virgin) {3557var sym;35583559lenfix = new utils.Buf32(512);3560distfix = new utils.Buf32(32);35613562/* literal/length table */3563sym = 0;3564while (sym < 144) { state.lens[sym++] = 8; }3565while (sym < 256) { state.lens[sym++] = 9; }3566while (sym < 280) { state.lens[sym++] = 7; }3567while (sym < 288) { state.lens[sym++] = 8; }35683569inflate_table(LENS, state.lens, 0, 288, lenfix, 0, state.work, {bits: 9});35703571/* distance table */3572sym = 0;3573while (sym < 32) { state.lens[sym++] = 5; }35743575inflate_table(DISTS, state.lens, 0, 32, distfix, 0, state.work, {bits: 5});35763577/* do this just once */3578virgin = false;3579}35803581state.lencode = lenfix;3582state.lenbits = 9;3583state.distcode = distfix;3584state.distbits = 5;3585}358635873588/*3589Update the window with the last wsize (normally 32K) bytes written before3590returning. If window does not exist yet, create it. This is only called3591when a window is already in use, or when output has been written during this3592inflate call, but the end of the deflate stream has not been reached yet.3593It is also called to create a window for dictionary data when a dictionary3594is loaded.35953596Providing output buffers larger than 32K to inflate() should provide a speed3597advantage, since only the last 32K of output is copied to the sliding window3598upon return from inflate(), and since all distances after the first 32K of3599output will fall in the output data, making match copies simpler and faster.3600The advantage may be dependent on the size of the processor's data caches.3601*/3602function updatewindow(strm, src, end, copy) {3603var dist;3604var state = strm.state;36053606/* if it hasn't been done already, allocate space for the window */3607if (state.window === null) {3608state.wsize = 1 << state.wbits;3609state.wnext = 0;3610state.whave = 0;36113612state.window = new utils.Buf8(state.wsize);3613}36143615/* copy state->wsize or less output bytes into the circular window */3616if (copy >= state.wsize) {3617utils.arraySet(state.window,src, end - state.wsize, state.wsize, 0);3618state.wnext = 0;3619state.whave = state.wsize;3620}3621else {3622dist = state.wsize - state.wnext;3623if (dist > copy) {3624dist = copy;3625}3626//zmemcpy(state->window + state->wnext, end - copy, dist);3627utils.arraySet(state.window,src, end - copy, dist, state.wnext);3628copy -= dist;3629if (copy) {3630//zmemcpy(state->window, end - copy, copy);3631utils.arraySet(state.window,src, end - copy, copy, 0);3632state.wnext = copy;3633state.whave = state.wsize;3634}3635else {3636state.wnext += dist;3637if (state.wnext === state.wsize) { state.wnext = 0; }3638if (state.whave < state.wsize) { state.whave += dist; }3639}3640}3641return 0;3642}36433644function inflate(strm, flush) {3645var state;3646var input, output; // input/output buffers3647var next; /* next input INDEX */3648var put; /* next output INDEX */3649var have, left; /* available input and output */3650var hold; /* bit buffer */3651var bits; /* bits in bit buffer */3652var _in, _out; /* save starting available input and output */3653var copy; /* number of stored or match bytes to copy */3654var from; /* where to copy match bytes from */3655var from_source;3656var here = 0; /* current decoding table entry */3657var here_bits, here_op, here_val; // paked "here" denormalized (JS specific)3658//var last; /* parent table entry */3659var last_bits, last_op, last_val; // paked "last" denormalized (JS specific)3660var len; /* length to copy for repeats, bits to drop */3661var ret; /* return code */3662var hbuf = new utils.Buf8(4); /* buffer for gzip header crc calculation */3663var opts;36643665var n; // temporary var for NEED_BITS36663667var order = /* permutation of code lengths */3668[16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];366936703671if (!strm || !strm.state || !strm.output ||3672(!strm.input && strm.avail_in !== 0)) {3673return Z_STREAM_ERROR;3674}36753676state = strm.state;3677if (state.mode === TYPE) { state.mode = TYPEDO; } /* skip check */367836793680//--- LOAD() ---3681put = strm.next_out;3682output = strm.output;3683left = strm.avail_out;3684next = strm.next_in;3685input = strm.input;3686have = strm.avail_in;3687hold = state.hold;3688bits = state.bits;3689//---36903691_in = have;3692_out = left;3693ret = Z_OK;36943695inf_leave: // goto emulation3696for (;;) {3697switch (state.mode) {3698case HEAD:3699if (state.wrap === 0) {3700state.mode = TYPEDO;3701break;3702}3703//=== NEEDBITS(16);3704while (bits < 16) {3705if (have === 0) { break inf_leave; }3706have--;3707hold += input[next++] << bits;3708bits += 8;3709}3710//===//3711if ((state.wrap & 2) && hold === 0x8b1f) { /* gzip header */3712state.check = 0/*crc32(0L, Z_NULL, 0)*/;3713//=== CRC2(state.check, hold);3714hbuf[0] = hold & 0xff;3715hbuf[1] = (hold >>> 8) & 0xff;3716state.check = crc32(state.check, hbuf, 2, 0);3717//===//37183719//=== INITBITS();3720hold = 0;3721bits = 0;3722//===//3723state.mode = FLAGS;3724break;3725}3726state.flags = 0; /* expect zlib header */3727if (state.head) {3728state.head.done = false;3729}3730if (!(state.wrap & 1) || /* check if zlib header allowed */3731(((hold & 0xff)/*BITS(8)*/ << 8) + (hold >> 8)) % 31) {3732strm.msg = 'incorrect header check';3733state.mode = BAD;3734break;3735}3736if ((hold & 0x0f)/*BITS(4)*/ !== Z_DEFLATED) {3737strm.msg = 'unknown compression method';3738state.mode = BAD;3739break;3740}3741//--- DROPBITS(4) ---//3742hold >>>= 4;3743bits -= 4;3744//---//3745len = (hold & 0x0f)/*BITS(4)*/ + 8;3746if (state.wbits === 0) {3747state.wbits = len;3748}3749else if (len > state.wbits) {3750strm.msg = 'invalid window size';3751state.mode = BAD;3752break;3753}3754state.dmax = 1 << len;3755//Tracev((stderr, "inflate: zlib header ok\n"));3756strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;3757state.mode = hold & 0x200 ? DICTID : TYPE;3758//=== INITBITS();3759hold = 0;3760bits = 0;3761//===//3762break;3763case FLAGS:3764//=== NEEDBITS(16); */3765while (bits < 16) {3766if (have === 0) { break inf_leave; }3767have--;3768hold += input[next++] << bits;3769bits += 8;3770}3771//===//3772state.flags = hold;3773if ((state.flags & 0xff) !== Z_DEFLATED) {3774strm.msg = 'unknown compression method';3775state.mode = BAD;3776break;3777}3778if (state.flags & 0xe000) {3779strm.msg = 'unknown header flags set';3780state.mode = BAD;3781break;3782}3783if (state.head) {3784state.head.text = ((hold >> 8) & 1);3785}3786if (state.flags & 0x0200) {3787//=== CRC2(state.check, hold);3788hbuf[0] = hold & 0xff;3789hbuf[1] = (hold >>> 8) & 0xff;3790state.check = crc32(state.check, hbuf, 2, 0);3791//===//3792}3793//=== INITBITS();3794hold = 0;3795bits = 0;3796//===//3797state.mode = TIME;3798/* falls through */3799case TIME:3800//=== NEEDBITS(32); */3801while (bits < 32) {3802if (have === 0) { break inf_leave; }3803have--;3804hold += input[next++] << bits;3805bits += 8;3806}3807//===//3808if (state.head) {3809state.head.time = hold;3810}3811if (state.flags & 0x0200) {3812//=== CRC4(state.check, hold)3813hbuf[0] = hold & 0xff;3814hbuf[1] = (hold >>> 8) & 0xff;3815hbuf[2] = (hold >>> 16) & 0xff;3816hbuf[3] = (hold >>> 24) & 0xff;3817state.check = crc32(state.check, hbuf, 4, 0);3818//===3819}3820//=== INITBITS();3821hold = 0;3822bits = 0;3823//===//3824state.mode = OS;3825/* falls through */3826case OS:3827//=== NEEDBITS(16); */3828while (bits < 16) {3829if (have === 0) { break inf_leave; }3830have--;3831hold += input[next++] << bits;3832bits += 8;3833}3834//===//3835if (state.head) {3836state.head.xflags = (hold & 0xff);3837state.head.os = (hold >> 8);3838}3839if (state.flags & 0x0200) {3840//=== CRC2(state.check, hold);3841hbuf[0] = hold & 0xff;3842hbuf[1] = (hold >>> 8) & 0xff;3843state.check = crc32(state.check, hbuf, 2, 0);3844//===//3845}3846//=== INITBITS();3847hold = 0;3848bits = 0;3849//===//3850state.mode = EXLEN;3851/* falls through */3852case EXLEN:3853if (state.flags & 0x0400) {3854//=== NEEDBITS(16); */3855while (bits < 16) {3856if (have === 0) { break inf_leave; }3857have--;3858hold += input[next++] << bits;3859bits += 8;3860}3861//===//3862state.length = hold;3863if (state.head) {3864state.head.extra_len = hold;3865}3866if (state.flags & 0x0200) {3867//=== CRC2(state.check, hold);3868hbuf[0] = hold & 0xff;3869hbuf[1] = (hold >>> 8) & 0xff;3870state.check = crc32(state.check, hbuf, 2, 0);3871//===//3872}3873//=== INITBITS();3874hold = 0;3875bits = 0;3876//===//3877}3878else if (state.head) {3879state.head.extra = null/*Z_NULL*/;3880}3881state.mode = EXTRA;3882/* falls through */3883case EXTRA:3884if (state.flags & 0x0400) {3885copy = state.length;3886if (copy > have) { copy = have; }3887if (copy) {3888if (state.head) {3889len = state.head.extra_len - state.length;3890if (!state.head.extra) {3891// Use untyped array for more conveniend processing later3892state.head.extra = new Array(state.head.extra_len);3893}3894utils.arraySet(3895state.head.extra,3896input,3897next,3898// extra field is limited to 65536 bytes3899// - no need for additional size check3900copy,3901/*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/3902len3903);3904//zmemcpy(state.head.extra + len, next,3905// len + copy > state.head.extra_max ?3906// state.head.extra_max - len : copy);3907}3908if (state.flags & 0x0200) {3909state.check = crc32(state.check, input, copy, next);3910}3911have -= copy;3912next += copy;3913state.length -= copy;3914}3915if (state.length) { break inf_leave; }3916}3917state.length = 0;3918state.mode = NAME;3919/* falls through */3920case NAME:3921if (state.flags & 0x0800) {3922if (have === 0) { break inf_leave; }3923copy = 0;3924do {3925// TODO: 2 or 1 bytes?3926len = input[next + copy++];3927/* use constant limit because in js we should not preallocate memory */3928if (state.head && len &&3929(state.length < 65536 /*state.head.name_max*/)) {3930state.head.name += String.fromCharCode(len);3931}3932} while (len && copy < have);39333934if (state.flags & 0x0200) {3935state.check = crc32(state.check, input, copy, next);3936}3937have -= copy;3938next += copy;3939if (len) { break inf_leave; }3940}3941else if (state.head) {3942state.head.name = null;3943}3944state.length = 0;3945state.mode = COMMENT;3946/* falls through */3947case COMMENT:3948if (state.flags & 0x1000) {3949if (have === 0) { break inf_leave; }3950copy = 0;3951do {3952len = input[next + copy++];3953/* use constant limit because in js we should not preallocate memory */3954if (state.head && len &&3955(state.length < 65536 /*state.head.comm_max*/)) {3956state.head.comment += String.fromCharCode(len);3957}3958} while (len && copy < have);3959if (state.flags & 0x0200) {3960state.check = crc32(state.check, input, copy, next);3961}3962have -= copy;3963next += copy;3964if (len) { break inf_leave; }3965}3966else if (state.head) {3967state.head.comment = null;3968}3969state.mode = HCRC;3970/* falls through */3971case HCRC:3972if (state.flags & 0x0200) {3973//=== NEEDBITS(16); */3974while (bits < 16) {3975if (have === 0) { break inf_leave; }3976have--;3977hold += input[next++] << bits;3978bits += 8;3979}3980//===//3981if (hold !== (state.check & 0xffff)) {3982strm.msg = 'header crc mismatch';3983state.mode = BAD;3984break;3985}3986//=== INITBITS();3987hold = 0;3988bits = 0;3989//===//3990}3991if (state.head) {3992state.head.hcrc = ((state.flags >> 9) & 1);3993state.head.done = true;3994}3995strm.adler = state.check = 0 /*crc32(0L, Z_NULL, 0)*/;3996state.mode = TYPE;3997break;3998case DICTID:3999//=== NEEDBITS(32); */4000while (bits < 32) {4001if (have === 0) { break inf_leave; }4002have--;4003hold += input[next++] << bits;4004bits += 8;4005}4006//===//4007strm.adler = state.check = ZSWAP32(hold);4008//=== INITBITS();4009hold = 0;4010bits = 0;4011//===//4012state.mode = DICT;4013/* falls through */4014case DICT:4015if (state.havedict === 0) {4016//--- RESTORE() ---4017strm.next_out = put;4018strm.avail_out = left;4019strm.next_in = next;4020strm.avail_in = have;4021state.hold = hold;4022state.bits = bits;4023//---4024return Z_NEED_DICT;4025}4026strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;4027state.mode = TYPE;4028/* falls through */4029case TYPE:4030if (flush === Z_BLOCK || flush === Z_TREES) { break inf_leave; }4031/* falls through */4032case TYPEDO:4033if (state.last) {4034//--- BYTEBITS() ---//4035hold >>>= bits & 7;4036bits -= bits & 7;4037//---//4038state.mode = CHECK;4039break;4040}4041//=== NEEDBITS(3); */4042while (bits < 3) {4043if (have === 0) { break inf_leave; }4044have--;4045hold += input[next++] << bits;4046bits += 8;4047}4048//===//4049state.last = (hold & 0x01)/*BITS(1)*/;4050//--- DROPBITS(1) ---//4051hold >>>= 1;4052bits -= 1;4053//---//40544055switch ((hold & 0x03)/*BITS(2)*/) {4056case 0: /* stored block */4057//Tracev((stderr, "inflate: stored block%s\n",4058// state.last ? " (last)" : ""));4059state.mode = STORED;4060break;4061case 1: /* fixed block */4062fixedtables(state);4063//Tracev((stderr, "inflate: fixed codes block%s\n",4064// state.last ? " (last)" : ""));4065state.mode = LEN_; /* decode codes */4066if (flush === Z_TREES) {4067//--- DROPBITS(2) ---//4068hold >>>= 2;4069bits -= 2;4070//---//4071break inf_leave;4072}4073break;4074case 2: /* dynamic block */4075//Tracev((stderr, "inflate: dynamic codes block%s\n",4076// state.last ? " (last)" : ""));4077state.mode = TABLE;4078break;4079case 3:4080strm.msg = 'invalid block type';4081state.mode = BAD;4082}4083//--- DROPBITS(2) ---//4084hold >>>= 2;4085bits -= 2;4086//---//4087break;4088case STORED:4089//--- BYTEBITS() ---// /* go to byte boundary */4090hold >>>= bits & 7;4091bits -= bits & 7;4092//---//4093//=== NEEDBITS(32); */4094while (bits < 32) {4095if (have === 0) { break inf_leave; }4096have--;4097hold += input[next++] << bits;4098bits += 8;4099}4100//===//4101if ((hold & 0xffff) !== ((hold >>> 16) ^ 0xffff)) {4102strm.msg = 'invalid stored block lengths';4103state.mode = BAD;4104break;4105}4106state.length = hold & 0xffff;4107//Tracev((stderr, "inflate: stored length %u\n",4108// state.length));4109//=== INITBITS();4110hold = 0;4111bits = 0;4112//===//4113state.mode = COPY_;4114if (flush === Z_TREES) { break inf_leave; }4115/* falls through */4116case COPY_:4117state.mode = COPY;4118/* falls through */4119case COPY:4120copy = state.length;4121if (copy) {4122if (copy > have) { copy = have; }4123if (copy > left) { copy = left; }4124if (copy === 0) { break inf_leave; }4125//--- zmemcpy(put, next, copy); ---4126utils.arraySet(output, input, next, copy, put);4127//---//4128have -= copy;4129next += copy;4130left -= copy;4131put += copy;4132state.length -= copy;4133break;4134}4135//Tracev((stderr, "inflate: stored end\n"));4136state.mode = TYPE;4137break;4138case TABLE:4139//=== NEEDBITS(14); */4140while (bits < 14) {4141if (have === 0) { break inf_leave; }4142have--;4143hold += input[next++] << bits;4144bits += 8;4145}4146//===//4147state.nlen = (hold & 0x1f)/*BITS(5)*/ + 257;4148//--- DROPBITS(5) ---//4149hold >>>= 5;4150bits -= 5;4151//---//4152state.ndist = (hold & 0x1f)/*BITS(5)*/ + 1;4153//--- DROPBITS(5) ---//4154hold >>>= 5;4155bits -= 5;4156//---//4157state.ncode = (hold & 0x0f)/*BITS(4)*/ + 4;4158//--- DROPBITS(4) ---//4159hold >>>= 4;4160bits -= 4;4161//---//4162//#ifndef PKZIP_BUG_WORKAROUND4163if (state.nlen > 286 || state.ndist > 30) {4164strm.msg = 'too many length or distance symbols';4165state.mode = BAD;4166break;4167}4168//#endif4169//Tracev((stderr, "inflate: table sizes ok\n"));4170state.have = 0;4171state.mode = LENLENS;4172/* falls through */4173case LENLENS:4174while (state.have < state.ncode) {4175//=== NEEDBITS(3);4176while (bits < 3) {4177if (have === 0) { break inf_leave; }4178have--;4179hold += input[next++] << bits;4180bits += 8;4181}4182//===//4183state.lens[order[state.have++]] = (hold & 0x07);//BITS(3);4184//--- DROPBITS(3) ---//4185hold >>>= 3;4186bits -= 3;4187//---//4188}4189while (state.have < 19) {4190state.lens[order[state.have++]] = 0;4191}4192// We have separate tables & no pointers. 2 commented lines below not needed.4193//state.next = state.codes;4194//state.lencode = state.next;4195// Switch to use dynamic table4196state.lencode = state.lendyn;4197state.lenbits = 7;41984199opts = {bits: state.lenbits};4200ret = inflate_table(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts);4201state.lenbits = opts.bits;42024203if (ret) {4204strm.msg = 'invalid code lengths set';4205state.mode = BAD;4206break;4207}4208//Tracev((stderr, "inflate: code lengths ok\n"));4209state.have = 0;4210state.mode = CODELENS;4211/* falls through */4212case CODELENS:4213while (state.have < state.nlen + state.ndist) {4214for (;;) {4215here = state.lencode[hold & ((1 << state.lenbits) - 1)];/*BITS(state.lenbits)*/4216here_bits = here >>> 24;4217here_op = (here >>> 16) & 0xff;4218here_val = here & 0xffff;42194220if ((here_bits) <= bits) { break; }4221//--- PULLBYTE() ---//4222if (have === 0) { break inf_leave; }4223have--;4224hold += input[next++] << bits;4225bits += 8;4226//---//4227}4228if (here_val < 16) {4229//--- DROPBITS(here.bits) ---//4230hold >>>= here_bits;4231bits -= here_bits;4232//---//4233state.lens[state.have++] = here_val;4234}4235else {4236if (here_val === 16) {4237//=== NEEDBITS(here.bits + 2);4238n = here_bits + 2;4239while (bits < n) {4240if (have === 0) { break inf_leave; }4241have--;4242hold += input[next++] << bits;4243bits += 8;4244}4245//===//4246//--- DROPBITS(here.bits) ---//4247hold >>>= here_bits;4248bits -= here_bits;4249//---//4250if (state.have === 0) {4251strm.msg = 'invalid bit length repeat';4252state.mode = BAD;4253break;4254}4255len = state.lens[state.have - 1];4256copy = 3 + (hold & 0x03);//BITS(2);4257//--- DROPBITS(2) ---//4258hold >>>= 2;4259bits -= 2;4260//---//4261}4262else if (here_val === 17) {4263//=== NEEDBITS(here.bits + 3);4264n = here_bits + 3;4265while (bits < n) {4266if (have === 0) { break inf_leave; }4267have--;4268hold += input[next++] << bits;4269bits += 8;4270}4271//===//4272//--- DROPBITS(here.bits) ---//4273hold >>>= here_bits;4274bits -= here_bits;4275//---//4276len = 0;4277copy = 3 + (hold & 0x07);//BITS(3);4278//--- DROPBITS(3) ---//4279hold >>>= 3;4280bits -= 3;4281//---//4282}4283else {4284//=== NEEDBITS(here.bits + 7);4285n = here_bits + 7;4286while (bits < n) {4287if (have === 0) { break inf_leave; }4288have--;4289hold += input[next++] << bits;4290bits += 8;4291}4292//===//4293//--- DROPBITS(here.bits) ---//4294hold >>>= here_bits;4295bits -= here_bits;4296//---//4297len = 0;4298copy = 11 + (hold & 0x7f);//BITS(7);4299//--- DROPBITS(7) ---//4300hold >>>= 7;4301bits -= 7;4302//---//4303}4304if (state.have + copy > state.nlen + state.ndist) {4305strm.msg = 'invalid bit length repeat';4306state.mode = BAD;4307break;4308}4309while (copy--) {4310state.lens[state.have++] = len;4311}4312}4313}43144315/* handle error breaks in while */4316if (state.mode === BAD) { break; }43174318/* check for end-of-block code (better have one) */4319if (state.lens[256] === 0) {4320strm.msg = 'invalid code -- missing end-of-block';4321state.mode = BAD;4322break;4323}43244325/* build code tables -- note: do not change the lenbits or distbits4326values here (9 and 6) without reading the comments in inftrees.h4327concerning the ENOUGH constants, which depend on those values */4328state.lenbits = 9;43294330opts = {bits: state.lenbits};4331ret = inflate_table(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts);4332// We have separate tables & no pointers. 2 commented lines below not needed.4333// state.next_index = opts.table_index;4334state.lenbits = opts.bits;4335// state.lencode = state.next;43364337if (ret) {4338strm.msg = 'invalid literal/lengths set';4339state.mode = BAD;4340break;4341}43424343state.distbits = 6;4344//state.distcode.copy(state.codes);4345// Switch to use dynamic table4346state.distcode = state.distdyn;4347opts = {bits: state.distbits};4348ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts);4349// We have separate tables & no pointers. 2 commented lines below not needed.4350// state.next_index = opts.table_index;4351state.distbits = opts.bits;4352// state.distcode = state.next;43534354if (ret) {4355strm.msg = 'invalid distances set';4356state.mode = BAD;4357break;4358}4359//Tracev((stderr, 'inflate: codes ok\n'));4360state.mode = LEN_;4361if (flush === Z_TREES) { break inf_leave; }4362/* falls through */4363case LEN_:4364state.mode = LEN;4365/* falls through */4366case LEN:4367if (have >= 6 && left >= 258) {4368//--- RESTORE() ---4369strm.next_out = put;4370strm.avail_out = left;4371strm.next_in = next;4372strm.avail_in = have;4373state.hold = hold;4374state.bits = bits;4375//---4376inflate_fast(strm, _out);4377//--- LOAD() ---4378put = strm.next_out;4379output = strm.output;4380left = strm.avail_out;4381next = strm.next_in;4382input = strm.input;4383have = strm.avail_in;4384hold = state.hold;4385bits = state.bits;4386//---43874388if (state.mode === TYPE) {4389state.back = -1;4390}4391break;4392}4393state.back = 0;4394for (;;) {4395here = state.lencode[hold & ((1 << state.lenbits) -1)]; /*BITS(state.lenbits)*/4396here_bits = here >>> 24;4397here_op = (here >>> 16) & 0xff;4398here_val = here & 0xffff;43994400if (here_bits <= bits) { break; }4401//--- PULLBYTE() ---//4402if (have === 0) { break inf_leave; }4403have--;4404hold += input[next++] << bits;4405bits += 8;4406//---//4407}4408if (here_op && (here_op & 0xf0) === 0) {4409last_bits = here_bits;4410last_op = here_op;4411last_val = here_val;4412for (;;) {4413here = state.lencode[last_val +4414((hold & ((1 << (last_bits + last_op)) -1))/*BITS(last.bits + last.op)*/ >> last_bits)];4415here_bits = here >>> 24;4416here_op = (here >>> 16) & 0xff;4417here_val = here & 0xffff;44184419if ((last_bits + here_bits) <= bits) { break; }4420//--- PULLBYTE() ---//4421if (have === 0) { break inf_leave; }4422have--;4423hold += input[next++] << bits;4424bits += 8;4425//---//4426}4427//--- DROPBITS(last.bits) ---//4428hold >>>= last_bits;4429bits -= last_bits;4430//---//4431state.back += last_bits;4432}4433//--- DROPBITS(here.bits) ---//4434hold >>>= here_bits;4435bits -= here_bits;4436//---//4437state.back += here_bits;4438state.length = here_val;4439if (here_op === 0) {4440//Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?4441// "inflate: literal '%c'\n" :4442// "inflate: literal 0x%02x\n", here.val));4443state.mode = LIT;4444break;4445}4446if (here_op & 32) {4447//Tracevv((stderr, "inflate: end of block\n"));4448state.back = -1;4449state.mode = TYPE;4450break;4451}4452if (here_op & 64) {4453strm.msg = 'invalid literal/length code';4454state.mode = BAD;4455break;4456}4457state.extra = here_op & 15;4458state.mode = LENEXT;4459/* falls through */4460case LENEXT:4461if (state.extra) {4462//=== NEEDBITS(state.extra);4463n = state.extra;4464while (bits < n) {4465if (have === 0) { break inf_leave; }4466have--;4467hold += input[next++] << bits;4468bits += 8;4469}4470//===//4471state.length += hold & ((1 << state.extra) -1)/*BITS(state.extra)*/;4472//--- DROPBITS(state.extra) ---//4473hold >>>= state.extra;4474bits -= state.extra;4475//---//4476state.back += state.extra;4477}4478//Tracevv((stderr, "inflate: length %u\n", state.length));4479state.was = state.length;4480state.mode = DIST;4481/* falls through */4482case DIST:4483for (;;) {4484here = state.distcode[hold & ((1 << state.distbits) -1)];/*BITS(state.distbits)*/4485here_bits = here >>> 24;4486here_op = (here >>> 16) & 0xff;4487here_val = here & 0xffff;44884489if ((here_bits) <= bits) { break; }4490//--- PULLBYTE() ---//4491if (have === 0) { break inf_leave; }4492have--;4493hold += input[next++] << bits;4494bits += 8;4495//---//4496}4497if ((here_op & 0xf0) === 0) {4498last_bits = here_bits;4499last_op = here_op;4500last_val = here_val;4501for (;;) {4502here = state.distcode[last_val +4503((hold & ((1 << (last_bits + last_op)) -1))/*BITS(last.bits + last.op)*/ >> last_bits)];4504here_bits = here >>> 24;4505here_op = (here >>> 16) & 0xff;4506here_val = here & 0xffff;45074508if ((last_bits + here_bits) <= bits) { break; }4509//--- PULLBYTE() ---//4510if (have === 0) { break inf_leave; }4511have--;4512hold += input[next++] << bits;4513bits += 8;4514//---//4515}4516//--- DROPBITS(last.bits) ---//4517hold >>>= last_bits;4518bits -= last_bits;4519//---//4520state.back += last_bits;4521}4522//--- DROPBITS(here.bits) ---//4523hold >>>= here_bits;4524bits -= here_bits;4525//---//4526state.back += here_bits;4527if (here_op & 64) {4528strm.msg = 'invalid distance code';4529state.mode = BAD;4530break;4531}4532state.offset = here_val;4533state.extra = (here_op) & 15;4534state.mode = DISTEXT;4535/* falls through */4536case DISTEXT:4537if (state.extra) {4538//=== NEEDBITS(state.extra);4539n = state.extra;4540while (bits < n) {4541if (have === 0) { break inf_leave; }4542have--;4543hold += input[next++] << bits;4544bits += 8;4545}4546//===//4547state.offset += hold & ((1 << state.extra) -1)/*BITS(state.extra)*/;4548//--- DROPBITS(state.extra) ---//4549hold >>>= state.extra;4550bits -= state.extra;4551//---//4552state.back += state.extra;4553}4554//#ifdef INFLATE_STRICT4555if (state.offset > state.dmax) {4556strm.msg = 'invalid distance too far back';4557state.mode = BAD;4558break;4559}4560//#endif4561//Tracevv((stderr, "inflate: distance %u\n", state.offset));4562state.mode = MATCH;4563/* falls through */4564case MATCH:4565if (left === 0) { break inf_leave; }4566copy = _out - left;4567if (state.offset > copy) { /* copy from window */4568copy = state.offset - copy;4569if (copy > state.whave) {4570if (state.sane) {4571strm.msg = 'invalid distance too far back';4572state.mode = BAD;4573break;4574}4575// (!) This block is disabled in zlib defailts,4576// don't enable it for binary compatibility4577//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR4578// Trace((stderr, "inflate.c too far\n"));4579// copy -= state.whave;4580// if (copy > state.length) { copy = state.length; }4581// if (copy > left) { copy = left; }4582// left -= copy;4583// state.length -= copy;4584// do {4585// output[put++] = 0;4586// } while (--copy);4587// if (state.length === 0) { state.mode = LEN; }4588// break;4589//#endif4590}4591if (copy > state.wnext) {4592copy -= state.wnext;4593from = state.wsize - copy;4594}4595else {4596from = state.wnext - copy;4597}4598if (copy > state.length) { copy = state.length; }4599from_source = state.window;4600}4601else { /* copy from output */4602from_source = output;4603from = put - state.offset;4604copy = state.length;4605}4606if (copy > left) { copy = left; }4607left -= copy;4608state.length -= copy;4609do {4610output[put++] = from_source[from++];4611} while (--copy);4612if (state.length === 0) { state.mode = LEN; }4613break;4614case LIT:4615if (left === 0) { break inf_leave; }4616output[put++] = state.length;4617left--;4618state.mode = LEN;4619break;4620case CHECK:4621if (state.wrap) {4622//=== NEEDBITS(32);4623while (bits < 32) {4624if (have === 0) { break inf_leave; }4625have--;4626// Use '|' insdead of '+' to make sure that result is signed4627hold |= input[next++] << bits;4628bits += 8;4629}4630//===//4631_out -= left;4632strm.total_out += _out;4633state.total += _out;4634if (_out) {4635strm.adler = state.check =4636/*UPDATE(state.check, put - _out, _out);*/4637(state.flags ? crc32(state.check, output, _out, put - _out) : adler32(state.check, output, _out, put - _out));46384639}4640_out = left;4641// NB: crc32 stored as signed 32-bit int, ZSWAP32 returns signed too4642if ((state.flags ? hold : ZSWAP32(hold)) !== state.check) {4643strm.msg = 'incorrect data check';4644state.mode = BAD;4645break;4646}4647//=== INITBITS();4648hold = 0;4649bits = 0;4650//===//4651//Tracev((stderr, "inflate: check matches trailer\n"));4652}4653state.mode = LENGTH;4654/* falls through */4655case LENGTH:4656if (state.wrap && state.flags) {4657//=== NEEDBITS(32);4658while (bits < 32) {4659if (have === 0) { break inf_leave; }4660have--;4661hold += input[next++] << bits;4662bits += 8;4663}4664//===//4665if (hold !== (state.total & 0xffffffff)) {4666strm.msg = 'incorrect length check';4667state.mode = BAD;4668break;4669}4670//=== INITBITS();4671hold = 0;4672bits = 0;4673//===//4674//Tracev((stderr, "inflate: length matches trailer\n"));4675}4676state.mode = DONE;4677/* falls through */4678case DONE:4679ret = Z_STREAM_END;4680break inf_leave;4681case BAD:4682ret = Z_DATA_ERROR;4683break inf_leave;4684case MEM:4685return Z_MEM_ERROR;4686case SYNC:4687/* falls through */4688default:4689return Z_STREAM_ERROR;4690}4691}46924693// inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave"46944695/*4696Return from inflate(), updating the total counts and the check value.4697If there was no progress during the inflate() call, return a buffer4698error. Call updatewindow() to create and/or update the window state.4699Note: a memory error from inflate() is non-recoverable.4700*/47014702//--- RESTORE() ---4703strm.next_out = put;4704strm.avail_out = left;4705strm.next_in = next;4706strm.avail_in = have;4707state.hold = hold;4708state.bits = bits;4709//---47104711if (state.wsize || (_out !== strm.avail_out && state.mode < BAD &&4712(state.mode < CHECK || flush !== Z_FINISH))) {4713if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) {4714state.mode = MEM;4715return Z_MEM_ERROR;4716}4717}4718_in -= strm.avail_in;4719_out -= strm.avail_out;4720strm.total_in += _in;4721strm.total_out += _out;4722state.total += _out;4723if (state.wrap && _out) {4724strm.adler = state.check = /*UPDATE(state.check, strm.next_out - _out, _out);*/4725(state.flags ? crc32(state.check, output, _out, strm.next_out - _out) : adler32(state.check, output, _out, strm.next_out - _out));4726}4727strm.data_type = state.bits + (state.last ? 64 : 0) +4728(state.mode === TYPE ? 128 : 0) +4729(state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);4730if (((_in === 0 && _out === 0) || flush === Z_FINISH) && ret === Z_OK) {4731ret = Z_BUF_ERROR;4732}4733return ret;4734}47354736function inflateEnd(strm) {47374738if (!strm || !strm.state /*|| strm->zfree == (free_func)0*/) {4739return Z_STREAM_ERROR;4740}47414742var state = strm.state;4743if (state.window) {4744state.window = null;4745}4746strm.state = null;4747return Z_OK;4748}47494750function inflateGetHeader(strm, head) {4751var state;47524753/* check state */4754if (!strm || !strm.state) { return Z_STREAM_ERROR; }4755state = strm.state;4756if ((state.wrap & 2) === 0) { return Z_STREAM_ERROR; }47574758/* save header structure */4759state.head = head;4760head.done = false;4761return Z_OK;4762}476347644765exports.inflateReset = inflateReset;4766exports.inflateReset2 = inflateReset2;4767exports.inflateResetKeep = inflateResetKeep;4768exports.inflateInit = inflateInit;4769exports.inflateInit2 = inflateInit2;4770exports.inflate = inflate;4771exports.inflateEnd = inflateEnd;4772exports.inflateGetHeader = inflateGetHeader;4773exports.inflateInfo = 'pako inflate (from Nodeca project)';47744775/* Not implemented4776exports.inflateCopy = inflateCopy;4777exports.inflateGetDictionary = inflateGetDictionary;4778exports.inflateMark = inflateMark;4779exports.inflatePrime = inflatePrime;4780exports.inflateSetDictionary = inflateSetDictionary;4781exports.inflateSync = inflateSync;4782exports.inflateSyncPoint = inflateSyncPoint;4783exports.inflateUndermine = inflateUndermine;4784*/4785},{"../utils/common":3,"./adler32":5,"./crc32":7,"./inffast":10,"./inftrees":12}],12:[function(require,module,exports){4786'use strict';478747884789var utils = require('../utils/common');47904791var MAXBITS = 15;4792var ENOUGH_LENS = 852;4793var ENOUGH_DISTS = 592;4794//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);47954796var CODES = 0;4797var LENS = 1;4798var DISTS = 2;47994800var lbase = [ /* Length codes 257..285 base */48013, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,480235, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 04803];48044805var lext = [ /* Length codes 257..285 extra */480616, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,480719, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 784808];48094810var dbase = [ /* Distance codes 0..29 base */48111, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,4812257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,48138193, 12289, 16385, 24577, 0, 04814];48154816var dext = [ /* Distance codes 0..29 extra */481716, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,481823, 23, 24, 24, 25, 25, 26, 26, 27, 27,481928, 28, 29, 29, 64, 644820];48214822module.exports = function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts)4823{4824var bits = opts.bits;4825//here = opts.here; /* table entry for duplication */48264827var len = 0; /* a code's length in bits */4828var sym = 0; /* index of code symbols */4829var min = 0, max = 0; /* minimum and maximum code lengths */4830var root = 0; /* number of index bits for root table */4831var curr = 0; /* number of index bits for current table */4832var drop = 0; /* code bits to drop for sub-table */4833var left = 0; /* number of prefix codes available */4834var used = 0; /* code entries in table used */4835var huff = 0; /* Huffman code */4836var incr; /* for incrementing code, index */4837var fill; /* index for replicating entries */4838var low; /* low bits for current root entry */4839var mask; /* mask for low root bits */4840var next; /* next available space in table */4841var base = null; /* base value table to use */4842var base_index = 0;4843// var shoextra; /* extra bits table to use */4844var end; /* use base and extra for symbol > end */4845var count = new utils.Buf16(MAXBITS+1); //[MAXBITS+1]; /* number of codes of each length */4846var offs = new utils.Buf16(MAXBITS+1); //[MAXBITS+1]; /* offsets in table for each length */4847var extra = null;4848var extra_index = 0;48494850var here_bits, here_op, here_val;48514852/*4853Process a set of code lengths to create a canonical Huffman code. The4854code lengths are lens[0..codes-1]. Each length corresponds to the4855symbols 0..codes-1. The Huffman code is generated by first sorting the4856symbols by length from short to long, and retaining the symbol order4857for codes with equal lengths. Then the code starts with all zero bits4858for the first code of the shortest length, and the codes are integer4859increments for the same length, and zeros are appended as the length4860increases. For the deflate format, these bits are stored backwards4861from their more natural integer increment ordering, and so when the4862decoding tables are built in the large loop below, the integer codes4863are incremented backwards.48644865This routine assumes, but does not check, that all of the entries in4866lens[] are in the range 0..MAXBITS. The caller must assure this.48671..MAXBITS is interpreted as that code length. zero means that that4868symbol does not occur in this code.48694870The codes are sorted by computing a count of codes for each length,4871creating from that a table of starting indices for each length in the4872sorted table, and then entering the symbols in order in the sorted4873table. The sorted table is work[], with that space being provided by4874the caller.48754876The length counts are used for other purposes as well, i.e. finding4877the minimum and maximum length codes, determining if there are any4878codes at all, checking for a valid set of lengths, and looking ahead4879at length counts to determine sub-table sizes when building the4880decoding tables.4881*/48824883/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */4884for (len = 0; len <= MAXBITS; len++) {4885count[len] = 0;4886}4887for (sym = 0; sym < codes; sym++) {4888count[lens[lens_index + sym]]++;4889}48904891/* bound code lengths, force root to be within code lengths */4892root = bits;4893for (max = MAXBITS; max >= 1; max--) {4894if (count[max] !== 0) { break; }4895}4896if (root > max) {4897root = max;4898}4899if (max === 0) { /* no symbols to code at all */4900//table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */4901//table.bits[opts.table_index] = 1; //here.bits = (var char)1;4902//table.val[opts.table_index++] = 0; //here.val = (var short)0;4903table[table_index++] = (1 << 24) | (64 << 16) | 0;490449054906//table.op[opts.table_index] = 64;4907//table.bits[opts.table_index] = 1;4908//table.val[opts.table_index++] = 0;4909table[table_index++] = (1 << 24) | (64 << 16) | 0;49104911opts.bits = 1;4912return 0; /* no symbols, but wait for decoding to report error */4913}4914for (min = 1; min < max; min++) {4915if (count[min] !== 0) { break; }4916}4917if (root < min) {4918root = min;4919}49204921/* check for an over-subscribed or incomplete set of lengths */4922left = 1;4923for (len = 1; len <= MAXBITS; len++) {4924left <<= 1;4925left -= count[len];4926if (left < 0) {4927return -1;4928} /* over-subscribed */4929}4930if (left > 0 && (type === CODES || max !== 1)) {4931return -1; /* incomplete set */4932}49334934/* generate offsets into symbol table for each length for sorting */4935offs[1] = 0;4936for (len = 1; len < MAXBITS; len++) {4937offs[len + 1] = offs[len] + count[len];4938}49394940/* sort symbols by length, by symbol order within each length */4941for (sym = 0; sym < codes; sym++) {4942if (lens[lens_index + sym] !== 0) {4943work[offs[lens[lens_index + sym]]++] = sym;4944}4945}49464947/*4948Create and fill in decoding tables. In this loop, the table being4949filled is at next and has curr index bits. The code being used is huff4950with length len. That code is converted to an index by dropping drop4951bits off of the bottom. For codes where len is less than drop + curr,4952those top drop + curr - len bits are incremented through all values to4953fill the table with replicated entries.49544955root is the number of index bits for the root table. When len exceeds4956root, sub-tables are created pointed to by the root entry with an index4957of the low root bits of huff. This is saved in low to check for when a4958new sub-table should be started. drop is zero when the root table is4959being filled, and drop is root when sub-tables are being filled.49604961When a new sub-table is needed, it is necessary to look ahead in the4962code lengths to determine what size sub-table is needed. The length4963counts are used for this, and so count[] is decremented as codes are4964entered in the tables.49654966used keeps track of how many table entries have been allocated from the4967provided *table space. It is checked for LENS and DIST tables against4968the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in4969the initial root table size constants. See the comments in inftrees.h4970for more information.49714972sym increments through all symbols, and the loop terminates when4973all codes of length max, i.e. all codes, have been processed. This4974routine permits incomplete codes, so another loop after this one fills4975in the rest of the decoding tables with invalid code markers.4976*/49774978/* set up for code type */4979// poor man optimization - use if-else instead of switch,4980// to avoid deopts in old v84981if (type === CODES) {4982base = extra = work; /* dummy value--not used */4983end = 19;4984} else if (type === LENS) {4985base = lbase;4986base_index -= 257;4987extra = lext;4988extra_index -= 257;4989end = 256;4990} else { /* DISTS */4991base = dbase;4992extra = dext;4993end = -1;4994}49954996/* initialize opts for loop */4997huff = 0; /* starting code */4998sym = 0; /* starting code symbol */4999len = min; /* starting code length */5000next = table_index; /* current table to fill in */5001curr = root; /* current table index bits */5002drop = 0; /* current bits to drop from code for index */5003low = -1; /* trigger new sub-table when len > root */5004used = 1 << root; /* use root table entries */5005mask = used - 1; /* mask for comparing low */50065007/* check available table space */5008if ((type === LENS && used > ENOUGH_LENS) ||5009(type === DISTS && used > ENOUGH_DISTS)) {5010return 1;5011}50125013var i=0;5014/* process all codes and make table entries */5015for (;;) {5016i++;5017/* create table entry */5018here_bits = len - drop;5019if (work[sym] < end) {5020here_op = 0;5021here_val = work[sym];5022}5023else if (work[sym] > end) {5024here_op = extra[extra_index + work[sym]];5025here_val = base[base_index + work[sym]];5026}5027else {5028here_op = 32 + 64; /* end of block */5029here_val = 0;5030}50315032/* replicate for those indices with low len bits equal to huff */5033incr = 1 << (len - drop);5034fill = 1 << curr;5035min = fill; /* save offset to next table */5036do {5037fill -= incr;5038table[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val |0;5039} while (fill !== 0);50405041/* backwards increment the len-bit code huff */5042incr = 1 << (len - 1);5043while (huff & incr) {5044incr >>= 1;5045}5046if (incr !== 0) {5047huff &= incr - 1;5048huff += incr;5049} else {5050huff = 0;5051}50525053/* go to next symbol, update count, len */5054sym++;5055if (--count[len] === 0) {5056if (len === max) { break; }5057len = lens[lens_index + work[sym]];5058}50595060/* create new sub-table if needed */5061if (len > root && (huff & mask) !== low) {5062/* if first time, transition to sub-tables */5063if (drop === 0) {5064drop = root;5065}50665067/* increment past last table */5068next += min; /* here min is 1 << curr */50695070/* determine length of next table */5071curr = len - drop;5072left = 1 << curr;5073while (curr + drop < max) {5074left -= count[curr + drop];5075if (left <= 0) { break; }5076curr++;5077left <<= 1;5078}50795080/* check for enough space */5081used += 1 << curr;5082if ((type === LENS && used > ENOUGH_LENS) ||5083(type === DISTS && used > ENOUGH_DISTS)) {5084return 1;5085}50865087/* point entry in root table to sub-table */5088low = huff & mask;5089/*table.op[low] = curr;5090table.bits[low] = root;5091table.val[low] = next - opts.table_index;*/5092table[low] = (root << 24) | (curr << 16) | (next - table_index) |0;5093}5094}50955096/* fill in remaining table entry if code is incomplete (guaranteed to have5097at most one remaining entry, since if the code is incomplete, the5098maximum code length that was allowed to get this far is one bit) */5099if (huff !== 0) {5100//table.op[next + huff] = 64; /* invalid code marker */5101//table.bits[next + huff] = len - drop;5102//table.val[next + huff] = 0;5103table[next + huff] = ((len - drop) << 24) | (64 << 16) |0;5104}51055106/* set return parameters */5107//opts.table_index += used;5108opts.bits = root;5109return 0;5110};51115112},{"../utils/common":3}],13:[function(require,module,exports){5113'use strict';51145115module.exports = {5116'2': 'need dictionary', /* Z_NEED_DICT 2 */5117'1': 'stream end', /* Z_STREAM_END 1 */5118'0': '', /* Z_OK 0 */5119'-1': 'file error', /* Z_ERRNO (-1) */5120'-2': 'stream error', /* Z_STREAM_ERROR (-2) */5121'-3': 'data error', /* Z_DATA_ERROR (-3) */5122'-4': 'insufficient memory', /* Z_MEM_ERROR (-4) */5123'-5': 'buffer error', /* Z_BUF_ERROR (-5) */5124'-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */5125};5126},{}],14:[function(require,module,exports){5127'use strict';512851295130var utils = require('../utils/common');51315132/* Public constants ==========================================================*/5133/* ===========================================================================*/513451355136//var Z_FILTERED = 1;5137//var Z_HUFFMAN_ONLY = 2;5138//var Z_RLE = 3;5139var Z_FIXED = 4;5140//var Z_DEFAULT_STRATEGY = 0;51415142/* Possible values of the data_type field (though see inflate()) */5143var Z_BINARY = 0;5144var Z_TEXT = 1;5145//var Z_ASCII = 1; // = Z_TEXT5146var Z_UNKNOWN = 2;51475148/*============================================================================*/514951505151function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }51525153// From zutil.h51545155var STORED_BLOCK = 0;5156var STATIC_TREES = 1;5157var DYN_TREES = 2;5158/* The three kinds of block type */51595160var MIN_MATCH = 3;5161var MAX_MATCH = 258;5162/* The minimum and maximum match lengths */51635164// From deflate.h5165/* ===========================================================================5166* Internal compression state.5167*/51685169var LENGTH_CODES = 29;5170/* number of length codes, not counting the special END_BLOCK code */51715172var LITERALS = 256;5173/* number of literal bytes 0..255 */51745175var L_CODES = LITERALS + 1 + LENGTH_CODES;5176/* number of Literal or Length codes, including the END_BLOCK code */51775178var D_CODES = 30;5179/* number of distance codes */51805181var BL_CODES = 19;5182/* number of codes used to transfer the bit lengths */51835184var HEAP_SIZE = 2*L_CODES + 1;5185/* maximum heap size */51865187var MAX_BITS = 15;5188/* All codes must not exceed MAX_BITS bits */51895190var Buf_size = 16;5191/* size of bit buffer in bi_buf */519251935194/* ===========================================================================5195* Constants5196*/51975198var MAX_BL_BITS = 7;5199/* Bit length codes must not exceed MAX_BL_BITS bits */52005201var END_BLOCK = 256;5202/* end of block literal code */52035204var REP_3_6 = 16;5205/* repeat previous bit length 3-6 times (2 bits of repeat count) */52065207var REPZ_3_10 = 17;5208/* repeat a zero length 3-10 times (3 bits of repeat count) */52095210var REPZ_11_138 = 18;5211/* repeat a zero length 11-138 times (7 bits of repeat count) */52125213var extra_lbits = /* extra bits for each length code */5214[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];52155216var extra_dbits = /* extra bits for each distance code */5217[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];52185219var extra_blbits = /* extra bits for each bit length code */5220[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7];52215222var bl_order =5223[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];5224/* The lengths of the bit length codes are sent in order of decreasing5225* probability, to avoid transmitting the lengths for unused bit length codes.5226*/52275228/* ===========================================================================5229* Local data. These are initialized only once.5230*/52315232// We pre-fill arrays with 0 to avoid uninitialized gaps52335234var DIST_CODE_LEN = 512; /* see definition of array dist_code below */52355236// !!!! Use flat array insdead of structure, Freq = i*2, Len = i*2+15237var static_ltree = new Array((L_CODES+2) * 2);5238zero(static_ltree);5239/* The static literal tree. Since the bit lengths are imposed, there is no5240* need for the L_CODES extra codes used during heap construction. However5241* The codes 286 and 287 are needed to build a canonical tree (see _tr_init5242* below).5243*/52445245var static_dtree = new Array(D_CODES * 2);5246zero(static_dtree);5247/* The static distance tree. (Actually a trivial tree since all codes use5248* 5 bits.)5249*/52505251var _dist_code = new Array(DIST_CODE_LEN);5252zero(_dist_code);5253/* Distance codes. The first 256 values correspond to the distances5254* 3 .. 258, the last 256 values correspond to the top 8 bits of5255* the 15 bit distances.5256*/52575258var _length_code = new Array(MAX_MATCH-MIN_MATCH+1);5259zero(_length_code);5260/* length code for each normalized match length (0 == MIN_MATCH) */52615262var base_length = new Array(LENGTH_CODES);5263zero(base_length);5264/* First normalized length for each code (0 = MIN_MATCH) */52655266var base_dist = new Array(D_CODES);5267zero(base_dist);5268/* First normalized distance for each code (0 = distance of 1) */526952705271var StaticTreeDesc = function (static_tree, extra_bits, extra_base, elems, max_length) {52725273this.static_tree = static_tree; /* static tree or NULL */5274this.extra_bits = extra_bits; /* extra bits for each code or NULL */5275this.extra_base = extra_base; /* base index for extra_bits */5276this.elems = elems; /* max number of elements in the tree */5277this.max_length = max_length; /* max bit length for the codes */52785279// show if `static_tree` has data or dummy - needed for monomorphic objects5280this.has_stree = static_tree && static_tree.length;5281};528252835284var static_l_desc;5285var static_d_desc;5286var static_bl_desc;528752885289var TreeDesc = function(dyn_tree, stat_desc) {5290this.dyn_tree = dyn_tree; /* the dynamic tree */5291this.max_code = 0; /* largest code with non zero frequency */5292this.stat_desc = stat_desc; /* the corresponding static tree */5293};5294529552965297function d_code(dist) {5298return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];5299}530053015302/* ===========================================================================5303* Output a short LSB first on the stream.5304* IN assertion: there is enough room in pendingBuf.5305*/5306function put_short (s, w) {5307// put_byte(s, (uch)((w) & 0xff));5308// put_byte(s, (uch)((ush)(w) >> 8));5309s.pending_buf[s.pending++] = (w) & 0xff;5310s.pending_buf[s.pending++] = (w >>> 8) & 0xff;5311}531253135314/* ===========================================================================5315* Send a value on a given number of bits.5316* IN assertion: length <= 16 and value fits in length bits.5317*/5318function send_bits(s, value, length) {5319if (s.bi_valid > (Buf_size - length)) {5320s.bi_buf |= (value << s.bi_valid) & 0xffff;5321put_short(s, s.bi_buf);5322s.bi_buf = value >> (Buf_size - s.bi_valid);5323s.bi_valid += length - Buf_size;5324} else {5325s.bi_buf |= (value << s.bi_valid) & 0xffff;5326s.bi_valid += length;5327}5328}532953305331function send_code(s, c, tree) {5332send_bits(s, tree[c*2]/*.Code*/, tree[c*2 + 1]/*.Len*/);5333}533453355336/* ===========================================================================5337* Reverse the first len bits of a code, using straightforward code (a faster5338* method would use a table)5339* IN assertion: 1 <= len <= 155340*/5341function bi_reverse(code, len) {5342var res = 0;5343do {5344res |= code & 1;5345code >>>= 1;5346res <<= 1;5347} while (--len > 0);5348return res >>> 1;5349}535053515352/* ===========================================================================5353* Flush the bit buffer, keeping at most 7 bits in it.5354*/5355function bi_flush(s) {5356if (s.bi_valid === 16) {5357put_short(s, s.bi_buf);5358s.bi_buf = 0;5359s.bi_valid = 0;53605361} else if (s.bi_valid >= 8) {5362s.pending_buf[s.pending++] = s.bi_buf & 0xff;5363s.bi_buf >>= 8;5364s.bi_valid -= 8;5365}5366}536753685369/* ===========================================================================5370* Compute the optimal bit lengths for a tree and update the total bit length5371* for the current block.5372* IN assertion: the fields freq and dad are set, heap[heap_max] and5373* above are the tree nodes sorted by increasing frequency.5374* OUT assertions: the field len is set to the optimal bit length, the5375* array bl_count contains the frequencies for each bit length.5376* The length opt_len is updated; static_len is also updated if stree is5377* not null.5378*/5379function gen_bitlen(s, desc)5380// deflate_state *s;5381// tree_desc *desc; /* the tree descriptor */5382{5383var tree = desc.dyn_tree;5384var max_code = desc.max_code;5385var stree = desc.stat_desc.static_tree;5386var has_stree = desc.stat_desc.has_stree;5387var extra = desc.stat_desc.extra_bits;5388var base = desc.stat_desc.extra_base;5389var max_length = desc.stat_desc.max_length;5390var h; /* heap index */5391var n, m; /* iterate over the tree elements */5392var bits; /* bit length */5393var xbits; /* extra bits */5394var f; /* frequency */5395var overflow = 0; /* number of elements with bit length too large */53965397for (bits = 0; bits <= MAX_BITS; bits++) {5398s.bl_count[bits] = 0;5399}54005401/* In a first pass, compute the optimal bit lengths (which may5402* overflow in the case of the bit length tree).5403*/5404tree[s.heap[s.heap_max]*2 + 1]/*.Len*/ = 0; /* root of the heap */54055406for (h = s.heap_max+1; h < HEAP_SIZE; h++) {5407n = s.heap[h];5408bits = tree[tree[n*2 +1]/*.Dad*/ * 2 + 1]/*.Len*/ + 1;5409if (bits > max_length) {5410bits = max_length;5411overflow++;5412}5413tree[n*2 + 1]/*.Len*/ = bits;5414/* We overwrite tree[n].Dad which is no longer needed */54155416if (n > max_code) { continue; } /* not a leaf node */54175418s.bl_count[bits]++;5419xbits = 0;5420if (n >= base) {5421xbits = extra[n-base];5422}5423f = tree[n * 2]/*.Freq*/;5424s.opt_len += f * (bits + xbits);5425if (has_stree) {5426s.static_len += f * (stree[n*2 + 1]/*.Len*/ + xbits);5427}5428}5429if (overflow === 0) { return; }54305431// Trace((stderr,"\nbit length overflow\n"));5432/* This happens for example on obj2 and pic of the Calgary corpus */54335434/* Find the first bit length which could increase: */5435do {5436bits = max_length-1;5437while (s.bl_count[bits] === 0) { bits--; }5438s.bl_count[bits]--; /* move one leaf down the tree */5439s.bl_count[bits+1] += 2; /* move one overflow item as its brother */5440s.bl_count[max_length]--;5441/* The brother of the overflow item also moves one step up,5442* but this does not affect bl_count[max_length]5443*/5444overflow -= 2;5445} while (overflow > 0);54465447/* Now recompute all bit lengths, scanning in increasing frequency.5448* h is still equal to HEAP_SIZE. (It is simpler to reconstruct all5449* lengths instead of fixing only the wrong ones. This idea is taken5450* from 'ar' written by Haruhiko Okumura.)5451*/5452for (bits = max_length; bits !== 0; bits--) {5453n = s.bl_count[bits];5454while (n !== 0) {5455m = s.heap[--h];5456if (m > max_code) { continue; }5457if (tree[m*2 + 1]/*.Len*/ !== bits) {5458// Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));5459s.opt_len += (bits - tree[m*2 + 1]/*.Len*/)*tree[m*2]/*.Freq*/;5460tree[m*2 + 1]/*.Len*/ = bits;5461}5462n--;5463}5464}5465}546654675468/* ===========================================================================5469* Generate the codes for a given tree and bit counts (which need not be5470* optimal).5471* IN assertion: the array bl_count contains the bit length statistics for5472* the given tree and the field len is set for all tree elements.5473* OUT assertion: the field code is set for all tree elements of non5474* zero code length.5475*/5476function gen_codes(tree, max_code, bl_count)5477// ct_data *tree; /* the tree to decorate */5478// int max_code; /* largest code with non zero frequency */5479// ushf *bl_count; /* number of codes at each bit length */5480{5481var next_code = new Array(MAX_BITS+1); /* next code value for each bit length */5482var code = 0; /* running code value */5483var bits; /* bit index */5484var n; /* code index */54855486/* The distribution counts are first used to generate the code values5487* without bit reversal.5488*/5489for (bits = 1; bits <= MAX_BITS; bits++) {5490next_code[bits] = code = (code + bl_count[bits-1]) << 1;5491}5492/* Check that the bit counts in bl_count are consistent. The last code5493* must be all ones.5494*/5495//Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,5496// "inconsistent bit counts");5497//Tracev((stderr,"\ngen_codes: max_code %d ", max_code));54985499for (n = 0; n <= max_code; n++) {5500var len = tree[n*2 + 1]/*.Len*/;5501if (len === 0) { continue; }5502/* Now reverse the bits */5503tree[n*2]/*.Code*/ = bi_reverse(next_code[len]++, len);55045505//Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",5506// n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));5507}5508}550955105511/* ===========================================================================5512* Initialize the various 'constant' tables.5513*/5514function tr_static_init() {5515var n; /* iterates over tree elements */5516var bits; /* bit counter */5517var length; /* length value */5518var code; /* code value */5519var dist; /* distance index */5520var bl_count = new Array(MAX_BITS+1);5521/* number of codes at each bit length for an optimal tree */55225523// do check in _tr_init()5524//if (static_init_done) return;55255526/* For some embedded targets, global variables are not initialized: */5527/*#ifdef NO_INIT_GLOBAL_POINTERS5528static_l_desc.static_tree = static_ltree;5529static_l_desc.extra_bits = extra_lbits;5530static_d_desc.static_tree = static_dtree;5531static_d_desc.extra_bits = extra_dbits;5532static_bl_desc.extra_bits = extra_blbits;5533#endif*/55345535/* Initialize the mapping length (0..255) -> length code (0..28) */5536length = 0;5537for (code = 0; code < LENGTH_CODES-1; code++) {5538base_length[code] = length;5539for (n = 0; n < (1<<extra_lbits[code]); n++) {5540_length_code[length++] = code;5541}5542}5543//Assert (length == 256, "tr_static_init: length != 256");5544/* Note that the length 255 (match length 258) can be represented5545* in two different ways: code 284 + 5 bits or code 285, so we5546* overwrite length_code[255] to use the best encoding:5547*/5548_length_code[length-1] = code;55495550/* Initialize the mapping dist (0..32K) -> dist code (0..29) */5551dist = 0;5552for (code = 0 ; code < 16; code++) {5553base_dist[code] = dist;5554for (n = 0; n < (1<<extra_dbits[code]); n++) {5555_dist_code[dist++] = code;5556}5557}5558//Assert (dist == 256, "tr_static_init: dist != 256");5559dist >>= 7; /* from now on, all distances are divided by 128 */5560for ( ; code < D_CODES; code++) {5561base_dist[code] = dist << 7;5562for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {5563_dist_code[256 + dist++] = code;5564}5565}5566//Assert (dist == 256, "tr_static_init: 256+dist != 512");55675568/* Construct the codes of the static literal tree */5569for (bits = 0; bits <= MAX_BITS; bits++) {5570bl_count[bits] = 0;5571}55725573n = 0;5574while (n <= 143) {5575static_ltree[n*2 + 1]/*.Len*/ = 8;5576n++;5577bl_count[8]++;5578}5579while (n <= 255) {5580static_ltree[n*2 + 1]/*.Len*/ = 9;5581n++;5582bl_count[9]++;5583}5584while (n <= 279) {5585static_ltree[n*2 + 1]/*.Len*/ = 7;5586n++;5587bl_count[7]++;5588}5589while (n <= 287) {5590static_ltree[n*2 + 1]/*.Len*/ = 8;5591n++;5592bl_count[8]++;5593}5594/* Codes 286 and 287 do not exist, but we must include them in the5595* tree construction to get a canonical Huffman tree (longest code5596* all ones)5597*/5598gen_codes(static_ltree, L_CODES+1, bl_count);55995600/* The static distance tree is trivial: */5601for (n = 0; n < D_CODES; n++) {5602static_dtree[n*2 + 1]/*.Len*/ = 5;5603static_dtree[n*2]/*.Code*/ = bi_reverse(n, 5);5604}56055606// Now data ready and we can init static trees5607static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS);5608static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS);5609static_bl_desc =new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS);56105611//static_init_done = true;5612}561356145615/* ===========================================================================5616* Initialize a new block.5617*/5618function init_block(s) {5619var n; /* iterates over tree elements */56205621/* Initialize the trees. */5622for (n = 0; n < L_CODES; n++) { s.dyn_ltree[n*2]/*.Freq*/ = 0; }5623for (n = 0; n < D_CODES; n++) { s.dyn_dtree[n*2]/*.Freq*/ = 0; }5624for (n = 0; n < BL_CODES; n++) { s.bl_tree[n*2]/*.Freq*/ = 0; }56255626s.dyn_ltree[END_BLOCK*2]/*.Freq*/ = 1;5627s.opt_len = s.static_len = 0;5628s.last_lit = s.matches = 0;5629}563056315632/* ===========================================================================5633* Flush the bit buffer and align the output on a byte boundary5634*/5635function bi_windup(s)5636{5637if (s.bi_valid > 8) {5638put_short(s, s.bi_buf);5639} else if (s.bi_valid > 0) {5640//put_byte(s, (Byte)s->bi_buf);5641s.pending_buf[s.pending++] = s.bi_buf;5642}5643s.bi_buf = 0;5644s.bi_valid = 0;5645}56465647/* ===========================================================================5648* Copy a stored block, storing first the length and its5649* one's complement if requested.5650*/5651function copy_block(s, buf, len, header)5652//DeflateState *s;5653//charf *buf; /* the input data */5654//unsigned len; /* its length */5655//int header; /* true if block header must be written */5656{5657bi_windup(s); /* align on byte boundary */56585659if (header) {5660put_short(s, len);5661put_short(s, ~len);5662}5663// while (len--) {5664// put_byte(s, *buf++);5665// }5666utils.arraySet(s.pending_buf, s.window, buf, len, s.pending);5667s.pending += len;5668}56695670/* ===========================================================================5671* Compares to subtrees, using the tree depth as tie breaker when5672* the subtrees have equal frequency. This minimizes the worst case length.5673*/5674function smaller(tree, n, m, depth) {5675var _n2 = n*2;5676var _m2 = m*2;5677return (tree[_n2]/*.Freq*/ < tree[_m2]/*.Freq*/ ||5678(tree[_n2]/*.Freq*/ === tree[_m2]/*.Freq*/ && depth[n] <= depth[m]));5679}56805681/* ===========================================================================5682* Restore the heap property by moving down the tree starting at node k,5683* exchanging a node with the smallest of its two sons if necessary, stopping5684* when the heap property is re-established (each father smaller than its5685* two sons).5686*/5687function pqdownheap(s, tree, k)5688// deflate_state *s;5689// ct_data *tree; /* the tree to restore */5690// int k; /* node to move down */5691{5692var v = s.heap[k];5693var j = k << 1; /* left son of k */5694while (j <= s.heap_len) {5695/* Set j to the smallest of the two sons: */5696if (j < s.heap_len &&5697smaller(tree, s.heap[j+1], s.heap[j], s.depth)) {5698j++;5699}5700/* Exit if v is smaller than both sons */5701if (smaller(tree, v, s.heap[j], s.depth)) { break; }57025703/* Exchange v with the smallest son */5704s.heap[k] = s.heap[j];5705k = j;57065707/* And continue down the tree, setting j to the left son of k */5708j <<= 1;5709}5710s.heap[k] = v;5711}571257135714// inlined manually5715// var SMALLEST = 1;57165717/* ===========================================================================5718* Send the block data compressed using the given Huffman trees5719*/5720function compress_block(s, ltree, dtree)5721// deflate_state *s;5722// const ct_data *ltree; /* literal tree */5723// const ct_data *dtree; /* distance tree */5724{5725var dist; /* distance of matched string */5726var lc; /* match length or unmatched char (if dist == 0) */5727var lx = 0; /* running index in l_buf */5728var code; /* the code to send */5729var extra; /* number of extra bits to send */57305731if (s.last_lit !== 0) {5732do {5733dist = (s.pending_buf[s.d_buf + lx*2] << 8) | (s.pending_buf[s.d_buf + lx*2 + 1]);5734lc = s.pending_buf[s.l_buf + lx];5735lx++;57365737if (dist === 0) {5738send_code(s, lc, ltree); /* send a literal byte */5739//Tracecv(isgraph(lc), (stderr," '%c' ", lc));5740} else {5741/* Here, lc is the match length - MIN_MATCH */5742code = _length_code[lc];5743send_code(s, code+LITERALS+1, ltree); /* send the length code */5744extra = extra_lbits[code];5745if (extra !== 0) {5746lc -= base_length[code];5747send_bits(s, lc, extra); /* send the extra length bits */5748}5749dist--; /* dist is now the match distance - 1 */5750code = d_code(dist);5751//Assert (code < D_CODES, "bad d_code");57525753send_code(s, code, dtree); /* send the distance code */5754extra = extra_dbits[code];5755if (extra !== 0) {5756dist -= base_dist[code];5757send_bits(s, dist, extra); /* send the extra distance bits */5758}5759} /* literal or match pair ? */57605761/* Check that the overlay between pending_buf and d_buf+l_buf is ok: */5762//Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,5763// "pendingBuf overflow");57645765} while (lx < s.last_lit);5766}57675768send_code(s, END_BLOCK, ltree);5769}577057715772/* ===========================================================================5773* Construct one Huffman tree and assigns the code bit strings and lengths.5774* Update the total bit length for the current block.5775* IN assertion: the field freq is set for all tree elements.5776* OUT assertions: the fields len and code are set to the optimal bit length5777* and corresponding code. The length opt_len is updated; static_len is5778* also updated if stree is not null. The field max_code is set.5779*/5780function build_tree(s, desc)5781// deflate_state *s;5782// tree_desc *desc; /* the tree descriptor */5783{5784var tree = desc.dyn_tree;5785var stree = desc.stat_desc.static_tree;5786var has_stree = desc.stat_desc.has_stree;5787var elems = desc.stat_desc.elems;5788var n, m; /* iterate over heap elements */5789var max_code = -1; /* largest code with non zero frequency */5790var node; /* new node being created */57915792/* Construct the initial heap, with least frequent element in5793* heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].5794* heap[0] is not used.5795*/5796s.heap_len = 0;5797s.heap_max = HEAP_SIZE;57985799for (n = 0; n < elems; n++) {5800if (tree[n * 2]/*.Freq*/ !== 0) {5801s.heap[++s.heap_len] = max_code = n;5802s.depth[n] = 0;58035804} else {5805tree[n*2 + 1]/*.Len*/ = 0;5806}5807}58085809/* The pkzip format requires that at least one distance code exists,5810* and that at least one bit should be sent even if there is only one5811* possible code. So to avoid special checks later on we force at least5812* two codes of non zero frequency.5813*/5814while (s.heap_len < 2) {5815node = s.heap[++s.heap_len] = (max_code < 2 ? ++max_code : 0);5816tree[node * 2]/*.Freq*/ = 1;5817s.depth[node] = 0;5818s.opt_len--;58195820if (has_stree) {5821s.static_len -= stree[node*2 + 1]/*.Len*/;5822}5823/* node is 0 or 1 so it does not have extra bits */5824}5825desc.max_code = max_code;58265827/* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,5828* establish sub-heaps of increasing lengths:5829*/5830for (n = (s.heap_len >> 1/*int /2*/); n >= 1; n--) { pqdownheap(s, tree, n); }58315832/* Construct the Huffman tree by repeatedly combining the least two5833* frequent nodes.5834*/5835node = elems; /* next internal node of the tree */5836do {5837//pqremove(s, tree, n); /* n = node of least frequency */5838/*** pqremove ***/5839n = s.heap[1/*SMALLEST*/];5840s.heap[1/*SMALLEST*/] = s.heap[s.heap_len--];5841pqdownheap(s, tree, 1/*SMALLEST*/);5842/***/58435844m = s.heap[1/*SMALLEST*/]; /* m = node of next least frequency */58455846s.heap[--s.heap_max] = n; /* keep the nodes sorted by frequency */5847s.heap[--s.heap_max] = m;58485849/* Create a new node father of n and m */5850tree[node * 2]/*.Freq*/ = tree[n * 2]/*.Freq*/ + tree[m * 2]/*.Freq*/;5851s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;5852tree[n*2 + 1]/*.Dad*/ = tree[m*2 + 1]/*.Dad*/ = node;58535854/* and insert the new node in the heap */5855s.heap[1/*SMALLEST*/] = node++;5856pqdownheap(s, tree, 1/*SMALLEST*/);58575858} while (s.heap_len >= 2);58595860s.heap[--s.heap_max] = s.heap[1/*SMALLEST*/];58615862/* At this point, the fields freq and dad are set. We can now5863* generate the bit lengths.5864*/5865gen_bitlen(s, desc);58665867/* The field len is now set, we can generate the bit codes */5868gen_codes(tree, max_code, s.bl_count);5869}587058715872/* ===========================================================================5873* Scan a literal or distance tree to determine the frequencies of the codes5874* in the bit length tree.5875*/5876function scan_tree(s, tree, max_code)5877// deflate_state *s;5878// ct_data *tree; /* the tree to be scanned */5879// int max_code; /* and its largest code of non zero frequency */5880{5881var n; /* iterates over all tree elements */5882var prevlen = -1; /* last emitted length */5883var curlen; /* length of current code */58845885var nextlen = tree[0*2 + 1]/*.Len*/; /* length of next code */58865887var count = 0; /* repeat count of the current code */5888var max_count = 7; /* max repeat count */5889var min_count = 4; /* min repeat count */58905891if (nextlen === 0) {5892max_count = 138;5893min_count = 3;5894}5895tree[(max_code+1)*2 + 1]/*.Len*/ = 0xffff; /* guard */58965897for (n = 0; n <= max_code; n++) {5898curlen = nextlen;5899nextlen = tree[(n+1)*2 + 1]/*.Len*/;59005901if (++count < max_count && curlen === nextlen) {5902continue;59035904} else if (count < min_count) {5905s.bl_tree[curlen * 2]/*.Freq*/ += count;59065907} else if (curlen !== 0) {59085909if (curlen !== prevlen) { s.bl_tree[curlen * 2]/*.Freq*/++; }5910s.bl_tree[REP_3_6*2]/*.Freq*/++;59115912} else if (count <= 10) {5913s.bl_tree[REPZ_3_10*2]/*.Freq*/++;59145915} else {5916s.bl_tree[REPZ_11_138*2]/*.Freq*/++;5917}59185919count = 0;5920prevlen = curlen;59215922if (nextlen === 0) {5923max_count = 138;5924min_count = 3;59255926} else if (curlen === nextlen) {5927max_count = 6;5928min_count = 3;59295930} else {5931max_count = 7;5932min_count = 4;5933}5934}5935}593659375938/* ===========================================================================5939* Send a literal or distance tree in compressed form, using the codes in5940* bl_tree.5941*/5942function send_tree(s, tree, max_code)5943// deflate_state *s;5944// ct_data *tree; /* the tree to be scanned */5945// int max_code; /* and its largest code of non zero frequency */5946{5947var n; /* iterates over all tree elements */5948var prevlen = -1; /* last emitted length */5949var curlen; /* length of current code */59505951var nextlen = tree[0*2 + 1]/*.Len*/; /* length of next code */59525953var count = 0; /* repeat count of the current code */5954var max_count = 7; /* max repeat count */5955var min_count = 4; /* min repeat count */59565957/* tree[max_code+1].Len = -1; */ /* guard already set */5958if (nextlen === 0) {5959max_count = 138;5960min_count = 3;5961}59625963for (n = 0; n <= max_code; n++) {5964curlen = nextlen;5965nextlen = tree[(n+1)*2 + 1]/*.Len*/;59665967if (++count < max_count && curlen === nextlen) {5968continue;59695970} else if (count < min_count) {5971do { send_code(s, curlen, s.bl_tree); } while (--count !== 0);59725973} else if (curlen !== 0) {5974if (curlen !== prevlen) {5975send_code(s, curlen, s.bl_tree);5976count--;5977}5978//Assert(count >= 3 && count <= 6, " 3_6?");5979send_code(s, REP_3_6, s.bl_tree);5980send_bits(s, count-3, 2);59815982} else if (count <= 10) {5983send_code(s, REPZ_3_10, s.bl_tree);5984send_bits(s, count-3, 3);59855986} else {5987send_code(s, REPZ_11_138, s.bl_tree);5988send_bits(s, count-11, 7);5989}59905991count = 0;5992prevlen = curlen;5993if (nextlen === 0) {5994max_count = 138;5995min_count = 3;59965997} else if (curlen === nextlen) {5998max_count = 6;5999min_count = 3;60006001} else {6002max_count = 7;6003min_count = 4;6004}6005}6006}600760086009/* ===========================================================================6010* Construct the Huffman tree for the bit lengths and return the index in6011* bl_order of the last bit length code to send.6012*/6013function build_bl_tree(s) {6014var max_blindex; /* index of last bit length code of non zero freq */60156016/* Determine the bit length frequencies for literal and distance trees */6017scan_tree(s, s.dyn_ltree, s.l_desc.max_code);6018scan_tree(s, s.dyn_dtree, s.d_desc.max_code);60196020/* Build the bit length tree: */6021build_tree(s, s.bl_desc);6022/* opt_len now includes the length of the tree representations, except6023* the lengths of the bit lengths codes and the 5+5+4 bits for the counts.6024*/60256026/* Determine the number of bit length codes to send. The pkzip format6027* requires that at least 4 bit length codes be sent. (appnote.txt says6028* 3 but the actual value used is 4.)6029*/6030for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {6031if (s.bl_tree[bl_order[max_blindex]*2 + 1]/*.Len*/ !== 0) {6032break;6033}6034}6035/* Update opt_len to include the bit length tree and counts */6036s.opt_len += 3*(max_blindex+1) + 5+5+4;6037//Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",6038// s->opt_len, s->static_len));60396040return max_blindex;6041}604260436044/* ===========================================================================6045* Send the header for a block using dynamic Huffman trees: the counts, the6046* lengths of the bit length codes, the literal tree and the distance tree.6047* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.6048*/6049function send_all_trees(s, lcodes, dcodes, blcodes)6050// deflate_state *s;6051// int lcodes, dcodes, blcodes; /* number of codes for each tree */6052{6053var rank; /* index in bl_order */60546055//Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");6056//Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,6057// "too many codes");6058//Tracev((stderr, "\nbl counts: "));6059send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */6060send_bits(s, dcodes-1, 5);6061send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */6062for (rank = 0; rank < blcodes; rank++) {6063//Tracev((stderr, "\nbl code %2d ", bl_order[rank]));6064send_bits(s, s.bl_tree[bl_order[rank]*2 + 1]/*.Len*/, 3);6065}6066//Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));60676068send_tree(s, s.dyn_ltree, lcodes-1); /* literal tree */6069//Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));60706071send_tree(s, s.dyn_dtree, dcodes-1); /* distance tree */6072//Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));6073}607460756076/* ===========================================================================6077* Check if the data type is TEXT or BINARY, using the following algorithm:6078* - TEXT if the two conditions below are satisfied:6079* a) There are no non-portable control characters belonging to the6080* "black list" (0..6, 14..25, 28..31).6081* b) There is at least one printable character belonging to the6082* "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).6083* - BINARY otherwise.6084* - The following partially-portable control characters form a6085* "gray list" that is ignored in this detection algorithm:6086* (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).6087* IN assertion: the fields Freq of dyn_ltree are set.6088*/6089function detect_data_type(s) {6090/* black_mask is the bit mask of black-listed bytes6091* set bits 0..6, 14..25, and 28..316092* 0xf3ffc07f = binary 111100111111111111000000011111116093*/6094var black_mask = 0xf3ffc07f;6095var n;60966097/* Check for non-textual ("black-listed") bytes. */6098for (n = 0; n <= 31; n++, black_mask >>>= 1) {6099if ((black_mask & 1) && (s.dyn_ltree[n*2]/*.Freq*/ !== 0)) {6100return Z_BINARY;6101}6102}61036104/* Check for textual ("white-listed") bytes. */6105if (s.dyn_ltree[9 * 2]/*.Freq*/ !== 0 || s.dyn_ltree[10 * 2]/*.Freq*/ !== 0 ||6106s.dyn_ltree[13 * 2]/*.Freq*/ !== 0) {6107return Z_TEXT;6108}6109for (n = 32; n < LITERALS; n++) {6110if (s.dyn_ltree[n * 2]/*.Freq*/ !== 0) {6111return Z_TEXT;6112}6113}61146115/* There are no "black-listed" or "white-listed" bytes:6116* this stream either is empty or has tolerated ("gray-listed") bytes only.6117*/6118return Z_BINARY;6119}612061216122var static_init_done = false;61236124/* ===========================================================================6125* Initialize the tree data structures for a new zlib stream.6126*/6127function _tr_init(s)6128{61296130if (!static_init_done) {6131tr_static_init();6132static_init_done = true;6133}61346135s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc);6136s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc);6137s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc);61386139s.bi_buf = 0;6140s.bi_valid = 0;61416142/* Initialize the first block of the first file: */6143init_block(s);6144}614561466147/* ===========================================================================6148* Send a stored block6149*/6150function _tr_stored_block(s, buf, stored_len, last)6151//DeflateState *s;6152//charf *buf; /* input block */6153//ulg stored_len; /* length of input block */6154//int last; /* one if this is the last block for a file */6155{6156send_bits(s, (STORED_BLOCK<<1)+(last ? 1 : 0), 3); /* send block type */6157copy_block(s, buf, stored_len, true); /* with header */6158}615961606161/* ===========================================================================6162* Send one empty static block to give enough lookahead for inflate.6163* This takes 10 bits, of which 7 may remain in the bit buffer.6164*/6165function _tr_align(s) {6166send_bits(s, STATIC_TREES<<1, 3);6167send_code(s, END_BLOCK, static_ltree);6168bi_flush(s);6169}617061716172/* ===========================================================================6173* Determine the best encoding for the current block: dynamic trees, static6174* trees or store, and output the encoded block to the zip file.6175*/6176function _tr_flush_block(s, buf, stored_len, last)6177//DeflateState *s;6178//charf *buf; /* input block, or NULL if too old */6179//ulg stored_len; /* length of input block */6180//int last; /* one if this is the last block for a file */6181{6182var opt_lenb, static_lenb; /* opt_len and static_len in bytes */6183var max_blindex = 0; /* index of last bit length code of non zero freq */61846185/* Build the Huffman trees unless a stored block is forced */6186if (s.level > 0) {61876188/* Check if the file is binary or text */6189if (s.strm.data_type === Z_UNKNOWN) {6190s.strm.data_type = detect_data_type(s);6191}61926193/* Construct the literal and distance trees */6194build_tree(s, s.l_desc);6195// Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,6196// s->static_len));61976198build_tree(s, s.d_desc);6199// Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,6200// s->static_len));6201/* At this point, opt_len and static_len are the total bit lengths of6202* the compressed block data, excluding the tree representations.6203*/62046205/* Build the bit length tree for the above two trees, and get the index6206* in bl_order of the last bit length code to send.6207*/6208max_blindex = build_bl_tree(s);62096210/* Determine the best encoding. Compute the block lengths in bytes. */6211opt_lenb = (s.opt_len+3+7) >>> 3;6212static_lenb = (s.static_len+3+7) >>> 3;62136214// Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",6215// opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,6216// s->last_lit));62176218if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }62196220} else {6221// Assert(buf != (char*)0, "lost buf");6222opt_lenb = static_lenb = stored_len + 5; /* force a stored block */6223}62246225if ((stored_len+4 <= opt_lenb) && (buf !== -1)) {6226/* 4: two words for the lengths */62276228/* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.6229* Otherwise we can't have processed more than WSIZE input bytes since6230* the last block flush, because compression would have been6231* successful. If LIT_BUFSIZE <= WSIZE, it is never too late to6232* transform a block into a stored block.6233*/6234_tr_stored_block(s, buf, stored_len, last);62356236} else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) {62376238send_bits(s, (STATIC_TREES<<1) + (last ? 1 : 0), 3);6239compress_block(s, static_ltree, static_dtree);62406241} else {6242send_bits(s, (DYN_TREES<<1) + (last ? 1 : 0), 3);6243send_all_trees(s, s.l_desc.max_code+1, s.d_desc.max_code+1, max_blindex+1);6244compress_block(s, s.dyn_ltree, s.dyn_dtree);6245}6246// Assert (s->compressed_len == s->bits_sent, "bad compressed size");6247/* The above check is made mod 2^32, for files larger than 512 MB6248* and uLong implemented on 32 bits.6249*/6250init_block(s);62516252if (last) {6253bi_windup(s);6254}6255// Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,6256// s->compressed_len-7*last));6257}62586259/* ===========================================================================6260* Save the match info and tally the frequency counts. Return true if6261* the current block must be flushed.6262*/6263function _tr_tally(s, dist, lc)6264// deflate_state *s;6265// unsigned dist; /* distance of matched string */6266// unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */6267{6268//var out_length, in_length, dcode;62696270s.pending_buf[s.d_buf + s.last_lit * 2] = (dist >>> 8) & 0xff;6271s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff;62726273s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff;6274s.last_lit++;62756276if (dist === 0) {6277/* lc is the unmatched char */6278s.dyn_ltree[lc*2]/*.Freq*/++;6279} else {6280s.matches++;6281/* Here, lc is the match length - MIN_MATCH */6282dist--; /* dist = match distance - 1 */6283//Assert((ush)dist < (ush)MAX_DIST(s) &&6284// (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&6285// (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");62866287s.dyn_ltree[(_length_code[lc]+LITERALS+1) * 2]/*.Freq*/++;6288s.dyn_dtree[d_code(dist) * 2]/*.Freq*/++;6289}62906291// (!) This block is disabled in zlib defailts,6292// don't enable it for binary compatibility62936294//#ifdef TRUNCATE_BLOCK6295// /* Try to guess if it is profitable to stop the current block here */6296// if ((s.last_lit & 0x1fff) === 0 && s.level > 2) {6297// /* Compute an upper bound for the compressed length */6298// out_length = s.last_lit*8;6299// in_length = s.strstart - s.block_start;6300//6301// for (dcode = 0; dcode < D_CODES; dcode++) {6302// out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]);6303// }6304// out_length >>>= 3;6305// //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",6306// // s->last_lit, in_length, out_length,6307// // 100L - out_length*100L/in_length));6308// if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) {6309// return true;6310// }6311// }6312//#endif63136314return (s.last_lit === s.lit_bufsize-1);6315/* We avoid equality with lit_bufsize because of wraparound at 64K6316* on 16 bit machines and because stored blocks are restricted to6317* 64K-1 bytes.6318*/6319}63206321exports._tr_init = _tr_init;6322exports._tr_stored_block = _tr_stored_block;6323exports._tr_flush_block = _tr_flush_block;6324exports._tr_tally = _tr_tally;6325exports._tr_align = _tr_align;6326},{"../utils/common":3}],15:[function(require,module,exports){6327'use strict';632863296330function ZStream() {6331/* next input byte */6332this.input = null; // JS specific, because we have no pointers6333this.next_in = 0;6334/* number of bytes available at input */6335this.avail_in = 0;6336/* total number of input bytes read so far */6337this.total_in = 0;6338/* next output byte should be put there */6339this.output = null; // JS specific, because we have no pointers6340this.next_out = 0;6341/* remaining free space at output */6342this.avail_out = 0;6343/* total number of bytes output so far */6344this.total_out = 0;6345/* last error message, NULL if no error */6346this.msg = ''/*Z_NULL*/;6347/* not visible by applications */6348this.state = null;6349/* best guess about the data type: binary or text */6350this.data_type = 2/*Z_UNKNOWN*/;6351/* adler32 value of the uncompressed data */6352this.adler = 0;6353}63546355module.exports = ZStream;6356},{}],"/":[function(require,module,exports){6357// Top level file is just a mixin of submodules & constants6358'use strict';63596360var assign = require('./lib/utils/common').assign;63616362var deflate = require('./lib/deflate');6363var inflate = require('./lib/inflate');6364var constants = require('./lib/zlib/constants');63656366var pako = {};63676368assign(pako, deflate, inflate, constants);63696370module.exports = pako;6371},{"./lib/deflate":1,"./lib/inflate":2,"./lib/utils/common":3,"./lib/zlib/constants":6}]},{},[])("/")6372});63736374