Path: blob/master/web-gui/buildyourownbotnet/assets/js/datatables/JSZip-2.5.0/jszip.js
1293 views
/*!12JSZip - A Javascript class for generating and reading zip files3<http://stuartk.com/jszip>45(c) 2009-2014 Stuart Knightley <stuart [at] stuartk.com>6Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip/master/LICENSE.markdown.78JSZip uses the library pako released under the MIT license :9https://github.com/nodeca/pako/blob/master/LICENSE10*/11!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.JSZip=e()}}(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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.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(_dereq_,module,exports){12'use strict';13// private property14var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";151617// public method for encoding18exports.encode = function(input, utf8) {19var output = "";20var chr1, chr2, chr3, enc1, enc2, enc3, enc4;21var i = 0;2223while (i < input.length) {2425chr1 = input.charCodeAt(i++);26chr2 = input.charCodeAt(i++);27chr3 = input.charCodeAt(i++);2829enc1 = chr1 >> 2;30enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);31enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);32enc4 = chr3 & 63;3334if (isNaN(chr2)) {35enc3 = enc4 = 64;36}37else if (isNaN(chr3)) {38enc4 = 64;39}4041output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4);4243}4445return output;46};4748// public method for decoding49exports.decode = function(input, utf8) {50var output = "";51var chr1, chr2, chr3;52var enc1, enc2, enc3, enc4;53var i = 0;5455input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");5657while (i < input.length) {5859enc1 = _keyStr.indexOf(input.charAt(i++));60enc2 = _keyStr.indexOf(input.charAt(i++));61enc3 = _keyStr.indexOf(input.charAt(i++));62enc4 = _keyStr.indexOf(input.charAt(i++));6364chr1 = (enc1 << 2) | (enc2 >> 4);65chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);66chr3 = ((enc3 & 3) << 6) | enc4;6768output = output + String.fromCharCode(chr1);6970if (enc3 != 64) {71output = output + String.fromCharCode(chr2);72}73if (enc4 != 64) {74output = output + String.fromCharCode(chr3);75}7677}7879return output;8081};8283},{}],2:[function(_dereq_,module,exports){84'use strict';85function CompressedObject() {86this.compressedSize = 0;87this.uncompressedSize = 0;88this.crc32 = 0;89this.compressionMethod = null;90this.compressedContent = null;91}9293CompressedObject.prototype = {94/**95* Return the decompressed content in an unspecified format.96* The format will depend on the decompressor.97* @return {Object} the decompressed content.98*/99getContent: function() {100return null; // see implementation101},102/**103* Return the compressed content in an unspecified format.104* The format will depend on the compressed conten source.105* @return {Object} the compressed content.106*/107getCompressedContent: function() {108return null; // see implementation109}110};111module.exports = CompressedObject;112113},{}],3:[function(_dereq_,module,exports){114'use strict';115exports.STORE = {116magic: "\x00\x00",117compress: function(content, compressionOptions) {118return content; // no compression119},120uncompress: function(content) {121return content; // no compression122},123compressInputType: null,124uncompressInputType: null125};126exports.DEFLATE = _dereq_('./flate');127128},{"./flate":8}],4:[function(_dereq_,module,exports){129'use strict';130131var utils = _dereq_('./utils');132133var table = [1340x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,1350x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,1360x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,1370x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,1380x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,1390x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,1400x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,1410x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,1420x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,1430x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,1440x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,1450x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,1460x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,1470x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,1480x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,1490x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,1500x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,1510x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,1520x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,1530x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,1540x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,1550x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,1560x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,1570x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,1580x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,1590x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,1600x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,1610x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,1620x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,1630x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,1640x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,1650x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,1660xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,1670xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,1680xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,1690xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,1700xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,1710xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,1720xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,1730xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,1740xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,1750xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,1760xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,1770xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,1780xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,1790xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,1800xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,1810xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,1820x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,1830x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,1840x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,1850x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,1860x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,1870x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,1880x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,1890x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,1900xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,1910xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,1920xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,1930xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,1940xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,1950xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,1960xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,1970xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D198];199200/**201*202* Javascript crc32203* http://www.webtoolkit.info/204*205*/206module.exports = function crc32(input, crc) {207if (typeof input === "undefined" || !input.length) {208return 0;209}210211var isArray = utils.getTypeOf(input) !== "string";212213if (typeof(crc) == "undefined") {214crc = 0;215}216var x = 0;217var y = 0;218var b = 0;219220crc = crc ^ (-1);221for (var i = 0, iTop = input.length; i < iTop; i++) {222b = isArray ? input[i] : input.charCodeAt(i);223y = (crc ^ b) & 0xFF;224x = table[y];225crc = (crc >>> 8) ^ x;226}227228return crc ^ (-1);229};230// vim: set shiftwidth=4 softtabstop=4:231232},{"./utils":21}],5:[function(_dereq_,module,exports){233'use strict';234var utils = _dereq_('./utils');235236function DataReader(data) {237this.data = null; // type : see implementation238this.length = 0;239this.index = 0;240}241DataReader.prototype = {242/**243* Check that the offset will not go too far.244* @param {string} offset the additional offset to check.245* @throws {Error} an Error if the offset is out of bounds.246*/247checkOffset: function(offset) {248this.checkIndex(this.index + offset);249},250/**251* Check that the specifed index will not be too far.252* @param {string} newIndex the index to check.253* @throws {Error} an Error if the index is out of bounds.254*/255checkIndex: function(newIndex) {256if (this.length < newIndex || newIndex < 0) {257throw new Error("End of data reached (data length = " + this.length + ", asked index = " + (newIndex) + "). Corrupted zip ?");258}259},260/**261* Change the index.262* @param {number} newIndex The new index.263* @throws {Error} if the new index is out of the data.264*/265setIndex: function(newIndex) {266this.checkIndex(newIndex);267this.index = newIndex;268},269/**270* Skip the next n bytes.271* @param {number} n the number of bytes to skip.272* @throws {Error} if the new index is out of the data.273*/274skip: function(n) {275this.setIndex(this.index + n);276},277/**278* Get the byte at the specified index.279* @param {number} i the index to use.280* @return {number} a byte.281*/282byteAt: function(i) {283// see implementations284},285/**286* Get the next number with a given byte size.287* @param {number} size the number of bytes to read.288* @return {number} the corresponding number.289*/290readInt: function(size) {291var result = 0,292i;293this.checkOffset(size);294for (i = this.index + size - 1; i >= this.index; i--) {295result = (result << 8) + this.byteAt(i);296}297this.index += size;298return result;299},300/**301* Get the next string with a given byte size.302* @param {number} size the number of bytes to read.303* @return {string} the corresponding string.304*/305readString: function(size) {306return utils.transformTo("string", this.readData(size));307},308/**309* Get raw data without conversion, <size> bytes.310* @param {number} size the number of bytes to read.311* @return {Object} the raw data, implementation specific.312*/313readData: function(size) {314// see implementations315},316/**317* Find the last occurence of a zip signature (4 bytes).318* @param {string} sig the signature to find.319* @return {number} the index of the last occurence, -1 if not found.320*/321lastIndexOfSignature: function(sig) {322// see implementations323},324/**325* Get the next date.326* @return {Date} the date.327*/328readDate: function() {329var dostime = this.readInt(4);330return new Date(331((dostime >> 25) & 0x7f) + 1980, // year332((dostime >> 21) & 0x0f) - 1, // month333(dostime >> 16) & 0x1f, // day334(dostime >> 11) & 0x1f, // hour335(dostime >> 5) & 0x3f, // minute336(dostime & 0x1f) << 1); // second337}338};339module.exports = DataReader;340341},{"./utils":21}],6:[function(_dereq_,module,exports){342'use strict';343exports.base64 = false;344exports.binary = false;345exports.dir = false;346exports.createFolders = false;347exports.date = null;348exports.compression = null;349exports.compressionOptions = null;350exports.comment = null;351exports.unixPermissions = null;352exports.dosPermissions = null;353354},{}],7:[function(_dereq_,module,exports){355'use strict';356var utils = _dereq_('./utils');357358/**359* @deprecated360* This function will be removed in a future version without replacement.361*/362exports.string2binary = function(str) {363return utils.string2binary(str);364};365366/**367* @deprecated368* This function will be removed in a future version without replacement.369*/370exports.string2Uint8Array = function(str) {371return utils.transformTo("uint8array", str);372};373374/**375* @deprecated376* This function will be removed in a future version without replacement.377*/378exports.uint8Array2String = function(array) {379return utils.transformTo("string", array);380};381382/**383* @deprecated384* This function will be removed in a future version without replacement.385*/386exports.string2Blob = function(str) {387var buffer = utils.transformTo("arraybuffer", str);388return utils.arrayBuffer2Blob(buffer);389};390391/**392* @deprecated393* This function will be removed in a future version without replacement.394*/395exports.arrayBuffer2Blob = function(buffer) {396return utils.arrayBuffer2Blob(buffer);397};398399/**400* @deprecated401* This function will be removed in a future version without replacement.402*/403exports.transformTo = function(outputType, input) {404return utils.transformTo(outputType, input);405};406407/**408* @deprecated409* This function will be removed in a future version without replacement.410*/411exports.getTypeOf = function(input) {412return utils.getTypeOf(input);413};414415/**416* @deprecated417* This function will be removed in a future version without replacement.418*/419exports.checkSupport = function(type) {420return utils.checkSupport(type);421};422423/**424* @deprecated425* This value will be removed in a future version without replacement.426*/427exports.MAX_VALUE_16BITS = utils.MAX_VALUE_16BITS;428429/**430* @deprecated431* This value will be removed in a future version without replacement.432*/433exports.MAX_VALUE_32BITS = utils.MAX_VALUE_32BITS;434435436/**437* @deprecated438* This function will be removed in a future version without replacement.439*/440exports.pretty = function(str) {441return utils.pretty(str);442};443444/**445* @deprecated446* This function will be removed in a future version without replacement.447*/448exports.findCompression = function(compressionMethod) {449return utils.findCompression(compressionMethod);450};451452/**453* @deprecated454* This function will be removed in a future version without replacement.455*/456exports.isRegExp = function (object) {457return utils.isRegExp(object);458};459460461},{"./utils":21}],8:[function(_dereq_,module,exports){462'use strict';463var USE_TYPEDARRAY = (typeof Uint8Array !== 'undefined') && (typeof Uint16Array !== 'undefined') && (typeof Uint32Array !== 'undefined');464465var pako = _dereq_("pako");466exports.uncompressInputType = USE_TYPEDARRAY ? "uint8array" : "array";467exports.compressInputType = USE_TYPEDARRAY ? "uint8array" : "array";468469exports.magic = "\x08\x00";470exports.compress = function(input, compressionOptions) {471return pako.deflateRaw(input, {472level : compressionOptions.level || -1 // default compression473});474};475exports.uncompress = function(input) {476return pako.inflateRaw(input);477};478479},{"pako":24}],9:[function(_dereq_,module,exports){480'use strict';481482var base64 = _dereq_('./base64');483484/**485Usage:486zip = new JSZip();487zip.file("hello.txt", "Hello, World!").file("tempfile", "nothing");488zip.folder("images").file("smile.gif", base64Data, {base64: true});489zip.file("Xmas.txt", "Ho ho ho !", {date : new Date("December 25, 2007 00:00:01")});490zip.remove("tempfile");491492base64zip = zip.generate();493494**/495496/**497* Representation a of zip file in js498* @constructor499* @param {String=|ArrayBuffer=|Uint8Array=} data the data to load, if any (optional).500* @param {Object=} options the options for creating this objects (optional).501*/502function JSZip(data, options) {503// if this constructor is used without `new`, it adds `new` before itself:504if(!(this instanceof JSZip)) return new JSZip(data, options);505506// object containing the files :507// {508// "folder/" : {...},509// "folder/data.txt" : {...}510// }511this.files = {};512513this.comment = null;514515// Where we are in the hierarchy516this.root = "";517if (data) {518this.load(data, options);519}520this.clone = function() {521var newObj = new JSZip();522for (var i in this) {523if (typeof this[i] !== "function") {524newObj[i] = this[i];525}526}527return newObj;528};529}530JSZip.prototype = _dereq_('./object');531JSZip.prototype.load = _dereq_('./load');532JSZip.support = _dereq_('./support');533JSZip.defaults = _dereq_('./defaults');534535/**536* @deprecated537* This namespace will be removed in a future version without replacement.538*/539JSZip.utils = _dereq_('./deprecatedPublicUtils');540541JSZip.base64 = {542/**543* @deprecated544* This method will be removed in a future version without replacement.545*/546encode : function(input) {547return base64.encode(input);548},549/**550* @deprecated551* This method will be removed in a future version without replacement.552*/553decode : function(input) {554return base64.decode(input);555}556};557JSZip.compressions = _dereq_('./compressions');558module.exports = JSZip;559560},{"./base64":1,"./compressions":3,"./defaults":6,"./deprecatedPublicUtils":7,"./load":10,"./object":13,"./support":17}],10:[function(_dereq_,module,exports){561'use strict';562var base64 = _dereq_('./base64');563var ZipEntries = _dereq_('./zipEntries');564module.exports = function(data, options) {565var files, zipEntries, i, input;566options = options || {};567if (options.base64) {568data = base64.decode(data);569}570571zipEntries = new ZipEntries(data, options);572files = zipEntries.files;573for (i = 0; i < files.length; i++) {574input = files[i];575this.file(input.fileName, input.decompressed, {576binary: true,577optimizedBinaryString: true,578date: input.date,579dir: input.dir,580comment : input.fileComment.length ? input.fileComment : null,581unixPermissions : input.unixPermissions,582dosPermissions : input.dosPermissions,583createFolders: options.createFolders584});585}586if (zipEntries.zipComment.length) {587this.comment = zipEntries.zipComment;588}589590return this;591};592593},{"./base64":1,"./zipEntries":22}],11:[function(_dereq_,module,exports){594(function (Buffer){595'use strict';596module.exports = function(data, encoding){597return new Buffer(data, encoding);598};599module.exports.test = function(b){600return Buffer.isBuffer(b);601};602603}).call(this,(typeof Buffer !== "undefined" ? Buffer : undefined))604},{}],12:[function(_dereq_,module,exports){605'use strict';606var Uint8ArrayReader = _dereq_('./uint8ArrayReader');607608function NodeBufferReader(data) {609this.data = data;610this.length = this.data.length;611this.index = 0;612}613NodeBufferReader.prototype = new Uint8ArrayReader();614615/**616* @see DataReader.readData617*/618NodeBufferReader.prototype.readData = function(size) {619this.checkOffset(size);620var result = this.data.slice(this.index, this.index + size);621this.index += size;622return result;623};624module.exports = NodeBufferReader;625626},{"./uint8ArrayReader":18}],13:[function(_dereq_,module,exports){627'use strict';628var support = _dereq_('./support');629var utils = _dereq_('./utils');630var crc32 = _dereq_('./crc32');631var signature = _dereq_('./signature');632var defaults = _dereq_('./defaults');633var base64 = _dereq_('./base64');634var compressions = _dereq_('./compressions');635var CompressedObject = _dereq_('./compressedObject');636var nodeBuffer = _dereq_('./nodeBuffer');637var utf8 = _dereq_('./utf8');638var StringWriter = _dereq_('./stringWriter');639var Uint8ArrayWriter = _dereq_('./uint8ArrayWriter');640641/**642* Returns the raw data of a ZipObject, decompress the content if necessary.643* @param {ZipObject} file the file to use.644* @return {String|ArrayBuffer|Uint8Array|Buffer} the data.645*/646var getRawData = function(file) {647if (file._data instanceof CompressedObject) {648file._data = file._data.getContent();649file.options.binary = true;650file.options.base64 = false;651652if (utils.getTypeOf(file._data) === "uint8array") {653var copy = file._data;654// when reading an arraybuffer, the CompressedObject mechanism will keep it and subarray() a Uint8Array.655// if we request a file in the same format, we might get the same Uint8Array or its ArrayBuffer (the original zip file).656file._data = new Uint8Array(copy.length);657// with an empty Uint8Array, Opera fails with a "Offset larger than array size"658if (copy.length !== 0) {659file._data.set(copy, 0);660}661}662}663return file._data;664};665666/**667* Returns the data of a ZipObject in a binary form. If the content is an unicode string, encode it.668* @param {ZipObject} file the file to use.669* @return {String|ArrayBuffer|Uint8Array|Buffer} the data.670*/671var getBinaryData = function(file) {672var result = getRawData(file),673type = utils.getTypeOf(result);674if (type === "string") {675if (!file.options.binary) {676// unicode text !677// unicode string => binary string is a painful process, check if we can avoid it.678if (support.nodebuffer) {679return nodeBuffer(result, "utf-8");680}681}682return file.asBinary();683}684return result;685};686687/**688* Transform this._data into a string.689* @param {function} filter a function String -> String, applied if not null on the result.690* @return {String} the string representing this._data.691*/692var dataToString = function(asUTF8) {693var result = getRawData(this);694if (result === null || typeof result === "undefined") {695return "";696}697// if the data is a base64 string, we decode it before checking the encoding !698if (this.options.base64) {699result = base64.decode(result);700}701if (asUTF8 && this.options.binary) {702// JSZip.prototype.utf8decode supports arrays as input703// skip to array => string step, utf8decode will do it.704result = out.utf8decode(result);705}706else {707// no utf8 transformation, do the array => string step.708result = utils.transformTo("string", result);709}710711if (!asUTF8 && !this.options.binary) {712result = utils.transformTo("string", out.utf8encode(result));713}714return result;715};716/**717* A simple object representing a file in the zip file.718* @constructor719* @param {string} name the name of the file720* @param {String|ArrayBuffer|Uint8Array|Buffer} data the data721* @param {Object} options the options of the file722*/723var ZipObject = function(name, data, options) {724this.name = name;725this.dir = options.dir;726this.date = options.date;727this.comment = options.comment;728this.unixPermissions = options.unixPermissions;729this.dosPermissions = options.dosPermissions;730731this._data = data;732this.options = options;733734/*735* This object contains initial values for dir and date.736* With them, we can check if the user changed the deprecated metadata in737* `ZipObject#options` or not.738*/739this._initialMetadata = {740dir : options.dir,741date : options.date742};743};744745ZipObject.prototype = {746/**747* Return the content as UTF8 string.748* @return {string} the UTF8 string.749*/750asText: function() {751return dataToString.call(this, true);752},753/**754* Returns the binary content.755* @return {string} the content as binary.756*/757asBinary: function() {758return dataToString.call(this, false);759},760/**761* Returns the content as a nodejs Buffer.762* @return {Buffer} the content as a Buffer.763*/764asNodeBuffer: function() {765var result = getBinaryData(this);766return utils.transformTo("nodebuffer", result);767},768/**769* Returns the content as an Uint8Array.770* @return {Uint8Array} the content as an Uint8Array.771*/772asUint8Array: function() {773var result = getBinaryData(this);774return utils.transformTo("uint8array", result);775},776/**777* Returns the content as an ArrayBuffer.778* @return {ArrayBuffer} the content as an ArrayBufer.779*/780asArrayBuffer: function() {781return this.asUint8Array().buffer;782}783};784785/**786* Transform an integer into a string in hexadecimal.787* @private788* @param {number} dec the number to convert.789* @param {number} bytes the number of bytes to generate.790* @returns {string} the result.791*/792var decToHex = function(dec, bytes) {793var hex = "",794i;795for (i = 0; i < bytes; i++) {796hex += String.fromCharCode(dec & 0xff);797dec = dec >>> 8;798}799return hex;800};801802/**803* Merge the objects passed as parameters into a new one.804* @private805* @param {...Object} var_args All objects to merge.806* @return {Object} a new object with the data of the others.807*/808var extend = function() {809var result = {}, i, attr;810for (i = 0; i < arguments.length; i++) { // arguments is not enumerable in some browsers811for (attr in arguments[i]) {812if (arguments[i].hasOwnProperty(attr) && typeof result[attr] === "undefined") {813result[attr] = arguments[i][attr];814}815}816}817return result;818};819820/**821* Transforms the (incomplete) options from the user into the complete822* set of options to create a file.823* @private824* @param {Object} o the options from the user.825* @return {Object} the complete set of options.826*/827var prepareFileAttrs = function(o) {828o = o || {};829if (o.base64 === true && (o.binary === null || o.binary === undefined)) {830o.binary = true;831}832o = extend(o, defaults);833o.date = o.date || new Date();834if (o.compression !== null) o.compression = o.compression.toUpperCase();835836return o;837};838839/**840* Add a file in the current folder.841* @private842* @param {string} name the name of the file843* @param {String|ArrayBuffer|Uint8Array|Buffer} data the data of the file844* @param {Object} o the options of the file845* @return {Object} the new file.846*/847var fileAdd = function(name, data, o) {848// be sure sub folders exist849var dataType = utils.getTypeOf(data),850parent;851852o = prepareFileAttrs(o);853854if (typeof o.unixPermissions === "string") {855o.unixPermissions = parseInt(o.unixPermissions, 8);856}857858// UNX_IFDIR 0040000 see zipinfo.c859if (o.unixPermissions && (o.unixPermissions & 0x4000)) {860o.dir = true;861}862// Bit 4 Directory863if (o.dosPermissions && (o.dosPermissions & 0x0010)) {864o.dir = true;865}866867if (o.dir) {868name = forceTrailingSlash(name);869}870871if (o.createFolders && (parent = parentFolder(name))) {872folderAdd.call(this, parent, true);873}874875if (o.dir || data === null || typeof data === "undefined") {876o.base64 = false;877o.binary = false;878data = null;879dataType = null;880}881else if (dataType === "string") {882if (o.binary && !o.base64) {883// optimizedBinaryString == true means that the file has already been filtered with a 0xFF mask884if (o.optimizedBinaryString !== true) {885// this is a string, not in a base64 format.886// Be sure that this is a correct "binary string"887data = utils.string2binary(data);888}889}890}891else { // arraybuffer, uint8array, ...892o.base64 = false;893o.binary = true;894895if (!dataType && !(data instanceof CompressedObject)) {896throw new Error("The data of '" + name + "' is in an unsupported format !");897}898899// special case : it's way easier to work with Uint8Array than with ArrayBuffer900if (dataType === "arraybuffer") {901data = utils.transformTo("uint8array", data);902}903}904905var object = new ZipObject(name, data, o);906this.files[name] = object;907return object;908};909910/**911* Find the parent folder of the path.912* @private913* @param {string} path the path to use914* @return {string} the parent folder, or ""915*/916var parentFolder = function (path) {917if (path.slice(-1) == '/') {918path = path.substring(0, path.length - 1);919}920var lastSlash = path.lastIndexOf('/');921return (lastSlash > 0) ? path.substring(0, lastSlash) : "";922};923924925/**926* Returns the path with a slash at the end.927* @private928* @param {String} path the path to check.929* @return {String} the path with a trailing slash.930*/931var forceTrailingSlash = function(path) {932// Check the name ends with a /933if (path.slice(-1) != "/") {934path += "/"; // IE doesn't like substr(-1)935}936return path;937};938/**939* Add a (sub) folder in the current folder.940* @private941* @param {string} name the folder's name942* @param {boolean=} [createFolders] If true, automatically create sub943* folders. Defaults to false.944* @return {Object} the new folder.945*/946var folderAdd = function(name, createFolders) {947createFolders = (typeof createFolders !== 'undefined') ? createFolders : false;948949name = forceTrailingSlash(name);950951// Does this folder already exist?952if (!this.files[name]) {953fileAdd.call(this, name, null, {954dir: true,955createFolders: createFolders956});957}958return this.files[name];959};960961/**962* Generate a JSZip.CompressedObject for a given zipOject.963* @param {ZipObject} file the object to read.964* @param {JSZip.compression} compression the compression to use.965* @param {Object} compressionOptions the options to use when compressing.966* @return {JSZip.CompressedObject} the compressed result.967*/968var generateCompressedObjectFrom = function(file, compression, compressionOptions) {969var result = new CompressedObject(),970content;971972// the data has not been decompressed, we might reuse things !973if (file._data instanceof CompressedObject) {974result.uncompressedSize = file._data.uncompressedSize;975result.crc32 = file._data.crc32;976977if (result.uncompressedSize === 0 || file.dir) {978compression = compressions['STORE'];979result.compressedContent = "";980result.crc32 = 0;981}982else if (file._data.compressionMethod === compression.magic) {983result.compressedContent = file._data.getCompressedContent();984}985else {986content = file._data.getContent();987// need to decompress / recompress988result.compressedContent = compression.compress(utils.transformTo(compression.compressInputType, content), compressionOptions);989}990}991else {992// have uncompressed data993content = getBinaryData(file);994if (!content || content.length === 0 || file.dir) {995compression = compressions['STORE'];996content = "";997}998result.uncompressedSize = content.length;999result.crc32 = crc32(content);1000result.compressedContent = compression.compress(utils.transformTo(compression.compressInputType, content), compressionOptions);1001}10021003result.compressedSize = result.compressedContent.length;1004result.compressionMethod = compression.magic;10051006return result;1007};10081009101010111012/**1013* Generate the UNIX part of the external file attributes.1014* @param {Object} unixPermissions the unix permissions or null.1015* @param {Boolean} isDir true if the entry is a directory, false otherwise.1016* @return {Number} a 32 bit integer.1017*1018* adapted from http://unix.stackexchange.com/questions/14705/the-zip-formats-external-file-attribute :1019*1020* TTTTsstrwxrwxrwx0000000000ADVSHR1021* ^^^^____________________________ file type, see zipinfo.c (UNX_*)1022* ^^^_________________________ setuid, setgid, sticky1023* ^^^^^^^^^________________ permissions1024* ^^^^^^^^^^______ not used ?1025* ^^^^^^ DOS attribute bits : Archive, Directory, Volume label, System file, Hidden, Read only1026*/1027var generateUnixExternalFileAttr = function (unixPermissions, isDir) {10281029var result = unixPermissions;1030if (!unixPermissions) {1031// I can't use octal values in strict mode, hence the hexa.1032// 040775 => 0x41fd1033// 0100664 => 0x81b41034result = isDir ? 0x41fd : 0x81b4;1035}10361037return (result & 0xFFFF) << 16;1038};10391040/**1041* Generate the DOS part of the external file attributes.1042* @param {Object} dosPermissions the dos permissions or null.1043* @param {Boolean} isDir true if the entry is a directory, false otherwise.1044* @return {Number} a 32 bit integer.1045*1046* Bit 0 Read-Only1047* Bit 1 Hidden1048* Bit 2 System1049* Bit 3 Volume Label1050* Bit 4 Directory1051* Bit 5 Archive1052*/1053var generateDosExternalFileAttr = function (dosPermissions, isDir) {10541055// the dir flag is already set for compatibility10561057return (dosPermissions || 0) & 0x3F;1058};10591060/**1061* Generate the various parts used in the construction of the final zip file.1062* @param {string} name the file name.1063* @param {ZipObject} file the file content.1064* @param {JSZip.CompressedObject} compressedObject the compressed object.1065* @param {number} offset the current offset from the start of the zip file.1066* @param {String} platform let's pretend we are this platform (change platform dependents fields)1067* @return {object} the zip parts.1068*/1069var generateZipParts = function(name, file, compressedObject, offset, platform) {1070var data = compressedObject.compressedContent,1071utfEncodedFileName = utils.transformTo("string", utf8.utf8encode(file.name)),1072comment = file.comment || "",1073utfEncodedComment = utils.transformTo("string", utf8.utf8encode(comment)),1074useUTF8ForFileName = utfEncodedFileName.length !== file.name.length,1075useUTF8ForComment = utfEncodedComment.length !== comment.length,1076o = file.options,1077dosTime,1078dosDate,1079extraFields = "",1080unicodePathExtraField = "",1081unicodeCommentExtraField = "",1082dir, date;108310841085// handle the deprecated options.dir1086if (file._initialMetadata.dir !== file.dir) {1087dir = file.dir;1088} else {1089dir = o.dir;1090}10911092// handle the deprecated options.date1093if(file._initialMetadata.date !== file.date) {1094date = file.date;1095} else {1096date = o.date;1097}10981099var extFileAttr = 0;1100var versionMadeBy = 0;1101if (dir) {1102// dos or unix, we set the dos dir flag1103extFileAttr |= 0x00010;1104}1105if(platform === "UNIX") {1106versionMadeBy = 0x031E; // UNIX, version 3.01107extFileAttr |= generateUnixExternalFileAttr(file.unixPermissions, dir);1108} else { // DOS or other, fallback to DOS1109versionMadeBy = 0x0014; // DOS, version 2.01110extFileAttr |= generateDosExternalFileAttr(file.dosPermissions, dir);1111}11121113// date1114// @see http://www.delorie.com/djgpp/doc/rbinter/it/52/13.html1115// @see http://www.delorie.com/djgpp/doc/rbinter/it/65/16.html1116// @see http://www.delorie.com/djgpp/doc/rbinter/it/66/16.html11171118dosTime = date.getHours();1119dosTime = dosTime << 6;1120dosTime = dosTime | date.getMinutes();1121dosTime = dosTime << 5;1122dosTime = dosTime | date.getSeconds() / 2;11231124dosDate = date.getFullYear() - 1980;1125dosDate = dosDate << 4;1126dosDate = dosDate | (date.getMonth() + 1);1127dosDate = dosDate << 5;1128dosDate = dosDate | date.getDate();11291130if (useUTF8ForFileName) {1131// set the unicode path extra field. unzip needs at least one extra1132// field to correctly handle unicode path, so using the path is as good1133// as any other information. This could improve the situation with1134// other archive managers too.1135// This field is usually used without the utf8 flag, with a non1136// unicode path in the header (winrar, winzip). This helps (a bit)1137// with the messy Windows' default compressed folders feature but1138// breaks on p7zip which doesn't seek the unicode path extra field.1139// So for now, UTF-8 everywhere !1140unicodePathExtraField =1141// Version1142decToHex(1, 1) +1143// NameCRC321144decToHex(crc32(utfEncodedFileName), 4) +1145// UnicodeName1146utfEncodedFileName;11471148extraFields +=1149// Info-ZIP Unicode Path Extra Field1150"\x75\x70" +1151// size1152decToHex(unicodePathExtraField.length, 2) +1153// content1154unicodePathExtraField;1155}11561157if(useUTF8ForComment) {11581159unicodeCommentExtraField =1160// Version1161decToHex(1, 1) +1162// CommentCRC321163decToHex(this.crc32(utfEncodedComment), 4) +1164// UnicodeName1165utfEncodedComment;11661167extraFields +=1168// Info-ZIP Unicode Path Extra Field1169"\x75\x63" +1170// size1171decToHex(unicodeCommentExtraField.length, 2) +1172// content1173unicodeCommentExtraField;1174}11751176var header = "";11771178// version needed to extract1179header += "\x0A\x00";1180// general purpose bit flag1181// set bit 11 if utf81182header += (useUTF8ForFileName || useUTF8ForComment) ? "\x00\x08" : "\x00\x00";1183// compression method1184header += compressedObject.compressionMethod;1185// last mod file time1186header += decToHex(dosTime, 2);1187// last mod file date1188header += decToHex(dosDate, 2);1189// crc-321190header += decToHex(compressedObject.crc32, 4);1191// compressed size1192header += decToHex(compressedObject.compressedSize, 4);1193// uncompressed size1194header += decToHex(compressedObject.uncompressedSize, 4);1195// file name length1196header += decToHex(utfEncodedFileName.length, 2);1197// extra field length1198header += decToHex(extraFields.length, 2);119912001201var fileRecord = signature.LOCAL_FILE_HEADER + header + utfEncodedFileName + extraFields;12021203var dirRecord = signature.CENTRAL_FILE_HEADER +1204// version made by (00: DOS)1205decToHex(versionMadeBy, 2) +1206// file header (common to file and central directory)1207header +1208// file comment length1209decToHex(utfEncodedComment.length, 2) +1210// disk number start1211"\x00\x00" +1212// internal file attributes TODO1213"\x00\x00" +1214// external file attributes1215decToHex(extFileAttr, 4) +1216// relative offset of local header1217decToHex(offset, 4) +1218// file name1219utfEncodedFileName +1220// extra field1221extraFields +1222// file comment1223utfEncodedComment;12241225return {1226fileRecord: fileRecord,1227dirRecord: dirRecord,1228compressedObject: compressedObject1229};1230};123112321233// return the actual prototype of JSZip1234var out = {1235/**1236* Read an existing zip and merge the data in the current JSZip object.1237* The implementation is in jszip-load.js, don't forget to include it.1238* @param {String|ArrayBuffer|Uint8Array|Buffer} stream The stream to load1239* @param {Object} options Options for loading the stream.1240* options.base64 : is the stream in base64 ? default : false1241* @return {JSZip} the current JSZip object1242*/1243load: function(stream, options) {1244throw new Error("Load method is not defined. Is the file jszip-load.js included ?");1245},12461247/**1248* Filter nested files/folders with the specified function.1249* @param {Function} search the predicate to use :1250* function (relativePath, file) {...}1251* It takes 2 arguments : the relative path and the file.1252* @return {Array} An array of matching elements.1253*/1254filter: function(search) {1255var result = [],1256filename, relativePath, file, fileClone;1257for (filename in this.files) {1258if (!this.files.hasOwnProperty(filename)) {1259continue;1260}1261file = this.files[filename];1262// return a new object, don't let the user mess with our internal objects :)1263fileClone = new ZipObject(file.name, file._data, extend(file.options));1264relativePath = filename.slice(this.root.length, filename.length);1265if (filename.slice(0, this.root.length) === this.root && // the file is in the current root1266search(relativePath, fileClone)) { // and the file matches the function1267result.push(fileClone);1268}1269}1270return result;1271},12721273/**1274* Add a file to the zip file, or search a file.1275* @param {string|RegExp} name The name of the file to add (if data is defined),1276* the name of the file to find (if no data) or a regex to match files.1277* @param {String|ArrayBuffer|Uint8Array|Buffer} data The file data, either raw or base64 encoded1278* @param {Object} o File options1279* @return {JSZip|Object|Array} this JSZip object (when adding a file),1280* a file (when searching by string) or an array of files (when searching by regex).1281*/1282file: function(name, data, o) {1283if (arguments.length === 1) {1284if (utils.isRegExp(name)) {1285var regexp = name;1286return this.filter(function(relativePath, file) {1287return !file.dir && regexp.test(relativePath);1288});1289}1290else { // text1291return this.filter(function(relativePath, file) {1292return !file.dir && relativePath === name;1293})[0] || null;1294}1295}1296else { // more than one argument : we have data !1297name = this.root + name;1298fileAdd.call(this, name, data, o);1299}1300return this;1301},13021303/**1304* Add a directory to the zip file, or search.1305* @param {String|RegExp} arg The name of the directory to add, or a regex to search folders.1306* @return {JSZip} an object with the new directory as the root, or an array containing matching folders.1307*/1308folder: function(arg) {1309if (!arg) {1310return this;1311}13121313if (utils.isRegExp(arg)) {1314return this.filter(function(relativePath, file) {1315return file.dir && arg.test(relativePath);1316});1317}13181319// else, name is a new folder1320var name = this.root + arg;1321var newFolder = folderAdd.call(this, name);13221323// Allow chaining by returning a new object with this folder as the root1324var ret = this.clone();1325ret.root = newFolder.name;1326return ret;1327},13281329/**1330* Delete a file, or a directory and all sub-files, from the zip1331* @param {string} name the name of the file to delete1332* @return {JSZip} this JSZip object1333*/1334remove: function(name) {1335name = this.root + name;1336var file = this.files[name];1337if (!file) {1338// Look for any folders1339if (name.slice(-1) != "/") {1340name += "/";1341}1342file = this.files[name];1343}13441345if (file && !file.dir) {1346// file1347delete this.files[name];1348} else {1349// maybe a folder, delete recursively1350var kids = this.filter(function(relativePath, file) {1351return file.name.slice(0, name.length) === name;1352});1353for (var i = 0; i < kids.length; i++) {1354delete this.files[kids[i].name];1355}1356}13571358return this;1359},13601361/**1362* Generate the complete zip file1363* @param {Object} options the options to generate the zip file :1364* - base64, (deprecated, use type instead) true to generate base64.1365* - compression, "STORE" by default.1366* - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob.1367* @return {String|Uint8Array|ArrayBuffer|Buffer|Blob} the zip file1368*/1369generate: function(options) {1370options = extend(options || {}, {1371base64: true,1372compression: "STORE",1373compressionOptions : null,1374type: "base64",1375platform: "DOS",1376comment: null,1377mimeType: 'application/zip'1378});13791380utils.checkSupport(options.type);13811382// accept nodejs `process.platform`1383if(1384options.platform === 'darwin' ||1385options.platform === 'freebsd' ||1386options.platform === 'linux' ||1387options.platform === 'sunos'1388) {1389options.platform = "UNIX";1390}1391if (options.platform === 'win32') {1392options.platform = "DOS";1393}13941395var zipData = [],1396localDirLength = 0,1397centralDirLength = 0,1398writer, i,1399utfEncodedComment = utils.transformTo("string", this.utf8encode(options.comment || this.comment || ""));14001401// first, generate all the zip parts.1402for (var name in this.files) {1403if (!this.files.hasOwnProperty(name)) {1404continue;1405}1406var file = this.files[name];14071408var compressionName = file.options.compression || options.compression.toUpperCase();1409var compression = compressions[compressionName];1410if (!compression) {1411throw new Error(compressionName + " is not a valid compression method !");1412}1413var compressionOptions = file.options.compressionOptions || options.compressionOptions || {};14141415var compressedObject = generateCompressedObjectFrom.call(this, file, compression, compressionOptions);14161417var zipPart = generateZipParts.call(this, name, file, compressedObject, localDirLength, options.platform);1418localDirLength += zipPart.fileRecord.length + compressedObject.compressedSize;1419centralDirLength += zipPart.dirRecord.length;1420zipData.push(zipPart);1421}14221423var dirEnd = "";14241425// end of central dir signature1426dirEnd = signature.CENTRAL_DIRECTORY_END +1427// number of this disk1428"\x00\x00" +1429// number of the disk with the start of the central directory1430"\x00\x00" +1431// total number of entries in the central directory on this disk1432decToHex(zipData.length, 2) +1433// total number of entries in the central directory1434decToHex(zipData.length, 2) +1435// size of the central directory 4 bytes1436decToHex(centralDirLength, 4) +1437// offset of start of central directory with respect to the starting disk number1438decToHex(localDirLength, 4) +1439// .ZIP file comment length1440decToHex(utfEncodedComment.length, 2) +1441// .ZIP file comment1442utfEncodedComment;144314441445// we have all the parts (and the total length)1446// time to create a writer !1447var typeName = options.type.toLowerCase();1448if(typeName==="uint8array"||typeName==="arraybuffer"||typeName==="blob"||typeName==="nodebuffer") {1449writer = new Uint8ArrayWriter(localDirLength + centralDirLength + dirEnd.length);1450}else{1451writer = new StringWriter(localDirLength + centralDirLength + dirEnd.length);1452}14531454for (i = 0; i < zipData.length; i++) {1455writer.append(zipData[i].fileRecord);1456writer.append(zipData[i].compressedObject.compressedContent);1457}1458for (i = 0; i < zipData.length; i++) {1459writer.append(zipData[i].dirRecord);1460}14611462writer.append(dirEnd);14631464var zip = writer.finalize();1465146614671468switch(options.type.toLowerCase()) {1469// case "zip is an Uint8Array"1470case "uint8array" :1471case "arraybuffer" :1472case "nodebuffer" :1473return utils.transformTo(options.type.toLowerCase(), zip);1474case "blob" :1475return utils.arrayBuffer2Blob(utils.transformTo("arraybuffer", zip), options.mimeType);1476// case "zip is a string"1477case "base64" :1478return (options.base64) ? base64.encode(zip) : zip;1479default : // case "string" :1480return zip;1481}14821483},14841485/**1486* @deprecated1487* This method will be removed in a future version without replacement.1488*/1489crc32: function (input, crc) {1490return crc32(input, crc);1491},14921493/**1494* @deprecated1495* This method will be removed in a future version without replacement.1496*/1497utf8encode: function (string) {1498return utils.transformTo("string", utf8.utf8encode(string));1499},15001501/**1502* @deprecated1503* This method will be removed in a future version without replacement.1504*/1505utf8decode: function (input) {1506return utf8.utf8decode(input);1507}1508};1509module.exports = out;15101511},{"./base64":1,"./compressedObject":2,"./compressions":3,"./crc32":4,"./defaults":6,"./nodeBuffer":11,"./signature":14,"./stringWriter":16,"./support":17,"./uint8ArrayWriter":19,"./utf8":20,"./utils":21}],14:[function(_dereq_,module,exports){1512'use strict';1513exports.LOCAL_FILE_HEADER = "PK\x03\x04";1514exports.CENTRAL_FILE_HEADER = "PK\x01\x02";1515exports.CENTRAL_DIRECTORY_END = "PK\x05\x06";1516exports.ZIP64_CENTRAL_DIRECTORY_LOCATOR = "PK\x06\x07";1517exports.ZIP64_CENTRAL_DIRECTORY_END = "PK\x06\x06";1518exports.DATA_DESCRIPTOR = "PK\x07\x08";15191520},{}],15:[function(_dereq_,module,exports){1521'use strict';1522var DataReader = _dereq_('./dataReader');1523var utils = _dereq_('./utils');15241525function StringReader(data, optimizedBinaryString) {1526this.data = data;1527if (!optimizedBinaryString) {1528this.data = utils.string2binary(this.data);1529}1530this.length = this.data.length;1531this.index = 0;1532}1533StringReader.prototype = new DataReader();1534/**1535* @see DataReader.byteAt1536*/1537StringReader.prototype.byteAt = function(i) {1538return this.data.charCodeAt(i);1539};1540/**1541* @see DataReader.lastIndexOfSignature1542*/1543StringReader.prototype.lastIndexOfSignature = function(sig) {1544return this.data.lastIndexOf(sig);1545};1546/**1547* @see DataReader.readData1548*/1549StringReader.prototype.readData = function(size) {1550this.checkOffset(size);1551// this will work because the constructor applied the "& 0xff" mask.1552var result = this.data.slice(this.index, this.index + size);1553this.index += size;1554return result;1555};1556module.exports = StringReader;15571558},{"./dataReader":5,"./utils":21}],16:[function(_dereq_,module,exports){1559'use strict';15601561var utils = _dereq_('./utils');15621563/**1564* An object to write any content to a string.1565* @constructor1566*/1567var StringWriter = function() {1568this.data = [];1569};1570StringWriter.prototype = {1571/**1572* Append any content to the current string.1573* @param {Object} input the content to add.1574*/1575append: function(input) {1576input = utils.transformTo("string", input);1577this.data.push(input);1578},1579/**1580* Finalize the construction an return the result.1581* @return {string} the generated string.1582*/1583finalize: function() {1584return this.data.join("");1585}1586};15871588module.exports = StringWriter;15891590},{"./utils":21}],17:[function(_dereq_,module,exports){1591(function (Buffer){1592'use strict';1593exports.base64 = true;1594exports.array = true;1595exports.string = true;1596exports.arraybuffer = typeof ArrayBuffer !== "undefined" && typeof Uint8Array !== "undefined";1597// contains true if JSZip can read/generate nodejs Buffer, false otherwise.1598// Browserify will provide a Buffer implementation for browsers, which is1599// an augmented Uint8Array (i.e., can be used as either Buffer or U8).1600exports.nodebuffer = typeof Buffer !== "undefined";1601// contains true if JSZip can read/generate Uint8Array, false otherwise.1602exports.uint8array = typeof Uint8Array !== "undefined";16031604if (typeof ArrayBuffer === "undefined") {1605exports.blob = false;1606}1607else {1608var buffer = new ArrayBuffer(0);1609try {1610exports.blob = new Blob([buffer], {1611type: "application/zip"1612}).size === 0;1613}1614catch (e) {1615try {1616var Builder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;1617var builder = new Builder();1618builder.append(buffer);1619exports.blob = builder.getBlob('application/zip').size === 0;1620}1621catch (e) {1622exports.blob = false;1623}1624}1625}16261627}).call(this,(typeof Buffer !== "undefined" ? Buffer : undefined))1628},{}],18:[function(_dereq_,module,exports){1629'use strict';1630var DataReader = _dereq_('./dataReader');16311632function Uint8ArrayReader(data) {1633if (data) {1634this.data = data;1635this.length = this.data.length;1636this.index = 0;1637}1638}1639Uint8ArrayReader.prototype = new DataReader();1640/**1641* @see DataReader.byteAt1642*/1643Uint8ArrayReader.prototype.byteAt = function(i) {1644return this.data[i];1645};1646/**1647* @see DataReader.lastIndexOfSignature1648*/1649Uint8ArrayReader.prototype.lastIndexOfSignature = function(sig) {1650var sig0 = sig.charCodeAt(0),1651sig1 = sig.charCodeAt(1),1652sig2 = sig.charCodeAt(2),1653sig3 = sig.charCodeAt(3);1654for (var i = this.length - 4; i >= 0; --i) {1655if (this.data[i] === sig0 && this.data[i + 1] === sig1 && this.data[i + 2] === sig2 && this.data[i + 3] === sig3) {1656return i;1657}1658}16591660return -1;1661};1662/**1663* @see DataReader.readData1664*/1665Uint8ArrayReader.prototype.readData = function(size) {1666this.checkOffset(size);1667if(size === 0) {1668// in IE10, when using subarray(idx, idx), we get the array [0x00] instead of [].1669return new Uint8Array(0);1670}1671var result = this.data.subarray(this.index, this.index + size);1672this.index += size;1673return result;1674};1675module.exports = Uint8ArrayReader;16761677},{"./dataReader":5}],19:[function(_dereq_,module,exports){1678'use strict';16791680var utils = _dereq_('./utils');16811682/**1683* An object to write any content to an Uint8Array.1684* @constructor1685* @param {number} length The length of the array.1686*/1687var Uint8ArrayWriter = function(length) {1688this.data = new Uint8Array(length);1689this.index = 0;1690};1691Uint8ArrayWriter.prototype = {1692/**1693* Append any content to the current array.1694* @param {Object} input the content to add.1695*/1696append: function(input) {1697if (input.length !== 0) {1698// with an empty Uint8Array, Opera fails with a "Offset larger than array size"1699input = utils.transformTo("uint8array", input);1700this.data.set(input, this.index);1701this.index += input.length;1702}1703},1704/**1705* Finalize the construction an return the result.1706* @return {Uint8Array} the generated array.1707*/1708finalize: function() {1709return this.data;1710}1711};17121713module.exports = Uint8ArrayWriter;17141715},{"./utils":21}],20:[function(_dereq_,module,exports){1716'use strict';17171718var utils = _dereq_('./utils');1719var support = _dereq_('./support');1720var nodeBuffer = _dereq_('./nodeBuffer');17211722/**1723* The following functions come from pako, from pako/lib/utils/strings1724* released under the MIT license, see pako https://github.com/nodeca/pako/1725*/17261727// Table with utf8 lengths (calculated by first byte of sequence)1728// Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,1729// because max possible codepoint is 0x10ffff1730var _utf8len = new Array(256);1731for (var i=0; i<256; i++) {1732_utf8len[i] = (i >= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1);1733}1734_utf8len[254]=_utf8len[254]=1; // Invalid sequence start17351736// convert string to array (typed, when possible)1737var string2buf = function (str) {1738var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;17391740// count binary size1741for (m_pos = 0; m_pos < str_len; m_pos++) {1742c = str.charCodeAt(m_pos);1743if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {1744c2 = str.charCodeAt(m_pos+1);1745if ((c2 & 0xfc00) === 0xdc00) {1746c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);1747m_pos++;1748}1749}1750buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;1751}17521753// allocate buffer1754if (support.uint8array) {1755buf = new Uint8Array(buf_len);1756} else {1757buf = new Array(buf_len);1758}17591760// convert1761for (i=0, m_pos = 0; i < buf_len; m_pos++) {1762c = str.charCodeAt(m_pos);1763if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {1764c2 = str.charCodeAt(m_pos+1);1765if ((c2 & 0xfc00) === 0xdc00) {1766c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);1767m_pos++;1768}1769}1770if (c < 0x80) {1771/* one byte */1772buf[i++] = c;1773} else if (c < 0x800) {1774/* two bytes */1775buf[i++] = 0xC0 | (c >>> 6);1776buf[i++] = 0x80 | (c & 0x3f);1777} else if (c < 0x10000) {1778/* three bytes */1779buf[i++] = 0xE0 | (c >>> 12);1780buf[i++] = 0x80 | (c >>> 6 & 0x3f);1781buf[i++] = 0x80 | (c & 0x3f);1782} else {1783/* four bytes */1784buf[i++] = 0xf0 | (c >>> 18);1785buf[i++] = 0x80 | (c >>> 12 & 0x3f);1786buf[i++] = 0x80 | (c >>> 6 & 0x3f);1787buf[i++] = 0x80 | (c & 0x3f);1788}1789}17901791return buf;1792};17931794// Calculate max possible position in utf8 buffer,1795// that will not break sequence. If that's not possible1796// - (very small limits) return max size as is.1797//1798// buf[] - utf8 bytes array1799// max - length limit (mandatory);1800var utf8border = function(buf, max) {1801var pos;18021803max = max || buf.length;1804if (max > buf.length) { max = buf.length; }18051806// go back from last position, until start of sequence found1807pos = max-1;1808while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }18091810// Fuckup - very small and broken sequence,1811// return max, because we should return something anyway.1812if (pos < 0) { return max; }18131814// If we came to start of buffer - that means vuffer is too small,1815// return max too.1816if (pos === 0) { return max; }18171818return (pos + _utf8len[buf[pos]] > max) ? pos : max;1819};18201821// convert array to string1822var buf2string = function (buf) {1823var str, i, out, c, c_len;1824var len = buf.length;18251826// Reserve max possible length (2 words per char)1827// NB: by unknown reasons, Array is significantly faster for1828// String.fromCharCode.apply than Uint16Array.1829var utf16buf = new Array(len*2);18301831for (out=0, i=0; i<len;) {1832c = buf[i++];1833// quick process ascii1834if (c < 0x80) { utf16buf[out++] = c; continue; }18351836c_len = _utf8len[c];1837// skip 5 & 6 byte codes1838if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len-1; continue; }18391840// apply mask on first byte1841c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;1842// join the rest1843while (c_len > 1 && i < len) {1844c = (c << 6) | (buf[i++] & 0x3f);1845c_len--;1846}18471848// terminated by end of string?1849if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }18501851if (c < 0x10000) {1852utf16buf[out++] = c;1853} else {1854c -= 0x10000;1855utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);1856utf16buf[out++] = 0xdc00 | (c & 0x3ff);1857}1858}18591860// shrinkBuf(utf16buf, out)1861if (utf16buf.length !== out) {1862if(utf16buf.subarray) {1863utf16buf = utf16buf.subarray(0, out);1864} else {1865utf16buf.length = out;1866}1867}18681869// return String.fromCharCode.apply(null, utf16buf);1870return utils.applyFromCharCode(utf16buf);1871};187218731874// That's all for the pako functions.187518761877/**1878* Transform a javascript string into an array (typed if possible) of bytes,1879* UTF-8 encoded.1880* @param {String} str the string to encode1881* @return {Array|Uint8Array|Buffer} the UTF-8 encoded string.1882*/1883exports.utf8encode = function utf8encode(str) {1884if (support.nodebuffer) {1885return nodeBuffer(str, "utf-8");1886}18871888return string2buf(str);1889};189018911892/**1893* Transform a bytes array (or a representation) representing an UTF-8 encoded1894* string into a javascript string.1895* @param {Array|Uint8Array|Buffer} buf the data de decode1896* @return {String} the decoded string.1897*/1898exports.utf8decode = function utf8decode(buf) {1899if (support.nodebuffer) {1900return utils.transformTo("nodebuffer", buf).toString("utf-8");1901}19021903buf = utils.transformTo(support.uint8array ? "uint8array" : "array", buf);19041905// return buf2string(buf);1906// Chrome prefers to work with "small" chunks of data1907// for the method buf2string.1908// Firefox and Chrome has their own shortcut, IE doesn't seem to really care.1909var result = [], k = 0, len = buf.length, chunk = 65536;1910while (k < len) {1911var nextBoundary = utf8border(buf, Math.min(k + chunk, len));1912if (support.uint8array) {1913result.push(buf2string(buf.subarray(k, nextBoundary)));1914} else {1915result.push(buf2string(buf.slice(k, nextBoundary)));1916}1917k = nextBoundary;1918}1919return result.join("");19201921};1922// vim: set shiftwidth=4 softtabstop=4:19231924},{"./nodeBuffer":11,"./support":17,"./utils":21}],21:[function(_dereq_,module,exports){1925'use strict';1926var support = _dereq_('./support');1927var compressions = _dereq_('./compressions');1928var nodeBuffer = _dereq_('./nodeBuffer');1929/**1930* Convert a string to a "binary string" : a string containing only char codes between 0 and 255.1931* @param {string} str the string to transform.1932* @return {String} the binary string.1933*/1934exports.string2binary = function(str) {1935var result = "";1936for (var i = 0; i < str.length; i++) {1937result += String.fromCharCode(str.charCodeAt(i) & 0xff);1938}1939return result;1940};1941exports.arrayBuffer2Blob = function(buffer, mimeType) {1942exports.checkSupport("blob");1943mimeType = mimeType || 'application/zip';19441945try {1946// Blob constructor1947return new Blob([buffer], {1948type: mimeType1949});1950}1951catch (e) {19521953try {1954// deprecated, browser only, old way1955var Builder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;1956var builder = new Builder();1957builder.append(buffer);1958return builder.getBlob(mimeType);1959}1960catch (e) {19611962// well, fuck ?!1963throw new Error("Bug : can't construct the Blob.");1964}1965}196619671968};1969/**1970* The identity function.1971* @param {Object} input the input.1972* @return {Object} the same input.1973*/1974function identity(input) {1975return input;1976}19771978/**1979* Fill in an array with a string.1980* @param {String} str the string to use.1981* @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to fill in (will be mutated).1982* @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated array.1983*/1984function stringToArrayLike(str, array) {1985for (var i = 0; i < str.length; ++i) {1986array[i] = str.charCodeAt(i) & 0xFF;1987}1988return array;1989}19901991/**1992* Transform an array-like object to a string.1993* @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.1994* @return {String} the result.1995*/1996function arrayLikeToString(array) {1997// Performances notes :1998// --------------------1999// String.fromCharCode.apply(null, array) is the fastest, see2000// see http://jsperf.com/converting-a-uint8array-to-a-string/22001// but the stack is limited (and we can get huge arrays !).2002//2003// result += String.fromCharCode(array[i]); generate too many strings !2004//2005// This code is inspired by http://jsperf.com/arraybuffer-to-string-apply-performance/22006var chunk = 65536;2007var result = [],2008len = array.length,2009type = exports.getTypeOf(array),2010k = 0,2011canUseApply = true;2012try {2013switch(type) {2014case "uint8array":2015String.fromCharCode.apply(null, new Uint8Array(0));2016break;2017case "nodebuffer":2018String.fromCharCode.apply(null, nodeBuffer(0));2019break;2020}2021} catch(e) {2022canUseApply = false;2023}20242025// no apply : slow and painful algorithm2026// default browser on android 4.*2027if (!canUseApply) {2028var resultStr = "";2029for(var i = 0; i < array.length;i++) {2030resultStr += String.fromCharCode(array[i]);2031}2032return resultStr;2033}2034while (k < len && chunk > 1) {2035try {2036if (type === "array" || type === "nodebuffer") {2037result.push(String.fromCharCode.apply(null, array.slice(k, Math.min(k + chunk, len))));2038}2039else {2040result.push(String.fromCharCode.apply(null, array.subarray(k, Math.min(k + chunk, len))));2041}2042k += chunk;2043}2044catch (e) {2045chunk = Math.floor(chunk / 2);2046}2047}2048return result.join("");2049}20502051exports.applyFromCharCode = arrayLikeToString;205220532054/**2055* Copy the data from an array-like to an other array-like.2056* @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayFrom the origin array.2057* @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayTo the destination array which will be mutated.2058* @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated destination array.2059*/2060function arrayLikeToArrayLike(arrayFrom, arrayTo) {2061for (var i = 0; i < arrayFrom.length; i++) {2062arrayTo[i] = arrayFrom[i];2063}2064return arrayTo;2065}20662067// a matrix containing functions to transform everything into everything.2068var transform = {};20692070// string to ?2071transform["string"] = {2072"string": identity,2073"array": function(input) {2074return stringToArrayLike(input, new Array(input.length));2075},2076"arraybuffer": function(input) {2077return transform["string"]["uint8array"](input).buffer;2078},2079"uint8array": function(input) {2080return stringToArrayLike(input, new Uint8Array(input.length));2081},2082"nodebuffer": function(input) {2083return stringToArrayLike(input, nodeBuffer(input.length));2084}2085};20862087// array to ?2088transform["array"] = {2089"string": arrayLikeToString,2090"array": identity,2091"arraybuffer": function(input) {2092return (new Uint8Array(input)).buffer;2093},2094"uint8array": function(input) {2095return new Uint8Array(input);2096},2097"nodebuffer": function(input) {2098return nodeBuffer(input);2099}2100};21012102// arraybuffer to ?2103transform["arraybuffer"] = {2104"string": function(input) {2105return arrayLikeToString(new Uint8Array(input));2106},2107"array": function(input) {2108return arrayLikeToArrayLike(new Uint8Array(input), new Array(input.byteLength));2109},2110"arraybuffer": identity,2111"uint8array": function(input) {2112return new Uint8Array(input);2113},2114"nodebuffer": function(input) {2115return nodeBuffer(new Uint8Array(input));2116}2117};21182119// uint8array to ?2120transform["uint8array"] = {2121"string": arrayLikeToString,2122"array": function(input) {2123return arrayLikeToArrayLike(input, new Array(input.length));2124},2125"arraybuffer": function(input) {2126return input.buffer;2127},2128"uint8array": identity,2129"nodebuffer": function(input) {2130return nodeBuffer(input);2131}2132};21332134// nodebuffer to ?2135transform["nodebuffer"] = {2136"string": arrayLikeToString,2137"array": function(input) {2138return arrayLikeToArrayLike(input, new Array(input.length));2139},2140"arraybuffer": function(input) {2141return transform["nodebuffer"]["uint8array"](input).buffer;2142},2143"uint8array": function(input) {2144return arrayLikeToArrayLike(input, new Uint8Array(input.length));2145},2146"nodebuffer": identity2147};21482149/**2150* Transform an input into any type.2151* The supported output type are : string, array, uint8array, arraybuffer, nodebuffer.2152* If no output type is specified, the unmodified input will be returned.2153* @param {String} outputType the output type.2154* @param {String|Array|ArrayBuffer|Uint8Array|Buffer} input the input to convert.2155* @throws {Error} an Error if the browser doesn't support the requested output type.2156*/2157exports.transformTo = function(outputType, input) {2158if (!input) {2159// undefined, null, etc2160// an empty string won't harm.2161input = "";2162}2163if (!outputType) {2164return input;2165}2166exports.checkSupport(outputType);2167var inputType = exports.getTypeOf(input);2168var result = transform[inputType][outputType](input);2169return result;2170};21712172/**2173* Return the type of the input.2174* The type will be in a format valid for JSZip.utils.transformTo : string, array, uint8array, arraybuffer.2175* @param {Object} input the input to identify.2176* @return {String} the (lowercase) type of the input.2177*/2178exports.getTypeOf = function(input) {2179if (typeof input === "string") {2180return "string";2181}2182if (Object.prototype.toString.call(input) === "[object Array]") {2183return "array";2184}2185if (support.nodebuffer && nodeBuffer.test(input)) {2186return "nodebuffer";2187}2188if (support.uint8array && input instanceof Uint8Array) {2189return "uint8array";2190}2191if (support.arraybuffer && input instanceof ArrayBuffer) {2192return "arraybuffer";2193}2194};21952196/**2197* Throw an exception if the type is not supported.2198* @param {String} type the type to check.2199* @throws {Error} an Error if the browser doesn't support the requested type.2200*/2201exports.checkSupport = function(type) {2202var supported = support[type.toLowerCase()];2203if (!supported) {2204throw new Error(type + " is not supported by this browser");2205}2206};2207exports.MAX_VALUE_16BITS = 65535;2208exports.MAX_VALUE_32BITS = -1; // well, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" is parsed as -122092210/**2211* Prettify a string read as binary.2212* @param {string} str the string to prettify.2213* @return {string} a pretty string.2214*/2215exports.pretty = function(str) {2216var res = '',2217code, i;2218for (i = 0; i < (str || "").length; i++) {2219code = str.charCodeAt(i);2220res += '\\x' + (code < 16 ? "0" : "") + code.toString(16).toUpperCase();2221}2222return res;2223};22242225/**2226* Find a compression registered in JSZip.2227* @param {string} compressionMethod the method magic to find.2228* @return {Object|null} the JSZip compression object, null if none found.2229*/2230exports.findCompression = function(compressionMethod) {2231for (var method in compressions) {2232if (!compressions.hasOwnProperty(method)) {2233continue;2234}2235if (compressions[method].magic === compressionMethod) {2236return compressions[method];2237}2238}2239return null;2240};2241/**2242* Cross-window, cross-Node-context regular expression detection2243* @param {Object} object Anything2244* @return {Boolean} true if the object is a regular expression,2245* false otherwise2246*/2247exports.isRegExp = function (object) {2248return Object.prototype.toString.call(object) === "[object RegExp]";2249};225022512252},{"./compressions":3,"./nodeBuffer":11,"./support":17}],22:[function(_dereq_,module,exports){2253'use strict';2254var StringReader = _dereq_('./stringReader');2255var NodeBufferReader = _dereq_('./nodeBufferReader');2256var Uint8ArrayReader = _dereq_('./uint8ArrayReader');2257var utils = _dereq_('./utils');2258var sig = _dereq_('./signature');2259var ZipEntry = _dereq_('./zipEntry');2260var support = _dereq_('./support');2261var jszipProto = _dereq_('./object');2262// class ZipEntries {{{2263/**2264* All the entries in the zip file.2265* @constructor2266* @param {String|ArrayBuffer|Uint8Array} data the binary stream to load.2267* @param {Object} loadOptions Options for loading the stream.2268*/2269function ZipEntries(data, loadOptions) {2270this.files = [];2271this.loadOptions = loadOptions;2272if (data) {2273this.load(data);2274}2275}2276ZipEntries.prototype = {2277/**2278* Check that the reader is on the speficied signature.2279* @param {string} expectedSignature the expected signature.2280* @throws {Error} if it is an other signature.2281*/2282checkSignature: function(expectedSignature) {2283var signature = this.reader.readString(4);2284if (signature !== expectedSignature) {2285throw new Error("Corrupted zip or bug : unexpected signature " + "(" + utils.pretty(signature) + ", expected " + utils.pretty(expectedSignature) + ")");2286}2287},2288/**2289* Read the end of the central directory.2290*/2291readBlockEndOfCentral: function() {2292this.diskNumber = this.reader.readInt(2);2293this.diskWithCentralDirStart = this.reader.readInt(2);2294this.centralDirRecordsOnThisDisk = this.reader.readInt(2);2295this.centralDirRecords = this.reader.readInt(2);2296this.centralDirSize = this.reader.readInt(4);2297this.centralDirOffset = this.reader.readInt(4);22982299this.zipCommentLength = this.reader.readInt(2);2300// warning : the encoding depends of the system locale2301// On a linux machine with LANG=en_US.utf8, this field is utf8 encoded.2302// On a windows machine, this field is encoded with the localized windows code page.2303this.zipComment = this.reader.readString(this.zipCommentLength);2304// To get consistent behavior with the generation part, we will assume that2305// this is utf8 encoded.2306this.zipComment = jszipProto.utf8decode(this.zipComment);2307},2308/**2309* Read the end of the Zip 64 central directory.2310* Not merged with the method readEndOfCentral :2311* The end of central can coexist with its Zip64 brother,2312* I don't want to read the wrong number of bytes !2313*/2314readBlockZip64EndOfCentral: function() {2315this.zip64EndOfCentralSize = this.reader.readInt(8);2316this.versionMadeBy = this.reader.readString(2);2317this.versionNeeded = this.reader.readInt(2);2318this.diskNumber = this.reader.readInt(4);2319this.diskWithCentralDirStart = this.reader.readInt(4);2320this.centralDirRecordsOnThisDisk = this.reader.readInt(8);2321this.centralDirRecords = this.reader.readInt(8);2322this.centralDirSize = this.reader.readInt(8);2323this.centralDirOffset = this.reader.readInt(8);23242325this.zip64ExtensibleData = {};2326var extraDataSize = this.zip64EndOfCentralSize - 44,2327index = 0,2328extraFieldId,2329extraFieldLength,2330extraFieldValue;2331while (index < extraDataSize) {2332extraFieldId = this.reader.readInt(2);2333extraFieldLength = this.reader.readInt(4);2334extraFieldValue = this.reader.readString(extraFieldLength);2335this.zip64ExtensibleData[extraFieldId] = {2336id: extraFieldId,2337length: extraFieldLength,2338value: extraFieldValue2339};2340}2341},2342/**2343* Read the end of the Zip 64 central directory locator.2344*/2345readBlockZip64EndOfCentralLocator: function() {2346this.diskWithZip64CentralDirStart = this.reader.readInt(4);2347this.relativeOffsetEndOfZip64CentralDir = this.reader.readInt(8);2348this.disksCount = this.reader.readInt(4);2349if (this.disksCount > 1) {2350throw new Error("Multi-volumes zip are not supported");2351}2352},2353/**2354* Read the local files, based on the offset read in the central part.2355*/2356readLocalFiles: function() {2357var i, file;2358for (i = 0; i < this.files.length; i++) {2359file = this.files[i];2360this.reader.setIndex(file.localHeaderOffset);2361this.checkSignature(sig.LOCAL_FILE_HEADER);2362file.readLocalPart(this.reader);2363file.handleUTF8();2364file.processAttributes();2365}2366},2367/**2368* Read the central directory.2369*/2370readCentralDir: function() {2371var file;23722373this.reader.setIndex(this.centralDirOffset);2374while (this.reader.readString(4) === sig.CENTRAL_FILE_HEADER) {2375file = new ZipEntry({2376zip64: this.zip642377}, this.loadOptions);2378file.readCentralPart(this.reader);2379this.files.push(file);2380}2381},2382/**2383* Read the end of central directory.2384*/2385readEndOfCentral: function() {2386var offset = this.reader.lastIndexOfSignature(sig.CENTRAL_DIRECTORY_END);2387if (offset === -1) {2388// Check if the content is a truncated zip or complete garbage.2389// A "LOCAL_FILE_HEADER" is not required at the beginning (auto2390// extractible zip for example) but it can give a good hint.2391// If an ajax request was used without responseType, we will also2392// get unreadable data.2393var isGarbage = true;2394try {2395this.reader.setIndex(0);2396this.checkSignature(sig.LOCAL_FILE_HEADER);2397isGarbage = false;2398} catch (e) {}23992400if (isGarbage) {2401throw new Error("Can't find end of central directory : is this a zip file ? " +2402"If it is, see http://stuk.github.io/jszip/documentation/howto/read_zip.html");2403} else {2404throw new Error("Corrupted zip : can't find end of central directory");2405}2406}2407this.reader.setIndex(offset);2408this.checkSignature(sig.CENTRAL_DIRECTORY_END);2409this.readBlockEndOfCentral();241024112412/* extract from the zip spec :24134) If one of the fields in the end of central directory2414record is too small to hold required data, the field2415should be set to -1 (0xFFFF or 0xFFFFFFFF) and the2416ZIP64 format record should be created.24175) The end of central directory record and the2418Zip64 end of central directory locator record must2419reside on the same disk when splitting or spanning2420an archive.2421*/2422if (this.diskNumber === utils.MAX_VALUE_16BITS || this.diskWithCentralDirStart === utils.MAX_VALUE_16BITS || this.centralDirRecordsOnThisDisk === utils.MAX_VALUE_16BITS || this.centralDirRecords === utils.MAX_VALUE_16BITS || this.centralDirSize === utils.MAX_VALUE_32BITS || this.centralDirOffset === utils.MAX_VALUE_32BITS) {2423this.zip64 = true;24242425/*2426Warning : the zip64 extension is supported, but ONLY if the 64bits integer read from2427the zip file can fit into a 32bits integer. This cannot be solved : Javascript represents2428all numbers as 64-bit double precision IEEE 754 floating point numbers.2429So, we have 53bits for integers and bitwise operations treat everything as 32bits.2430see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Bitwise_Operators2431and http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf section 8.52432*/24332434// should look for a zip64 EOCD locator2435offset = this.reader.lastIndexOfSignature(sig.ZIP64_CENTRAL_DIRECTORY_LOCATOR);2436if (offset === -1) {2437throw new Error("Corrupted zip : can't find the ZIP64 end of central directory locator");2438}2439this.reader.setIndex(offset);2440this.checkSignature(sig.ZIP64_CENTRAL_DIRECTORY_LOCATOR);2441this.readBlockZip64EndOfCentralLocator();24422443// now the zip64 EOCD record2444this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir);2445this.checkSignature(sig.ZIP64_CENTRAL_DIRECTORY_END);2446this.readBlockZip64EndOfCentral();2447}2448},2449prepareReader: function(data) {2450var type = utils.getTypeOf(data);2451if (type === "string" && !support.uint8array) {2452this.reader = new StringReader(data, this.loadOptions.optimizedBinaryString);2453}2454else if (type === "nodebuffer") {2455this.reader = new NodeBufferReader(data);2456}2457else {2458this.reader = new Uint8ArrayReader(utils.transformTo("uint8array", data));2459}2460},2461/**2462* Read a zip file and create ZipEntries.2463* @param {String|ArrayBuffer|Uint8Array|Buffer} data the binary string representing a zip file.2464*/2465load: function(data) {2466this.prepareReader(data);2467this.readEndOfCentral();2468this.readCentralDir();2469this.readLocalFiles();2470}2471};2472// }}} end of ZipEntries2473module.exports = ZipEntries;24742475},{"./nodeBufferReader":12,"./object":13,"./signature":14,"./stringReader":15,"./support":17,"./uint8ArrayReader":18,"./utils":21,"./zipEntry":23}],23:[function(_dereq_,module,exports){2476'use strict';2477var StringReader = _dereq_('./stringReader');2478var utils = _dereq_('./utils');2479var CompressedObject = _dereq_('./compressedObject');2480var jszipProto = _dereq_('./object');24812482var MADE_BY_DOS = 0x00;2483var MADE_BY_UNIX = 0x03;24842485// class ZipEntry {{{2486/**2487* An entry in the zip file.2488* @constructor2489* @param {Object} options Options of the current file.2490* @param {Object} loadOptions Options for loading the stream.2491*/2492function ZipEntry(options, loadOptions) {2493this.options = options;2494this.loadOptions = loadOptions;2495}2496ZipEntry.prototype = {2497/**2498* say if the file is encrypted.2499* @return {boolean} true if the file is encrypted, false otherwise.2500*/2501isEncrypted: function() {2502// bit 1 is set2503return (this.bitFlag & 0x0001) === 0x0001;2504},2505/**2506* say if the file has utf-8 filename/comment.2507* @return {boolean} true if the filename/comment is in utf-8, false otherwise.2508*/2509useUTF8: function() {2510// bit 11 is set2511return (this.bitFlag & 0x0800) === 0x0800;2512},2513/**2514* Prepare the function used to generate the compressed content from this ZipFile.2515* @param {DataReader} reader the reader to use.2516* @param {number} from the offset from where we should read the data.2517* @param {number} length the length of the data to read.2518* @return {Function} the callback to get the compressed content (the type depends of the DataReader class).2519*/2520prepareCompressedContent: function(reader, from, length) {2521return function() {2522var previousIndex = reader.index;2523reader.setIndex(from);2524var compressedFileData = reader.readData(length);2525reader.setIndex(previousIndex);25262527return compressedFileData;2528};2529},2530/**2531* Prepare the function used to generate the uncompressed content from this ZipFile.2532* @param {DataReader} reader the reader to use.2533* @param {number} from the offset from where we should read the data.2534* @param {number} length the length of the data to read.2535* @param {JSZip.compression} compression the compression used on this file.2536* @param {number} uncompressedSize the uncompressed size to expect.2537* @return {Function} the callback to get the uncompressed content (the type depends of the DataReader class).2538*/2539prepareContent: function(reader, from, length, compression, uncompressedSize) {2540return function() {25412542var compressedFileData = utils.transformTo(compression.uncompressInputType, this.getCompressedContent());2543var uncompressedFileData = compression.uncompress(compressedFileData);25442545if (uncompressedFileData.length !== uncompressedSize) {2546throw new Error("Bug : uncompressed data size mismatch");2547}25482549return uncompressedFileData;2550};2551},2552/**2553* Read the local part of a zip file and add the info in this object.2554* @param {DataReader} reader the reader to use.2555*/2556readLocalPart: function(reader) {2557var compression, localExtraFieldsLength;25582559// we already know everything from the central dir !2560// If the central dir data are false, we are doomed.2561// On the bright side, the local part is scary : zip64, data descriptors, both, etc.2562// The less data we get here, the more reliable this should be.2563// Let's skip the whole header and dash to the data !2564reader.skip(22);2565// in some zip created on windows, the filename stored in the central dir contains \ instead of /.2566// Strangely, the filename here is OK.2567// I would love to treat these zip files as corrupted (see http://www.info-zip.org/FAQ.html#backslashes2568// or APPNOTE#4.4.17.1, "All slashes MUST be forward slashes '/'") but there are a lot of bad zip generators...2569// Search "unzip mismatching "local" filename continuing with "central" filename version" on2570// the internet.2571//2572// I think I see the logic here : the central directory is used to display2573// content and the local directory is used to extract the files. Mixing / and \2574// may be used to display \ to windows users and use / when extracting the files.2575// Unfortunately, this lead also to some issues : http://seclists.org/fulldisclosure/2009/Sep/3942576this.fileNameLength = reader.readInt(2);2577localExtraFieldsLength = reader.readInt(2); // can't be sure this will be the same as the central dir2578this.fileName = reader.readString(this.fileNameLength);2579reader.skip(localExtraFieldsLength);25802581if (this.compressedSize == -1 || this.uncompressedSize == -1) {2582throw new Error("Bug or corrupted zip : didn't get enough informations from the central directory " + "(compressedSize == -1 || uncompressedSize == -1)");2583}25842585compression = utils.findCompression(this.compressionMethod);2586if (compression === null) { // no compression found2587throw new Error("Corrupted zip : compression " + utils.pretty(this.compressionMethod) + " unknown (inner file : " + this.fileName + ")");2588}2589this.decompressed = new CompressedObject();2590this.decompressed.compressedSize = this.compressedSize;2591this.decompressed.uncompressedSize = this.uncompressedSize;2592this.decompressed.crc32 = this.crc32;2593this.decompressed.compressionMethod = this.compressionMethod;2594this.decompressed.getCompressedContent = this.prepareCompressedContent(reader, reader.index, this.compressedSize, compression);2595this.decompressed.getContent = this.prepareContent(reader, reader.index, this.compressedSize, compression, this.uncompressedSize);25962597// we need to compute the crc32...2598if (this.loadOptions.checkCRC32) {2599this.decompressed = utils.transformTo("string", this.decompressed.getContent());2600if (jszipProto.crc32(this.decompressed) !== this.crc32) {2601throw new Error("Corrupted zip : CRC32 mismatch");2602}2603}2604},26052606/**2607* Read the central part of a zip file and add the info in this object.2608* @param {DataReader} reader the reader to use.2609*/2610readCentralPart: function(reader) {2611this.versionMadeBy = reader.readInt(2);2612this.versionNeeded = reader.readInt(2);2613this.bitFlag = reader.readInt(2);2614this.compressionMethod = reader.readString(2);2615this.date = reader.readDate();2616this.crc32 = reader.readInt(4);2617this.compressedSize = reader.readInt(4);2618this.uncompressedSize = reader.readInt(4);2619this.fileNameLength = reader.readInt(2);2620this.extraFieldsLength = reader.readInt(2);2621this.fileCommentLength = reader.readInt(2);2622this.diskNumberStart = reader.readInt(2);2623this.internalFileAttributes = reader.readInt(2);2624this.externalFileAttributes = reader.readInt(4);2625this.localHeaderOffset = reader.readInt(4);26262627if (this.isEncrypted()) {2628throw new Error("Encrypted zip are not supported");2629}26302631this.fileName = reader.readString(this.fileNameLength);2632this.readExtraFields(reader);2633this.parseZIP64ExtraField(reader);2634this.fileComment = reader.readString(this.fileCommentLength);2635},26362637/**2638* Parse the external file attributes and get the unix/dos permissions.2639*/2640processAttributes: function () {2641this.unixPermissions = null;2642this.dosPermissions = null;2643var madeBy = this.versionMadeBy >> 8;26442645// Check if we have the DOS directory flag set.2646// We look for it in the DOS and UNIX permissions2647// but some unknown platform could set it as a compatibility flag.2648this.dir = this.externalFileAttributes & 0x0010 ? true : false;26492650if(madeBy === MADE_BY_DOS) {2651// first 6 bits (0 to 5)2652this.dosPermissions = this.externalFileAttributes & 0x3F;2653}26542655if(madeBy === MADE_BY_UNIX) {2656this.unixPermissions = (this.externalFileAttributes >> 16) & 0xFFFF;2657// the octal permissions are in (this.unixPermissions & 0x01FF).toString(8);2658}26592660// fail safe : if the name ends with a / it probably means a folder2661if (!this.dir && this.fileName.slice(-1) === '/') {2662this.dir = true;2663}2664},26652666/**2667* Parse the ZIP64 extra field and merge the info in the current ZipEntry.2668* @param {DataReader} reader the reader to use.2669*/2670parseZIP64ExtraField: function(reader) {26712672if (!this.extraFields[0x0001]) {2673return;2674}26752676// should be something, preparing the extra reader2677var extraReader = new StringReader(this.extraFields[0x0001].value);26782679// I really hope that these 64bits integer can fit in 32 bits integer, because js2680// won't let us have more.2681if (this.uncompressedSize === utils.MAX_VALUE_32BITS) {2682this.uncompressedSize = extraReader.readInt(8);2683}2684if (this.compressedSize === utils.MAX_VALUE_32BITS) {2685this.compressedSize = extraReader.readInt(8);2686}2687if (this.localHeaderOffset === utils.MAX_VALUE_32BITS) {2688this.localHeaderOffset = extraReader.readInt(8);2689}2690if (this.diskNumberStart === utils.MAX_VALUE_32BITS) {2691this.diskNumberStart = extraReader.readInt(4);2692}2693},2694/**2695* Read the central part of a zip file and add the info in this object.2696* @param {DataReader} reader the reader to use.2697*/2698readExtraFields: function(reader) {2699var start = reader.index,2700extraFieldId,2701extraFieldLength,2702extraFieldValue;27032704this.extraFields = this.extraFields || {};27052706while (reader.index < start + this.extraFieldsLength) {2707extraFieldId = reader.readInt(2);2708extraFieldLength = reader.readInt(2);2709extraFieldValue = reader.readString(extraFieldLength);27102711this.extraFields[extraFieldId] = {2712id: extraFieldId,2713length: extraFieldLength,2714value: extraFieldValue2715};2716}2717},2718/**2719* Apply an UTF8 transformation if needed.2720*/2721handleUTF8: function() {2722if (this.useUTF8()) {2723this.fileName = jszipProto.utf8decode(this.fileName);2724this.fileComment = jszipProto.utf8decode(this.fileComment);2725} else {2726var upath = this.findExtraFieldUnicodePath();2727if (upath !== null) {2728this.fileName = upath;2729}2730var ucomment = this.findExtraFieldUnicodeComment();2731if (ucomment !== null) {2732this.fileComment = ucomment;2733}2734}2735},27362737/**2738* Find the unicode path declared in the extra field, if any.2739* @return {String} the unicode path, null otherwise.2740*/2741findExtraFieldUnicodePath: function() {2742var upathField = this.extraFields[0x7075];2743if (upathField) {2744var extraReader = new StringReader(upathField.value);27452746// wrong version2747if (extraReader.readInt(1) !== 1) {2748return null;2749}27502751// the crc of the filename changed, this field is out of date.2752if (jszipProto.crc32(this.fileName) !== extraReader.readInt(4)) {2753return null;2754}27552756return jszipProto.utf8decode(extraReader.readString(upathField.length - 5));2757}2758return null;2759},27602761/**2762* Find the unicode comment declared in the extra field, if any.2763* @return {String} the unicode comment, null otherwise.2764*/2765findExtraFieldUnicodeComment: function() {2766var ucommentField = this.extraFields[0x6375];2767if (ucommentField) {2768var extraReader = new StringReader(ucommentField.value);27692770// wrong version2771if (extraReader.readInt(1) !== 1) {2772return null;2773}27742775// the crc of the comment changed, this field is out of date.2776if (jszipProto.crc32(this.fileComment) !== extraReader.readInt(4)) {2777return null;2778}27792780return jszipProto.utf8decode(extraReader.readString(ucommentField.length - 5));2781}2782return null;2783}2784};2785module.exports = ZipEntry;27862787},{"./compressedObject":2,"./object":13,"./stringReader":15,"./utils":21}],24:[function(_dereq_,module,exports){2788// Top level file is just a mixin of submodules & constants2789'use strict';27902791var assign = _dereq_('./lib/utils/common').assign;27922793var deflate = _dereq_('./lib/deflate');2794var inflate = _dereq_('./lib/inflate');2795var constants = _dereq_('./lib/zlib/constants');27962797var pako = {};27982799assign(pako, deflate, inflate, constants);28002801module.exports = pako;2802},{"./lib/deflate":25,"./lib/inflate":26,"./lib/utils/common":27,"./lib/zlib/constants":30}],25:[function(_dereq_,module,exports){2803'use strict';280428052806var zlib_deflate = _dereq_('./zlib/deflate.js');2807var utils = _dereq_('./utils/common');2808var strings = _dereq_('./utils/strings');2809var msg = _dereq_('./zlib/messages');2810var zstream = _dereq_('./zlib/zstream');281128122813/* Public constants ==========================================================*/2814/* ===========================================================================*/28152816var Z_NO_FLUSH = 0;2817var Z_FINISH = 4;28182819var Z_OK = 0;2820var Z_STREAM_END = 1;28212822var Z_DEFAULT_COMPRESSION = -1;28232824var Z_DEFAULT_STRATEGY = 0;28252826var Z_DEFLATED = 8;28272828/* ===========================================================================*/282928302831/**2832* class Deflate2833*2834* Generic JS-style wrapper for zlib calls. If you don't need2835* streaming behaviour - use more simple functions: [[deflate]],2836* [[deflateRaw]] and [[gzip]].2837**/28382839/* internal2840* Deflate.chunks -> Array2841*2842* Chunks of output data, if [[Deflate#onData]] not overriden.2843**/28442845/**2846* Deflate.result -> Uint8Array|Array2847*2848* Compressed result, generated by default [[Deflate#onData]]2849* and [[Deflate#onEnd]] handlers. Filled after you push last chunk2850* (call [[Deflate#push]] with `Z_FINISH` / `true` param).2851**/28522853/**2854* Deflate.err -> Number2855*2856* Error code after deflate finished. 0 (Z_OK) on success.2857* You will not need it in real life, because deflate errors2858* are possible only on wrong options or bad `onData` / `onEnd`2859* custom handlers.2860**/28612862/**2863* Deflate.msg -> String2864*2865* Error message, if [[Deflate.err]] != 02866**/286728682869/**2870* new Deflate(options)2871* - options (Object): zlib deflate options.2872*2873* Creates new deflator instance with specified params. Throws exception2874* on bad params. Supported options:2875*2876* - `level`2877* - `windowBits`2878* - `memLevel`2879* - `strategy`2880*2881* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)2882* for more information on these.2883*2884* Additional options, for internal needs:2885*2886* - `chunkSize` - size of generated data chunks (16K by default)2887* - `raw` (Boolean) - do raw deflate2888* - `gzip` (Boolean) - create gzip wrapper2889* - `to` (String) - if equal to 'string', then result will be "binary string"2890* (each char code [0..255])2891* - `header` (Object) - custom header for gzip2892* - `text` (Boolean) - true if compressed data believed to be text2893* - `time` (Number) - modification time, unix timestamp2894* - `os` (Number) - operation system code2895* - `extra` (Array) - array of bytes with extra data (max 65536)2896* - `name` (String) - file name (binary string)2897* - `comment` (String) - comment (binary string)2898* - `hcrc` (Boolean) - true if header crc should be added2899*2900* ##### Example:2901*2902* ```javascript2903* var pako = require('pako')2904* , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])2905* , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);2906*2907* var deflate = new pako.Deflate({ level: 3});2908*2909* deflate.push(chunk1, false);2910* deflate.push(chunk2, true); // true -> last chunk2911*2912* if (deflate.err) { throw new Error(deflate.err); }2913*2914* console.log(deflate.result);2915* ```2916**/2917var Deflate = function(options) {29182919this.options = utils.assign({2920level: Z_DEFAULT_COMPRESSION,2921method: Z_DEFLATED,2922chunkSize: 16384,2923windowBits: 15,2924memLevel: 8,2925strategy: Z_DEFAULT_STRATEGY,2926to: ''2927}, options || {});29282929var opt = this.options;29302931if (opt.raw && (opt.windowBits > 0)) {2932opt.windowBits = -opt.windowBits;2933}29342935else if (opt.gzip && (opt.windowBits > 0) && (opt.windowBits < 16)) {2936opt.windowBits += 16;2937}29382939this.err = 0; // error code, if happens (0 = Z_OK)2940this.msg = ''; // error message2941this.ended = false; // used to avoid multiple onEnd() calls2942this.chunks = []; // chunks of compressed data29432944this.strm = new zstream();2945this.strm.avail_out = 0;29462947var status = zlib_deflate.deflateInit2(2948this.strm,2949opt.level,2950opt.method,2951opt.windowBits,2952opt.memLevel,2953opt.strategy2954);29552956if (status !== Z_OK) {2957throw new Error(msg[status]);2958}29592960if (opt.header) {2961zlib_deflate.deflateSetHeader(this.strm, opt.header);2962}2963};29642965/**2966* Deflate#push(data[, mode]) -> Boolean2967* - data (Uint8Array|Array|String): input data. Strings will be converted to2968* utf8 byte sequence.2969* - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.2970* See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.2971*2972* Sends input data to deflate pipe, generating [[Deflate#onData]] calls with2973* new compressed chunks. Returns `true` on success. The last data block must have2974* mode Z_FINISH (or `true`). That flush internal pending buffers and call2975* [[Deflate#onEnd]].2976*2977* On fail call [[Deflate#onEnd]] with error code and return false.2978*2979* We strongly recommend to use `Uint8Array` on input for best speed (output2980* array format is detected automatically). Also, don't skip last param and always2981* use the same type in your code (boolean or number). That will improve JS speed.2982*2983* For regular `Array`-s make sure all elements are [0..255].2984*2985* ##### Example2986*2987* ```javascript2988* push(chunk, false); // push one of data chunks2989* ...2990* push(chunk, true); // push last chunk2991* ```2992**/2993Deflate.prototype.push = function(data, mode) {2994var strm = this.strm;2995var chunkSize = this.options.chunkSize;2996var status, _mode;29972998if (this.ended) { return false; }29993000_mode = (mode === ~~mode) ? mode : ((mode === true) ? Z_FINISH : Z_NO_FLUSH);30013002// Convert data if needed3003if (typeof data === 'string') {3004// If we need to compress text, change encoding to utf8.3005strm.input = strings.string2buf(data);3006} else {3007strm.input = data;3008}30093010strm.next_in = 0;3011strm.avail_in = strm.input.length;30123013do {3014if (strm.avail_out === 0) {3015strm.output = new utils.Buf8(chunkSize);3016strm.next_out = 0;3017strm.avail_out = chunkSize;3018}3019status = zlib_deflate.deflate(strm, _mode); /* no bad return value */30203021if (status !== Z_STREAM_END && status !== Z_OK) {3022this.onEnd(status);3023this.ended = true;3024return false;3025}3026if (strm.avail_out === 0 || (strm.avail_in === 0 && _mode === Z_FINISH)) {3027if (this.options.to === 'string') {3028this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out)));3029} else {3030this.onData(utils.shrinkBuf(strm.output, strm.next_out));3031}3032}3033} while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END);30343035// Finalize on the last chunk.3036if (_mode === Z_FINISH) {3037status = zlib_deflate.deflateEnd(this.strm);3038this.onEnd(status);3039this.ended = true;3040return status === Z_OK;3041}30423043return true;3044};304530463047/**3048* Deflate#onData(chunk) -> Void3049* - chunk (Uint8Array|Array|String): ouput data. Type of array depends3050* on js engine support. When string output requested, each chunk3051* will be string.3052*3053* By default, stores data blocks in `chunks[]` property and glue3054* those in `onEnd`. Override this handler, if you need another behaviour.3055**/3056Deflate.prototype.onData = function(chunk) {3057this.chunks.push(chunk);3058};305930603061/**3062* Deflate#onEnd(status) -> Void3063* - status (Number): deflate status. 0 (Z_OK) on success,3064* other if not.3065*3066* Called once after you tell deflate that input stream complete3067* or error happenned. By default - join collected chunks,3068* free memory and fill `results` / `err` properties.3069**/3070Deflate.prototype.onEnd = function(status) {3071// On success - join3072if (status === Z_OK) {3073if (this.options.to === 'string') {3074this.result = this.chunks.join('');3075} else {3076this.result = utils.flattenChunks(this.chunks);3077}3078}3079this.chunks = [];3080this.err = status;3081this.msg = this.strm.msg;3082};308330843085/**3086* deflate(data[, options]) -> Uint8Array|Array|String3087* - data (Uint8Array|Array|String): input data to compress.3088* - options (Object): zlib deflate options.3089*3090* Compress `data` with deflate alrorythm and `options`.3091*3092* Supported options are:3093*3094* - level3095* - windowBits3096* - memLevel3097* - strategy3098*3099* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)3100* for more information on these.3101*3102* Sugar (options):3103*3104* - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify3105* negative windowBits implicitly.3106* - `to` (String) - if equal to 'string', then result will be "binary string"3107* (each char code [0..255])3108*3109* ##### Example:3110*3111* ```javascript3112* var pako = require('pako')3113* , data = Uint8Array([1,2,3,4,5,6,7,8,9]);3114*3115* console.log(pako.deflate(data));3116* ```3117**/3118function deflate(input, options) {3119var deflator = new Deflate(options);31203121deflator.push(input, true);31223123// That will never happens, if you don't cheat with options :)3124if (deflator.err) { throw deflator.msg; }31253126return deflator.result;3127}312831293130/**3131* deflateRaw(data[, options]) -> Uint8Array|Array|String3132* - data (Uint8Array|Array|String): input data to compress.3133* - options (Object): zlib deflate options.3134*3135* The same as [[deflate]], but creates raw data, without wrapper3136* (header and adler32 crc).3137**/3138function deflateRaw(input, options) {3139options = options || {};3140options.raw = true;3141return deflate(input, options);3142}314331443145/**3146* gzip(data[, options]) -> Uint8Array|Array|String3147* - data (Uint8Array|Array|String): input data to compress.3148* - options (Object): zlib deflate options.3149*3150* The same as [[deflate]], but create gzip wrapper instead of3151* deflate one.3152**/3153function gzip(input, options) {3154options = options || {};3155options.gzip = true;3156return deflate(input, options);3157}315831593160exports.Deflate = Deflate;3161exports.deflate = deflate;3162exports.deflateRaw = deflateRaw;3163exports.gzip = gzip;3164},{"./utils/common":27,"./utils/strings":28,"./zlib/deflate.js":32,"./zlib/messages":37,"./zlib/zstream":39}],26:[function(_dereq_,module,exports){3165'use strict';316631673168var zlib_inflate = _dereq_('./zlib/inflate.js');3169var utils = _dereq_('./utils/common');3170var strings = _dereq_('./utils/strings');3171var c = _dereq_('./zlib/constants');3172var msg = _dereq_('./zlib/messages');3173var zstream = _dereq_('./zlib/zstream');3174var gzheader = _dereq_('./zlib/gzheader');317531763177/**3178* class Inflate3179*3180* Generic JS-style wrapper for zlib calls. If you don't need3181* streaming behaviour - use more simple functions: [[inflate]]3182* and [[inflateRaw]].3183**/31843185/* internal3186* inflate.chunks -> Array3187*3188* Chunks of output data, if [[Inflate#onData]] not overriden.3189**/31903191/**3192* Inflate.result -> Uint8Array|Array|String3193*3194* Uncompressed result, generated by default [[Inflate#onData]]3195* and [[Inflate#onEnd]] handlers. Filled after you push last chunk3196* (call [[Inflate#push]] with `Z_FINISH` / `true` param).3197**/31983199/**3200* Inflate.err -> Number3201*3202* Error code after inflate finished. 0 (Z_OK) on success.3203* Should be checked if broken data possible.3204**/32053206/**3207* Inflate.msg -> String3208*3209* Error message, if [[Inflate.err]] != 03210**/321132123213/**3214* new Inflate(options)3215* - options (Object): zlib inflate options.3216*3217* Creates new inflator instance with specified params. Throws exception3218* on bad params. Supported options:3219*3220* - `windowBits`3221*3222* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)3223* for more information on these.3224*3225* Additional options, for internal needs:3226*3227* - `chunkSize` - size of generated data chunks (16K by default)3228* - `raw` (Boolean) - do raw inflate3229* - `to` (String) - if equal to 'string', then result will be converted3230* from utf8 to utf16 (javascript) string. When string output requested,3231* chunk length can differ from `chunkSize`, depending on content.3232*3233* By default, when no options set, autodetect deflate/gzip data format via3234* wrapper header.3235*3236* ##### Example:3237*3238* ```javascript3239* var pako = require('pako')3240* , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])3241* , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);3242*3243* var inflate = new pako.Inflate({ level: 3});3244*3245* inflate.push(chunk1, false);3246* inflate.push(chunk2, true); // true -> last chunk3247*3248* if (inflate.err) { throw new Error(inflate.err); }3249*3250* console.log(inflate.result);3251* ```3252**/3253var Inflate = function(options) {32543255this.options = utils.assign({3256chunkSize: 16384,3257windowBits: 0,3258to: ''3259}, options || {});32603261var opt = this.options;32623263// Force window size for `raw` data, if not set directly,3264// because we have no header for autodetect.3265if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {3266opt.windowBits = -opt.windowBits;3267if (opt.windowBits === 0) { opt.windowBits = -15; }3268}32693270// If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate3271if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&3272!(options && options.windowBits)) {3273opt.windowBits += 32;3274}32753276// Gzip header has no info about windows size, we can do autodetect only3277// for deflate. So, if window size not set, force it to max when gzip possible3278if ((opt.windowBits > 15) && (opt.windowBits < 48)) {3279// bit 3 (16) -> gzipped data3280// bit 4 (32) -> autodetect gzip/deflate3281if ((opt.windowBits & 15) === 0) {3282opt.windowBits |= 15;3283}3284}32853286this.err = 0; // error code, if happens (0 = Z_OK)3287this.msg = ''; // error message3288this.ended = false; // used to avoid multiple onEnd() calls3289this.chunks = []; // chunks of compressed data32903291this.strm = new zstream();3292this.strm.avail_out = 0;32933294var status = zlib_inflate.inflateInit2(3295this.strm,3296opt.windowBits3297);32983299if (status !== c.Z_OK) {3300throw new Error(msg[status]);3301}33023303this.header = new gzheader();33043305zlib_inflate.inflateGetHeader(this.strm, this.header);3306};33073308/**3309* Inflate#push(data[, mode]) -> Boolean3310* - data (Uint8Array|Array|String): input data3311* - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.3312* See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.3313*3314* Sends input data to inflate pipe, generating [[Inflate#onData]] calls with3315* new output chunks. Returns `true` on success. The last data block must have3316* mode Z_FINISH (or `true`). That flush internal pending buffers and call3317* [[Inflate#onEnd]].3318*3319* On fail call [[Inflate#onEnd]] with error code and return false.3320*3321* We strongly recommend to use `Uint8Array` on input for best speed (output3322* format is detected automatically). Also, don't skip last param and always3323* use the same type in your code (boolean or number). That will improve JS speed.3324*3325* For regular `Array`-s make sure all elements are [0..255].3326*3327* ##### Example3328*3329* ```javascript3330* push(chunk, false); // push one of data chunks3331* ...3332* push(chunk, true); // push last chunk3333* ```3334**/3335Inflate.prototype.push = function(data, mode) {3336var strm = this.strm;3337var chunkSize = this.options.chunkSize;3338var status, _mode;3339var next_out_utf8, tail, utf8str;33403341if (this.ended) { return false; }3342_mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH);33433344// Convert data if needed3345if (typeof data === 'string') {3346// Only binary strings can be decompressed on practice3347strm.input = strings.binstring2buf(data);3348} else {3349strm.input = data;3350}33513352strm.next_in = 0;3353strm.avail_in = strm.input.length;33543355do {3356if (strm.avail_out === 0) {3357strm.output = new utils.Buf8(chunkSize);3358strm.next_out = 0;3359strm.avail_out = chunkSize;3360}33613362status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH); /* no bad return value */33633364if (status !== c.Z_STREAM_END && status !== c.Z_OK) {3365this.onEnd(status);3366this.ended = true;3367return false;3368}33693370if (strm.next_out) {3371if (strm.avail_out === 0 || status === c.Z_STREAM_END || (strm.avail_in === 0 && _mode === c.Z_FINISH)) {33723373if (this.options.to === 'string') {33743375next_out_utf8 = strings.utf8border(strm.output, strm.next_out);33763377tail = strm.next_out - next_out_utf8;3378utf8str = strings.buf2string(strm.output, next_out_utf8);33793380// move tail3381strm.next_out = tail;3382strm.avail_out = chunkSize - tail;3383if (tail) { utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0); }33843385this.onData(utf8str);33863387} else {3388this.onData(utils.shrinkBuf(strm.output, strm.next_out));3389}3390}3391}3392} while ((strm.avail_in > 0) && status !== c.Z_STREAM_END);33933394if (status === c.Z_STREAM_END) {3395_mode = c.Z_FINISH;3396}3397// Finalize on the last chunk.3398if (_mode === c.Z_FINISH) {3399status = zlib_inflate.inflateEnd(this.strm);3400this.onEnd(status);3401this.ended = true;3402return status === c.Z_OK;3403}34043405return true;3406};340734083409/**3410* Inflate#onData(chunk) -> Void3411* - chunk (Uint8Array|Array|String): ouput data. Type of array depends3412* on js engine support. When string output requested, each chunk3413* will be string.3414*3415* By default, stores data blocks in `chunks[]` property and glue3416* those in `onEnd`. Override this handler, if you need another behaviour.3417**/3418Inflate.prototype.onData = function(chunk) {3419this.chunks.push(chunk);3420};342134223423/**3424* Inflate#onEnd(status) -> Void3425* - status (Number): inflate status. 0 (Z_OK) on success,3426* other if not.3427*3428* Called once after you tell inflate that input stream complete3429* or error happenned. By default - join collected chunks,3430* free memory and fill `results` / `err` properties.3431**/3432Inflate.prototype.onEnd = function(status) {3433// On success - join3434if (status === c.Z_OK) {3435if (this.options.to === 'string') {3436// Glue & convert here, until we teach pako to send3437// utf8 alligned strings to onData3438this.result = this.chunks.join('');3439} else {3440this.result = utils.flattenChunks(this.chunks);3441}3442}3443this.chunks = [];3444this.err = status;3445this.msg = this.strm.msg;3446};344734483449/**3450* inflate(data[, options]) -> Uint8Array|Array|String3451* - data (Uint8Array|Array|String): input data to decompress.3452* - options (Object): zlib inflate options.3453*3454* Decompress `data` with inflate/ungzip and `options`. Autodetect3455* format via wrapper header by default. That's why we don't provide3456* separate `ungzip` method.3457*3458* Supported options are:3459*3460* - windowBits3461*3462* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)3463* for more information.3464*3465* Sugar (options):3466*3467* - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify3468* negative windowBits implicitly.3469* - `to` (String) - if equal to 'string', then result will be converted3470* from utf8 to utf16 (javascript) string. When string output requested,3471* chunk length can differ from `chunkSize`, depending on content.3472*3473*3474* ##### Example:3475*3476* ```javascript3477* var pako = require('pako')3478* , input = pako.deflate([1,2,3,4,5,6,7,8,9])3479* , output;3480*3481* try {3482* output = pako.inflate(input);3483* } catch (err)3484* console.log(err);3485* }3486* ```3487**/3488function inflate(input, options) {3489var inflator = new Inflate(options);34903491inflator.push(input, true);34923493// That will never happens, if you don't cheat with options :)3494if (inflator.err) { throw inflator.msg; }34953496return inflator.result;3497}349834993500/**3501* inflateRaw(data[, options]) -> Uint8Array|Array|String3502* - data (Uint8Array|Array|String): input data to decompress.3503* - options (Object): zlib inflate options.3504*3505* The same as [[inflate]], but creates raw data, without wrapper3506* (header and adler32 crc).3507**/3508function inflateRaw(input, options) {3509options = options || {};3510options.raw = true;3511return inflate(input, options);3512}351335143515/**3516* ungzip(data[, options]) -> Uint8Array|Array|String3517* - data (Uint8Array|Array|String): input data to decompress.3518* - options (Object): zlib inflate options.3519*3520* Just shortcut to [[inflate]], because it autodetects format3521* by header.content. Done for convenience.3522**/352335243525exports.Inflate = Inflate;3526exports.inflate = inflate;3527exports.inflateRaw = inflateRaw;3528exports.ungzip = inflate;35293530},{"./utils/common":27,"./utils/strings":28,"./zlib/constants":30,"./zlib/gzheader":33,"./zlib/inflate.js":35,"./zlib/messages":37,"./zlib/zstream":39}],27:[function(_dereq_,module,exports){3531'use strict';353235333534var TYPED_OK = (typeof Uint8Array !== 'undefined') &&3535(typeof Uint16Array !== 'undefined') &&3536(typeof Int32Array !== 'undefined');353735383539exports.assign = function (obj /*from1, from2, from3, ...*/) {3540var sources = Array.prototype.slice.call(arguments, 1);3541while (sources.length) {3542var source = sources.shift();3543if (!source) { continue; }35443545if (typeof(source) !== 'object') {3546throw new TypeError(source + 'must be non-object');3547}35483549for (var p in source) {3550if (source.hasOwnProperty(p)) {3551obj[p] = source[p];3552}3553}3554}35553556return obj;3557};355835593560// reduce buffer size, avoiding mem copy3561exports.shrinkBuf = function (buf, size) {3562if (buf.length === size) { return buf; }3563if (buf.subarray) { return buf.subarray(0, size); }3564buf.length = size;3565return buf;3566};356735683569var fnTyped = {3570arraySet: function (dest, src, src_offs, len, dest_offs) {3571if (src.subarray && dest.subarray) {3572dest.set(src.subarray(src_offs, src_offs+len), dest_offs);3573return;3574}3575// Fallback to ordinary array3576for(var i=0; i<len; i++) {3577dest[dest_offs + i] = src[src_offs + i];3578}3579},3580// Join array of chunks to single array.3581flattenChunks: function(chunks) {3582var i, l, len, pos, chunk, result;35833584// calculate data length3585len = 0;3586for (i=0, l=chunks.length; i<l; i++) {3587len += chunks[i].length;3588}35893590// join chunks3591result = new Uint8Array(len);3592pos = 0;3593for (i=0, l=chunks.length; i<l; i++) {3594chunk = chunks[i];3595result.set(chunk, pos);3596pos += chunk.length;3597}35983599return result;3600}3601};36023603var fnUntyped = {3604arraySet: function (dest, src, src_offs, len, dest_offs) {3605for(var i=0; i<len; i++) {3606dest[dest_offs + i] = src[src_offs + i];3607}3608},3609// Join array of chunks to single array.3610flattenChunks: function(chunks) {3611return [].concat.apply([], chunks);3612}3613};361436153616// Enable/Disable typed arrays use, for testing3617//3618exports.setTyped = function (on) {3619if (on) {3620exports.Buf8 = Uint8Array;3621exports.Buf16 = Uint16Array;3622exports.Buf32 = Int32Array;3623exports.assign(exports, fnTyped);3624} else {3625exports.Buf8 = Array;3626exports.Buf16 = Array;3627exports.Buf32 = Array;3628exports.assign(exports, fnUntyped);3629}3630};36313632exports.setTyped(TYPED_OK);3633},{}],28:[function(_dereq_,module,exports){3634// String encode/decode helpers3635'use strict';363636373638var utils = _dereq_('./common');363936403641// Quick check if we can use fast array to bin string conversion3642//3643// - apply(Array) can fail on Android 2.23644// - apply(Uint8Array) can fail on iOS 5.1 Safary3645//3646var STR_APPLY_OK = true;3647var STR_APPLY_UIA_OK = true;36483649try { String.fromCharCode.apply(null, [0]); } catch(__) { STR_APPLY_OK = false; }3650try { String.fromCharCode.apply(null, new Uint8Array(1)); } catch(__) { STR_APPLY_UIA_OK = false; }365136523653// Table with utf8 lengths (calculated by first byte of sequence)3654// Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,3655// because max possible codepoint is 0x10ffff3656var _utf8len = new utils.Buf8(256);3657for (var i=0; i<256; i++) {3658_utf8len[i] = (i >= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1);3659}3660_utf8len[254]=_utf8len[254]=1; // Invalid sequence start366136623663// convert string to array (typed, when possible)3664exports.string2buf = function (str) {3665var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;36663667// count binary size3668for (m_pos = 0; m_pos < str_len; m_pos++) {3669c = str.charCodeAt(m_pos);3670if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {3671c2 = str.charCodeAt(m_pos+1);3672if ((c2 & 0xfc00) === 0xdc00) {3673c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);3674m_pos++;3675}3676}3677buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;3678}36793680// allocate buffer3681buf = new utils.Buf8(buf_len);36823683// convert3684for (i=0, m_pos = 0; i < buf_len; m_pos++) {3685c = str.charCodeAt(m_pos);3686if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {3687c2 = str.charCodeAt(m_pos+1);3688if ((c2 & 0xfc00) === 0xdc00) {3689c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);3690m_pos++;3691}3692}3693if (c < 0x80) {3694/* one byte */3695buf[i++] = c;3696} else if (c < 0x800) {3697/* two bytes */3698buf[i++] = 0xC0 | (c >>> 6);3699buf[i++] = 0x80 | (c & 0x3f);3700} else if (c < 0x10000) {3701/* three bytes */3702buf[i++] = 0xE0 | (c >>> 12);3703buf[i++] = 0x80 | (c >>> 6 & 0x3f);3704buf[i++] = 0x80 | (c & 0x3f);3705} else {3706/* four bytes */3707buf[i++] = 0xf0 | (c >>> 18);3708buf[i++] = 0x80 | (c >>> 12 & 0x3f);3709buf[i++] = 0x80 | (c >>> 6 & 0x3f);3710buf[i++] = 0x80 | (c & 0x3f);3711}3712}37133714return buf;3715};37163717// Helper (used in 2 places)3718function buf2binstring(buf, len) {3719// use fallback for big arrays to avoid stack overflow3720if (len < 65537) {3721if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) {3722return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len));3723}3724}37253726var result = '';3727for(var i=0; i < len; i++) {3728result += String.fromCharCode(buf[i]);3729}3730return result;3731}373237333734// Convert byte array to binary string3735exports.buf2binstring = function(buf) {3736return buf2binstring(buf, buf.length);3737};373837393740// Convert binary string (typed, when possible)3741exports.binstring2buf = function(str) {3742var buf = new utils.Buf8(str.length);3743for(var i=0, len=buf.length; i < len; i++) {3744buf[i] = str.charCodeAt(i);3745}3746return buf;3747};374837493750// convert array to string3751exports.buf2string = function (buf, max) {3752var i, out, c, c_len;3753var len = max || buf.length;37543755// Reserve max possible length (2 words per char)3756// NB: by unknown reasons, Array is significantly faster for3757// String.fromCharCode.apply than Uint16Array.3758var utf16buf = new Array(len*2);37593760for (out=0, i=0; i<len;) {3761c = buf[i++];3762// quick process ascii3763if (c < 0x80) { utf16buf[out++] = c; continue; }37643765c_len = _utf8len[c];3766// skip 5 & 6 byte codes3767if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len-1; continue; }37683769// apply mask on first byte3770c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;3771// join the rest3772while (c_len > 1 && i < len) {3773c = (c << 6) | (buf[i++] & 0x3f);3774c_len--;3775}37763777// terminated by end of string?3778if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }37793780if (c < 0x10000) {3781utf16buf[out++] = c;3782} else {3783c -= 0x10000;3784utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);3785utf16buf[out++] = 0xdc00 | (c & 0x3ff);3786}3787}37883789return buf2binstring(utf16buf, out);3790};379137923793// Calculate max possible position in utf8 buffer,3794// that will not break sequence. If that's not possible3795// - (very small limits) return max size as is.3796//3797// buf[] - utf8 bytes array3798// max - length limit (mandatory);3799exports.utf8border = function(buf, max) {3800var pos;38013802max = max || buf.length;3803if (max > buf.length) { max = buf.length; }38043805// go back from last position, until start of sequence found3806pos = max-1;3807while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }38083809// Fuckup - very small and broken sequence,3810// return max, because we should return something anyway.3811if (pos < 0) { return max; }38123813// If we came to start of buffer - that means vuffer is too small,3814// return max too.3815if (pos === 0) { return max; }38163817return (pos + _utf8len[buf[pos]] > max) ? pos : max;3818};38193820},{"./common":27}],29:[function(_dereq_,module,exports){3821'use strict';38223823// Note: adler32 takes 12% for level 0 and 2% for level 6.3824// It doesn't worth to make additional optimizationa as in original.3825// Small size is preferable.38263827function adler32(adler, buf, len, pos) {3828var s1 = (adler & 0xffff) |03829, s2 = ((adler >>> 16) & 0xffff) |03830, n = 0;38313832while (len !== 0) {3833// Set limit ~ twice less than 5552, to keep3834// s2 in 31-bits, because we force signed ints.3835// in other case %= will fail.3836n = len > 2000 ? 2000 : len;3837len -= n;38383839do {3840s1 = (s1 + buf[pos++]) |0;3841s2 = (s2 + s1) |0;3842} while (--n);38433844s1 %= 65521;3845s2 %= 65521;3846}38473848return (s1 | (s2 << 16)) |0;3849}385038513852module.exports = adler32;3853},{}],30:[function(_dereq_,module,exports){3854module.exports = {38553856/* Allowed flush values; see deflate() and inflate() below for details */3857Z_NO_FLUSH: 0,3858Z_PARTIAL_FLUSH: 1,3859Z_SYNC_FLUSH: 2,3860Z_FULL_FLUSH: 3,3861Z_FINISH: 4,3862Z_BLOCK: 5,3863Z_TREES: 6,38643865/* Return codes for the compression/decompression functions. Negative values3866* are errors, positive values are used for special but normal events.3867*/3868Z_OK: 0,3869Z_STREAM_END: 1,3870Z_NEED_DICT: 2,3871Z_ERRNO: -1,3872Z_STREAM_ERROR: -2,3873Z_DATA_ERROR: -3,3874//Z_MEM_ERROR: -4,3875Z_BUF_ERROR: -5,3876//Z_VERSION_ERROR: -6,38773878/* compression levels */3879Z_NO_COMPRESSION: 0,3880Z_BEST_SPEED: 1,3881Z_BEST_COMPRESSION: 9,3882Z_DEFAULT_COMPRESSION: -1,388338843885Z_FILTERED: 1,3886Z_HUFFMAN_ONLY: 2,3887Z_RLE: 3,3888Z_FIXED: 4,3889Z_DEFAULT_STRATEGY: 0,38903891/* Possible values of the data_type field (though see inflate()) */3892Z_BINARY: 0,3893Z_TEXT: 1,3894//Z_ASCII: 1, // = Z_TEXT (deprecated)3895Z_UNKNOWN: 2,38963897/* The deflate compression method */3898Z_DEFLATED: 83899//Z_NULL: null // Use -1 or null inline, depending on var type3900};3901},{}],31:[function(_dereq_,module,exports){3902'use strict';39033904// Note: we can't get significant speed boost here.3905// So write code to minimize size - no pregenerated tables3906// and array tools dependencies.390739083909// Use ordinary array, since untyped makes no boost here3910function makeTable() {3911var c, table = [];39123913for(var n =0; n < 256; n++){3914c = n;3915for(var k =0; k < 8; k++){3916c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));3917}3918table[n] = c;3919}39203921return table;3922}39233924// Create table on load. Just 255 signed longs. Not a problem.3925var crcTable = makeTable();392639273928function crc32(crc, buf, len, pos) {3929var t = crcTable3930, end = pos + len;39313932crc = crc ^ (-1);39333934for (var i = pos; i < end; i++ ) {3935crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];3936}39373938return (crc ^ (-1)); // >>> 0;3939}394039413942module.exports = crc32;3943},{}],32:[function(_dereq_,module,exports){3944'use strict';39453946var utils = _dereq_('../utils/common');3947var trees = _dereq_('./trees');3948var adler32 = _dereq_('./adler32');3949var crc32 = _dereq_('./crc32');3950var msg = _dereq_('./messages');39513952/* Public constants ==========================================================*/3953/* ===========================================================================*/395439553956/* Allowed flush values; see deflate() and inflate() below for details */3957var Z_NO_FLUSH = 0;3958var Z_PARTIAL_FLUSH = 1;3959//var Z_SYNC_FLUSH = 2;3960var Z_FULL_FLUSH = 3;3961var Z_FINISH = 4;3962var Z_BLOCK = 5;3963//var Z_TREES = 6;396439653966/* Return codes for the compression/decompression functions. Negative values3967* are errors, positive values are used for special but normal events.3968*/3969var Z_OK = 0;3970var Z_STREAM_END = 1;3971//var Z_NEED_DICT = 2;3972//var Z_ERRNO = -1;3973var Z_STREAM_ERROR = -2;3974var Z_DATA_ERROR = -3;3975//var Z_MEM_ERROR = -4;3976var Z_BUF_ERROR = -5;3977//var Z_VERSION_ERROR = -6;397839793980/* compression levels */3981//var Z_NO_COMPRESSION = 0;3982//var Z_BEST_SPEED = 1;3983//var Z_BEST_COMPRESSION = 9;3984var Z_DEFAULT_COMPRESSION = -1;398539863987var Z_FILTERED = 1;3988var Z_HUFFMAN_ONLY = 2;3989var Z_RLE = 3;3990var Z_FIXED = 4;3991var Z_DEFAULT_STRATEGY = 0;39923993/* Possible values of the data_type field (though see inflate()) */3994//var Z_BINARY = 0;3995//var Z_TEXT = 1;3996//var Z_ASCII = 1; // = Z_TEXT3997var Z_UNKNOWN = 2;399839994000/* The deflate compression method */4001var Z_DEFLATED = 8;40024003/*============================================================================*/400440054006var MAX_MEM_LEVEL = 9;4007/* Maximum value for memLevel in deflateInit2 */4008var MAX_WBITS = 15;4009/* 32K LZ77 window */4010var DEF_MEM_LEVEL = 8;401140124013var LENGTH_CODES = 29;4014/* number of length codes, not counting the special END_BLOCK code */4015var LITERALS = 256;4016/* number of literal bytes 0..255 */4017var L_CODES = LITERALS + 1 + LENGTH_CODES;4018/* number of Literal or Length codes, including the END_BLOCK code */4019var D_CODES = 30;4020/* number of distance codes */4021var BL_CODES = 19;4022/* number of codes used to transfer the bit lengths */4023var HEAP_SIZE = 2*L_CODES + 1;4024/* maximum heap size */4025var MAX_BITS = 15;4026/* All codes must not exceed MAX_BITS bits */40274028var MIN_MATCH = 3;4029var MAX_MATCH = 258;4030var MIN_LOOKAHEAD = (MAX_MATCH + MIN_MATCH + 1);40314032var PRESET_DICT = 0x20;40334034var INIT_STATE = 42;4035var EXTRA_STATE = 69;4036var NAME_STATE = 73;4037var COMMENT_STATE = 91;4038var HCRC_STATE = 103;4039var BUSY_STATE = 113;4040var FINISH_STATE = 666;40414042var BS_NEED_MORE = 1; /* block not completed, need more input or more output */4043var BS_BLOCK_DONE = 2; /* block flush performed */4044var BS_FINISH_STARTED = 3; /* finish started, need only more output at next deflate */4045var BS_FINISH_DONE = 4; /* finish done, accept no more input or output */40464047var OS_CODE = 0x03; // Unix :) . Don't detect, use this default.40484049function err(strm, errorCode) {4050strm.msg = msg[errorCode];4051return errorCode;4052}40534054function rank(f) {4055return ((f) << 1) - ((f) > 4 ? 9 : 0);4056}40574058function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }405940604061/* =========================================================================4062* Flush as much pending output as possible. All deflate() output goes4063* through this function so some applications may wish to modify it4064* to avoid allocating a large strm->output buffer and copying into it.4065* (See also read_buf()).4066*/4067function flush_pending(strm) {4068var s = strm.state;40694070//_tr_flush_bits(s);4071var len = s.pending;4072if (len > strm.avail_out) {4073len = strm.avail_out;4074}4075if (len === 0) { return; }40764077utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out);4078strm.next_out += len;4079s.pending_out += len;4080strm.total_out += len;4081strm.avail_out -= len;4082s.pending -= len;4083if (s.pending === 0) {4084s.pending_out = 0;4085}4086}408740884089function flush_block_only (s, last) {4090trees._tr_flush_block(s, (s.block_start >= 0 ? s.block_start : -1), s.strstart - s.block_start, last);4091s.block_start = s.strstart;4092flush_pending(s.strm);4093}409440954096function put_byte(s, b) {4097s.pending_buf[s.pending++] = b;4098}409941004101/* =========================================================================4102* Put a short in the pending buffer. The 16-bit value is put in MSB order.4103* IN assertion: the stream state is correct and there is enough room in4104* pending_buf.4105*/4106function putShortMSB(s, b) {4107// put_byte(s, (Byte)(b >> 8));4108// put_byte(s, (Byte)(b & 0xff));4109s.pending_buf[s.pending++] = (b >>> 8) & 0xff;4110s.pending_buf[s.pending++] = b & 0xff;4111}411241134114/* ===========================================================================4115* Read a new buffer from the current input stream, update the adler324116* and total number of bytes read. All deflate() input goes through4117* this function so some applications may wish to modify it to avoid4118* allocating a large strm->input buffer and copying from it.4119* (See also flush_pending()).4120*/4121function read_buf(strm, buf, start, size) {4122var len = strm.avail_in;41234124if (len > size) { len = size; }4125if (len === 0) { return 0; }41264127strm.avail_in -= len;41284129utils.arraySet(buf, strm.input, strm.next_in, len, start);4130if (strm.state.wrap === 1) {4131strm.adler = adler32(strm.adler, buf, len, start);4132}41334134else if (strm.state.wrap === 2) {4135strm.adler = crc32(strm.adler, buf, len, start);4136}41374138strm.next_in += len;4139strm.total_in += len;41404141return len;4142}414341444145/* ===========================================================================4146* Set match_start to the longest match starting at the given string and4147* return its length. Matches shorter or equal to prev_length are discarded,4148* in which case the result is equal to prev_length and match_start is4149* garbage.4150* IN assertions: cur_match is the head of the hash chain for the current4151* string (strstart) and its distance is <= MAX_DIST, and prev_length >= 14152* OUT assertion: the match length is not greater than s->lookahead.4153*/4154function longest_match(s, cur_match) {4155var chain_length = s.max_chain_length; /* max hash chain length */4156var scan = s.strstart; /* current string */4157var match; /* matched string */4158var len; /* length of current match */4159var best_len = s.prev_length; /* best match length so far */4160var nice_match = s.nice_match; /* stop if match long enough */4161var limit = (s.strstart > (s.w_size - MIN_LOOKAHEAD)) ?4162s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0/*NIL*/;41634164var _win = s.window; // shortcut41654166var wmask = s.w_mask;4167var prev = s.prev;41684169/* Stop when cur_match becomes <= limit. To simplify the code,4170* we prevent matches with the string of window index 0.4171*/41724173var strend = s.strstart + MAX_MATCH;4174var scan_end1 = _win[scan + best_len - 1];4175var scan_end = _win[scan + best_len];41764177/* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.4178* It is easy to get rid of this optimization if necessary.4179*/4180// Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");41814182/* Do not waste too much time if we already have a good match: */4183if (s.prev_length >= s.good_match) {4184chain_length >>= 2;4185}4186/* Do not look for matches beyond the end of the input. This is necessary4187* to make deflate deterministic.4188*/4189if (nice_match > s.lookahead) { nice_match = s.lookahead; }41904191// Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");41924193do {4194// Assert(cur_match < s->strstart, "no future");4195match = cur_match;41964197/* Skip to next match if the match length cannot increase4198* or if the match length is less than 2. Note that the checks below4199* for insufficient lookahead only occur occasionally for performance4200* reasons. Therefore uninitialized memory will be accessed, and4201* conditional jumps will be made that depend on those values.4202* However the length of the match is limited to the lookahead, so4203* the output of deflate is not affected by the uninitialized values.4204*/42054206if (_win[match + best_len] !== scan_end ||4207_win[match + best_len - 1] !== scan_end1 ||4208_win[match] !== _win[scan] ||4209_win[++match] !== _win[scan + 1]) {4210continue;4211}42124213/* The check at best_len-1 can be removed because it will be made4214* again later. (This heuristic is not always a win.)4215* It is not necessary to compare scan[2] and match[2] since they4216* are always equal when the other bytes match, given that4217* the hash keys are equal and that HASH_BITS >= 8.4218*/4219scan += 2;4220match++;4221// Assert(*scan == *match, "match[2]?");42224223/* We check for insufficient lookahead only every 8th comparison;4224* the 256th check will be made at strstart+258.4225*/4226do {4227/*jshint noempty:false*/4228} while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&4229_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&4230_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&4231_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&4232scan < strend);42334234// Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");42354236len = MAX_MATCH - (strend - scan);4237scan = strend - MAX_MATCH;42384239if (len > best_len) {4240s.match_start = cur_match;4241best_len = len;4242if (len >= nice_match) {4243break;4244}4245scan_end1 = _win[scan + best_len - 1];4246scan_end = _win[scan + best_len];4247}4248} while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0);42494250if (best_len <= s.lookahead) {4251return best_len;4252}4253return s.lookahead;4254}425542564257/* ===========================================================================4258* Fill the window when the lookahead becomes insufficient.4259* Updates strstart and lookahead.4260*4261* IN assertion: lookahead < MIN_LOOKAHEAD4262* OUT assertions: strstart <= window_size-MIN_LOOKAHEAD4263* At least one byte has been read, or avail_in == 0; reads are4264* performed for at least two bytes (required for the zip translate_eol4265* option -- not supported here).4266*/4267function fill_window(s) {4268var _w_size = s.w_size;4269var p, n, m, more, str;42704271//Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");42724273do {4274more = s.window_size - s.lookahead - s.strstart;42754276// JS ints have 32 bit, block below not needed4277/* Deal with !@#$% 64K limit: */4278//if (sizeof(int) <= 2) {4279// if (more == 0 && s->strstart == 0 && s->lookahead == 0) {4280// more = wsize;4281//4282// } else if (more == (unsigned)(-1)) {4283// /* Very unlikely, but possible on 16 bit machine if4284// * strstart == 0 && lookahead == 1 (input done a byte at time)4285// */4286// more--;4287// }4288//}428942904291/* If the window is almost full and there is insufficient lookahead,4292* move the upper half to the lower one to make room in the upper half.4293*/4294if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {42954296utils.arraySet(s.window, s.window, _w_size, _w_size, 0);4297s.match_start -= _w_size;4298s.strstart -= _w_size;4299/* we now have strstart >= MAX_DIST */4300s.block_start -= _w_size;43014302/* Slide the hash table (could be avoided with 32 bit values4303at the expense of memory usage). We slide even when level == 04304to keep the hash table consistent if we switch back to level > 04305later. (Using level 0 permanently is not an optimal usage of4306zlib, so we don't care about this pathological case.)4307*/43084309n = s.hash_size;4310p = n;4311do {4312m = s.head[--p];4313s.head[p] = (m >= _w_size ? m - _w_size : 0);4314} while (--n);43154316n = _w_size;4317p = n;4318do {4319m = s.prev[--p];4320s.prev[p] = (m >= _w_size ? m - _w_size : 0);4321/* If n is not on any hash chain, prev[n] is garbage but4322* its value will never be used.4323*/4324} while (--n);43254326more += _w_size;4327}4328if (s.strm.avail_in === 0) {4329break;4330}43314332/* If there was no sliding:4333* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&4334* more == window_size - lookahead - strstart4335* => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)4336* => more >= window_size - 2*WSIZE + 24337* In the BIG_MEM or MMAP case (not yet supported),4338* window_size == input_size + MIN_LOOKAHEAD &&4339* strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.4340* Otherwise, window_size == 2*WSIZE so more >= 2.4341* If there was sliding, more >= WSIZE. So in all cases, more >= 2.4342*/4343//Assert(more >= 2, "more < 2");4344n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more);4345s.lookahead += n;43464347/* Initialize the hash value now that we have some input: */4348if (s.lookahead + s.insert >= MIN_MATCH) {4349str = s.strstart - s.insert;4350s.ins_h = s.window[str];43514352/* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */4353s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + 1]) & s.hash_mask;4354//#if MIN_MATCH != 34355// Call update_hash() MIN_MATCH-3 more times4356//#endif4357while (s.insert) {4358/* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */4359s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH-1]) & s.hash_mask;43604361s.prev[str & s.w_mask] = s.head[s.ins_h];4362s.head[s.ins_h] = str;4363str++;4364s.insert--;4365if (s.lookahead + s.insert < MIN_MATCH) {4366break;4367}4368}4369}4370/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,4371* but this is not important since only literal bytes will be emitted.4372*/43734374} while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0);43754376/* If the WIN_INIT bytes after the end of the current data have never been4377* written, then zero those bytes in order to avoid memory check reports of4378* the use of uninitialized (or uninitialised as Julian writes) bytes by4379* the longest match routines. Update the high water mark for the next4380* time through here. WIN_INIT is set to MAX_MATCH since the longest match4381* routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.4382*/4383// if (s.high_water < s.window_size) {4384// var curr = s.strstart + s.lookahead;4385// var init = 0;4386//4387// if (s.high_water < curr) {4388// /* Previous high water mark below current data -- zero WIN_INIT4389// * bytes or up to end of window, whichever is less.4390// */4391// init = s.window_size - curr;4392// if (init > WIN_INIT)4393// init = WIN_INIT;4394// zmemzero(s->window + curr, (unsigned)init);4395// s->high_water = curr + init;4396// }4397// else if (s->high_water < (ulg)curr + WIN_INIT) {4398// /* High water mark at or above current data, but below current data4399// * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up4400// * to end of window, whichever is less.4401// */4402// init = (ulg)curr + WIN_INIT - s->high_water;4403// if (init > s->window_size - s->high_water)4404// init = s->window_size - s->high_water;4405// zmemzero(s->window + s->high_water, (unsigned)init);4406// s->high_water += init;4407// }4408// }4409//4410// Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,4411// "not enough room for search");4412}44134414/* ===========================================================================4415* Copy without compression as much as possible from the input stream, return4416* the current block state.4417* This function does not insert new strings in the dictionary since4418* uncompressible data is probably not useful. This function is used4419* only for the level=0 compression option.4420* NOTE: this function should be optimized to avoid extra copying from4421* window to pending_buf.4422*/4423function deflate_stored(s, flush) {4424/* Stored blocks are limited to 0xffff bytes, pending_buf is limited4425* to pending_buf_size, and each stored block has a 5 byte header:4426*/4427var max_block_size = 0xffff;44284429if (max_block_size > s.pending_buf_size - 5) {4430max_block_size = s.pending_buf_size - 5;4431}44324433/* Copy as much as possible from input to output: */4434for (;;) {4435/* Fill the window as much as possible: */4436if (s.lookahead <= 1) {44374438//Assert(s->strstart < s->w_size+MAX_DIST(s) ||4439// s->block_start >= (long)s->w_size, "slide too late");4440// if (!(s.strstart < s.w_size + (s.w_size - MIN_LOOKAHEAD) ||4441// s.block_start >= s.w_size)) {4442// throw new Error("slide too late");4443// }44444445fill_window(s);4446if (s.lookahead === 0 && flush === Z_NO_FLUSH) {4447return BS_NEED_MORE;4448}44494450if (s.lookahead === 0) {4451break;4452}4453/* flush the current block */4454}4455//Assert(s->block_start >= 0L, "block gone");4456// if (s.block_start < 0) throw new Error("block gone");44574458s.strstart += s.lookahead;4459s.lookahead = 0;44604461/* Emit a stored block if pending_buf will be full: */4462var max_start = s.block_start + max_block_size;44634464if (s.strstart === 0 || s.strstart >= max_start) {4465/* strstart == 0 is possible when wraparound on 16-bit machine */4466s.lookahead = s.strstart - max_start;4467s.strstart = max_start;4468/*** FLUSH_BLOCK(s, 0); ***/4469flush_block_only(s, false);4470if (s.strm.avail_out === 0) {4471return BS_NEED_MORE;4472}4473/***/447444754476}4477/* Flush if we may have to slide, otherwise block_start may become4478* negative and the data will be gone:4479*/4480if (s.strstart - s.block_start >= (s.w_size - MIN_LOOKAHEAD)) {4481/*** FLUSH_BLOCK(s, 0); ***/4482flush_block_only(s, false);4483if (s.strm.avail_out === 0) {4484return BS_NEED_MORE;4485}4486/***/4487}4488}44894490s.insert = 0;44914492if (flush === Z_FINISH) {4493/*** FLUSH_BLOCK(s, 1); ***/4494flush_block_only(s, true);4495if (s.strm.avail_out === 0) {4496return BS_FINISH_STARTED;4497}4498/***/4499return BS_FINISH_DONE;4500}45014502if (s.strstart > s.block_start) {4503/*** FLUSH_BLOCK(s, 0); ***/4504flush_block_only(s, false);4505if (s.strm.avail_out === 0) {4506return BS_NEED_MORE;4507}4508/***/4509}45104511return BS_NEED_MORE;4512}45134514/* ===========================================================================4515* Compress as much as possible from the input stream, return the current4516* block state.4517* This function does not perform lazy evaluation of matches and inserts4518* new strings in the dictionary only for unmatched strings or for short4519* matches. It is used only for the fast compression options.4520*/4521function deflate_fast(s, flush) {4522var hash_head; /* head of the hash chain */4523var bflush; /* set if current block must be flushed */45244525for (;;) {4526/* Make sure that we always have enough lookahead, except4527* at the end of the input file. We need MAX_MATCH bytes4528* for the next match, plus MIN_MATCH bytes to insert the4529* string following the next match.4530*/4531if (s.lookahead < MIN_LOOKAHEAD) {4532fill_window(s);4533if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {4534return BS_NEED_MORE;4535}4536if (s.lookahead === 0) {4537break; /* flush the current block */4538}4539}45404541/* Insert the string window[strstart .. strstart+2] in the4542* dictionary, and set hash_head to the head of the hash chain:4543*/4544hash_head = 0/*NIL*/;4545if (s.lookahead >= MIN_MATCH) {4546/*** INSERT_STRING(s, s.strstart, hash_head); ***/4547s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;4548hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];4549s.head[s.ins_h] = s.strstart;4550/***/4551}45524553/* Find the longest match, discarding those <= prev_length.4554* At this point we have always match_length < MIN_MATCH4555*/4556if (hash_head !== 0/*NIL*/ && ((s.strstart - hash_head) <= (s.w_size - MIN_LOOKAHEAD))) {4557/* To simplify the code, we prevent matches with the string4558* of window index 0 (in particular we have to avoid a match4559* of the string with itself at the start of the input file).4560*/4561s.match_length = longest_match(s, hash_head);4562/* longest_match() sets match_start */4563}4564if (s.match_length >= MIN_MATCH) {4565// check_match(s, s.strstart, s.match_start, s.match_length); // for debug only45664567/*** _tr_tally_dist(s, s.strstart - s.match_start,4568s.match_length - MIN_MATCH, bflush); ***/4569bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);45704571s.lookahead -= s.match_length;45724573/* Insert new strings in the hash table only if the match length4574* is not too large. This saves time but degrades compression.4575*/4576if (s.match_length <= s.max_lazy_match/*max_insert_length*/ && s.lookahead >= MIN_MATCH) {4577s.match_length--; /* string at strstart already in table */4578do {4579s.strstart++;4580/*** INSERT_STRING(s, s.strstart, hash_head); ***/4581s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;4582hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];4583s.head[s.ins_h] = s.strstart;4584/***/4585/* strstart never exceeds WSIZE-MAX_MATCH, so there are4586* always MIN_MATCH bytes ahead.4587*/4588} while (--s.match_length !== 0);4589s.strstart++;4590} else4591{4592s.strstart += s.match_length;4593s.match_length = 0;4594s.ins_h = s.window[s.strstart];4595/* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */4596s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + 1]) & s.hash_mask;45974598//#if MIN_MATCH != 34599// Call UPDATE_HASH() MIN_MATCH-3 more times4600//#endif4601/* If lookahead < MIN_MATCH, ins_h is garbage, but it does not4602* matter since it will be recomputed at next deflate call.4603*/4604}4605} else {4606/* No match, output a literal byte */4607//Tracevv((stderr,"%c", s.window[s.strstart]));4608/*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/4609bflush = trees._tr_tally(s, 0, s.window[s.strstart]);46104611s.lookahead--;4612s.strstart++;4613}4614if (bflush) {4615/*** FLUSH_BLOCK(s, 0); ***/4616flush_block_only(s, false);4617if (s.strm.avail_out === 0) {4618return BS_NEED_MORE;4619}4620/***/4621}4622}4623s.insert = ((s.strstart < (MIN_MATCH-1)) ? s.strstart : MIN_MATCH-1);4624if (flush === Z_FINISH) {4625/*** FLUSH_BLOCK(s, 1); ***/4626flush_block_only(s, true);4627if (s.strm.avail_out === 0) {4628return BS_FINISH_STARTED;4629}4630/***/4631return BS_FINISH_DONE;4632}4633if (s.last_lit) {4634/*** FLUSH_BLOCK(s, 0); ***/4635flush_block_only(s, false);4636if (s.strm.avail_out === 0) {4637return BS_NEED_MORE;4638}4639/***/4640}4641return BS_BLOCK_DONE;4642}46434644/* ===========================================================================4645* Same as above, but achieves better compression. We use a lazy4646* evaluation for matches: a match is finally adopted only if there is4647* no better match at the next window position.4648*/4649function deflate_slow(s, flush) {4650var hash_head; /* head of hash chain */4651var bflush; /* set if current block must be flushed */46524653var max_insert;46544655/* Process the input block. */4656for (;;) {4657/* Make sure that we always have enough lookahead, except4658* at the end of the input file. We need MAX_MATCH bytes4659* for the next match, plus MIN_MATCH bytes to insert the4660* string following the next match.4661*/4662if (s.lookahead < MIN_LOOKAHEAD) {4663fill_window(s);4664if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {4665return BS_NEED_MORE;4666}4667if (s.lookahead === 0) { break; } /* flush the current block */4668}46694670/* Insert the string window[strstart .. strstart+2] in the4671* dictionary, and set hash_head to the head of the hash chain:4672*/4673hash_head = 0/*NIL*/;4674if (s.lookahead >= MIN_MATCH) {4675/*** INSERT_STRING(s, s.strstart, hash_head); ***/4676s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;4677hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];4678s.head[s.ins_h] = s.strstart;4679/***/4680}46814682/* Find the longest match, discarding those <= prev_length.4683*/4684s.prev_length = s.match_length;4685s.prev_match = s.match_start;4686s.match_length = MIN_MATCH-1;46874688if (hash_head !== 0/*NIL*/ && s.prev_length < s.max_lazy_match &&4689s.strstart - hash_head <= (s.w_size-MIN_LOOKAHEAD)/*MAX_DIST(s)*/) {4690/* To simplify the code, we prevent matches with the string4691* of window index 0 (in particular we have to avoid a match4692* of the string with itself at the start of the input file).4693*/4694s.match_length = longest_match(s, hash_head);4695/* longest_match() sets match_start */46964697if (s.match_length <= 5 &&4698(s.strategy === Z_FILTERED || (s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096/*TOO_FAR*/))) {46994700/* If prev_match is also MIN_MATCH, match_start is garbage4701* but we will ignore the current match anyway.4702*/4703s.match_length = MIN_MATCH-1;4704}4705}4706/* If there was a match at the previous step and the current4707* match is not better, output the previous match:4708*/4709if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) {4710max_insert = s.strstart + s.lookahead - MIN_MATCH;4711/* Do not insert strings in hash table beyond this. */47124713//check_match(s, s.strstart-1, s.prev_match, s.prev_length);47144715/***_tr_tally_dist(s, s.strstart - 1 - s.prev_match,4716s.prev_length - MIN_MATCH, bflush);***/4717bflush = trees._tr_tally(s, s.strstart - 1- s.prev_match, s.prev_length - MIN_MATCH);4718/* Insert in hash table all strings up to the end of the match.4719* strstart-1 and strstart are already inserted. If there is not4720* enough lookahead, the last two strings are not inserted in4721* the hash table.4722*/4723s.lookahead -= s.prev_length-1;4724s.prev_length -= 2;4725do {4726if (++s.strstart <= max_insert) {4727/*** INSERT_STRING(s, s.strstart, hash_head); ***/4728s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;4729hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];4730s.head[s.ins_h] = s.strstart;4731/***/4732}4733} while (--s.prev_length !== 0);4734s.match_available = 0;4735s.match_length = MIN_MATCH-1;4736s.strstart++;47374738if (bflush) {4739/*** FLUSH_BLOCK(s, 0); ***/4740flush_block_only(s, false);4741if (s.strm.avail_out === 0) {4742return BS_NEED_MORE;4743}4744/***/4745}47464747} else if (s.match_available) {4748/* If there was no match at the previous position, output a4749* single literal. If there was a match but the current match4750* is longer, truncate the previous match to a single literal.4751*/4752//Tracevv((stderr,"%c", s->window[s->strstart-1]));4753/*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/4754bflush = trees._tr_tally(s, 0, s.window[s.strstart-1]);47554756if (bflush) {4757/*** FLUSH_BLOCK_ONLY(s, 0) ***/4758flush_block_only(s, false);4759/***/4760}4761s.strstart++;4762s.lookahead--;4763if (s.strm.avail_out === 0) {4764return BS_NEED_MORE;4765}4766} else {4767/* There is no previous match to compare with, wait for4768* the next step to decide.4769*/4770s.match_available = 1;4771s.strstart++;4772s.lookahead--;4773}4774}4775//Assert (flush != Z_NO_FLUSH, "no flush?");4776if (s.match_available) {4777//Tracevv((stderr,"%c", s->window[s->strstart-1]));4778/*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/4779bflush = trees._tr_tally(s, 0, s.window[s.strstart-1]);47804781s.match_available = 0;4782}4783s.insert = s.strstart < MIN_MATCH-1 ? s.strstart : MIN_MATCH-1;4784if (flush === Z_FINISH) {4785/*** FLUSH_BLOCK(s, 1); ***/4786flush_block_only(s, true);4787if (s.strm.avail_out === 0) {4788return BS_FINISH_STARTED;4789}4790/***/4791return BS_FINISH_DONE;4792}4793if (s.last_lit) {4794/*** FLUSH_BLOCK(s, 0); ***/4795flush_block_only(s, false);4796if (s.strm.avail_out === 0) {4797return BS_NEED_MORE;4798}4799/***/4800}48014802return BS_BLOCK_DONE;4803}480448054806/* ===========================================================================4807* For Z_RLE, simply look for runs of bytes, generate matches only of distance4808* one. Do not maintain a hash table. (It will be regenerated if this run of4809* deflate switches away from Z_RLE.)4810*/4811function deflate_rle(s, flush) {4812var bflush; /* set if current block must be flushed */4813var prev; /* byte at distance one to match */4814var scan, strend; /* scan goes up to strend for length of run */48154816var _win = s.window;48174818for (;;) {4819/* Make sure that we always have enough lookahead, except4820* at the end of the input file. We need MAX_MATCH bytes4821* for the longest run, plus one for the unrolled loop.4822*/4823if (s.lookahead <= MAX_MATCH) {4824fill_window(s);4825if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) {4826return BS_NEED_MORE;4827}4828if (s.lookahead === 0) { break; } /* flush the current block */4829}48304831/* See how many times the previous byte repeats */4832s.match_length = 0;4833if (s.lookahead >= MIN_MATCH && s.strstart > 0) {4834scan = s.strstart - 1;4835prev = _win[scan];4836if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) {4837strend = s.strstart + MAX_MATCH;4838do {4839/*jshint noempty:false*/4840} while (prev === _win[++scan] && prev === _win[++scan] &&4841prev === _win[++scan] && prev === _win[++scan] &&4842prev === _win[++scan] && prev === _win[++scan] &&4843prev === _win[++scan] && prev === _win[++scan] &&4844scan < strend);4845s.match_length = MAX_MATCH - (strend - scan);4846if (s.match_length > s.lookahead) {4847s.match_length = s.lookahead;4848}4849}4850//Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");4851}48524853/* Emit match if have run of MIN_MATCH or longer, else emit literal */4854if (s.match_length >= MIN_MATCH) {4855//check_match(s, s.strstart, s.strstart - 1, s.match_length);48564857/*** _tr_tally_dist(s, 1, s.match_length - MIN_MATCH, bflush); ***/4858bflush = trees._tr_tally(s, 1, s.match_length - MIN_MATCH);48594860s.lookahead -= s.match_length;4861s.strstart += s.match_length;4862s.match_length = 0;4863} else {4864/* No match, output a literal byte */4865//Tracevv((stderr,"%c", s->window[s->strstart]));4866/*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/4867bflush = trees._tr_tally(s, 0, s.window[s.strstart]);48684869s.lookahead--;4870s.strstart++;4871}4872if (bflush) {4873/*** FLUSH_BLOCK(s, 0); ***/4874flush_block_only(s, false);4875if (s.strm.avail_out === 0) {4876return BS_NEED_MORE;4877}4878/***/4879}4880}4881s.insert = 0;4882if (flush === Z_FINISH) {4883/*** FLUSH_BLOCK(s, 1); ***/4884flush_block_only(s, true);4885if (s.strm.avail_out === 0) {4886return BS_FINISH_STARTED;4887}4888/***/4889return BS_FINISH_DONE;4890}4891if (s.last_lit) {4892/*** FLUSH_BLOCK(s, 0); ***/4893flush_block_only(s, false);4894if (s.strm.avail_out === 0) {4895return BS_NEED_MORE;4896}4897/***/4898}4899return BS_BLOCK_DONE;4900}49014902/* ===========================================================================4903* For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.4904* (It will be regenerated if this run of deflate switches away from Huffman.)4905*/4906function deflate_huff(s, flush) {4907var bflush; /* set if current block must be flushed */49084909for (;;) {4910/* Make sure that we have a literal to write. */4911if (s.lookahead === 0) {4912fill_window(s);4913if (s.lookahead === 0) {4914if (flush === Z_NO_FLUSH) {4915return BS_NEED_MORE;4916}4917break; /* flush the current block */4918}4919}49204921/* Output a literal byte */4922s.match_length = 0;4923//Tracevv((stderr,"%c", s->window[s->strstart]));4924/*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/4925bflush = trees._tr_tally(s, 0, s.window[s.strstart]);4926s.lookahead--;4927s.strstart++;4928if (bflush) {4929/*** FLUSH_BLOCK(s, 0); ***/4930flush_block_only(s, false);4931if (s.strm.avail_out === 0) {4932return BS_NEED_MORE;4933}4934/***/4935}4936}4937s.insert = 0;4938if (flush === Z_FINISH) {4939/*** FLUSH_BLOCK(s, 1); ***/4940flush_block_only(s, true);4941if (s.strm.avail_out === 0) {4942return BS_FINISH_STARTED;4943}4944/***/4945return BS_FINISH_DONE;4946}4947if (s.last_lit) {4948/*** FLUSH_BLOCK(s, 0); ***/4949flush_block_only(s, false);4950if (s.strm.avail_out === 0) {4951return BS_NEED_MORE;4952}4953/***/4954}4955return BS_BLOCK_DONE;4956}49574958/* Values for max_lazy_match, good_match and max_chain_length, depending on4959* the desired pack level (0..9). The values given below have been tuned to4960* exclude worst case performance for pathological files. Better values may be4961* found for specific files.4962*/4963var Config = function (good_length, max_lazy, nice_length, max_chain, func) {4964this.good_length = good_length;4965this.max_lazy = max_lazy;4966this.nice_length = nice_length;4967this.max_chain = max_chain;4968this.func = func;4969};49704971var configuration_table;49724973configuration_table = [4974/* good lazy nice chain */4975new Config(0, 0, 0, 0, deflate_stored), /* 0 store only */4976new Config(4, 4, 8, 4, deflate_fast), /* 1 max speed, no lazy matches */4977new Config(4, 5, 16, 8, deflate_fast), /* 2 */4978new Config(4, 6, 32, 32, deflate_fast), /* 3 */49794980new Config(4, 4, 16, 16, deflate_slow), /* 4 lazy matches */4981new Config(8, 16, 32, 32, deflate_slow), /* 5 */4982new Config(8, 16, 128, 128, deflate_slow), /* 6 */4983new Config(8, 32, 128, 256, deflate_slow), /* 7 */4984new Config(32, 128, 258, 1024, deflate_slow), /* 8 */4985new Config(32, 258, 258, 4096, deflate_slow) /* 9 max compression */4986];498749884989/* ===========================================================================4990* Initialize the "longest match" routines for a new zlib stream4991*/4992function lm_init(s) {4993s.window_size = 2 * s.w_size;49944995/*** CLEAR_HASH(s); ***/4996zero(s.head); // Fill with NIL (= 0);49974998/* Set the default configuration parameters:4999*/5000s.max_lazy_match = configuration_table[s.level].max_lazy;5001s.good_match = configuration_table[s.level].good_length;5002s.nice_match = configuration_table[s.level].nice_length;5003s.max_chain_length = configuration_table[s.level].max_chain;50045005s.strstart = 0;5006s.block_start = 0;5007s.lookahead = 0;5008s.insert = 0;5009s.match_length = s.prev_length = MIN_MATCH - 1;5010s.match_available = 0;5011s.ins_h = 0;5012}501350145015function DeflateState() {5016this.strm = null; /* pointer back to this zlib stream */5017this.status = 0; /* as the name implies */5018this.pending_buf = null; /* output still pending */5019this.pending_buf_size = 0; /* size of pending_buf */5020this.pending_out = 0; /* next pending byte to output to the stream */5021this.pending = 0; /* nb of bytes in the pending buffer */5022this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */5023this.gzhead = null; /* gzip header information to write */5024this.gzindex = 0; /* where in extra, name, or comment */5025this.method = Z_DEFLATED; /* can only be DEFLATED */5026this.last_flush = -1; /* value of flush param for previous deflate call */50275028this.w_size = 0; /* LZ77 window size (32K by default) */5029this.w_bits = 0; /* log2(w_size) (8..16) */5030this.w_mask = 0; /* w_size - 1 */50315032this.window = null;5033/* Sliding window. Input bytes are read into the second half of the window,5034* and move to the first half later to keep a dictionary of at least wSize5035* bytes. With this organization, matches are limited to a distance of5036* wSize-MAX_MATCH bytes, but this ensures that IO is always5037* performed with a length multiple of the block size.5038*/50395040this.window_size = 0;5041/* Actual size of window: 2*wSize, except when the user input buffer5042* is directly used as sliding window.5043*/50445045this.prev = null;5046/* Link to older string with same hash index. To limit the size of this5047* array to 64K, this link is maintained only for the last 32K strings.5048* An index in this array is thus a window index modulo 32K.5049*/50505051this.head = null; /* Heads of the hash chains or NIL. */50525053this.ins_h = 0; /* hash index of string to be inserted */5054this.hash_size = 0; /* number of elements in hash table */5055this.hash_bits = 0; /* log2(hash_size) */5056this.hash_mask = 0; /* hash_size-1 */50575058this.hash_shift = 0;5059/* Number of bits by which ins_h must be shifted at each input5060* step. It must be such that after MIN_MATCH steps, the oldest5061* byte no longer takes part in the hash key, that is:5062* hash_shift * MIN_MATCH >= hash_bits5063*/50645065this.block_start = 0;5066/* Window position at the beginning of the current output block. Gets5067* negative when the window is moved backwards.5068*/50695070this.match_length = 0; /* length of best match */5071this.prev_match = 0; /* previous match */5072this.match_available = 0; /* set if previous match exists */5073this.strstart = 0; /* start of string to insert */5074this.match_start = 0; /* start of matching string */5075this.lookahead = 0; /* number of valid bytes ahead in window */50765077this.prev_length = 0;5078/* Length of the best match at previous step. Matches not greater than this5079* are discarded. This is used in the lazy match evaluation.5080*/50815082this.max_chain_length = 0;5083/* To speed up deflation, hash chains are never searched beyond this5084* length. A higher limit improves compression ratio but degrades the5085* speed.5086*/50875088this.max_lazy_match = 0;5089/* Attempt to find a better match only when the current match is strictly5090* smaller than this value. This mechanism is used only for compression5091* levels >= 4.5092*/5093// That's alias to max_lazy_match, don't use directly5094//this.max_insert_length = 0;5095/* Insert new strings in the hash table only if the match length is not5096* greater than this length. This saves time but degrades compression.5097* max_insert_length is used only for compression levels <= 3.5098*/50995100this.level = 0; /* compression level (1..9) */5101this.strategy = 0; /* favor or force Huffman coding*/51025103this.good_match = 0;5104/* Use a faster search when the previous match is longer than this */51055106this.nice_match = 0; /* Stop searching when current match exceeds this */51075108/* used by trees.c: */51095110/* Didn't use ct_data typedef below to suppress compiler warning */51115112// struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */5113// struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */5114// struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */51155116// Use flat array of DOUBLE size, with interleaved fata,5117// because JS does not support effective5118this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2);5119this.dyn_dtree = new utils.Buf16((2*D_CODES+1) * 2);5120this.bl_tree = new utils.Buf16((2*BL_CODES+1) * 2);5121zero(this.dyn_ltree);5122zero(this.dyn_dtree);5123zero(this.bl_tree);51245125this.l_desc = null; /* desc. for literal tree */5126this.d_desc = null; /* desc. for distance tree */5127this.bl_desc = null; /* desc. for bit length tree */51285129//ush bl_count[MAX_BITS+1];5130this.bl_count = new utils.Buf16(MAX_BITS+1);5131/* number of codes at each bit length for an optimal tree */51325133//int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */5134this.heap = new utils.Buf16(2*L_CODES+1); /* heap used to build the Huffman trees */5135zero(this.heap);51365137this.heap_len = 0; /* number of elements in the heap */5138this.heap_max = 0; /* element of largest frequency */5139/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.5140* The same heap array is used to build all trees.5141*/51425143this.depth = new utils.Buf16(2*L_CODES+1); //uch depth[2*L_CODES+1];5144zero(this.depth);5145/* Depth of each subtree used as tie breaker for trees of equal frequency5146*/51475148this.l_buf = 0; /* buffer index for literals or lengths */51495150this.lit_bufsize = 0;5151/* Size of match buffer for literals/lengths. There are 4 reasons for5152* limiting lit_bufsize to 64K:5153* - frequencies can be kept in 16 bit counters5154* - if compression is not successful for the first block, all input5155* data is still in the window so we can still emit a stored block even5156* when input comes from standard input. (This can also be done for5157* all blocks if lit_bufsize is not greater than 32K.)5158* - if compression is not successful for a file smaller than 64K, we can5159* even emit a stored file instead of a stored block (saving 5 bytes).5160* This is applicable only for zip (not gzip or zlib).5161* - creating new Huffman trees less frequently may not provide fast5162* adaptation to changes in the input data statistics. (Take for5163* example a binary file with poorly compressible code followed by5164* a highly compressible string table.) Smaller buffer sizes give5165* fast adaptation but have of course the overhead of transmitting5166* trees more frequently.5167* - I can't count above 45168*/51695170this.last_lit = 0; /* running index in l_buf */51715172this.d_buf = 0;5173/* Buffer index for distances. To simplify the code, d_buf and l_buf have5174* the same number of elements. To use different lengths, an extra flag5175* array would be necessary.5176*/51775178this.opt_len = 0; /* bit length of current block with optimal trees */5179this.static_len = 0; /* bit length of current block with static trees */5180this.matches = 0; /* number of string matches in current block */5181this.insert = 0; /* bytes at end of window left to insert */518251835184this.bi_buf = 0;5185/* Output buffer. bits are inserted starting at the bottom (least5186* significant bits).5187*/5188this.bi_valid = 0;5189/* Number of valid bits in bi_buf. All bits above the last valid bit5190* are always zero.5191*/51925193// Used for window memory init. We safely ignore it for JS. That makes5194// sense only for pointers and memory check tools.5195//this.high_water = 0;5196/* High water mark offset in window for initialized bytes -- bytes above5197* this are set to zero in order to avoid memory check warnings when5198* longest match routines access bytes past the input. This is then5199* updated to the new high water mark.5200*/5201}520252035204function deflateResetKeep(strm) {5205var s;52065207if (!strm || !strm.state) {5208return err(strm, Z_STREAM_ERROR);5209}52105211strm.total_in = strm.total_out = 0;5212strm.data_type = Z_UNKNOWN;52135214s = strm.state;5215s.pending = 0;5216s.pending_out = 0;52175218if (s.wrap < 0) {5219s.wrap = -s.wrap;5220/* was made negative by deflate(..., Z_FINISH); */5221}5222s.status = (s.wrap ? INIT_STATE : BUSY_STATE);5223strm.adler = (s.wrap === 2) ?52240 // crc32(0, Z_NULL, 0)5225:52261; // adler32(0, Z_NULL, 0)5227s.last_flush = Z_NO_FLUSH;5228trees._tr_init(s);5229return Z_OK;5230}523152325233function deflateReset(strm) {5234var ret = deflateResetKeep(strm);5235if (ret === Z_OK) {5236lm_init(strm.state);5237}5238return ret;5239}524052415242function deflateSetHeader(strm, head) {5243if (!strm || !strm.state) { return Z_STREAM_ERROR; }5244if (strm.state.wrap !== 2) { return Z_STREAM_ERROR; }5245strm.state.gzhead = head;5246return Z_OK;5247}524852495250function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {5251if (!strm) { // === Z_NULL5252return Z_STREAM_ERROR;5253}5254var wrap = 1;52555256if (level === Z_DEFAULT_COMPRESSION) {5257level = 6;5258}52595260if (windowBits < 0) { /* suppress zlib wrapper */5261wrap = 0;5262windowBits = -windowBits;5263}52645265else if (windowBits > 15) {5266wrap = 2; /* write gzip wrapper instead */5267windowBits -= 16;5268}526952705271if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED ||5272windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||5273strategy < 0 || strategy > Z_FIXED) {5274return err(strm, Z_STREAM_ERROR);5275}527652775278if (windowBits === 8) {5279windowBits = 9;5280}5281/* until 256-byte window bug fixed */52825283var s = new DeflateState();52845285strm.state = s;5286s.strm = strm;52875288s.wrap = wrap;5289s.gzhead = null;5290s.w_bits = windowBits;5291s.w_size = 1 << s.w_bits;5292s.w_mask = s.w_size - 1;52935294s.hash_bits = memLevel + 7;5295s.hash_size = 1 << s.hash_bits;5296s.hash_mask = s.hash_size - 1;5297s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH);52985299s.window = new utils.Buf8(s.w_size * 2);5300s.head = new utils.Buf16(s.hash_size);5301s.prev = new utils.Buf16(s.w_size);53025303// Don't need mem init magic for JS.5304//s.high_water = 0; /* nothing written to s->window yet */53055306s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */53075308s.pending_buf_size = s.lit_bufsize * 4;5309s.pending_buf = new utils.Buf8(s.pending_buf_size);53105311s.d_buf = s.lit_bufsize >> 1;5312s.l_buf = (1 + 2) * s.lit_bufsize;53135314s.level = level;5315s.strategy = strategy;5316s.method = method;53175318return deflateReset(strm);5319}53205321function deflateInit(strm, level) {5322return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);5323}532453255326function deflate(strm, flush) {5327var old_flush, s;5328var beg, val; // for gzip header write only53295330if (!strm || !strm.state ||5331flush > Z_BLOCK || flush < 0) {5332return strm ? err(strm, Z_STREAM_ERROR) : Z_STREAM_ERROR;5333}53345335s = strm.state;53365337if (!strm.output ||5338(!strm.input && strm.avail_in !== 0) ||5339(s.status === FINISH_STATE && flush !== Z_FINISH)) {5340return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR);5341}53425343s.strm = strm; /* just in case */5344old_flush = s.last_flush;5345s.last_flush = flush;53465347/* Write the header */5348if (s.status === INIT_STATE) {53495350if (s.wrap === 2) { // GZIP header5351strm.adler = 0; //crc32(0L, Z_NULL, 0);5352put_byte(s, 31);5353put_byte(s, 139);5354put_byte(s, 8);5355if (!s.gzhead) { // s->gzhead == Z_NULL5356put_byte(s, 0);5357put_byte(s, 0);5358put_byte(s, 0);5359put_byte(s, 0);5360put_byte(s, 0);5361put_byte(s, s.level === 9 ? 2 :5362(s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?53634 : 0));5364put_byte(s, OS_CODE);5365s.status = BUSY_STATE;5366}5367else {5368put_byte(s, (s.gzhead.text ? 1 : 0) +5369(s.gzhead.hcrc ? 2 : 0) +5370(!s.gzhead.extra ? 0 : 4) +5371(!s.gzhead.name ? 0 : 8) +5372(!s.gzhead.comment ? 0 : 16)5373);5374put_byte(s, s.gzhead.time & 0xff);5375put_byte(s, (s.gzhead.time >> 8) & 0xff);5376put_byte(s, (s.gzhead.time >> 16) & 0xff);5377put_byte(s, (s.gzhead.time >> 24) & 0xff);5378put_byte(s, s.level === 9 ? 2 :5379(s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?53804 : 0));5381put_byte(s, s.gzhead.os & 0xff);5382if (s.gzhead.extra && s.gzhead.extra.length) {5383put_byte(s, s.gzhead.extra.length & 0xff);5384put_byte(s, (s.gzhead.extra.length >> 8) & 0xff);5385}5386if (s.gzhead.hcrc) {5387strm.adler = crc32(strm.adler, s.pending_buf, s.pending, 0);5388}5389s.gzindex = 0;5390s.status = EXTRA_STATE;5391}5392}5393else // DEFLATE header5394{5395var header = (Z_DEFLATED + ((s.w_bits - 8) << 4)) << 8;5396var level_flags = -1;53975398if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) {5399level_flags = 0;5400} else if (s.level < 6) {5401level_flags = 1;5402} else if (s.level === 6) {5403level_flags = 2;5404} else {5405level_flags = 3;5406}5407header |= (level_flags << 6);5408if (s.strstart !== 0) { header |= PRESET_DICT; }5409header += 31 - (header % 31);54105411s.status = BUSY_STATE;5412putShortMSB(s, header);54135414/* Save the adler32 of the preset dictionary: */5415if (s.strstart !== 0) {5416putShortMSB(s, strm.adler >>> 16);5417putShortMSB(s, strm.adler & 0xffff);5418}5419strm.adler = 1; // adler32(0L, Z_NULL, 0);5420}5421}54225423//#ifdef GZIP5424if (s.status === EXTRA_STATE) {5425if (s.gzhead.extra/* != Z_NULL*/) {5426beg = s.pending; /* start of bytes to update crc */54275428while (s.gzindex < (s.gzhead.extra.length & 0xffff)) {5429if (s.pending === s.pending_buf_size) {5430if (s.gzhead.hcrc && s.pending > beg) {5431strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);5432}5433flush_pending(strm);5434beg = s.pending;5435if (s.pending === s.pending_buf_size) {5436break;5437}5438}5439put_byte(s, s.gzhead.extra[s.gzindex] & 0xff);5440s.gzindex++;5441}5442if (s.gzhead.hcrc && s.pending > beg) {5443strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);5444}5445if (s.gzindex === s.gzhead.extra.length) {5446s.gzindex = 0;5447s.status = NAME_STATE;5448}5449}5450else {5451s.status = NAME_STATE;5452}5453}5454if (s.status === NAME_STATE) {5455if (s.gzhead.name/* != Z_NULL*/) {5456beg = s.pending; /* start of bytes to update crc */5457//int val;54585459do {5460if (s.pending === s.pending_buf_size) {5461if (s.gzhead.hcrc && s.pending > beg) {5462strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);5463}5464flush_pending(strm);5465beg = s.pending;5466if (s.pending === s.pending_buf_size) {5467val = 1;5468break;5469}5470}5471// JS specific: little magic to add zero terminator to end of string5472if (s.gzindex < s.gzhead.name.length) {5473val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff;5474} else {5475val = 0;5476}5477put_byte(s, val);5478} while (val !== 0);54795480if (s.gzhead.hcrc && s.pending > beg){5481strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);5482}5483if (val === 0) {5484s.gzindex = 0;5485s.status = COMMENT_STATE;5486}5487}5488else {5489s.status = COMMENT_STATE;5490}5491}5492if (s.status === COMMENT_STATE) {5493if (s.gzhead.comment/* != Z_NULL*/) {5494beg = s.pending; /* start of bytes to update crc */5495//int val;54965497do {5498if (s.pending === s.pending_buf_size) {5499if (s.gzhead.hcrc && s.pending > beg) {5500strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);5501}5502flush_pending(strm);5503beg = s.pending;5504if (s.pending === s.pending_buf_size) {5505val = 1;5506break;5507}5508}5509// JS specific: little magic to add zero terminator to end of string5510if (s.gzindex < s.gzhead.comment.length) {5511val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff;5512} else {5513val = 0;5514}5515put_byte(s, val);5516} while (val !== 0);55175518if (s.gzhead.hcrc && s.pending > beg) {5519strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);5520}5521if (val === 0) {5522s.status = HCRC_STATE;5523}5524}5525else {5526s.status = HCRC_STATE;5527}5528}5529if (s.status === HCRC_STATE) {5530if (s.gzhead.hcrc) {5531if (s.pending + 2 > s.pending_buf_size) {5532flush_pending(strm);5533}5534if (s.pending + 2 <= s.pending_buf_size) {5535put_byte(s, strm.adler & 0xff);5536put_byte(s, (strm.adler >> 8) & 0xff);5537strm.adler = 0; //crc32(0L, Z_NULL, 0);5538s.status = BUSY_STATE;5539}5540}5541else {5542s.status = BUSY_STATE;5543}5544}5545//#endif55465547/* Flush as much pending output as possible */5548if (s.pending !== 0) {5549flush_pending(strm);5550if (strm.avail_out === 0) {5551/* Since avail_out is 0, deflate will be called again with5552* more output space, but possibly with both pending and5553* avail_in equal to zero. There won't be anything to do,5554* but this is not an error situation so make sure we5555* return OK instead of BUF_ERROR at next call of deflate:5556*/5557s.last_flush = -1;5558return Z_OK;5559}55605561/* Make sure there is something to do and avoid duplicate consecutive5562* flushes. For repeated and useless calls with Z_FINISH, we keep5563* returning Z_STREAM_END instead of Z_BUF_ERROR.5564*/5565} else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) &&5566flush !== Z_FINISH) {5567return err(strm, Z_BUF_ERROR);5568}55695570/* User must not provide more input after the first FINISH: */5571if (s.status === FINISH_STATE && strm.avail_in !== 0) {5572return err(strm, Z_BUF_ERROR);5573}55745575/* Start a new block or continue the current one.5576*/5577if (strm.avail_in !== 0 || s.lookahead !== 0 ||5578(flush !== Z_NO_FLUSH && s.status !== FINISH_STATE)) {5579var bstate = (s.strategy === Z_HUFFMAN_ONLY) ? deflate_huff(s, flush) :5580(s.strategy === Z_RLE ? deflate_rle(s, flush) :5581configuration_table[s.level].func(s, flush));55825583if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) {5584s.status = FINISH_STATE;5585}5586if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) {5587if (strm.avail_out === 0) {5588s.last_flush = -1;5589/* avoid BUF_ERROR next call, see above */5590}5591return Z_OK;5592/* If flush != Z_NO_FLUSH && avail_out == 0, the next call5593* of deflate should use the same flush parameter to make sure5594* that the flush is complete. So we don't have to output an5595* empty block here, this will be done at next call. This also5596* ensures that for a very small output buffer, we emit at most5597* one empty block.5598*/5599}5600if (bstate === BS_BLOCK_DONE) {5601if (flush === Z_PARTIAL_FLUSH) {5602trees._tr_align(s);5603}5604else if (flush !== Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */56055606trees._tr_stored_block(s, 0, 0, false);5607/* For a full flush, this empty block will be recognized5608* as a special marker by inflate_sync().5609*/5610if (flush === Z_FULL_FLUSH) {5611/*** CLEAR_HASH(s); ***/ /* forget history */5612zero(s.head); // Fill with NIL (= 0);56135614if (s.lookahead === 0) {5615s.strstart = 0;5616s.block_start = 0;5617s.insert = 0;5618}5619}5620}5621flush_pending(strm);5622if (strm.avail_out === 0) {5623s.last_flush = -1; /* avoid BUF_ERROR at next call, see above */5624return Z_OK;5625}5626}5627}5628//Assert(strm->avail_out > 0, "bug2");5629//if (strm.avail_out <= 0) { throw new Error("bug2");}56305631if (flush !== Z_FINISH) { return Z_OK; }5632if (s.wrap <= 0) { return Z_STREAM_END; }56335634/* Write the trailer */5635if (s.wrap === 2) {5636put_byte(s, strm.adler & 0xff);5637put_byte(s, (strm.adler >> 8) & 0xff);5638put_byte(s, (strm.adler >> 16) & 0xff);5639put_byte(s, (strm.adler >> 24) & 0xff);5640put_byte(s, strm.total_in & 0xff);5641put_byte(s, (strm.total_in >> 8) & 0xff);5642put_byte(s, (strm.total_in >> 16) & 0xff);5643put_byte(s, (strm.total_in >> 24) & 0xff);5644}5645else5646{5647putShortMSB(s, strm.adler >>> 16);5648putShortMSB(s, strm.adler & 0xffff);5649}56505651flush_pending(strm);5652/* If avail_out is zero, the application will call deflate again5653* to flush the rest.5654*/5655if (s.wrap > 0) { s.wrap = -s.wrap; }5656/* write the trailer only once! */5657return s.pending !== 0 ? Z_OK : Z_STREAM_END;5658}56595660function deflateEnd(strm) {5661var status;56625663if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {5664return Z_STREAM_ERROR;5665}56665667status = strm.state.status;5668if (status !== INIT_STATE &&5669status !== EXTRA_STATE &&5670status !== NAME_STATE &&5671status !== COMMENT_STATE &&5672status !== HCRC_STATE &&5673status !== BUSY_STATE &&5674status !== FINISH_STATE5675) {5676return err(strm, Z_STREAM_ERROR);5677}56785679strm.state = null;56805681return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK;5682}56835684/* =========================================================================5685* Copy the source state to the destination state5686*/5687//function deflateCopy(dest, source) {5688//5689//}56905691exports.deflateInit = deflateInit;5692exports.deflateInit2 = deflateInit2;5693exports.deflateReset = deflateReset;5694exports.deflateResetKeep = deflateResetKeep;5695exports.deflateSetHeader = deflateSetHeader;5696exports.deflate = deflate;5697exports.deflateEnd = deflateEnd;5698exports.deflateInfo = 'pako deflate (from Nodeca project)';56995700/* Not implemented5701exports.deflateBound = deflateBound;5702exports.deflateCopy = deflateCopy;5703exports.deflateSetDictionary = deflateSetDictionary;5704exports.deflateParams = deflateParams;5705exports.deflatePending = deflatePending;5706exports.deflatePrime = deflatePrime;5707exports.deflateTune = deflateTune;5708*/5709},{"../utils/common":27,"./adler32":29,"./crc32":31,"./messages":37,"./trees":38}],33:[function(_dereq_,module,exports){5710'use strict';571157125713function GZheader() {5714/* true if compressed data believed to be text */5715this.text = 0;5716/* modification time */5717this.time = 0;5718/* extra flags (not used when writing a gzip file) */5719this.xflags = 0;5720/* operating system */5721this.os = 0;5722/* pointer to extra field or Z_NULL if none */5723this.extra = null;5724/* extra field length (valid if extra != Z_NULL) */5725this.extra_len = 0; // Actually, we don't need it in JS,5726// but leave for few code modifications57275728//5729// Setup limits is not necessary because in js we should not preallocate memory5730// for inflate use constant limit in 65536 bytes5731//57325733/* space at extra (only when reading header) */5734// this.extra_max = 0;5735/* pointer to zero-terminated file name or Z_NULL */5736this.name = '';5737/* space at name (only when reading header) */5738// this.name_max = 0;5739/* pointer to zero-terminated comment or Z_NULL */5740this.comment = '';5741/* space at comment (only when reading header) */5742// this.comm_max = 0;5743/* true if there was or will be a header crc */5744this.hcrc = 0;5745/* true when done reading gzip header (not used when writing a gzip file) */5746this.done = false;5747}57485749module.exports = GZheader;5750},{}],34:[function(_dereq_,module,exports){5751'use strict';57525753// See state defs from inflate.js5754var BAD = 30; /* got a data error -- remain here until reset */5755var TYPE = 12; /* i: waiting for type bits, including last-flag bit */57565757/*5758Decode literal, length, and distance codes and write out the resulting5759literal and match bytes until either not enough input or output is5760available, an end-of-block is encountered, or a data error is encountered.5761When large enough input and output buffers are supplied to inflate(), for5762example, a 16K input buffer and a 64K output buffer, more than 95% of the5763inflate execution time is spent in this routine.57645765Entry assumptions:57665767state.mode === LEN5768strm.avail_in >= 65769strm.avail_out >= 2585770start >= strm.avail_out5771state.bits < 857725773On return, state.mode is one of:57745775LEN -- ran out of enough output space or enough available input5776TYPE -- reached end of block code, inflate() to interpret next block5777BAD -- error in block data57785779Notes:57805781- The maximum input bits used by a length/distance pair is 15 bits for the5782length code, 5 bits for the length extra, 15 bits for the distance code,5783and 13 bits for the distance extra. This totals 48 bits, or six bytes.5784Therefore if strm.avail_in >= 6, then there is enough input to avoid5785checking for available input while decoding.57865787- The maximum bytes that a single length/distance pair can output is 2585788bytes, which is the maximum length that can be coded. inflate_fast()5789requires strm.avail_out >= 258 for each loop to avoid checking for5790output space.5791*/5792module.exports = function inflate_fast(strm, start) {5793var state;5794var _in; /* local strm.input */5795var last; /* have enough input while in < last */5796var _out; /* local strm.output */5797var beg; /* inflate()'s initial strm.output */5798var end; /* while out < end, enough space available */5799//#ifdef INFLATE_STRICT5800var dmax; /* maximum distance from zlib header */5801//#endif5802var wsize; /* window size or zero if not using window */5803var whave; /* valid bytes in the window */5804var wnext; /* window write index */5805var window; /* allocated sliding window, if wsize != 0 */5806var hold; /* local strm.hold */5807var bits; /* local strm.bits */5808var lcode; /* local strm.lencode */5809var dcode; /* local strm.distcode */5810var lmask; /* mask for first level of length codes */5811var dmask; /* mask for first level of distance codes */5812var here; /* retrieved table entry */5813var op; /* code bits, operation, extra bits, or */5814/* window position, window bytes to copy */5815var len; /* match length, unused bytes */5816var dist; /* match distance */5817var from; /* where to copy match from */5818var from_source;581958205821var input, output; // JS specific, because we have no pointers58225823/* copy state to local variables */5824state = strm.state;5825//here = state.here;5826_in = strm.next_in;5827input = strm.input;5828last = _in + (strm.avail_in - 5);5829_out = strm.next_out;5830output = strm.output;5831beg = _out - (start - strm.avail_out);5832end = _out + (strm.avail_out - 257);5833//#ifdef INFLATE_STRICT5834dmax = state.dmax;5835//#endif5836wsize = state.wsize;5837whave = state.whave;5838wnext = state.wnext;5839window = state.window;5840hold = state.hold;5841bits = state.bits;5842lcode = state.lencode;5843dcode = state.distcode;5844lmask = (1 << state.lenbits) - 1;5845dmask = (1 << state.distbits) - 1;584658475848/* decode literals and length/distances until end-of-block or not enough5849input data or output space */58505851top:5852do {5853if (bits < 15) {5854hold += input[_in++] << bits;5855bits += 8;5856hold += input[_in++] << bits;5857bits += 8;5858}58595860here = lcode[hold & lmask];58615862dolen:5863for (;;) { // Goto emulation5864op = here >>> 24/*here.bits*/;5865hold >>>= op;5866bits -= op;5867op = (here >>> 16) & 0xff/*here.op*/;5868if (op === 0) { /* literal */5869//Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?5870// "inflate: literal '%c'\n" :5871// "inflate: literal 0x%02x\n", here.val));5872output[_out++] = here & 0xffff/*here.val*/;5873}5874else if (op & 16) { /* length base */5875len = here & 0xffff/*here.val*/;5876op &= 15; /* number of extra bits */5877if (op) {5878if (bits < op) {5879hold += input[_in++] << bits;5880bits += 8;5881}5882len += hold & ((1 << op) - 1);5883hold >>>= op;5884bits -= op;5885}5886//Tracevv((stderr, "inflate: length %u\n", len));5887if (bits < 15) {5888hold += input[_in++] << bits;5889bits += 8;5890hold += input[_in++] << bits;5891bits += 8;5892}5893here = dcode[hold & dmask];58945895dodist:5896for (;;) { // goto emulation5897op = here >>> 24/*here.bits*/;5898hold >>>= op;5899bits -= op;5900op = (here >>> 16) & 0xff/*here.op*/;59015902if (op & 16) { /* distance base */5903dist = here & 0xffff/*here.val*/;5904op &= 15; /* number of extra bits */5905if (bits < op) {5906hold += input[_in++] << bits;5907bits += 8;5908if (bits < op) {5909hold += input[_in++] << bits;5910bits += 8;5911}5912}5913dist += hold & ((1 << op) - 1);5914//#ifdef INFLATE_STRICT5915if (dist > dmax) {5916strm.msg = 'invalid distance too far back';5917state.mode = BAD;5918break top;5919}5920//#endif5921hold >>>= op;5922bits -= op;5923//Tracevv((stderr, "inflate: distance %u\n", dist));5924op = _out - beg; /* max distance in output */5925if (dist > op) { /* see if copy from window */5926op = dist - op; /* distance back in window */5927if (op > whave) {5928if (state.sane) {5929strm.msg = 'invalid distance too far back';5930state.mode = BAD;5931break top;5932}59335934// (!) This block is disabled in zlib defailts,5935// don't enable it for binary compatibility5936//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR5937// if (len <= op - whave) {5938// do {5939// output[_out++] = 0;5940// } while (--len);5941// continue top;5942// }5943// len -= op - whave;5944// do {5945// output[_out++] = 0;5946// } while (--op > whave);5947// if (op === 0) {5948// from = _out - dist;5949// do {5950// output[_out++] = output[from++];5951// } while (--len);5952// continue top;5953// }5954//#endif5955}5956from = 0; // window index5957from_source = window;5958if (wnext === 0) { /* very common case */5959from += wsize - op;5960if (op < len) { /* some from window */5961len -= op;5962do {5963output[_out++] = window[from++];5964} while (--op);5965from = _out - dist; /* rest from output */5966from_source = output;5967}5968}5969else if (wnext < op) { /* wrap around window */5970from += wsize + wnext - op;5971op -= wnext;5972if (op < len) { /* some from end of window */5973len -= op;5974do {5975output[_out++] = window[from++];5976} while (--op);5977from = 0;5978if (wnext < len) { /* some from start of window */5979op = wnext;5980len -= op;5981do {5982output[_out++] = window[from++];5983} while (--op);5984from = _out - dist; /* rest from output */5985from_source = output;5986}5987}5988}5989else { /* contiguous in window */5990from += wnext - op;5991if (op < len) { /* some from window */5992len -= op;5993do {5994output[_out++] = window[from++];5995} while (--op);5996from = _out - dist; /* rest from output */5997from_source = output;5998}5999}6000while (len > 2) {6001output[_out++] = from_source[from++];6002output[_out++] = from_source[from++];6003output[_out++] = from_source[from++];6004len -= 3;6005}6006if (len) {6007output[_out++] = from_source[from++];6008if (len > 1) {6009output[_out++] = from_source[from++];6010}6011}6012}6013else {6014from = _out - dist; /* copy direct from output */6015do { /* minimum length is three */6016output[_out++] = output[from++];6017output[_out++] = output[from++];6018output[_out++] = output[from++];6019len -= 3;6020} while (len > 2);6021if (len) {6022output[_out++] = output[from++];6023if (len > 1) {6024output[_out++] = output[from++];6025}6026}6027}6028}6029else if ((op & 64) === 0) { /* 2nd level distance code */6030here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];6031continue dodist;6032}6033else {6034strm.msg = 'invalid distance code';6035state.mode = BAD;6036break top;6037}60386039break; // need to emulate goto via "continue"6040}6041}6042else if ((op & 64) === 0) { /* 2nd level length code */6043here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];6044continue dolen;6045}6046else if (op & 32) { /* end-of-block */6047//Tracevv((stderr, "inflate: end of block\n"));6048state.mode = TYPE;6049break top;6050}6051else {6052strm.msg = 'invalid literal/length code';6053state.mode = BAD;6054break top;6055}60566057break; // need to emulate goto via "continue"6058}6059} while (_in < last && _out < end);60606061/* return unused bytes (on entry, bits < 8, so in won't go too far back) */6062len = bits >> 3;6063_in -= len;6064bits -= len << 3;6065hold &= (1 << bits) - 1;60666067/* update state and return */6068strm.next_in = _in;6069strm.next_out = _out;6070strm.avail_in = (_in < last ? 5 + (last - _in) : 5 - (_in - last));6071strm.avail_out = (_out < end ? 257 + (end - _out) : 257 - (_out - end));6072state.hold = hold;6073state.bits = bits;6074return;6075};60766077},{}],35:[function(_dereq_,module,exports){6078'use strict';607960806081var utils = _dereq_('../utils/common');6082var adler32 = _dereq_('./adler32');6083var crc32 = _dereq_('./crc32');6084var inflate_fast = _dereq_('./inffast');6085var inflate_table = _dereq_('./inftrees');60866087var CODES = 0;6088var LENS = 1;6089var DISTS = 2;60906091/* Public constants ==========================================================*/6092/* ===========================================================================*/609360946095/* Allowed flush values; see deflate() and inflate() below for details */6096//var Z_NO_FLUSH = 0;6097//var Z_PARTIAL_FLUSH = 1;6098//var Z_SYNC_FLUSH = 2;6099//var Z_FULL_FLUSH = 3;6100var Z_FINISH = 4;6101var Z_BLOCK = 5;6102var Z_TREES = 6;610361046105/* Return codes for the compression/decompression functions. Negative values6106* are errors, positive values are used for special but normal events.6107*/6108var Z_OK = 0;6109var Z_STREAM_END = 1;6110var Z_NEED_DICT = 2;6111//var Z_ERRNO = -1;6112var Z_STREAM_ERROR = -2;6113var Z_DATA_ERROR = -3;6114var Z_MEM_ERROR = -4;6115var Z_BUF_ERROR = -5;6116//var Z_VERSION_ERROR = -6;61176118/* The deflate compression method */6119var Z_DEFLATED = 8;612061216122/* STATES ====================================================================*/6123/* ===========================================================================*/612461256126var HEAD = 1; /* i: waiting for magic header */6127var FLAGS = 2; /* i: waiting for method and flags (gzip) */6128var TIME = 3; /* i: waiting for modification time (gzip) */6129var OS = 4; /* i: waiting for extra flags and operating system (gzip) */6130var EXLEN = 5; /* i: waiting for extra length (gzip) */6131var EXTRA = 6; /* i: waiting for extra bytes (gzip) */6132var NAME = 7; /* i: waiting for end of file name (gzip) */6133var COMMENT = 8; /* i: waiting for end of comment (gzip) */6134var HCRC = 9; /* i: waiting for header crc (gzip) */6135var DICTID = 10; /* i: waiting for dictionary check value */6136var DICT = 11; /* waiting for inflateSetDictionary() call */6137var TYPE = 12; /* i: waiting for type bits, including last-flag bit */6138var TYPEDO = 13; /* i: same, but skip check to exit inflate on new block */6139var STORED = 14; /* i: waiting for stored size (length and complement) */6140var COPY_ = 15; /* i/o: same as COPY below, but only first time in */6141var COPY = 16; /* i/o: waiting for input or output to copy stored block */6142var TABLE = 17; /* i: waiting for dynamic block table lengths */6143var LENLENS = 18; /* i: waiting for code length code lengths */6144var CODELENS = 19; /* i: waiting for length/lit and distance code lengths */6145var LEN_ = 20; /* i: same as LEN below, but only first time in */6146var LEN = 21; /* i: waiting for length/lit/eob code */6147var LENEXT = 22; /* i: waiting for length extra bits */6148var DIST = 23; /* i: waiting for distance code */6149var DISTEXT = 24; /* i: waiting for distance extra bits */6150var MATCH = 25; /* o: waiting for output space to copy string */6151var LIT = 26; /* o: waiting for output space to write literal */6152var CHECK = 27; /* i: waiting for 32-bit check value */6153var LENGTH = 28; /* i: waiting for 32-bit length (gzip) */6154var DONE = 29; /* finished check, done -- remain here until reset */6155var BAD = 30; /* got a data error -- remain here until reset */6156var MEM = 31; /* got an inflate() memory error -- remain here until reset */6157var SYNC = 32; /* looking for synchronization bytes to restart inflate() */61586159/* ===========================================================================*/6160616161626163var ENOUGH_LENS = 852;6164var ENOUGH_DISTS = 592;6165//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);61666167var MAX_WBITS = 15;6168/* 32K LZ77 window */6169var DEF_WBITS = MAX_WBITS;617061716172function ZSWAP32(q) {6173return (((q >>> 24) & 0xff) +6174((q >>> 8) & 0xff00) +6175((q & 0xff00) << 8) +6176((q & 0xff) << 24));6177}617861796180function InflateState() {6181this.mode = 0; /* current inflate mode */6182this.last = false; /* true if processing last block */6183this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */6184this.havedict = false; /* true if dictionary provided */6185this.flags = 0; /* gzip header method and flags (0 if zlib) */6186this.dmax = 0; /* zlib header max distance (INFLATE_STRICT) */6187this.check = 0; /* protected copy of check value */6188this.total = 0; /* protected copy of output count */6189// TODO: may be {}6190this.head = null; /* where to save gzip header information */61916192/* sliding window */6193this.wbits = 0; /* log base 2 of requested window size */6194this.wsize = 0; /* window size or zero if not using window */6195this.whave = 0; /* valid bytes in the window */6196this.wnext = 0; /* window write index */6197this.window = null; /* allocated sliding window, if needed */61986199/* bit accumulator */6200this.hold = 0; /* input bit accumulator */6201this.bits = 0; /* number of bits in "in" */62026203/* for string and stored block copying */6204this.length = 0; /* literal or length of data to copy */6205this.offset = 0; /* distance back to copy string from */62066207/* for table and code decoding */6208this.extra = 0; /* extra bits needed */62096210/* fixed and dynamic code tables */6211this.lencode = null; /* starting table for length/literal codes */6212this.distcode = null; /* starting table for distance codes */6213this.lenbits = 0; /* index bits for lencode */6214this.distbits = 0; /* index bits for distcode */62156216/* dynamic table building */6217this.ncode = 0; /* number of code length code lengths */6218this.nlen = 0; /* number of length code lengths */6219this.ndist = 0; /* number of distance code lengths */6220this.have = 0; /* number of code lengths in lens[] */6221this.next = null; /* next available space in codes[] */62226223this.lens = new utils.Buf16(320); /* temporary storage for code lengths */6224this.work = new utils.Buf16(288); /* work area for code table building */62256226/*6227because we don't have pointers in js, we use lencode and distcode directly6228as buffers so we don't need codes6229*/6230//this.codes = new utils.Buf32(ENOUGH); /* space for code tables */6231this.lendyn = null; /* dynamic table for length/literal codes (JS specific) */6232this.distdyn = null; /* dynamic table for distance codes (JS specific) */6233this.sane = 0; /* if false, allow invalid distance too far */6234this.back = 0; /* bits back of last unprocessed length/lit */6235this.was = 0; /* initial length of match */6236}62376238function inflateResetKeep(strm) {6239var state;62406241if (!strm || !strm.state) { return Z_STREAM_ERROR; }6242state = strm.state;6243strm.total_in = strm.total_out = state.total = 0;6244strm.msg = ''; /*Z_NULL*/6245if (state.wrap) { /* to support ill-conceived Java test suite */6246strm.adler = state.wrap & 1;6247}6248state.mode = HEAD;6249state.last = 0;6250state.havedict = 0;6251state.dmax = 32768;6252state.head = null/*Z_NULL*/;6253state.hold = 0;6254state.bits = 0;6255//state.lencode = state.distcode = state.next = state.codes;6256state.lencode = state.lendyn = new utils.Buf32(ENOUGH_LENS);6257state.distcode = state.distdyn = new utils.Buf32(ENOUGH_DISTS);62586259state.sane = 1;6260state.back = -1;6261//Tracev((stderr, "inflate: reset\n"));6262return Z_OK;6263}62646265function inflateReset(strm) {6266var state;62676268if (!strm || !strm.state) { return Z_STREAM_ERROR; }6269state = strm.state;6270state.wsize = 0;6271state.whave = 0;6272state.wnext = 0;6273return inflateResetKeep(strm);62746275}62766277function inflateReset2(strm, windowBits) {6278var wrap;6279var state;62806281/* get the state */6282if (!strm || !strm.state) { return Z_STREAM_ERROR; }6283state = strm.state;62846285/* extract wrap request from windowBits parameter */6286if (windowBits < 0) {6287wrap = 0;6288windowBits = -windowBits;6289}6290else {6291wrap = (windowBits >> 4) + 1;6292if (windowBits < 48) {6293windowBits &= 15;6294}6295}62966297/* set number of window bits, free window if different */6298if (windowBits && (windowBits < 8 || windowBits > 15)) {6299return Z_STREAM_ERROR;6300}6301if (state.window !== null && state.wbits !== windowBits) {6302state.window = null;6303}63046305/* update state and reset the rest of it */6306state.wrap = wrap;6307state.wbits = windowBits;6308return inflateReset(strm);6309}63106311function inflateInit2(strm, windowBits) {6312var ret;6313var state;63146315if (!strm) { return Z_STREAM_ERROR; }6316//strm.msg = Z_NULL; /* in case we return an error */63176318state = new InflateState();63196320//if (state === Z_NULL) return Z_MEM_ERROR;6321//Tracev((stderr, "inflate: allocated\n"));6322strm.state = state;6323state.window = null/*Z_NULL*/;6324ret = inflateReset2(strm, windowBits);6325if (ret !== Z_OK) {6326strm.state = null/*Z_NULL*/;6327}6328return ret;6329}63306331function inflateInit(strm) {6332return inflateInit2(strm, DEF_WBITS);6333}633463356336/*6337Return state with length and distance decoding tables and index sizes set to6338fixed code decoding. Normally this returns fixed tables from inffixed.h.6339If BUILDFIXED is defined, then instead this routine builds the tables the6340first time it's called, and returns those tables the first time and6341thereafter. This reduces the size of the code by about 2K bytes, in6342exchange for a little execution time. However, BUILDFIXED should not be6343used for threaded applications, since the rewriting of the tables and virgin6344may not be thread-safe.6345*/6346var virgin = true;63476348var lenfix, distfix; // We have no pointers in JS, so keep tables separate63496350function fixedtables(state) {6351/* build fixed huffman tables if first call (may not be thread safe) */6352if (virgin) {6353var sym;63546355lenfix = new utils.Buf32(512);6356distfix = new utils.Buf32(32);63576358/* literal/length table */6359sym = 0;6360while (sym < 144) { state.lens[sym++] = 8; }6361while (sym < 256) { state.lens[sym++] = 9; }6362while (sym < 280) { state.lens[sym++] = 7; }6363while (sym < 288) { state.lens[sym++] = 8; }63646365inflate_table(LENS, state.lens, 0, 288, lenfix, 0, state.work, {bits: 9});63666367/* distance table */6368sym = 0;6369while (sym < 32) { state.lens[sym++] = 5; }63706371inflate_table(DISTS, state.lens, 0, 32, distfix, 0, state.work, {bits: 5});63726373/* do this just once */6374virgin = false;6375}63766377state.lencode = lenfix;6378state.lenbits = 9;6379state.distcode = distfix;6380state.distbits = 5;6381}638263836384/*6385Update the window with the last wsize (normally 32K) bytes written before6386returning. If window does not exist yet, create it. This is only called6387when a window is already in use, or when output has been written during this6388inflate call, but the end of the deflate stream has not been reached yet.6389It is also called to create a window for dictionary data when a dictionary6390is loaded.63916392Providing output buffers larger than 32K to inflate() should provide a speed6393advantage, since only the last 32K of output is copied to the sliding window6394upon return from inflate(), and since all distances after the first 32K of6395output will fall in the output data, making match copies simpler and faster.6396The advantage may be dependent on the size of the processor's data caches.6397*/6398function updatewindow(strm, src, end, copy) {6399var dist;6400var state = strm.state;64016402/* if it hasn't been done already, allocate space for the window */6403if (state.window === null) {6404state.wsize = 1 << state.wbits;6405state.wnext = 0;6406state.whave = 0;64076408state.window = new utils.Buf8(state.wsize);6409}64106411/* copy state->wsize or less output bytes into the circular window */6412if (copy >= state.wsize) {6413utils.arraySet(state.window,src, end - state.wsize, state.wsize, 0);6414state.wnext = 0;6415state.whave = state.wsize;6416}6417else {6418dist = state.wsize - state.wnext;6419if (dist > copy) {6420dist = copy;6421}6422//zmemcpy(state->window + state->wnext, end - copy, dist);6423utils.arraySet(state.window,src, end - copy, dist, state.wnext);6424copy -= dist;6425if (copy) {6426//zmemcpy(state->window, end - copy, copy);6427utils.arraySet(state.window,src, end - copy, copy, 0);6428state.wnext = copy;6429state.whave = state.wsize;6430}6431else {6432state.wnext += dist;6433if (state.wnext === state.wsize) { state.wnext = 0; }6434if (state.whave < state.wsize) { state.whave += dist; }6435}6436}6437return 0;6438}64396440function inflate(strm, flush) {6441var state;6442var input, output; // input/output buffers6443var next; /* next input INDEX */6444var put; /* next output INDEX */6445var have, left; /* available input and output */6446var hold; /* bit buffer */6447var bits; /* bits in bit buffer */6448var _in, _out; /* save starting available input and output */6449var copy; /* number of stored or match bytes to copy */6450var from; /* where to copy match bytes from */6451var from_source;6452var here = 0; /* current decoding table entry */6453var here_bits, here_op, here_val; // paked "here" denormalized (JS specific)6454//var last; /* parent table entry */6455var last_bits, last_op, last_val; // paked "last" denormalized (JS specific)6456var len; /* length to copy for repeats, bits to drop */6457var ret; /* return code */6458var hbuf = new utils.Buf8(4); /* buffer for gzip header crc calculation */6459var opts;64606461var n; // temporary var for NEED_BITS64626463var order = /* permutation of code lengths */6464[16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];646564666467if (!strm || !strm.state || !strm.output ||6468(!strm.input && strm.avail_in !== 0)) {6469return Z_STREAM_ERROR;6470}64716472state = strm.state;6473if (state.mode === TYPE) { state.mode = TYPEDO; } /* skip check */647464756476//--- LOAD() ---6477put = strm.next_out;6478output = strm.output;6479left = strm.avail_out;6480next = strm.next_in;6481input = strm.input;6482have = strm.avail_in;6483hold = state.hold;6484bits = state.bits;6485//---64866487_in = have;6488_out = left;6489ret = Z_OK;64906491inf_leave: // goto emulation6492for (;;) {6493switch (state.mode) {6494case HEAD:6495if (state.wrap === 0) {6496state.mode = TYPEDO;6497break;6498}6499//=== NEEDBITS(16);6500while (bits < 16) {6501if (have === 0) { break inf_leave; }6502have--;6503hold += input[next++] << bits;6504bits += 8;6505}6506//===//6507if ((state.wrap & 2) && hold === 0x8b1f) { /* gzip header */6508state.check = 0/*crc32(0L, Z_NULL, 0)*/;6509//=== CRC2(state.check, hold);6510hbuf[0] = hold & 0xff;6511hbuf[1] = (hold >>> 8) & 0xff;6512state.check = crc32(state.check, hbuf, 2, 0);6513//===//65146515//=== INITBITS();6516hold = 0;6517bits = 0;6518//===//6519state.mode = FLAGS;6520break;6521}6522state.flags = 0; /* expect zlib header */6523if (state.head) {6524state.head.done = false;6525}6526if (!(state.wrap & 1) || /* check if zlib header allowed */6527(((hold & 0xff)/*BITS(8)*/ << 8) + (hold >> 8)) % 31) {6528strm.msg = 'incorrect header check';6529state.mode = BAD;6530break;6531}6532if ((hold & 0x0f)/*BITS(4)*/ !== Z_DEFLATED) {6533strm.msg = 'unknown compression method';6534state.mode = BAD;6535break;6536}6537//--- DROPBITS(4) ---//6538hold >>>= 4;6539bits -= 4;6540//---//6541len = (hold & 0x0f)/*BITS(4)*/ + 8;6542if (state.wbits === 0) {6543state.wbits = len;6544}6545else if (len > state.wbits) {6546strm.msg = 'invalid window size';6547state.mode = BAD;6548break;6549}6550state.dmax = 1 << len;6551//Tracev((stderr, "inflate: zlib header ok\n"));6552strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;6553state.mode = hold & 0x200 ? DICTID : TYPE;6554//=== INITBITS();6555hold = 0;6556bits = 0;6557//===//6558break;6559case FLAGS:6560//=== NEEDBITS(16); */6561while (bits < 16) {6562if (have === 0) { break inf_leave; }6563have--;6564hold += input[next++] << bits;6565bits += 8;6566}6567//===//6568state.flags = hold;6569if ((state.flags & 0xff) !== Z_DEFLATED) {6570strm.msg = 'unknown compression method';6571state.mode = BAD;6572break;6573}6574if (state.flags & 0xe000) {6575strm.msg = 'unknown header flags set';6576state.mode = BAD;6577break;6578}6579if (state.head) {6580state.head.text = ((hold >> 8) & 1);6581}6582if (state.flags & 0x0200) {6583//=== CRC2(state.check, hold);6584hbuf[0] = hold & 0xff;6585hbuf[1] = (hold >>> 8) & 0xff;6586state.check = crc32(state.check, hbuf, 2, 0);6587//===//6588}6589//=== INITBITS();6590hold = 0;6591bits = 0;6592//===//6593state.mode = TIME;6594/* falls through */6595case TIME:6596//=== NEEDBITS(32); */6597while (bits < 32) {6598if (have === 0) { break inf_leave; }6599have--;6600hold += input[next++] << bits;6601bits += 8;6602}6603//===//6604if (state.head) {6605state.head.time = hold;6606}6607if (state.flags & 0x0200) {6608//=== CRC4(state.check, hold)6609hbuf[0] = hold & 0xff;6610hbuf[1] = (hold >>> 8) & 0xff;6611hbuf[2] = (hold >>> 16) & 0xff;6612hbuf[3] = (hold >>> 24) & 0xff;6613state.check = crc32(state.check, hbuf, 4, 0);6614//===6615}6616//=== INITBITS();6617hold = 0;6618bits = 0;6619//===//6620state.mode = OS;6621/* falls through */6622case OS:6623//=== NEEDBITS(16); */6624while (bits < 16) {6625if (have === 0) { break inf_leave; }6626have--;6627hold += input[next++] << bits;6628bits += 8;6629}6630//===//6631if (state.head) {6632state.head.xflags = (hold & 0xff);6633state.head.os = (hold >> 8);6634}6635if (state.flags & 0x0200) {6636//=== CRC2(state.check, hold);6637hbuf[0] = hold & 0xff;6638hbuf[1] = (hold >>> 8) & 0xff;6639state.check = crc32(state.check, hbuf, 2, 0);6640//===//6641}6642//=== INITBITS();6643hold = 0;6644bits = 0;6645//===//6646state.mode = EXLEN;6647/* falls through */6648case EXLEN:6649if (state.flags & 0x0400) {6650//=== NEEDBITS(16); */6651while (bits < 16) {6652if (have === 0) { break inf_leave; }6653have--;6654hold += input[next++] << bits;6655bits += 8;6656}6657//===//6658state.length = hold;6659if (state.head) {6660state.head.extra_len = hold;6661}6662if (state.flags & 0x0200) {6663//=== CRC2(state.check, hold);6664hbuf[0] = hold & 0xff;6665hbuf[1] = (hold >>> 8) & 0xff;6666state.check = crc32(state.check, hbuf, 2, 0);6667//===//6668}6669//=== INITBITS();6670hold = 0;6671bits = 0;6672//===//6673}6674else if (state.head) {6675state.head.extra = null/*Z_NULL*/;6676}6677state.mode = EXTRA;6678/* falls through */6679case EXTRA:6680if (state.flags & 0x0400) {6681copy = state.length;6682if (copy > have) { copy = have; }6683if (copy) {6684if (state.head) {6685len = state.head.extra_len - state.length;6686if (!state.head.extra) {6687// Use untyped array for more conveniend processing later6688state.head.extra = new Array(state.head.extra_len);6689}6690utils.arraySet(6691state.head.extra,6692input,6693next,6694// extra field is limited to 65536 bytes6695// - no need for additional size check6696copy,6697/*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/6698len6699);6700//zmemcpy(state.head.extra + len, next,6701// len + copy > state.head.extra_max ?6702// state.head.extra_max - len : copy);6703}6704if (state.flags & 0x0200) {6705state.check = crc32(state.check, input, copy, next);6706}6707have -= copy;6708next += copy;6709state.length -= copy;6710}6711if (state.length) { break inf_leave; }6712}6713state.length = 0;6714state.mode = NAME;6715/* falls through */6716case NAME:6717if (state.flags & 0x0800) {6718if (have === 0) { break inf_leave; }6719copy = 0;6720do {6721// TODO: 2 or 1 bytes?6722len = input[next + copy++];6723/* use constant limit because in js we should not preallocate memory */6724if (state.head && len &&6725(state.length < 65536 /*state.head.name_max*/)) {6726state.head.name += String.fromCharCode(len);6727}6728} while (len && copy < have);67296730if (state.flags & 0x0200) {6731state.check = crc32(state.check, input, copy, next);6732}6733have -= copy;6734next += copy;6735if (len) { break inf_leave; }6736}6737else if (state.head) {6738state.head.name = null;6739}6740state.length = 0;6741state.mode = COMMENT;6742/* falls through */6743case COMMENT:6744if (state.flags & 0x1000) {6745if (have === 0) { break inf_leave; }6746copy = 0;6747do {6748len = input[next + copy++];6749/* use constant limit because in js we should not preallocate memory */6750if (state.head && len &&6751(state.length < 65536 /*state.head.comm_max*/)) {6752state.head.comment += String.fromCharCode(len);6753}6754} while (len && copy < have);6755if (state.flags & 0x0200) {6756state.check = crc32(state.check, input, copy, next);6757}6758have -= copy;6759next += copy;6760if (len) { break inf_leave; }6761}6762else if (state.head) {6763state.head.comment = null;6764}6765state.mode = HCRC;6766/* falls through */6767case HCRC:6768if (state.flags & 0x0200) {6769//=== NEEDBITS(16); */6770while (bits < 16) {6771if (have === 0) { break inf_leave; }6772have--;6773hold += input[next++] << bits;6774bits += 8;6775}6776//===//6777if (hold !== (state.check & 0xffff)) {6778strm.msg = 'header crc mismatch';6779state.mode = BAD;6780break;6781}6782//=== INITBITS();6783hold = 0;6784bits = 0;6785//===//6786}6787if (state.head) {6788state.head.hcrc = ((state.flags >> 9) & 1);6789state.head.done = true;6790}6791strm.adler = state.check = 0 /*crc32(0L, Z_NULL, 0)*/;6792state.mode = TYPE;6793break;6794case DICTID:6795//=== NEEDBITS(32); */6796while (bits < 32) {6797if (have === 0) { break inf_leave; }6798have--;6799hold += input[next++] << bits;6800bits += 8;6801}6802//===//6803strm.adler = state.check = ZSWAP32(hold);6804//=== INITBITS();6805hold = 0;6806bits = 0;6807//===//6808state.mode = DICT;6809/* falls through */6810case DICT:6811if (state.havedict === 0) {6812//--- RESTORE() ---6813strm.next_out = put;6814strm.avail_out = left;6815strm.next_in = next;6816strm.avail_in = have;6817state.hold = hold;6818state.bits = bits;6819//---6820return Z_NEED_DICT;6821}6822strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;6823state.mode = TYPE;6824/* falls through */6825case TYPE:6826if (flush === Z_BLOCK || flush === Z_TREES) { break inf_leave; }6827/* falls through */6828case TYPEDO:6829if (state.last) {6830//--- BYTEBITS() ---//6831hold >>>= bits & 7;6832bits -= bits & 7;6833//---//6834state.mode = CHECK;6835break;6836}6837//=== NEEDBITS(3); */6838while (bits < 3) {6839if (have === 0) { break inf_leave; }6840have--;6841hold += input[next++] << bits;6842bits += 8;6843}6844//===//6845state.last = (hold & 0x01)/*BITS(1)*/;6846//--- DROPBITS(1) ---//6847hold >>>= 1;6848bits -= 1;6849//---//68506851switch ((hold & 0x03)/*BITS(2)*/) {6852case 0: /* stored block */6853//Tracev((stderr, "inflate: stored block%s\n",6854// state.last ? " (last)" : ""));6855state.mode = STORED;6856break;6857case 1: /* fixed block */6858fixedtables(state);6859//Tracev((stderr, "inflate: fixed codes block%s\n",6860// state.last ? " (last)" : ""));6861state.mode = LEN_; /* decode codes */6862if (flush === Z_TREES) {6863//--- DROPBITS(2) ---//6864hold >>>= 2;6865bits -= 2;6866//---//6867break inf_leave;6868}6869break;6870case 2: /* dynamic block */6871//Tracev((stderr, "inflate: dynamic codes block%s\n",6872// state.last ? " (last)" : ""));6873state.mode = TABLE;6874break;6875case 3:6876strm.msg = 'invalid block type';6877state.mode = BAD;6878}6879//--- DROPBITS(2) ---//6880hold >>>= 2;6881bits -= 2;6882//---//6883break;6884case STORED:6885//--- BYTEBITS() ---// /* go to byte boundary */6886hold >>>= bits & 7;6887bits -= bits & 7;6888//---//6889//=== NEEDBITS(32); */6890while (bits < 32) {6891if (have === 0) { break inf_leave; }6892have--;6893hold += input[next++] << bits;6894bits += 8;6895}6896//===//6897if ((hold & 0xffff) !== ((hold >>> 16) ^ 0xffff)) {6898strm.msg = 'invalid stored block lengths';6899state.mode = BAD;6900break;6901}6902state.length = hold & 0xffff;6903//Tracev((stderr, "inflate: stored length %u\n",6904// state.length));6905//=== INITBITS();6906hold = 0;6907bits = 0;6908//===//6909state.mode = COPY_;6910if (flush === Z_TREES) { break inf_leave; }6911/* falls through */6912case COPY_:6913state.mode = COPY;6914/* falls through */6915case COPY:6916copy = state.length;6917if (copy) {6918if (copy > have) { copy = have; }6919if (copy > left) { copy = left; }6920if (copy === 0) { break inf_leave; }6921//--- zmemcpy(put, next, copy); ---6922utils.arraySet(output, input, next, copy, put);6923//---//6924have -= copy;6925next += copy;6926left -= copy;6927put += copy;6928state.length -= copy;6929break;6930}6931//Tracev((stderr, "inflate: stored end\n"));6932state.mode = TYPE;6933break;6934case TABLE:6935//=== NEEDBITS(14); */6936while (bits < 14) {6937if (have === 0) { break inf_leave; }6938have--;6939hold += input[next++] << bits;6940bits += 8;6941}6942//===//6943state.nlen = (hold & 0x1f)/*BITS(5)*/ + 257;6944//--- DROPBITS(5) ---//6945hold >>>= 5;6946bits -= 5;6947//---//6948state.ndist = (hold & 0x1f)/*BITS(5)*/ + 1;6949//--- DROPBITS(5) ---//6950hold >>>= 5;6951bits -= 5;6952//---//6953state.ncode = (hold & 0x0f)/*BITS(4)*/ + 4;6954//--- DROPBITS(4) ---//6955hold >>>= 4;6956bits -= 4;6957//---//6958//#ifndef PKZIP_BUG_WORKAROUND6959if (state.nlen > 286 || state.ndist > 30) {6960strm.msg = 'too many length or distance symbols';6961state.mode = BAD;6962break;6963}6964//#endif6965//Tracev((stderr, "inflate: table sizes ok\n"));6966state.have = 0;6967state.mode = LENLENS;6968/* falls through */6969case LENLENS:6970while (state.have < state.ncode) {6971//=== NEEDBITS(3);6972while (bits < 3) {6973if (have === 0) { break inf_leave; }6974have--;6975hold += input[next++] << bits;6976bits += 8;6977}6978//===//6979state.lens[order[state.have++]] = (hold & 0x07);//BITS(3);6980//--- DROPBITS(3) ---//6981hold >>>= 3;6982bits -= 3;6983//---//6984}6985while (state.have < 19) {6986state.lens[order[state.have++]] = 0;6987}6988// We have separate tables & no pointers. 2 commented lines below not needed.6989//state.next = state.codes;6990//state.lencode = state.next;6991// Switch to use dynamic table6992state.lencode = state.lendyn;6993state.lenbits = 7;69946995opts = {bits: state.lenbits};6996ret = inflate_table(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts);6997state.lenbits = opts.bits;69986999if (ret) {7000strm.msg = 'invalid code lengths set';7001state.mode = BAD;7002break;7003}7004//Tracev((stderr, "inflate: code lengths ok\n"));7005state.have = 0;7006state.mode = CODELENS;7007/* falls through */7008case CODELENS:7009while (state.have < state.nlen + state.ndist) {7010for (;;) {7011here = state.lencode[hold & ((1 << state.lenbits) - 1)];/*BITS(state.lenbits)*/7012here_bits = here >>> 24;7013here_op = (here >>> 16) & 0xff;7014here_val = here & 0xffff;70157016if ((here_bits) <= bits) { break; }7017//--- PULLBYTE() ---//7018if (have === 0) { break inf_leave; }7019have--;7020hold += input[next++] << bits;7021bits += 8;7022//---//7023}7024if (here_val < 16) {7025//--- DROPBITS(here.bits) ---//7026hold >>>= here_bits;7027bits -= here_bits;7028//---//7029state.lens[state.have++] = here_val;7030}7031else {7032if (here_val === 16) {7033//=== NEEDBITS(here.bits + 2);7034n = here_bits + 2;7035while (bits < n) {7036if (have === 0) { break inf_leave; }7037have--;7038hold += input[next++] << bits;7039bits += 8;7040}7041//===//7042//--- DROPBITS(here.bits) ---//7043hold >>>= here_bits;7044bits -= here_bits;7045//---//7046if (state.have === 0) {7047strm.msg = 'invalid bit length repeat';7048state.mode = BAD;7049break;7050}7051len = state.lens[state.have - 1];7052copy = 3 + (hold & 0x03);//BITS(2);7053//--- DROPBITS(2) ---//7054hold >>>= 2;7055bits -= 2;7056//---//7057}7058else if (here_val === 17) {7059//=== NEEDBITS(here.bits + 3);7060n = here_bits + 3;7061while (bits < n) {7062if (have === 0) { break inf_leave; }7063have--;7064hold += input[next++] << bits;7065bits += 8;7066}7067//===//7068//--- DROPBITS(here.bits) ---//7069hold >>>= here_bits;7070bits -= here_bits;7071//---//7072len = 0;7073copy = 3 + (hold & 0x07);//BITS(3);7074//--- DROPBITS(3) ---//7075hold >>>= 3;7076bits -= 3;7077//---//7078}7079else {7080//=== NEEDBITS(here.bits + 7);7081n = here_bits + 7;7082while (bits < n) {7083if (have === 0) { break inf_leave; }7084have--;7085hold += input[next++] << bits;7086bits += 8;7087}7088//===//7089//--- DROPBITS(here.bits) ---//7090hold >>>= here_bits;7091bits -= here_bits;7092//---//7093len = 0;7094copy = 11 + (hold & 0x7f);//BITS(7);7095//--- DROPBITS(7) ---//7096hold >>>= 7;7097bits -= 7;7098//---//7099}7100if (state.have + copy > state.nlen + state.ndist) {7101strm.msg = 'invalid bit length repeat';7102state.mode = BAD;7103break;7104}7105while (copy--) {7106state.lens[state.have++] = len;7107}7108}7109}71107111/* handle error breaks in while */7112if (state.mode === BAD) { break; }71137114/* check for end-of-block code (better have one) */7115if (state.lens[256] === 0) {7116strm.msg = 'invalid code -- missing end-of-block';7117state.mode = BAD;7118break;7119}71207121/* build code tables -- note: do not change the lenbits or distbits7122values here (9 and 6) without reading the comments in inftrees.h7123concerning the ENOUGH constants, which depend on those values */7124state.lenbits = 9;71257126opts = {bits: state.lenbits};7127ret = inflate_table(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts);7128// We have separate tables & no pointers. 2 commented lines below not needed.7129// state.next_index = opts.table_index;7130state.lenbits = opts.bits;7131// state.lencode = state.next;71327133if (ret) {7134strm.msg = 'invalid literal/lengths set';7135state.mode = BAD;7136break;7137}71387139state.distbits = 6;7140//state.distcode.copy(state.codes);7141// Switch to use dynamic table7142state.distcode = state.distdyn;7143opts = {bits: state.distbits};7144ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts);7145// We have separate tables & no pointers. 2 commented lines below not needed.7146// state.next_index = opts.table_index;7147state.distbits = opts.bits;7148// state.distcode = state.next;71497150if (ret) {7151strm.msg = 'invalid distances set';7152state.mode = BAD;7153break;7154}7155//Tracev((stderr, 'inflate: codes ok\n'));7156state.mode = LEN_;7157if (flush === Z_TREES) { break inf_leave; }7158/* falls through */7159case LEN_:7160state.mode = LEN;7161/* falls through */7162case LEN:7163if (have >= 6 && left >= 258) {7164//--- RESTORE() ---7165strm.next_out = put;7166strm.avail_out = left;7167strm.next_in = next;7168strm.avail_in = have;7169state.hold = hold;7170state.bits = bits;7171//---7172inflate_fast(strm, _out);7173//--- LOAD() ---7174put = strm.next_out;7175output = strm.output;7176left = strm.avail_out;7177next = strm.next_in;7178input = strm.input;7179have = strm.avail_in;7180hold = state.hold;7181bits = state.bits;7182//---71837184if (state.mode === TYPE) {7185state.back = -1;7186}7187break;7188}7189state.back = 0;7190for (;;) {7191here = state.lencode[hold & ((1 << state.lenbits) -1)]; /*BITS(state.lenbits)*/7192here_bits = here >>> 24;7193here_op = (here >>> 16) & 0xff;7194here_val = here & 0xffff;71957196if (here_bits <= bits) { break; }7197//--- PULLBYTE() ---//7198if (have === 0) { break inf_leave; }7199have--;7200hold += input[next++] << bits;7201bits += 8;7202//---//7203}7204if (here_op && (here_op & 0xf0) === 0) {7205last_bits = here_bits;7206last_op = here_op;7207last_val = here_val;7208for (;;) {7209here = state.lencode[last_val +7210((hold & ((1 << (last_bits + last_op)) -1))/*BITS(last.bits + last.op)*/ >> last_bits)];7211here_bits = here >>> 24;7212here_op = (here >>> 16) & 0xff;7213here_val = here & 0xffff;72147215if ((last_bits + here_bits) <= bits) { break; }7216//--- PULLBYTE() ---//7217if (have === 0) { break inf_leave; }7218have--;7219hold += input[next++] << bits;7220bits += 8;7221//---//7222}7223//--- DROPBITS(last.bits) ---//7224hold >>>= last_bits;7225bits -= last_bits;7226//---//7227state.back += last_bits;7228}7229//--- DROPBITS(here.bits) ---//7230hold >>>= here_bits;7231bits -= here_bits;7232//---//7233state.back += here_bits;7234state.length = here_val;7235if (here_op === 0) {7236//Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?7237// "inflate: literal '%c'\n" :7238// "inflate: literal 0x%02x\n", here.val));7239state.mode = LIT;7240break;7241}7242if (here_op & 32) {7243//Tracevv((stderr, "inflate: end of block\n"));7244state.back = -1;7245state.mode = TYPE;7246break;7247}7248if (here_op & 64) {7249strm.msg = 'invalid literal/length code';7250state.mode = BAD;7251break;7252}7253state.extra = here_op & 15;7254state.mode = LENEXT;7255/* falls through */7256case LENEXT:7257if (state.extra) {7258//=== NEEDBITS(state.extra);7259n = state.extra;7260while (bits < n) {7261if (have === 0) { break inf_leave; }7262have--;7263hold += input[next++] << bits;7264bits += 8;7265}7266//===//7267state.length += hold & ((1 << state.extra) -1)/*BITS(state.extra)*/;7268//--- DROPBITS(state.extra) ---//7269hold >>>= state.extra;7270bits -= state.extra;7271//---//7272state.back += state.extra;7273}7274//Tracevv((stderr, "inflate: length %u\n", state.length));7275state.was = state.length;7276state.mode = DIST;7277/* falls through */7278case DIST:7279for (;;) {7280here = state.distcode[hold & ((1 << state.distbits) -1)];/*BITS(state.distbits)*/7281here_bits = here >>> 24;7282here_op = (here >>> 16) & 0xff;7283here_val = here & 0xffff;72847285if ((here_bits) <= bits) { break; }7286//--- PULLBYTE() ---//7287if (have === 0) { break inf_leave; }7288have--;7289hold += input[next++] << bits;7290bits += 8;7291//---//7292}7293if ((here_op & 0xf0) === 0) {7294last_bits = here_bits;7295last_op = here_op;7296last_val = here_val;7297for (;;) {7298here = state.distcode[last_val +7299((hold & ((1 << (last_bits + last_op)) -1))/*BITS(last.bits + last.op)*/ >> last_bits)];7300here_bits = here >>> 24;7301here_op = (here >>> 16) & 0xff;7302here_val = here & 0xffff;73037304if ((last_bits + here_bits) <= bits) { break; }7305//--- PULLBYTE() ---//7306if (have === 0) { break inf_leave; }7307have--;7308hold += input[next++] << bits;7309bits += 8;7310//---//7311}7312//--- DROPBITS(last.bits) ---//7313hold >>>= last_bits;7314bits -= last_bits;7315//---//7316state.back += last_bits;7317}7318//--- DROPBITS(here.bits) ---//7319hold >>>= here_bits;7320bits -= here_bits;7321//---//7322state.back += here_bits;7323if (here_op & 64) {7324strm.msg = 'invalid distance code';7325state.mode = BAD;7326break;7327}7328state.offset = here_val;7329state.extra = (here_op) & 15;7330state.mode = DISTEXT;7331/* falls through */7332case DISTEXT:7333if (state.extra) {7334//=== NEEDBITS(state.extra);7335n = state.extra;7336while (bits < n) {7337if (have === 0) { break inf_leave; }7338have--;7339hold += input[next++] << bits;7340bits += 8;7341}7342//===//7343state.offset += hold & ((1 << state.extra) -1)/*BITS(state.extra)*/;7344//--- DROPBITS(state.extra) ---//7345hold >>>= state.extra;7346bits -= state.extra;7347//---//7348state.back += state.extra;7349}7350//#ifdef INFLATE_STRICT7351if (state.offset > state.dmax) {7352strm.msg = 'invalid distance too far back';7353state.mode = BAD;7354break;7355}7356//#endif7357//Tracevv((stderr, "inflate: distance %u\n", state.offset));7358state.mode = MATCH;7359/* falls through */7360case MATCH:7361if (left === 0) { break inf_leave; }7362copy = _out - left;7363if (state.offset > copy) { /* copy from window */7364copy = state.offset - copy;7365if (copy > state.whave) {7366if (state.sane) {7367strm.msg = 'invalid distance too far back';7368state.mode = BAD;7369break;7370}7371// (!) This block is disabled in zlib defailts,7372// don't enable it for binary compatibility7373//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR7374// Trace((stderr, "inflate.c too far\n"));7375// copy -= state.whave;7376// if (copy > state.length) { copy = state.length; }7377// if (copy > left) { copy = left; }7378// left -= copy;7379// state.length -= copy;7380// do {7381// output[put++] = 0;7382// } while (--copy);7383// if (state.length === 0) { state.mode = LEN; }7384// break;7385//#endif7386}7387if (copy > state.wnext) {7388copy -= state.wnext;7389from = state.wsize - copy;7390}7391else {7392from = state.wnext - copy;7393}7394if (copy > state.length) { copy = state.length; }7395from_source = state.window;7396}7397else { /* copy from output */7398from_source = output;7399from = put - state.offset;7400copy = state.length;7401}7402if (copy > left) { copy = left; }7403left -= copy;7404state.length -= copy;7405do {7406output[put++] = from_source[from++];7407} while (--copy);7408if (state.length === 0) { state.mode = LEN; }7409break;7410case LIT:7411if (left === 0) { break inf_leave; }7412output[put++] = state.length;7413left--;7414state.mode = LEN;7415break;7416case CHECK:7417if (state.wrap) {7418//=== NEEDBITS(32);7419while (bits < 32) {7420if (have === 0) { break inf_leave; }7421have--;7422// Use '|' insdead of '+' to make sure that result is signed7423hold |= input[next++] << bits;7424bits += 8;7425}7426//===//7427_out -= left;7428strm.total_out += _out;7429state.total += _out;7430if (_out) {7431strm.adler = state.check =7432/*UPDATE(state.check, put - _out, _out);*/7433(state.flags ? crc32(state.check, output, _out, put - _out) : adler32(state.check, output, _out, put - _out));74347435}7436_out = left;7437// NB: crc32 stored as signed 32-bit int, ZSWAP32 returns signed too7438if ((state.flags ? hold : ZSWAP32(hold)) !== state.check) {7439strm.msg = 'incorrect data check';7440state.mode = BAD;7441break;7442}7443//=== INITBITS();7444hold = 0;7445bits = 0;7446//===//7447//Tracev((stderr, "inflate: check matches trailer\n"));7448}7449state.mode = LENGTH;7450/* falls through */7451case LENGTH:7452if (state.wrap && state.flags) {7453//=== NEEDBITS(32);7454while (bits < 32) {7455if (have === 0) { break inf_leave; }7456have--;7457hold += input[next++] << bits;7458bits += 8;7459}7460//===//7461if (hold !== (state.total & 0xffffffff)) {7462strm.msg = 'incorrect length check';7463state.mode = BAD;7464break;7465}7466//=== INITBITS();7467hold = 0;7468bits = 0;7469//===//7470//Tracev((stderr, "inflate: length matches trailer\n"));7471}7472state.mode = DONE;7473/* falls through */7474case DONE:7475ret = Z_STREAM_END;7476break inf_leave;7477case BAD:7478ret = Z_DATA_ERROR;7479break inf_leave;7480case MEM:7481return Z_MEM_ERROR;7482case SYNC:7483/* falls through */7484default:7485return Z_STREAM_ERROR;7486}7487}74887489// inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave"74907491/*7492Return from inflate(), updating the total counts and the check value.7493If there was no progress during the inflate() call, return a buffer7494error. Call updatewindow() to create and/or update the window state.7495Note: a memory error from inflate() is non-recoverable.7496*/74977498//--- RESTORE() ---7499strm.next_out = put;7500strm.avail_out = left;7501strm.next_in = next;7502strm.avail_in = have;7503state.hold = hold;7504state.bits = bits;7505//---75067507if (state.wsize || (_out !== strm.avail_out && state.mode < BAD &&7508(state.mode < CHECK || flush !== Z_FINISH))) {7509if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) {7510state.mode = MEM;7511return Z_MEM_ERROR;7512}7513}7514_in -= strm.avail_in;7515_out -= strm.avail_out;7516strm.total_in += _in;7517strm.total_out += _out;7518state.total += _out;7519if (state.wrap && _out) {7520strm.adler = state.check = /*UPDATE(state.check, strm.next_out - _out, _out);*/7521(state.flags ? crc32(state.check, output, _out, strm.next_out - _out) : adler32(state.check, output, _out, strm.next_out - _out));7522}7523strm.data_type = state.bits + (state.last ? 64 : 0) +7524(state.mode === TYPE ? 128 : 0) +7525(state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);7526if (((_in === 0 && _out === 0) || flush === Z_FINISH) && ret === Z_OK) {7527ret = Z_BUF_ERROR;7528}7529return ret;7530}75317532function inflateEnd(strm) {75337534if (!strm || !strm.state /*|| strm->zfree == (free_func)0*/) {7535return Z_STREAM_ERROR;7536}75377538var state = strm.state;7539if (state.window) {7540state.window = null;7541}7542strm.state = null;7543return Z_OK;7544}75457546function inflateGetHeader(strm, head) {7547var state;75487549/* check state */7550if (!strm || !strm.state) { return Z_STREAM_ERROR; }7551state = strm.state;7552if ((state.wrap & 2) === 0) { return Z_STREAM_ERROR; }75537554/* save header structure */7555state.head = head;7556head.done = false;7557return Z_OK;7558}755975607561exports.inflateReset = inflateReset;7562exports.inflateReset2 = inflateReset2;7563exports.inflateResetKeep = inflateResetKeep;7564exports.inflateInit = inflateInit;7565exports.inflateInit2 = inflateInit2;7566exports.inflate = inflate;7567exports.inflateEnd = inflateEnd;7568exports.inflateGetHeader = inflateGetHeader;7569exports.inflateInfo = 'pako inflate (from Nodeca project)';75707571/* Not implemented7572exports.inflateCopy = inflateCopy;7573exports.inflateGetDictionary = inflateGetDictionary;7574exports.inflateMark = inflateMark;7575exports.inflatePrime = inflatePrime;7576exports.inflateSetDictionary = inflateSetDictionary;7577exports.inflateSync = inflateSync;7578exports.inflateSyncPoint = inflateSyncPoint;7579exports.inflateUndermine = inflateUndermine;7580*/7581},{"../utils/common":27,"./adler32":29,"./crc32":31,"./inffast":34,"./inftrees":36}],36:[function(_dereq_,module,exports){7582'use strict';758375847585var utils = _dereq_('../utils/common');75867587var MAXBITS = 15;7588var ENOUGH_LENS = 852;7589var ENOUGH_DISTS = 592;7590//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);75917592var CODES = 0;7593var LENS = 1;7594var DISTS = 2;75957596var lbase = [ /* Length codes 257..285 base */75973, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,759835, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 07599];76007601var lext = [ /* Length codes 257..285 extra */760216, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,760319, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 787604];76057606var dbase = [ /* Distance codes 0..29 base */76071, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,7608257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,76098193, 12289, 16385, 24577, 0, 07610];76117612var dext = [ /* Distance codes 0..29 extra */761316, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,761423, 23, 24, 24, 25, 25, 26, 26, 27, 27,761528, 28, 29, 29, 64, 647616];76177618module.exports = function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts)7619{7620var bits = opts.bits;7621//here = opts.here; /* table entry for duplication */76227623var len = 0; /* a code's length in bits */7624var sym = 0; /* index of code symbols */7625var min = 0, max = 0; /* minimum and maximum code lengths */7626var root = 0; /* number of index bits for root table */7627var curr = 0; /* number of index bits for current table */7628var drop = 0; /* code bits to drop for sub-table */7629var left = 0; /* number of prefix codes available */7630var used = 0; /* code entries in table used */7631var huff = 0; /* Huffman code */7632var incr; /* for incrementing code, index */7633var fill; /* index for replicating entries */7634var low; /* low bits for current root entry */7635var mask; /* mask for low root bits */7636var next; /* next available space in table */7637var base = null; /* base value table to use */7638var base_index = 0;7639// var shoextra; /* extra bits table to use */7640var end; /* use base and extra for symbol > end */7641var count = new utils.Buf16(MAXBITS+1); //[MAXBITS+1]; /* number of codes of each length */7642var offs = new utils.Buf16(MAXBITS+1); //[MAXBITS+1]; /* offsets in table for each length */7643var extra = null;7644var extra_index = 0;76457646var here_bits, here_op, here_val;76477648/*7649Process a set of code lengths to create a canonical Huffman code. The7650code lengths are lens[0..codes-1]. Each length corresponds to the7651symbols 0..codes-1. The Huffman code is generated by first sorting the7652symbols by length from short to long, and retaining the symbol order7653for codes with equal lengths. Then the code starts with all zero bits7654for the first code of the shortest length, and the codes are integer7655increments for the same length, and zeros are appended as the length7656increases. For the deflate format, these bits are stored backwards7657from their more natural integer increment ordering, and so when the7658decoding tables are built in the large loop below, the integer codes7659are incremented backwards.76607661This routine assumes, but does not check, that all of the entries in7662lens[] are in the range 0..MAXBITS. The caller must assure this.76631..MAXBITS is interpreted as that code length. zero means that that7664symbol does not occur in this code.76657666The codes are sorted by computing a count of codes for each length,7667creating from that a table of starting indices for each length in the7668sorted table, and then entering the symbols in order in the sorted7669table. The sorted table is work[], with that space being provided by7670the caller.76717672The length counts are used for other purposes as well, i.e. finding7673the minimum and maximum length codes, determining if there are any7674codes at all, checking for a valid set of lengths, and looking ahead7675at length counts to determine sub-table sizes when building the7676decoding tables.7677*/76787679/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */7680for (len = 0; len <= MAXBITS; len++) {7681count[len] = 0;7682}7683for (sym = 0; sym < codes; sym++) {7684count[lens[lens_index + sym]]++;7685}76867687/* bound code lengths, force root to be within code lengths */7688root = bits;7689for (max = MAXBITS; max >= 1; max--) {7690if (count[max] !== 0) { break; }7691}7692if (root > max) {7693root = max;7694}7695if (max === 0) { /* no symbols to code at all */7696//table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */7697//table.bits[opts.table_index] = 1; //here.bits = (var char)1;7698//table.val[opts.table_index++] = 0; //here.val = (var short)0;7699table[table_index++] = (1 << 24) | (64 << 16) | 0;770077017702//table.op[opts.table_index] = 64;7703//table.bits[opts.table_index] = 1;7704//table.val[opts.table_index++] = 0;7705table[table_index++] = (1 << 24) | (64 << 16) | 0;77067707opts.bits = 1;7708return 0; /* no symbols, but wait for decoding to report error */7709}7710for (min = 1; min < max; min++) {7711if (count[min] !== 0) { break; }7712}7713if (root < min) {7714root = min;7715}77167717/* check for an over-subscribed or incomplete set of lengths */7718left = 1;7719for (len = 1; len <= MAXBITS; len++) {7720left <<= 1;7721left -= count[len];7722if (left < 0) {7723return -1;7724} /* over-subscribed */7725}7726if (left > 0 && (type === CODES || max !== 1)) {7727return -1; /* incomplete set */7728}77297730/* generate offsets into symbol table for each length for sorting */7731offs[1] = 0;7732for (len = 1; len < MAXBITS; len++) {7733offs[len + 1] = offs[len] + count[len];7734}77357736/* sort symbols by length, by symbol order within each length */7737for (sym = 0; sym < codes; sym++) {7738if (lens[lens_index + sym] !== 0) {7739work[offs[lens[lens_index + sym]]++] = sym;7740}7741}77427743/*7744Create and fill in decoding tables. In this loop, the table being7745filled is at next and has curr index bits. The code being used is huff7746with length len. That code is converted to an index by dropping drop7747bits off of the bottom. For codes where len is less than drop + curr,7748those top drop + curr - len bits are incremented through all values to7749fill the table with replicated entries.77507751root is the number of index bits for the root table. When len exceeds7752root, sub-tables are created pointed to by the root entry with an index7753of the low root bits of huff. This is saved in low to check for when a7754new sub-table should be started. drop is zero when the root table is7755being filled, and drop is root when sub-tables are being filled.77567757When a new sub-table is needed, it is necessary to look ahead in the7758code lengths to determine what size sub-table is needed. The length7759counts are used for this, and so count[] is decremented as codes are7760entered in the tables.77617762used keeps track of how many table entries have been allocated from the7763provided *table space. It is checked for LENS and DIST tables against7764the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in7765the initial root table size constants. See the comments in inftrees.h7766for more information.77677768sym increments through all symbols, and the loop terminates when7769all codes of length max, i.e. all codes, have been processed. This7770routine permits incomplete codes, so another loop after this one fills7771in the rest of the decoding tables with invalid code markers.7772*/77737774/* set up for code type */7775// poor man optimization - use if-else instead of switch,7776// to avoid deopts in old v87777if (type === CODES) {7778base = extra = work; /* dummy value--not used */7779end = 19;7780} else if (type === LENS) {7781base = lbase;7782base_index -= 257;7783extra = lext;7784extra_index -= 257;7785end = 256;7786} else { /* DISTS */7787base = dbase;7788extra = dext;7789end = -1;7790}77917792/* initialize opts for loop */7793huff = 0; /* starting code */7794sym = 0; /* starting code symbol */7795len = min; /* starting code length */7796next = table_index; /* current table to fill in */7797curr = root; /* current table index bits */7798drop = 0; /* current bits to drop from code for index */7799low = -1; /* trigger new sub-table when len > root */7800used = 1 << root; /* use root table entries */7801mask = used - 1; /* mask for comparing low */78027803/* check available table space */7804if ((type === LENS && used > ENOUGH_LENS) ||7805(type === DISTS && used > ENOUGH_DISTS)) {7806return 1;7807}78087809var i=0;7810/* process all codes and make table entries */7811for (;;) {7812i++;7813/* create table entry */7814here_bits = len - drop;7815if (work[sym] < end) {7816here_op = 0;7817here_val = work[sym];7818}7819else if (work[sym] > end) {7820here_op = extra[extra_index + work[sym]];7821here_val = base[base_index + work[sym]];7822}7823else {7824here_op = 32 + 64; /* end of block */7825here_val = 0;7826}78277828/* replicate for those indices with low len bits equal to huff */7829incr = 1 << (len - drop);7830fill = 1 << curr;7831min = fill; /* save offset to next table */7832do {7833fill -= incr;7834table[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val |0;7835} while (fill !== 0);78367837/* backwards increment the len-bit code huff */7838incr = 1 << (len - 1);7839while (huff & incr) {7840incr >>= 1;7841}7842if (incr !== 0) {7843huff &= incr - 1;7844huff += incr;7845} else {7846huff = 0;7847}78487849/* go to next symbol, update count, len */7850sym++;7851if (--count[len] === 0) {7852if (len === max) { break; }7853len = lens[lens_index + work[sym]];7854}78557856/* create new sub-table if needed */7857if (len > root && (huff & mask) !== low) {7858/* if first time, transition to sub-tables */7859if (drop === 0) {7860drop = root;7861}78627863/* increment past last table */7864next += min; /* here min is 1 << curr */78657866/* determine length of next table */7867curr = len - drop;7868left = 1 << curr;7869while (curr + drop < max) {7870left -= count[curr + drop];7871if (left <= 0) { break; }7872curr++;7873left <<= 1;7874}78757876/* check for enough space */7877used += 1 << curr;7878if ((type === LENS && used > ENOUGH_LENS) ||7879(type === DISTS && used > ENOUGH_DISTS)) {7880return 1;7881}78827883/* point entry in root table to sub-table */7884low = huff & mask;7885/*table.op[low] = curr;7886table.bits[low] = root;7887table.val[low] = next - opts.table_index;*/7888table[low] = (root << 24) | (curr << 16) | (next - table_index) |0;7889}7890}78917892/* fill in remaining table entry if code is incomplete (guaranteed to have7893at most one remaining entry, since if the code is incomplete, the7894maximum code length that was allowed to get this far is one bit) */7895if (huff !== 0) {7896//table.op[next + huff] = 64; /* invalid code marker */7897//table.bits[next + huff] = len - drop;7898//table.val[next + huff] = 0;7899table[next + huff] = ((len - drop) << 24) | (64 << 16) |0;7900}79017902/* set return parameters */7903//opts.table_index += used;7904opts.bits = root;7905return 0;7906};79077908},{"../utils/common":27}],37:[function(_dereq_,module,exports){7909'use strict';79107911module.exports = {7912'2': 'need dictionary', /* Z_NEED_DICT 2 */7913'1': 'stream end', /* Z_STREAM_END 1 */7914'0': '', /* Z_OK 0 */7915'-1': 'file error', /* Z_ERRNO (-1) */7916'-2': 'stream error', /* Z_STREAM_ERROR (-2) */7917'-3': 'data error', /* Z_DATA_ERROR (-3) */7918'-4': 'insufficient memory', /* Z_MEM_ERROR (-4) */7919'-5': 'buffer error', /* Z_BUF_ERROR (-5) */7920'-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */7921};7922},{}],38:[function(_dereq_,module,exports){7923'use strict';792479257926var utils = _dereq_('../utils/common');79277928/* Public constants ==========================================================*/7929/* ===========================================================================*/793079317932//var Z_FILTERED = 1;7933//var Z_HUFFMAN_ONLY = 2;7934//var Z_RLE = 3;7935var Z_FIXED = 4;7936//var Z_DEFAULT_STRATEGY = 0;79377938/* Possible values of the data_type field (though see inflate()) */7939var Z_BINARY = 0;7940var Z_TEXT = 1;7941//var Z_ASCII = 1; // = Z_TEXT7942var Z_UNKNOWN = 2;79437944/*============================================================================*/794579467947function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }79487949// From zutil.h79507951var STORED_BLOCK = 0;7952var STATIC_TREES = 1;7953var DYN_TREES = 2;7954/* The three kinds of block type */79557956var MIN_MATCH = 3;7957var MAX_MATCH = 258;7958/* The minimum and maximum match lengths */79597960// From deflate.h7961/* ===========================================================================7962* Internal compression state.7963*/79647965var LENGTH_CODES = 29;7966/* number of length codes, not counting the special END_BLOCK code */79677968var LITERALS = 256;7969/* number of literal bytes 0..255 */79707971var L_CODES = LITERALS + 1 + LENGTH_CODES;7972/* number of Literal or Length codes, including the END_BLOCK code */79737974var D_CODES = 30;7975/* number of distance codes */79767977var BL_CODES = 19;7978/* number of codes used to transfer the bit lengths */79797980var HEAP_SIZE = 2*L_CODES + 1;7981/* maximum heap size */79827983var MAX_BITS = 15;7984/* All codes must not exceed MAX_BITS bits */79857986var Buf_size = 16;7987/* size of bit buffer in bi_buf */798879897990/* ===========================================================================7991* Constants7992*/79937994var MAX_BL_BITS = 7;7995/* Bit length codes must not exceed MAX_BL_BITS bits */79967997var END_BLOCK = 256;7998/* end of block literal code */79998000var REP_3_6 = 16;8001/* repeat previous bit length 3-6 times (2 bits of repeat count) */80028003var REPZ_3_10 = 17;8004/* repeat a zero length 3-10 times (3 bits of repeat count) */80058006var REPZ_11_138 = 18;8007/* repeat a zero length 11-138 times (7 bits of repeat count) */80088009var extra_lbits = /* extra bits for each length code */8010[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];80118012var extra_dbits = /* extra bits for each distance code */8013[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];80148015var extra_blbits = /* extra bits for each bit length code */8016[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7];80178018var bl_order =8019[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];8020/* The lengths of the bit length codes are sent in order of decreasing8021* probability, to avoid transmitting the lengths for unused bit length codes.8022*/80238024/* ===========================================================================8025* Local data. These are initialized only once.8026*/80278028// We pre-fill arrays with 0 to avoid uninitialized gaps80298030var DIST_CODE_LEN = 512; /* see definition of array dist_code below */80318032// !!!! Use flat array insdead of structure, Freq = i*2, Len = i*2+18033var static_ltree = new Array((L_CODES+2) * 2);8034zero(static_ltree);8035/* The static literal tree. Since the bit lengths are imposed, there is no8036* need for the L_CODES extra codes used during heap construction. However8037* The codes 286 and 287 are needed to build a canonical tree (see _tr_init8038* below).8039*/80408041var static_dtree = new Array(D_CODES * 2);8042zero(static_dtree);8043/* The static distance tree. (Actually a trivial tree since all codes use8044* 5 bits.)8045*/80468047var _dist_code = new Array(DIST_CODE_LEN);8048zero(_dist_code);8049/* Distance codes. The first 256 values correspond to the distances8050* 3 .. 258, the last 256 values correspond to the top 8 bits of8051* the 15 bit distances.8052*/80538054var _length_code = new Array(MAX_MATCH-MIN_MATCH+1);8055zero(_length_code);8056/* length code for each normalized match length (0 == MIN_MATCH) */80578058var base_length = new Array(LENGTH_CODES);8059zero(base_length);8060/* First normalized length for each code (0 = MIN_MATCH) */80618062var base_dist = new Array(D_CODES);8063zero(base_dist);8064/* First normalized distance for each code (0 = distance of 1) */806580668067var StaticTreeDesc = function (static_tree, extra_bits, extra_base, elems, max_length) {80688069this.static_tree = static_tree; /* static tree or NULL */8070this.extra_bits = extra_bits; /* extra bits for each code or NULL */8071this.extra_base = extra_base; /* base index for extra_bits */8072this.elems = elems; /* max number of elements in the tree */8073this.max_length = max_length; /* max bit length for the codes */80748075// show if `static_tree` has data or dummy - needed for monomorphic objects8076this.has_stree = static_tree && static_tree.length;8077};807880798080var static_l_desc;8081var static_d_desc;8082var static_bl_desc;808380848085var TreeDesc = function(dyn_tree, stat_desc) {8086this.dyn_tree = dyn_tree; /* the dynamic tree */8087this.max_code = 0; /* largest code with non zero frequency */8088this.stat_desc = stat_desc; /* the corresponding static tree */8089};8090809180928093function d_code(dist) {8094return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];8095}809680978098/* ===========================================================================8099* Output a short LSB first on the stream.8100* IN assertion: there is enough room in pendingBuf.8101*/8102function put_short (s, w) {8103// put_byte(s, (uch)((w) & 0xff));8104// put_byte(s, (uch)((ush)(w) >> 8));8105s.pending_buf[s.pending++] = (w) & 0xff;8106s.pending_buf[s.pending++] = (w >>> 8) & 0xff;8107}810881098110/* ===========================================================================8111* Send a value on a given number of bits.8112* IN assertion: length <= 16 and value fits in length bits.8113*/8114function send_bits(s, value, length) {8115if (s.bi_valid > (Buf_size - length)) {8116s.bi_buf |= (value << s.bi_valid) & 0xffff;8117put_short(s, s.bi_buf);8118s.bi_buf = value >> (Buf_size - s.bi_valid);8119s.bi_valid += length - Buf_size;8120} else {8121s.bi_buf |= (value << s.bi_valid) & 0xffff;8122s.bi_valid += length;8123}8124}812581268127function send_code(s, c, tree) {8128send_bits(s, tree[c*2]/*.Code*/, tree[c*2 + 1]/*.Len*/);8129}813081318132/* ===========================================================================8133* Reverse the first len bits of a code, using straightforward code (a faster8134* method would use a table)8135* IN assertion: 1 <= len <= 158136*/8137function bi_reverse(code, len) {8138var res = 0;8139do {8140res |= code & 1;8141code >>>= 1;8142res <<= 1;8143} while (--len > 0);8144return res >>> 1;8145}814681478148/* ===========================================================================8149* Flush the bit buffer, keeping at most 7 bits in it.8150*/8151function bi_flush(s) {8152if (s.bi_valid === 16) {8153put_short(s, s.bi_buf);8154s.bi_buf = 0;8155s.bi_valid = 0;81568157} else if (s.bi_valid >= 8) {8158s.pending_buf[s.pending++] = s.bi_buf & 0xff;8159s.bi_buf >>= 8;8160s.bi_valid -= 8;8161}8162}816381648165/* ===========================================================================8166* Compute the optimal bit lengths for a tree and update the total bit length8167* for the current block.8168* IN assertion: the fields freq and dad are set, heap[heap_max] and8169* above are the tree nodes sorted by increasing frequency.8170* OUT assertions: the field len is set to the optimal bit length, the8171* array bl_count contains the frequencies for each bit length.8172* The length opt_len is updated; static_len is also updated if stree is8173* not null.8174*/8175function gen_bitlen(s, desc)8176// deflate_state *s;8177// tree_desc *desc; /* the tree descriptor */8178{8179var tree = desc.dyn_tree;8180var max_code = desc.max_code;8181var stree = desc.stat_desc.static_tree;8182var has_stree = desc.stat_desc.has_stree;8183var extra = desc.stat_desc.extra_bits;8184var base = desc.stat_desc.extra_base;8185var max_length = desc.stat_desc.max_length;8186var h; /* heap index */8187var n, m; /* iterate over the tree elements */8188var bits; /* bit length */8189var xbits; /* extra bits */8190var f; /* frequency */8191var overflow = 0; /* number of elements with bit length too large */81928193for (bits = 0; bits <= MAX_BITS; bits++) {8194s.bl_count[bits] = 0;8195}81968197/* In a first pass, compute the optimal bit lengths (which may8198* overflow in the case of the bit length tree).8199*/8200tree[s.heap[s.heap_max]*2 + 1]/*.Len*/ = 0; /* root of the heap */82018202for (h = s.heap_max+1; h < HEAP_SIZE; h++) {8203n = s.heap[h];8204bits = tree[tree[n*2 +1]/*.Dad*/ * 2 + 1]/*.Len*/ + 1;8205if (bits > max_length) {8206bits = max_length;8207overflow++;8208}8209tree[n*2 + 1]/*.Len*/ = bits;8210/* We overwrite tree[n].Dad which is no longer needed */82118212if (n > max_code) { continue; } /* not a leaf node */82138214s.bl_count[bits]++;8215xbits = 0;8216if (n >= base) {8217xbits = extra[n-base];8218}8219f = tree[n * 2]/*.Freq*/;8220s.opt_len += f * (bits + xbits);8221if (has_stree) {8222s.static_len += f * (stree[n*2 + 1]/*.Len*/ + xbits);8223}8224}8225if (overflow === 0) { return; }82268227// Trace((stderr,"\nbit length overflow\n"));8228/* This happens for example on obj2 and pic of the Calgary corpus */82298230/* Find the first bit length which could increase: */8231do {8232bits = max_length-1;8233while (s.bl_count[bits] === 0) { bits--; }8234s.bl_count[bits]--; /* move one leaf down the tree */8235s.bl_count[bits+1] += 2; /* move one overflow item as its brother */8236s.bl_count[max_length]--;8237/* The brother of the overflow item also moves one step up,8238* but this does not affect bl_count[max_length]8239*/8240overflow -= 2;8241} while (overflow > 0);82428243/* Now recompute all bit lengths, scanning in increasing frequency.8244* h is still equal to HEAP_SIZE. (It is simpler to reconstruct all8245* lengths instead of fixing only the wrong ones. This idea is taken8246* from 'ar' written by Haruhiko Okumura.)8247*/8248for (bits = max_length; bits !== 0; bits--) {8249n = s.bl_count[bits];8250while (n !== 0) {8251m = s.heap[--h];8252if (m > max_code) { continue; }8253if (tree[m*2 + 1]/*.Len*/ !== bits) {8254// Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));8255s.opt_len += (bits - tree[m*2 + 1]/*.Len*/)*tree[m*2]/*.Freq*/;8256tree[m*2 + 1]/*.Len*/ = bits;8257}8258n--;8259}8260}8261}826282638264/* ===========================================================================8265* Generate the codes for a given tree and bit counts (which need not be8266* optimal).8267* IN assertion: the array bl_count contains the bit length statistics for8268* the given tree and the field len is set for all tree elements.8269* OUT assertion: the field code is set for all tree elements of non8270* zero code length.8271*/8272function gen_codes(tree, max_code, bl_count)8273// ct_data *tree; /* the tree to decorate */8274// int max_code; /* largest code with non zero frequency */8275// ushf *bl_count; /* number of codes at each bit length */8276{8277var next_code = new Array(MAX_BITS+1); /* next code value for each bit length */8278var code = 0; /* running code value */8279var bits; /* bit index */8280var n; /* code index */82818282/* The distribution counts are first used to generate the code values8283* without bit reversal.8284*/8285for (bits = 1; bits <= MAX_BITS; bits++) {8286next_code[bits] = code = (code + bl_count[bits-1]) << 1;8287}8288/* Check that the bit counts in bl_count are consistent. The last code8289* must be all ones.8290*/8291//Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,8292// "inconsistent bit counts");8293//Tracev((stderr,"\ngen_codes: max_code %d ", max_code));82948295for (n = 0; n <= max_code; n++) {8296var len = tree[n*2 + 1]/*.Len*/;8297if (len === 0) { continue; }8298/* Now reverse the bits */8299tree[n*2]/*.Code*/ = bi_reverse(next_code[len]++, len);83008301//Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",8302// n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));8303}8304}830583068307/* ===========================================================================8308* Initialize the various 'constant' tables.8309*/8310function tr_static_init() {8311var n; /* iterates over tree elements */8312var bits; /* bit counter */8313var length; /* length value */8314var code; /* code value */8315var dist; /* distance index */8316var bl_count = new Array(MAX_BITS+1);8317/* number of codes at each bit length for an optimal tree */83188319// do check in _tr_init()8320//if (static_init_done) return;83218322/* For some embedded targets, global variables are not initialized: */8323/*#ifdef NO_INIT_GLOBAL_POINTERS8324static_l_desc.static_tree = static_ltree;8325static_l_desc.extra_bits = extra_lbits;8326static_d_desc.static_tree = static_dtree;8327static_d_desc.extra_bits = extra_dbits;8328static_bl_desc.extra_bits = extra_blbits;8329#endif*/83308331/* Initialize the mapping length (0..255) -> length code (0..28) */8332length = 0;8333for (code = 0; code < LENGTH_CODES-1; code++) {8334base_length[code] = length;8335for (n = 0; n < (1<<extra_lbits[code]); n++) {8336_length_code[length++] = code;8337}8338}8339//Assert (length == 256, "tr_static_init: length != 256");8340/* Note that the length 255 (match length 258) can be represented8341* in two different ways: code 284 + 5 bits or code 285, so we8342* overwrite length_code[255] to use the best encoding:8343*/8344_length_code[length-1] = code;83458346/* Initialize the mapping dist (0..32K) -> dist code (0..29) */8347dist = 0;8348for (code = 0 ; code < 16; code++) {8349base_dist[code] = dist;8350for (n = 0; n < (1<<extra_dbits[code]); n++) {8351_dist_code[dist++] = code;8352}8353}8354//Assert (dist == 256, "tr_static_init: dist != 256");8355dist >>= 7; /* from now on, all distances are divided by 128 */8356for ( ; code < D_CODES; code++) {8357base_dist[code] = dist << 7;8358for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {8359_dist_code[256 + dist++] = code;8360}8361}8362//Assert (dist == 256, "tr_static_init: 256+dist != 512");83638364/* Construct the codes of the static literal tree */8365for (bits = 0; bits <= MAX_BITS; bits++) {8366bl_count[bits] = 0;8367}83688369n = 0;8370while (n <= 143) {8371static_ltree[n*2 + 1]/*.Len*/ = 8;8372n++;8373bl_count[8]++;8374}8375while (n <= 255) {8376static_ltree[n*2 + 1]/*.Len*/ = 9;8377n++;8378bl_count[9]++;8379}8380while (n <= 279) {8381static_ltree[n*2 + 1]/*.Len*/ = 7;8382n++;8383bl_count[7]++;8384}8385while (n <= 287) {8386static_ltree[n*2 + 1]/*.Len*/ = 8;8387n++;8388bl_count[8]++;8389}8390/* Codes 286 and 287 do not exist, but we must include them in the8391* tree construction to get a canonical Huffman tree (longest code8392* all ones)8393*/8394gen_codes(static_ltree, L_CODES+1, bl_count);83958396/* The static distance tree is trivial: */8397for (n = 0; n < D_CODES; n++) {8398static_dtree[n*2 + 1]/*.Len*/ = 5;8399static_dtree[n*2]/*.Code*/ = bi_reverse(n, 5);8400}84018402// Now data ready and we can init static trees8403static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS);8404static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS);8405static_bl_desc =new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS);84068407//static_init_done = true;8408}840984108411/* ===========================================================================8412* Initialize a new block.8413*/8414function init_block(s) {8415var n; /* iterates over tree elements */84168417/* Initialize the trees. */8418for (n = 0; n < L_CODES; n++) { s.dyn_ltree[n*2]/*.Freq*/ = 0; }8419for (n = 0; n < D_CODES; n++) { s.dyn_dtree[n*2]/*.Freq*/ = 0; }8420for (n = 0; n < BL_CODES; n++) { s.bl_tree[n*2]/*.Freq*/ = 0; }84218422s.dyn_ltree[END_BLOCK*2]/*.Freq*/ = 1;8423s.opt_len = s.static_len = 0;8424s.last_lit = s.matches = 0;8425}842684278428/* ===========================================================================8429* Flush the bit buffer and align the output on a byte boundary8430*/8431function bi_windup(s)8432{8433if (s.bi_valid > 8) {8434put_short(s, s.bi_buf);8435} else if (s.bi_valid > 0) {8436//put_byte(s, (Byte)s->bi_buf);8437s.pending_buf[s.pending++] = s.bi_buf;8438}8439s.bi_buf = 0;8440s.bi_valid = 0;8441}84428443/* ===========================================================================8444* Copy a stored block, storing first the length and its8445* one's complement if requested.8446*/8447function copy_block(s, buf, len, header)8448//DeflateState *s;8449//charf *buf; /* the input data */8450//unsigned len; /* its length */8451//int header; /* true if block header must be written */8452{8453bi_windup(s); /* align on byte boundary */84548455if (header) {8456put_short(s, len);8457put_short(s, ~len);8458}8459// while (len--) {8460// put_byte(s, *buf++);8461// }8462utils.arraySet(s.pending_buf, s.window, buf, len, s.pending);8463s.pending += len;8464}84658466/* ===========================================================================8467* Compares to subtrees, using the tree depth as tie breaker when8468* the subtrees have equal frequency. This minimizes the worst case length.8469*/8470function smaller(tree, n, m, depth) {8471var _n2 = n*2;8472var _m2 = m*2;8473return (tree[_n2]/*.Freq*/ < tree[_m2]/*.Freq*/ ||8474(tree[_n2]/*.Freq*/ === tree[_m2]/*.Freq*/ && depth[n] <= depth[m]));8475}84768477/* ===========================================================================8478* Restore the heap property by moving down the tree starting at node k,8479* exchanging a node with the smallest of its two sons if necessary, stopping8480* when the heap property is re-established (each father smaller than its8481* two sons).8482*/8483function pqdownheap(s, tree, k)8484// deflate_state *s;8485// ct_data *tree; /* the tree to restore */8486// int k; /* node to move down */8487{8488var v = s.heap[k];8489var j = k << 1; /* left son of k */8490while (j <= s.heap_len) {8491/* Set j to the smallest of the two sons: */8492if (j < s.heap_len &&8493smaller(tree, s.heap[j+1], s.heap[j], s.depth)) {8494j++;8495}8496/* Exit if v is smaller than both sons */8497if (smaller(tree, v, s.heap[j], s.depth)) { break; }84988499/* Exchange v with the smallest son */8500s.heap[k] = s.heap[j];8501k = j;85028503/* And continue down the tree, setting j to the left son of k */8504j <<= 1;8505}8506s.heap[k] = v;8507}850885098510// inlined manually8511// var SMALLEST = 1;85128513/* ===========================================================================8514* Send the block data compressed using the given Huffman trees8515*/8516function compress_block(s, ltree, dtree)8517// deflate_state *s;8518// const ct_data *ltree; /* literal tree */8519// const ct_data *dtree; /* distance tree */8520{8521var dist; /* distance of matched string */8522var lc; /* match length or unmatched char (if dist == 0) */8523var lx = 0; /* running index in l_buf */8524var code; /* the code to send */8525var extra; /* number of extra bits to send */85268527if (s.last_lit !== 0) {8528do {8529dist = (s.pending_buf[s.d_buf + lx*2] << 8) | (s.pending_buf[s.d_buf + lx*2 + 1]);8530lc = s.pending_buf[s.l_buf + lx];8531lx++;85328533if (dist === 0) {8534send_code(s, lc, ltree); /* send a literal byte */8535//Tracecv(isgraph(lc), (stderr," '%c' ", lc));8536} else {8537/* Here, lc is the match length - MIN_MATCH */8538code = _length_code[lc];8539send_code(s, code+LITERALS+1, ltree); /* send the length code */8540extra = extra_lbits[code];8541if (extra !== 0) {8542lc -= base_length[code];8543send_bits(s, lc, extra); /* send the extra length bits */8544}8545dist--; /* dist is now the match distance - 1 */8546code = d_code(dist);8547//Assert (code < D_CODES, "bad d_code");85488549send_code(s, code, dtree); /* send the distance code */8550extra = extra_dbits[code];8551if (extra !== 0) {8552dist -= base_dist[code];8553send_bits(s, dist, extra); /* send the extra distance bits */8554}8555} /* literal or match pair ? */85568557/* Check that the overlay between pending_buf and d_buf+l_buf is ok: */8558//Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,8559// "pendingBuf overflow");85608561} while (lx < s.last_lit);8562}85638564send_code(s, END_BLOCK, ltree);8565}856685678568/* ===========================================================================8569* Construct one Huffman tree and assigns the code bit strings and lengths.8570* Update the total bit length for the current block.8571* IN assertion: the field freq is set for all tree elements.8572* OUT assertions: the fields len and code are set to the optimal bit length8573* and corresponding code. The length opt_len is updated; static_len is8574* also updated if stree is not null. The field max_code is set.8575*/8576function build_tree(s, desc)8577// deflate_state *s;8578// tree_desc *desc; /* the tree descriptor */8579{8580var tree = desc.dyn_tree;8581var stree = desc.stat_desc.static_tree;8582var has_stree = desc.stat_desc.has_stree;8583var elems = desc.stat_desc.elems;8584var n, m; /* iterate over heap elements */8585var max_code = -1; /* largest code with non zero frequency */8586var node; /* new node being created */85878588/* Construct the initial heap, with least frequent element in8589* heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].8590* heap[0] is not used.8591*/8592s.heap_len = 0;8593s.heap_max = HEAP_SIZE;85948595for (n = 0; n < elems; n++) {8596if (tree[n * 2]/*.Freq*/ !== 0) {8597s.heap[++s.heap_len] = max_code = n;8598s.depth[n] = 0;85998600} else {8601tree[n*2 + 1]/*.Len*/ = 0;8602}8603}86048605/* The pkzip format requires that at least one distance code exists,8606* and that at least one bit should be sent even if there is only one8607* possible code. So to avoid special checks later on we force at least8608* two codes of non zero frequency.8609*/8610while (s.heap_len < 2) {8611node = s.heap[++s.heap_len] = (max_code < 2 ? ++max_code : 0);8612tree[node * 2]/*.Freq*/ = 1;8613s.depth[node] = 0;8614s.opt_len--;86158616if (has_stree) {8617s.static_len -= stree[node*2 + 1]/*.Len*/;8618}8619/* node is 0 or 1 so it does not have extra bits */8620}8621desc.max_code = max_code;86228623/* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,8624* establish sub-heaps of increasing lengths:8625*/8626for (n = (s.heap_len >> 1/*int /2*/); n >= 1; n--) { pqdownheap(s, tree, n); }86278628/* Construct the Huffman tree by repeatedly combining the least two8629* frequent nodes.8630*/8631node = elems; /* next internal node of the tree */8632do {8633//pqremove(s, tree, n); /* n = node of least frequency */8634/*** pqremove ***/8635n = s.heap[1/*SMALLEST*/];8636s.heap[1/*SMALLEST*/] = s.heap[s.heap_len--];8637pqdownheap(s, tree, 1/*SMALLEST*/);8638/***/86398640m = s.heap[1/*SMALLEST*/]; /* m = node of next least frequency */86418642s.heap[--s.heap_max] = n; /* keep the nodes sorted by frequency */8643s.heap[--s.heap_max] = m;86448645/* Create a new node father of n and m */8646tree[node * 2]/*.Freq*/ = tree[n * 2]/*.Freq*/ + tree[m * 2]/*.Freq*/;8647s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;8648tree[n*2 + 1]/*.Dad*/ = tree[m*2 + 1]/*.Dad*/ = node;86498650/* and insert the new node in the heap */8651s.heap[1/*SMALLEST*/] = node++;8652pqdownheap(s, tree, 1/*SMALLEST*/);86538654} while (s.heap_len >= 2);86558656s.heap[--s.heap_max] = s.heap[1/*SMALLEST*/];86578658/* At this point, the fields freq and dad are set. We can now8659* generate the bit lengths.8660*/8661gen_bitlen(s, desc);86628663/* The field len is now set, we can generate the bit codes */8664gen_codes(tree, max_code, s.bl_count);8665}866686678668/* ===========================================================================8669* Scan a literal or distance tree to determine the frequencies of the codes8670* in the bit length tree.8671*/8672function scan_tree(s, tree, max_code)8673// deflate_state *s;8674// ct_data *tree; /* the tree to be scanned */8675// int max_code; /* and its largest code of non zero frequency */8676{8677var n; /* iterates over all tree elements */8678var prevlen = -1; /* last emitted length */8679var curlen; /* length of current code */86808681var nextlen = tree[0*2 + 1]/*.Len*/; /* length of next code */86828683var count = 0; /* repeat count of the current code */8684var max_count = 7; /* max repeat count */8685var min_count = 4; /* min repeat count */86868687if (nextlen === 0) {8688max_count = 138;8689min_count = 3;8690}8691tree[(max_code+1)*2 + 1]/*.Len*/ = 0xffff; /* guard */86928693for (n = 0; n <= max_code; n++) {8694curlen = nextlen;8695nextlen = tree[(n+1)*2 + 1]/*.Len*/;86968697if (++count < max_count && curlen === nextlen) {8698continue;86998700} else if (count < min_count) {8701s.bl_tree[curlen * 2]/*.Freq*/ += count;87028703} else if (curlen !== 0) {87048705if (curlen !== prevlen) { s.bl_tree[curlen * 2]/*.Freq*/++; }8706s.bl_tree[REP_3_6*2]/*.Freq*/++;87078708} else if (count <= 10) {8709s.bl_tree[REPZ_3_10*2]/*.Freq*/++;87108711} else {8712s.bl_tree[REPZ_11_138*2]/*.Freq*/++;8713}87148715count = 0;8716prevlen = curlen;87178718if (nextlen === 0) {8719max_count = 138;8720min_count = 3;87218722} else if (curlen === nextlen) {8723max_count = 6;8724min_count = 3;87258726} else {8727max_count = 7;8728min_count = 4;8729}8730}8731}873287338734/* ===========================================================================8735* Send a literal or distance tree in compressed form, using the codes in8736* bl_tree.8737*/8738function send_tree(s, tree, max_code)8739// deflate_state *s;8740// ct_data *tree; /* the tree to be scanned */8741// int max_code; /* and its largest code of non zero frequency */8742{8743var n; /* iterates over all tree elements */8744var prevlen = -1; /* last emitted length */8745var curlen; /* length of current code */87468747var nextlen = tree[0*2 + 1]/*.Len*/; /* length of next code */87488749var count = 0; /* repeat count of the current code */8750var max_count = 7; /* max repeat count */8751var min_count = 4; /* min repeat count */87528753/* tree[max_code+1].Len = -1; */ /* guard already set */8754if (nextlen === 0) {8755max_count = 138;8756min_count = 3;8757}87588759for (n = 0; n <= max_code; n++) {8760curlen = nextlen;8761nextlen = tree[(n+1)*2 + 1]/*.Len*/;87628763if (++count < max_count && curlen === nextlen) {8764continue;87658766} else if (count < min_count) {8767do { send_code(s, curlen, s.bl_tree); } while (--count !== 0);87688769} else if (curlen !== 0) {8770if (curlen !== prevlen) {8771send_code(s, curlen, s.bl_tree);8772count--;8773}8774//Assert(count >= 3 && count <= 6, " 3_6?");8775send_code(s, REP_3_6, s.bl_tree);8776send_bits(s, count-3, 2);87778778} else if (count <= 10) {8779send_code(s, REPZ_3_10, s.bl_tree);8780send_bits(s, count-3, 3);87818782} else {8783send_code(s, REPZ_11_138, s.bl_tree);8784send_bits(s, count-11, 7);8785}87868787count = 0;8788prevlen = curlen;8789if (nextlen === 0) {8790max_count = 138;8791min_count = 3;87928793} else if (curlen === nextlen) {8794max_count = 6;8795min_count = 3;87968797} else {8798max_count = 7;8799min_count = 4;8800}8801}8802}880388048805/* ===========================================================================8806* Construct the Huffman tree for the bit lengths and return the index in8807* bl_order of the last bit length code to send.8808*/8809function build_bl_tree(s) {8810var max_blindex; /* index of last bit length code of non zero freq */88118812/* Determine the bit length frequencies for literal and distance trees */8813scan_tree(s, s.dyn_ltree, s.l_desc.max_code);8814scan_tree(s, s.dyn_dtree, s.d_desc.max_code);88158816/* Build the bit length tree: */8817build_tree(s, s.bl_desc);8818/* opt_len now includes the length of the tree representations, except8819* the lengths of the bit lengths codes and the 5+5+4 bits for the counts.8820*/88218822/* Determine the number of bit length codes to send. The pkzip format8823* requires that at least 4 bit length codes be sent. (appnote.txt says8824* 3 but the actual value used is 4.)8825*/8826for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {8827if (s.bl_tree[bl_order[max_blindex]*2 + 1]/*.Len*/ !== 0) {8828break;8829}8830}8831/* Update opt_len to include the bit length tree and counts */8832s.opt_len += 3*(max_blindex+1) + 5+5+4;8833//Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",8834// s->opt_len, s->static_len));88358836return max_blindex;8837}883888398840/* ===========================================================================8841* Send the header for a block using dynamic Huffman trees: the counts, the8842* lengths of the bit length codes, the literal tree and the distance tree.8843* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.8844*/8845function send_all_trees(s, lcodes, dcodes, blcodes)8846// deflate_state *s;8847// int lcodes, dcodes, blcodes; /* number of codes for each tree */8848{8849var rank; /* index in bl_order */88508851//Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");8852//Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,8853// "too many codes");8854//Tracev((stderr, "\nbl counts: "));8855send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */8856send_bits(s, dcodes-1, 5);8857send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */8858for (rank = 0; rank < blcodes; rank++) {8859//Tracev((stderr, "\nbl code %2d ", bl_order[rank]));8860send_bits(s, s.bl_tree[bl_order[rank]*2 + 1]/*.Len*/, 3);8861}8862//Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));88638864send_tree(s, s.dyn_ltree, lcodes-1); /* literal tree */8865//Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));88668867send_tree(s, s.dyn_dtree, dcodes-1); /* distance tree */8868//Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));8869}887088718872/* ===========================================================================8873* Check if the data type is TEXT or BINARY, using the following algorithm:8874* - TEXT if the two conditions below are satisfied:8875* a) There are no non-portable control characters belonging to the8876* "black list" (0..6, 14..25, 28..31).8877* b) There is at least one printable character belonging to the8878* "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).8879* - BINARY otherwise.8880* - The following partially-portable control characters form a8881* "gray list" that is ignored in this detection algorithm:8882* (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).8883* IN assertion: the fields Freq of dyn_ltree are set.8884*/8885function detect_data_type(s) {8886/* black_mask is the bit mask of black-listed bytes8887* set bits 0..6, 14..25, and 28..318888* 0xf3ffc07f = binary 111100111111111111000000011111118889*/8890var black_mask = 0xf3ffc07f;8891var n;88928893/* Check for non-textual ("black-listed") bytes. */8894for (n = 0; n <= 31; n++, black_mask >>>= 1) {8895if ((black_mask & 1) && (s.dyn_ltree[n*2]/*.Freq*/ !== 0)) {8896return Z_BINARY;8897}8898}88998900/* Check for textual ("white-listed") bytes. */8901if (s.dyn_ltree[9 * 2]/*.Freq*/ !== 0 || s.dyn_ltree[10 * 2]/*.Freq*/ !== 0 ||8902s.dyn_ltree[13 * 2]/*.Freq*/ !== 0) {8903return Z_TEXT;8904}8905for (n = 32; n < LITERALS; n++) {8906if (s.dyn_ltree[n * 2]/*.Freq*/ !== 0) {8907return Z_TEXT;8908}8909}89108911/* There are no "black-listed" or "white-listed" bytes:8912* this stream either is empty or has tolerated ("gray-listed") bytes only.8913*/8914return Z_BINARY;8915}891689178918var static_init_done = false;89198920/* ===========================================================================8921* Initialize the tree data structures for a new zlib stream.8922*/8923function _tr_init(s)8924{89258926if (!static_init_done) {8927tr_static_init();8928static_init_done = true;8929}89308931s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc);8932s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc);8933s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc);89348935s.bi_buf = 0;8936s.bi_valid = 0;89378938/* Initialize the first block of the first file: */8939init_block(s);8940}894189428943/* ===========================================================================8944* Send a stored block8945*/8946function _tr_stored_block(s, buf, stored_len, last)8947//DeflateState *s;8948//charf *buf; /* input block */8949//ulg stored_len; /* length of input block */8950//int last; /* one if this is the last block for a file */8951{8952send_bits(s, (STORED_BLOCK<<1)+(last ? 1 : 0), 3); /* send block type */8953copy_block(s, buf, stored_len, true); /* with header */8954}895589568957/* ===========================================================================8958* Send one empty static block to give enough lookahead for inflate.8959* This takes 10 bits, of which 7 may remain in the bit buffer.8960*/8961function _tr_align(s) {8962send_bits(s, STATIC_TREES<<1, 3);8963send_code(s, END_BLOCK, static_ltree);8964bi_flush(s);8965}896689678968/* ===========================================================================8969* Determine the best encoding for the current block: dynamic trees, static8970* trees or store, and output the encoded block to the zip file.8971*/8972function _tr_flush_block(s, buf, stored_len, last)8973//DeflateState *s;8974//charf *buf; /* input block, or NULL if too old */8975//ulg stored_len; /* length of input block */8976//int last; /* one if this is the last block for a file */8977{8978var opt_lenb, static_lenb; /* opt_len and static_len in bytes */8979var max_blindex = 0; /* index of last bit length code of non zero freq */89808981/* Build the Huffman trees unless a stored block is forced */8982if (s.level > 0) {89838984/* Check if the file is binary or text */8985if (s.strm.data_type === Z_UNKNOWN) {8986s.strm.data_type = detect_data_type(s);8987}89888989/* Construct the literal and distance trees */8990build_tree(s, s.l_desc);8991// Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,8992// s->static_len));89938994build_tree(s, s.d_desc);8995// Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,8996// s->static_len));8997/* At this point, opt_len and static_len are the total bit lengths of8998* the compressed block data, excluding the tree representations.8999*/90009001/* Build the bit length tree for the above two trees, and get the index9002* in bl_order of the last bit length code to send.9003*/9004max_blindex = build_bl_tree(s);90059006/* Determine the best encoding. Compute the block lengths in bytes. */9007opt_lenb = (s.opt_len+3+7) >>> 3;9008static_lenb = (s.static_len+3+7) >>> 3;90099010// Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",9011// opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,9012// s->last_lit));90139014if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }90159016} else {9017// Assert(buf != (char*)0, "lost buf");9018opt_lenb = static_lenb = stored_len + 5; /* force a stored block */9019}90209021if ((stored_len+4 <= opt_lenb) && (buf !== -1)) {9022/* 4: two words for the lengths */90239024/* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.9025* Otherwise we can't have processed more than WSIZE input bytes since9026* the last block flush, because compression would have been9027* successful. If LIT_BUFSIZE <= WSIZE, it is never too late to9028* transform a block into a stored block.9029*/9030_tr_stored_block(s, buf, stored_len, last);90319032} else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) {90339034send_bits(s, (STATIC_TREES<<1) + (last ? 1 : 0), 3);9035compress_block(s, static_ltree, static_dtree);90369037} else {9038send_bits(s, (DYN_TREES<<1) + (last ? 1 : 0), 3);9039send_all_trees(s, s.l_desc.max_code+1, s.d_desc.max_code+1, max_blindex+1);9040compress_block(s, s.dyn_ltree, s.dyn_dtree);9041}9042// Assert (s->compressed_len == s->bits_sent, "bad compressed size");9043/* The above check is made mod 2^32, for files larger than 512 MB9044* and uLong implemented on 32 bits.9045*/9046init_block(s);90479048if (last) {9049bi_windup(s);9050}9051// Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,9052// s->compressed_len-7*last));9053}90549055/* ===========================================================================9056* Save the match info and tally the frequency counts. Return true if9057* the current block must be flushed.9058*/9059function _tr_tally(s, dist, lc)9060// deflate_state *s;9061// unsigned dist; /* distance of matched string */9062// unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */9063{9064//var out_length, in_length, dcode;90659066s.pending_buf[s.d_buf + s.last_lit * 2] = (dist >>> 8) & 0xff;9067s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff;90689069s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff;9070s.last_lit++;90719072if (dist === 0) {9073/* lc is the unmatched char */9074s.dyn_ltree[lc*2]/*.Freq*/++;9075} else {9076s.matches++;9077/* Here, lc is the match length - MIN_MATCH */9078dist--; /* dist = match distance - 1 */9079//Assert((ush)dist < (ush)MAX_DIST(s) &&9080// (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&9081// (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");90829083s.dyn_ltree[(_length_code[lc]+LITERALS+1) * 2]/*.Freq*/++;9084s.dyn_dtree[d_code(dist) * 2]/*.Freq*/++;9085}90869087// (!) This block is disabled in zlib defailts,9088// don't enable it for binary compatibility90899090//#ifdef TRUNCATE_BLOCK9091// /* Try to guess if it is profitable to stop the current block here */9092// if ((s.last_lit & 0x1fff) === 0 && s.level > 2) {9093// /* Compute an upper bound for the compressed length */9094// out_length = s.last_lit*8;9095// in_length = s.strstart - s.block_start;9096//9097// for (dcode = 0; dcode < D_CODES; dcode++) {9098// out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]);9099// }9100// out_length >>>= 3;9101// //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",9102// // s->last_lit, in_length, out_length,9103// // 100L - out_length*100L/in_length));9104// if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) {9105// return true;9106// }9107// }9108//#endif91099110return (s.last_lit === s.lit_bufsize-1);9111/* We avoid equality with lit_bufsize because of wraparound at 64K9112* on 16 bit machines and because stored blocks are restricted to9113* 64K-1 bytes.9114*/9115}91169117exports._tr_init = _tr_init;9118exports._tr_stored_block = _tr_stored_block;9119exports._tr_flush_block = _tr_flush_block;9120exports._tr_tally = _tr_tally;9121exports._tr_align = _tr_align;9122},{"../utils/common":27}],39:[function(_dereq_,module,exports){9123'use strict';912491259126function ZStream() {9127/* next input byte */9128this.input = null; // JS specific, because we have no pointers9129this.next_in = 0;9130/* number of bytes available at input */9131this.avail_in = 0;9132/* total number of input bytes read so far */9133this.total_in = 0;9134/* next output byte should be put there */9135this.output = null; // JS specific, because we have no pointers9136this.next_out = 0;9137/* remaining free space at output */9138this.avail_out = 0;9139/* total number of bytes output so far */9140this.total_out = 0;9141/* last error message, NULL if no error */9142this.msg = ''/*Z_NULL*/;9143/* not visible by applications */9144this.state = null;9145/* best guess about the data type: binary or text */9146this.data_type = 2/*Z_UNKNOWN*/;9147/* adler32 value of the uncompressed data */9148this.adler = 0;9149}91509151module.exports = ZStream;9152},{}]},{},[9])9153(9)9154});91559156