{“ast”:null,“code”:“'use strict';nnvar zlib_deflate = require('./zlib/deflate');nnvar utils = require('./utils/common');nnvar strings = require('./utils/strings');nnvar msg = require('./zlib/messages');nnvar ZStream = require('./zlib/zstream');nnvar toString = Object.prototype.toString;n/* Public constants ==========================================================*/nn/* ===========================================================================*/nnvar Z_NO_FLUSH = 0;nvar Z_FINISH = 4;nvar Z_OK = 0;nvar Z_STREAM_END = 1;nvar Z_SYNC_FLUSH = 2;nvar Z_DEFAULT_COMPRESSION = -1;nvar Z_DEFAULT_STRATEGY = 0;nvar Z_DEFLATED = 8;n/* ===========================================================================*/nn/**n * class Deflaten *n * Generic JS-style wrapper for zlib calls. If you don't needn * streaming behaviour - use more simple functions: [[deflate]],n * [[deflateRaw]] and [[gzip]].n **/nn/* internaln * Deflate.chunks -> Arrayn *n * Chunks of output data, if [[Deflate#onData]] not overridden.n **/nn/**n * Deflate.result -> Uint8Array|Arrayn *n * Compressed result, generated by default [[Deflate#onData]]n * and [[Deflate#onEnd]] handlers. Filled after you push last chunkn * (call [[Deflate#push]] with `Z_FINISH` / `true` param) or if youn * push a chunk with explicit flush (call [[Deflate#push]] withn * `Z_SYNC_FLUSH` param).n **/nn/**n * Deflate.err -> Numbern *n * Error code after deflate finished. 0 (Z_OK) on success.n * You will not need it in real life, because deflate errorsn * are possible only on wrong options or bad `onData` / `onEnd`n * custom handlers.n **/nn/**n * Deflate.msg -> Stringn *n * Error message, if [[Deflate.err]] != 0n **/nn/**n * new Deflate(options)n * - options (Object
): zlib deflate options.n *n * Creates new deflator instance with specified params. Throws exceptionn * on bad params. Supported options:n *n * - `level`n * - `windowBits`n * - `memLevel`n * - `strategy`n * - `dictionary`n *n * [zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)n * for more information on these.n *n * Additional options, for internal needs:n *n * - `chunkSize` - size of generated data chunks (16K by default)n * - `raw` (Boolean) - do raw deflaten * - `gzip` (Boolean) - create gzip wrappern * - `to` (String) - if equal to 'string', then result will be "binary string"n * (each char code [0..255])n * - `header` (Object
) - custom header for gzipn * - `text` (Boolean) - true if compressed data believed to be textn * - `time` (Number
) - modification time, unix timestampn * - `os` (Number
) - operation system coden * - `extra` (Array) - array of bytes with extra data (max 65536)n * - `name` (String) - file name (binary string)n * - `comment` (String) - comment (binary string)n * - `hcrc` (Boolean) - true if header crc should be addedn *n * ##### Example:n *n * “`javascriptn * var pako = require('pako')n * , chunk1 = Uint8Array()n * , chunk2 = Uint8Array();n *n * var deflate = new pako.Deflate({ level: 3});n *n * deflate.push(chunk1, false);n * deflate.push(chunk2, true); // true -> last chunkn *n * if (deflate.err) { throw new Error(deflate.err); }n *n * console.log(deflate.result);n * “`n **/nnfunction Deflate(options) {n if (!(this instanceof Deflate)) return new Deflate(options);n this.options = utils.assign({n level: Z_DEFAULT_COMPRESSION,n method: Z_DEFLATED,n chunkSize: 16384,n windowBits: 15,n memLevel: 8,n strategy: Z_DEFAULT_STRATEGY,n to: ''n }, options || {});n var opt = this.options;nn if (opt.raw && opt.windowBits > 0) {n opt.windowBits = -opt.windowBits;n } else if (opt.gzip && opt.windowBits > 0 && opt.windowBits < 16) {n opt.windowBits += 16;n }nn this.err = 0; // error code, if happens (0 = Z_OK)nn this.msg = ''; // error messagenn this.ended = false; // used to avoid multiple onEnd() callsnn this.chunks = []; // chunks of compressed datann this.strm = new ZStream();n this.strm.avail_out = 0;n var status = zlib_deflate.deflateInit2(this.strm, opt.level, opt.method, opt.windowBits, opt.memLevel, opt.strategy);nn if (status !== Z_OK) {n throw new Error(msg);n }nn if (opt.header) {n zlib_deflate.deflateSetHeader(this.strm, opt.header);n }nn if (opt.dictionary) {n var dict; // Convert data if needednn if (typeof opt.dictionary === 'string') {n // If we need to compress text, change encoding to utf8.n dict = strings.string2buf(opt.dictionary);n } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {n dict = new Uint8Array(opt.dictionary);n } else {n dict = opt.dictionary;n }nn status = zlib_deflate.deflateSetDictionary(this.strm, dict);nn if (status !== Z_OK) {n throw new Error(msg);n }nn this._dict_set = true;n }n}n/**n * Deflate#push(data[, mode]) -> Booleann * - data (Uint8Array|Array|ArrayBuffer|String): input data. Strings will ben * converted to utf8 byte sequence.n * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.n * See constants. Skipped or `false` means Z_NO_FLUSH, `true` means Z_FINISH.n *n * Sends input data to deflate pipe, generating [[Deflate#onData]] calls withn * new compressed chunks. Returns `true` on success. The last data block must haven * mode Z_FINISH (or `true`). That will flush internal pending buffers and calln * [[Deflate#onEnd]]. For interim explicit flushes (without ending the stream) youn * can use mode Z_SYNC_FLUSH, keeping the compression context.n *n * On fail call [[Deflate#onEnd]] with error code and return false.n *n * We strongly recommend to use `Uint8Array` on input for best speed (outputn * array format is detected automatically). Also, don't skip last param and alwaysn * use the same type in your code (boolean or number). That will improve JS speed.n *n * For regular `Array`-s make sure all elements are [0..255].n *n * ##### Examplen *n * “`javascriptn * push(chunk, false); // push one of data chunksn * …n * push(chunk, true); // push last chunkn * “`n **/nnnDeflate.prototype.push = function (data, mode) {n var strm = this.strm;n var chunkSize = this.options.chunkSize;nn var status, _mode;nn if (this.ended) {n return false;n }nn _mode = mode === ~~mode ? mode : mode === true ? Z_FINISH : Z_NO_FLUSH; // Convert data if needednn if (typeof data === 'string') {n // If we need to compress text, change encoding to utf8.n strm.input = strings.string2buf(data);n } else if (toString.call(data) === '[object ArrayBuffer]') {n strm.input = new Uint8Array(data);n } else {n strm.input = data;n }nn strm.next_in = 0;n strm.avail_in = strm.input.length;nn do {n if (strm.avail_out === 0) {n strm.output = new utils.Buf8(chunkSize);n strm.next_out = 0;n strm.avail_out = chunkSize;n }nn status = zlib_deflate.deflate(strm, _mode);n /* no bad return value */nn if (status !== Z_STREAM_END && status !== Z_OK) {n this.onEnd(status);n this.ended = true;n return false;n }nn if (strm.avail_out === 0 || strm.avail_in === 0 && (_mode === Z_FINISH || _mode === Z_SYNC_FLUSH)) {n if (this.options.to === 'string') {n this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out)));n } else {n this.onData(utils.shrinkBuf(strm.output, strm.next_out));n }n }n } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END); // Finalize on the last chunk.nnn if (_mode === Z_FINISH) {n status = zlib_deflate.deflateEnd(this.strm);n this.onEnd(status);n this.ended = true;n return status === Z_OK;n } // callback interim results if Z_SYNC_FLUSH.nnn if (_mode === Z_SYNC_FLUSH) {n this.onEnd(Z_OK);n strm.avail_out = 0;n return true;n }nn return true;n};n/**n * Deflate#onData(chunk) -> Voidn * - chunk (Uint8Array|Array|String): output data. Type
of array dependsn * on js engine support. When string output requested, each chunkn * will be string.n *n * By default, stores data blocks in `chunks[]` property and gluen * those in `onEnd`. Override this handler, if you need another behaviour.n **/nnnDeflate.prototype.onData = function (chunk) {n this.chunks.push(chunk);n};n/**n * Deflate#onEnd(status) -> Voidn * - status (Number
): deflate status. 0 (Z_OK) on success,n * other if not.n *n * Called once after you tell deflate that the input stream isn * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)n * or if an error happened. By default - join collected chunks,n * free memory and fill `results` / `err` properties.n **/nnnDeflate.prototype.onEnd = function (status) {n // On success - joinn if (status === Z_OK) {n if (this.options.to === 'string') {n this.result = this.chunks.join('');n } else {n this.result = utils.flattenChunks(this.chunks);n }n }nn this.chunks = [];n this.err = status;n this.msg = this.strm.msg;n};n/**n * deflate(data[, options]) -> Uint8Array|Array|Stringn * - data (Uint8Array|Array|String): input data to compress.n * - options (Object
): zlib deflate options.n *n * Compress `data` with deflate algorithm and `options`.n *n * Supported options are:n *n * - leveln * - windowBitsn * - memLeveln * - strategyn * - dictionaryn *n * [zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)n * for more information on these.n *n * Sugar (options):n *n * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specifyn * negative windowBits implicitly.n * - `to` (String) - if equal to 'string', then result will be "binary string"n * (each char code [0..255])n *n * ##### Example:n *n * “`javascriptn * var pako = require('pako')n * , data = Uint8Array();n *n * console.log(pako.deflate(data));n * “`n **/nnnfunction deflate(input, options) {n var deflator = new Deflate(options);n deflator.push(input, true); // That will never happens, if you don't cheat with options :)nn if (deflator.err) {n throw deflator.msg || msg;n }nn return deflator.result;n}n/**n * deflateRaw(data[, options]) -> Uint8Array|Array|Stringn * - data (Uint8Array|Array|String): input data to compress.n * - options (Object
): zlib deflate options.n *n * The same as [[deflate]], but creates raw data, without wrappern * (header and adler32 crc).n **/nnnfunction deflateRaw(input, options) {n options = options || {};n options.raw = true;n return deflate(input, options);n}n/**n * gzip(data[, options]) -> Uint8Array|Array|Stringn * - data (Uint8Array|Array|String): input data to compress.n * - options (Object
): zlib deflate options.n *n * The same as [[deflate]], but create gzip wrapper instead ofn * deflate one.n **/nnnfunction gzip(input, options) {n options = options || {};n options.gzip = true;n return deflate(input, options);n}nnexports.Deflate = Deflate;nexports.deflate = deflate;nexports.deflateRaw = deflateRaw;nexports.gzip = gzip;”,“map”:null,“metadata”:{},“sourceType”:“module”}