mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-10 22:00:58 +01:00
Browser files rebuild
This commit is contained in:
parent
c6f03f4522
commit
fae8ad56d0
6 changed files with 841 additions and 832 deletions
125
dist/pako.js
vendored
125
dist/pako.js
vendored
|
@ -1,28 +1,14 @@
|
||||||
/* pako 0.2.5 nodeca/pako */!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.pako=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){
|
/* pako 0.2.6 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||||||
// Top level file is just a mixin of submodules & constants
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var assign = _dereq_('./lib/utils/common').assign;
|
|
||||||
|
|
||||||
var deflate = _dereq_('./lib/deflate');
|
|
||||||
var inflate = _dereq_('./lib/inflate');
|
|
||||||
var constants = _dereq_('./lib/zlib/constants');
|
|
||||||
|
|
||||||
var pako = {};
|
|
||||||
|
|
||||||
assign(pako, deflate, inflate, constants);
|
|
||||||
|
|
||||||
module.exports = pako;
|
|
||||||
},{"./lib/deflate":2,"./lib/inflate":3,"./lib/utils/common":4,"./lib/zlib/constants":7}],2:[function(_dereq_,module,exports){
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var zlib_deflate = _dereq_('./zlib/deflate.js');
|
var zlib_deflate = require('./zlib/deflate.js');
|
||||||
var utils = _dereq_('./utils/common');
|
var utils = require('./utils/common');
|
||||||
var strings = _dereq_('./utils/strings');
|
var strings = require('./utils/strings');
|
||||||
var msg = _dereq_('./zlib/messages');
|
var msg = require('./zlib/messages');
|
||||||
var zstream = _dereq_('./zlib/zstream');
|
var zstream = require('./zlib/zstream');
|
||||||
|
|
||||||
|
var toString = Object.prototype.toString;
|
||||||
|
|
||||||
/* Public constants ==========================================================*/
|
/* Public constants ==========================================================*/
|
||||||
/* ===========================================================================*/
|
/* ===========================================================================*/
|
||||||
|
@ -178,8 +164,8 @@ var Deflate = function(options) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deflate#push(data[, mode]) -> Boolean
|
* Deflate#push(data[, mode]) -> Boolean
|
||||||
* - data (Uint8Array|Array|String): input data. Strings will be converted to
|
* - data (Uint8Array|Array|ArrayBuffer|String): input data. Strings will be
|
||||||
* utf8 byte sequence.
|
* converted to utf8 byte sequence.
|
||||||
* - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
|
* - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
|
||||||
* See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.
|
* See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.
|
||||||
*
|
*
|
||||||
|
@ -217,6 +203,8 @@ Deflate.prototype.push = function(data, mode) {
|
||||||
if (typeof data === 'string') {
|
if (typeof data === 'string') {
|
||||||
// If we need to compress text, change encoding to utf8.
|
// If we need to compress text, change encoding to utf8.
|
||||||
strm.input = strings.string2buf(data);
|
strm.input = strings.string2buf(data);
|
||||||
|
} else if (toString.call(data) === '[object ArrayBuffer]') {
|
||||||
|
strm.input = new Uint8Array(data);
|
||||||
} else {
|
} else {
|
||||||
strm.input = data;
|
strm.input = data;
|
||||||
}
|
}
|
||||||
|
@ -375,18 +363,19 @@ exports.Deflate = Deflate;
|
||||||
exports.deflate = deflate;
|
exports.deflate = deflate;
|
||||||
exports.deflateRaw = deflateRaw;
|
exports.deflateRaw = deflateRaw;
|
||||||
exports.gzip = gzip;
|
exports.gzip = gzip;
|
||||||
},{"./utils/common":4,"./utils/strings":5,"./zlib/deflate.js":9,"./zlib/messages":14,"./zlib/zstream":16}],3:[function(_dereq_,module,exports){
|
},{"./utils/common":3,"./utils/strings":4,"./zlib/deflate.js":8,"./zlib/messages":13,"./zlib/zstream":15}],2:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var zlib_inflate = _dereq_('./zlib/inflate.js');
|
var zlib_inflate = require('./zlib/inflate.js');
|
||||||
var utils = _dereq_('./utils/common');
|
var utils = require('./utils/common');
|
||||||
var strings = _dereq_('./utils/strings');
|
var strings = require('./utils/strings');
|
||||||
var c = _dereq_('./zlib/constants');
|
var c = require('./zlib/constants');
|
||||||
var msg = _dereq_('./zlib/messages');
|
var msg = require('./zlib/messages');
|
||||||
var zstream = _dereq_('./zlib/zstream');
|
var zstream = require('./zlib/zstream');
|
||||||
var gzheader = _dereq_('./zlib/gzheader');
|
var gzheader = require('./zlib/gzheader');
|
||||||
|
|
||||||
|
var toString = Object.prototype.toString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class Inflate
|
* class Inflate
|
||||||
|
@ -521,7 +510,7 @@ var Inflate = function(options) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inflate#push(data[, mode]) -> Boolean
|
* Inflate#push(data[, mode]) -> Boolean
|
||||||
* - data (Uint8Array|Array|String): input data
|
* - data (Uint8Array|Array|ArrayBuffer|String): input data
|
||||||
* - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
|
* - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
|
||||||
* See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.
|
* See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.
|
||||||
*
|
*
|
||||||
|
@ -559,6 +548,8 @@ Inflate.prototype.push = function(data, mode) {
|
||||||
if (typeof data === 'string') {
|
if (typeof data === 'string') {
|
||||||
// Only binary strings can be decompressed on practice
|
// Only binary strings can be decompressed on practice
|
||||||
strm.input = strings.binstring2buf(data);
|
strm.input = strings.binstring2buf(data);
|
||||||
|
} else if (toString.call(data) === '[object ArrayBuffer]') {
|
||||||
|
strm.input = new Uint8Array(data);
|
||||||
} else {
|
} else {
|
||||||
strm.input = data;
|
strm.input = data;
|
||||||
}
|
}
|
||||||
|
@ -741,7 +732,7 @@ exports.inflate = inflate;
|
||||||
exports.inflateRaw = inflateRaw;
|
exports.inflateRaw = inflateRaw;
|
||||||
exports.ungzip = inflate;
|
exports.ungzip = inflate;
|
||||||
|
|
||||||
},{"./utils/common":4,"./utils/strings":5,"./zlib/constants":7,"./zlib/gzheader":10,"./zlib/inflate.js":12,"./zlib/messages":14,"./zlib/zstream":16}],4:[function(_dereq_,module,exports){
|
},{"./utils/common":3,"./utils/strings":4,"./zlib/constants":6,"./zlib/gzheader":9,"./zlib/inflate.js":11,"./zlib/messages":13,"./zlib/zstream":15}],3:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
@ -844,12 +835,12 @@ exports.setTyped = function (on) {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.setTyped(TYPED_OK);
|
exports.setTyped(TYPED_OK);
|
||||||
},{}],5:[function(_dereq_,module,exports){
|
},{}],4:[function(require,module,exports){
|
||||||
// String encode/decode helpers
|
// String encode/decode helpers
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var utils = _dereq_('./common');
|
var utils = require('./common');
|
||||||
|
|
||||||
|
|
||||||
// Quick check if we can use fast array to bin string conversion
|
// Quick check if we can use fast array to bin string conversion
|
||||||
|
@ -1031,7 +1022,7 @@ exports.utf8border = function(buf, max) {
|
||||||
return (pos + _utf8len[buf[pos]] > max) ? pos : max;
|
return (pos + _utf8len[buf[pos]] > max) ? pos : max;
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"./common":4}],6:[function(_dereq_,module,exports){
|
},{"./common":3}],5:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Note: adler32 takes 12% for level 0 and 2% for level 6.
|
// Note: adler32 takes 12% for level 0 and 2% for level 6.
|
||||||
|
@ -1064,7 +1055,7 @@ function adler32(adler, buf, len, pos) {
|
||||||
|
|
||||||
|
|
||||||
module.exports = adler32;
|
module.exports = adler32;
|
||||||
},{}],7:[function(_dereq_,module,exports){
|
},{}],6:[function(require,module,exports){
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
/* Allowed flush values; see deflate() and inflate() below for details */
|
/* Allowed flush values; see deflate() and inflate() below for details */
|
||||||
|
@ -1112,7 +1103,7 @@ module.exports = {
|
||||||
Z_DEFLATED: 8
|
Z_DEFLATED: 8
|
||||||
//Z_NULL: null // Use -1 or null inline, depending on var type
|
//Z_NULL: null // Use -1 or null inline, depending on var type
|
||||||
};
|
};
|
||||||
},{}],8:[function(_dereq_,module,exports){
|
},{}],7:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Note: we can't get significant speed boost here.
|
// Note: we can't get significant speed boost here.
|
||||||
|
@ -1154,14 +1145,14 @@ function crc32(crc, buf, len, pos) {
|
||||||
|
|
||||||
|
|
||||||
module.exports = crc32;
|
module.exports = crc32;
|
||||||
},{}],9:[function(_dereq_,module,exports){
|
},{}],8:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var utils = _dereq_('../utils/common');
|
var utils = require('../utils/common');
|
||||||
var trees = _dereq_('./trees');
|
var trees = require('./trees');
|
||||||
var adler32 = _dereq_('./adler32');
|
var adler32 = require('./adler32');
|
||||||
var crc32 = _dereq_('./crc32');
|
var crc32 = require('./crc32');
|
||||||
var msg = _dereq_('./messages');
|
var msg = require('./messages');
|
||||||
|
|
||||||
/* Public constants ==========================================================*/
|
/* Public constants ==========================================================*/
|
||||||
/* ===========================================================================*/
|
/* ===========================================================================*/
|
||||||
|
@ -2920,7 +2911,7 @@ exports.deflatePending = deflatePending;
|
||||||
exports.deflatePrime = deflatePrime;
|
exports.deflatePrime = deflatePrime;
|
||||||
exports.deflateTune = deflateTune;
|
exports.deflateTune = deflateTune;
|
||||||
*/
|
*/
|
||||||
},{"../utils/common":4,"./adler32":6,"./crc32":8,"./messages":14,"./trees":15}],10:[function(_dereq_,module,exports){
|
},{"../utils/common":3,"./adler32":5,"./crc32":7,"./messages":13,"./trees":14}],9:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
@ -2961,7 +2952,7 @@ function GZheader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = GZheader;
|
module.exports = GZheader;
|
||||||
},{}],11:[function(_dereq_,module,exports){
|
},{}],10:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// See state defs from inflate.js
|
// See state defs from inflate.js
|
||||||
|
@ -3288,15 +3279,15 @@ module.exports = function inflate_fast(strm, start) {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
},{}],12:[function(_dereq_,module,exports){
|
},{}],11:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var utils = _dereq_('../utils/common');
|
var utils = require('../utils/common');
|
||||||
var adler32 = _dereq_('./adler32');
|
var adler32 = require('./adler32');
|
||||||
var crc32 = _dereq_('./crc32');
|
var crc32 = require('./crc32');
|
||||||
var inflate_fast = _dereq_('./inffast');
|
var inflate_fast = require('./inffast');
|
||||||
var inflate_table = _dereq_('./inftrees');
|
var inflate_table = require('./inftrees');
|
||||||
|
|
||||||
var CODES = 0;
|
var CODES = 0;
|
||||||
var LENS = 1;
|
var LENS = 1;
|
||||||
|
@ -4792,11 +4783,11 @@ exports.inflateSync = inflateSync;
|
||||||
exports.inflateSyncPoint = inflateSyncPoint;
|
exports.inflateSyncPoint = inflateSyncPoint;
|
||||||
exports.inflateUndermine = inflateUndermine;
|
exports.inflateUndermine = inflateUndermine;
|
||||||
*/
|
*/
|
||||||
},{"../utils/common":4,"./adler32":6,"./crc32":8,"./inffast":11,"./inftrees":13}],13:[function(_dereq_,module,exports){
|
},{"../utils/common":3,"./adler32":5,"./crc32":7,"./inffast":10,"./inftrees":12}],12:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var utils = _dereq_('../utils/common');
|
var utils = require('../utils/common');
|
||||||
|
|
||||||
var MAXBITS = 15;
|
var MAXBITS = 15;
|
||||||
var ENOUGH_LENS = 852;
|
var ENOUGH_LENS = 852;
|
||||||
|
@ -5119,7 +5110,7 @@ module.exports = function inflate_table(type, lens, lens_index, codes, table, ta
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"../utils/common":4}],14:[function(_dereq_,module,exports){
|
},{"../utils/common":3}],13:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -5133,11 +5124,11 @@ module.exports = {
|
||||||
'-5': 'buffer error', /* Z_BUF_ERROR (-5) */
|
'-5': 'buffer error', /* Z_BUF_ERROR (-5) */
|
||||||
'-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */
|
'-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */
|
||||||
};
|
};
|
||||||
},{}],15:[function(_dereq_,module,exports){
|
},{}],14:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var utils = _dereq_('../utils/common');
|
var utils = require('../utils/common');
|
||||||
|
|
||||||
/* Public constants ==========================================================*/
|
/* Public constants ==========================================================*/
|
||||||
/* ===========================================================================*/
|
/* ===========================================================================*/
|
||||||
|
@ -6333,7 +6324,7 @@ exports._tr_stored_block = _tr_stored_block;
|
||||||
exports._tr_flush_block = _tr_flush_block;
|
exports._tr_flush_block = _tr_flush_block;
|
||||||
exports._tr_tally = _tr_tally;
|
exports._tr_tally = _tr_tally;
|
||||||
exports._tr_align = _tr_align;
|
exports._tr_align = _tr_align;
|
||||||
},{"../utils/common":4}],16:[function(_dereq_,module,exports){
|
},{"../utils/common":3}],15:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
@ -6363,6 +6354,20 @@ function ZStream() {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ZStream;
|
module.exports = ZStream;
|
||||||
},{}]},{},[1])
|
},{}],"/":[function(require,module,exports){
|
||||||
(1)
|
// Top level file is just a mixin of submodules & constants
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var assign = require('./lib/utils/common').assign;
|
||||||
|
|
||||||
|
var deflate = require('./lib/deflate');
|
||||||
|
var inflate = require('./lib/inflate');
|
||||||
|
var constants = require('./lib/zlib/constants');
|
||||||
|
|
||||||
|
var pako = {};
|
||||||
|
|
||||||
|
assign(pako, deflate, inflate, constants);
|
||||||
|
|
||||||
|
module.exports = pako;
|
||||||
|
},{"./lib/deflate":1,"./lib/inflate":2,"./lib/utils/common":3,"./lib/zlib/constants":6}]},{},[])("/")
|
||||||
});
|
});
|
6
dist/pako.min.js
vendored
6
dist/pako.min.js
vendored
File diff suppressed because one or more lines are too long
760
dist/pako_deflate.js
vendored
760
dist/pako_deflate.js
vendored
|
@ -1,366 +1,4 @@
|
||||||
/* pako 0.2.5 nodeca/pako */!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.pako=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){
|
/* pako 0.2.6 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||||||
'use strict';
|
|
||||||
|
|
||||||
|
|
||||||
var zlib_deflate = _dereq_('./zlib/deflate.js');
|
|
||||||
var utils = _dereq_('./utils/common');
|
|
||||||
var strings = _dereq_('./utils/strings');
|
|
||||||
var msg = _dereq_('./zlib/messages');
|
|
||||||
var zstream = _dereq_('./zlib/zstream');
|
|
||||||
|
|
||||||
|
|
||||||
/* Public constants ==========================================================*/
|
|
||||||
/* ===========================================================================*/
|
|
||||||
|
|
||||||
var Z_NO_FLUSH = 0;
|
|
||||||
var Z_FINISH = 4;
|
|
||||||
|
|
||||||
var Z_OK = 0;
|
|
||||||
var Z_STREAM_END = 1;
|
|
||||||
|
|
||||||
var Z_DEFAULT_COMPRESSION = -1;
|
|
||||||
|
|
||||||
var Z_DEFAULT_STRATEGY = 0;
|
|
||||||
|
|
||||||
var Z_DEFLATED = 8;
|
|
||||||
|
|
||||||
/* ===========================================================================*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* class Deflate
|
|
||||||
*
|
|
||||||
* Generic JS-style wrapper for zlib calls. If you don't need
|
|
||||||
* streaming behaviour - use more simple functions: [[deflate]],
|
|
||||||
* [[deflateRaw]] and [[gzip]].
|
|
||||||
**/
|
|
||||||
|
|
||||||
/* internal
|
|
||||||
* Deflate.chunks -> Array
|
|
||||||
*
|
|
||||||
* Chunks of output data, if [[Deflate#onData]] not overriden.
|
|
||||||
**/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deflate.result -> Uint8Array|Array
|
|
||||||
*
|
|
||||||
* Compressed result, generated by default [[Deflate#onData]]
|
|
||||||
* and [[Deflate#onEnd]] handlers. Filled after you push last chunk
|
|
||||||
* (call [[Deflate#push]] with `Z_FINISH` / `true` param).
|
|
||||||
**/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deflate.err -> Number
|
|
||||||
*
|
|
||||||
* Error code after deflate finished. 0 (Z_OK) on success.
|
|
||||||
* You will not need it in real life, because deflate errors
|
|
||||||
* are possible only on wrong options or bad `onData` / `onEnd`
|
|
||||||
* custom handlers.
|
|
||||||
**/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deflate.msg -> String
|
|
||||||
*
|
|
||||||
* Error message, if [[Deflate.err]] != 0
|
|
||||||
**/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* new Deflate(options)
|
|
||||||
* - options (Object): zlib deflate options.
|
|
||||||
*
|
|
||||||
* Creates new deflator instance with specified params. Throws exception
|
|
||||||
* on bad params. Supported options:
|
|
||||||
*
|
|
||||||
* - `level`
|
|
||||||
* - `windowBits`
|
|
||||||
* - `memLevel`
|
|
||||||
* - `strategy`
|
|
||||||
*
|
|
||||||
* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
|
|
||||||
* for more information on these.
|
|
||||||
*
|
|
||||||
* Additional options, for internal needs:
|
|
||||||
*
|
|
||||||
* - `chunkSize` - size of generated data chunks (16K by default)
|
|
||||||
* - `raw` (Boolean) - do raw deflate
|
|
||||||
* - `gzip` (Boolean) - create gzip wrapper
|
|
||||||
* - `to` (String) - if equal to 'string', then result will be "binary string"
|
|
||||||
* (each char code [0..255])
|
|
||||||
* - `header` (Object) - custom header for gzip
|
|
||||||
* - `text` (Boolean) - true if compressed data believed to be text
|
|
||||||
* - `time` (Number) - modification time, unix timestamp
|
|
||||||
* - `os` (Number) - operation system code
|
|
||||||
* - `extra` (Array) - array of bytes with extra data (max 65536)
|
|
||||||
* - `name` (String) - file name (binary string)
|
|
||||||
* - `comment` (String) - comment (binary string)
|
|
||||||
* - `hcrc` (Boolean) - true if header crc should be added
|
|
||||||
*
|
|
||||||
* ##### Example:
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* var pako = require('pako')
|
|
||||||
* , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
|
|
||||||
* , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
|
|
||||||
*
|
|
||||||
* var deflate = new pako.Deflate({ level: 3});
|
|
||||||
*
|
|
||||||
* deflate.push(chunk1, false);
|
|
||||||
* deflate.push(chunk2, true); // true -> last chunk
|
|
||||||
*
|
|
||||||
* if (deflate.err) { throw new Error(deflate.err); }
|
|
||||||
*
|
|
||||||
* console.log(deflate.result);
|
|
||||||
* ```
|
|
||||||
**/
|
|
||||||
var Deflate = function(options) {
|
|
||||||
|
|
||||||
this.options = utils.assign({
|
|
||||||
level: Z_DEFAULT_COMPRESSION,
|
|
||||||
method: Z_DEFLATED,
|
|
||||||
chunkSize: 16384,
|
|
||||||
windowBits: 15,
|
|
||||||
memLevel: 8,
|
|
||||||
strategy: Z_DEFAULT_STRATEGY,
|
|
||||||
to: ''
|
|
||||||
}, options || {});
|
|
||||||
|
|
||||||
var opt = this.options;
|
|
||||||
|
|
||||||
if (opt.raw && (opt.windowBits > 0)) {
|
|
||||||
opt.windowBits = -opt.windowBits;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (opt.gzip && (opt.windowBits > 0) && (opt.windowBits < 16)) {
|
|
||||||
opt.windowBits += 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.err = 0; // error code, if happens (0 = Z_OK)
|
|
||||||
this.msg = ''; // error message
|
|
||||||
this.ended = false; // used to avoid multiple onEnd() calls
|
|
||||||
this.chunks = []; // chunks of compressed data
|
|
||||||
|
|
||||||
this.strm = new zstream();
|
|
||||||
this.strm.avail_out = 0;
|
|
||||||
|
|
||||||
var status = zlib_deflate.deflateInit2(
|
|
||||||
this.strm,
|
|
||||||
opt.level,
|
|
||||||
opt.method,
|
|
||||||
opt.windowBits,
|
|
||||||
opt.memLevel,
|
|
||||||
opt.strategy
|
|
||||||
);
|
|
||||||
|
|
||||||
if (status !== Z_OK) {
|
|
||||||
throw new Error(msg[status]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opt.header) {
|
|
||||||
zlib_deflate.deflateSetHeader(this.strm, opt.header);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deflate#push(data[, mode]) -> Boolean
|
|
||||||
* - data (Uint8Array|Array|String): input data. Strings will be converted to
|
|
||||||
* utf8 byte sequence.
|
|
||||||
* - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
|
|
||||||
* See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.
|
|
||||||
*
|
|
||||||
* Sends input data to deflate pipe, generating [[Deflate#onData]] calls with
|
|
||||||
* new compressed chunks. Returns `true` on success. The last data block must have
|
|
||||||
* mode Z_FINISH (or `true`). That flush internal pending buffers and call
|
|
||||||
* [[Deflate#onEnd]].
|
|
||||||
*
|
|
||||||
* On fail call [[Deflate#onEnd]] with error code and return false.
|
|
||||||
*
|
|
||||||
* We strongly recommend to use `Uint8Array` on input for best speed (output
|
|
||||||
* array format is detected automatically). Also, don't skip last param and always
|
|
||||||
* use the same type in your code (boolean or number). That will improve JS speed.
|
|
||||||
*
|
|
||||||
* For regular `Array`-s make sure all elements are [0..255].
|
|
||||||
*
|
|
||||||
* ##### Example
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* push(chunk, false); // push one of data chunks
|
|
||||||
* ...
|
|
||||||
* push(chunk, true); // push last chunk
|
|
||||||
* ```
|
|
||||||
**/
|
|
||||||
Deflate.prototype.push = function(data, mode) {
|
|
||||||
var strm = this.strm;
|
|
||||||
var chunkSize = this.options.chunkSize;
|
|
||||||
var status, _mode;
|
|
||||||
|
|
||||||
if (this.ended) { return false; }
|
|
||||||
|
|
||||||
_mode = (mode === ~~mode) ? mode : ((mode === true) ? Z_FINISH : Z_NO_FLUSH);
|
|
||||||
|
|
||||||
// Convert data if needed
|
|
||||||
if (typeof data === 'string') {
|
|
||||||
// If we need to compress text, change encoding to utf8.
|
|
||||||
strm.input = strings.string2buf(data);
|
|
||||||
} else {
|
|
||||||
strm.input = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
strm.next_in = 0;
|
|
||||||
strm.avail_in = strm.input.length;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (strm.avail_out === 0) {
|
|
||||||
strm.output = new utils.Buf8(chunkSize);
|
|
||||||
strm.next_out = 0;
|
|
||||||
strm.avail_out = chunkSize;
|
|
||||||
}
|
|
||||||
status = zlib_deflate.deflate(strm, _mode); /* no bad return value */
|
|
||||||
|
|
||||||
if (status !== Z_STREAM_END && status !== Z_OK) {
|
|
||||||
this.onEnd(status);
|
|
||||||
this.ended = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (strm.avail_out === 0 || (strm.avail_in === 0 && _mode === Z_FINISH)) {
|
|
||||||
if (this.options.to === 'string') {
|
|
||||||
this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out)));
|
|
||||||
} else {
|
|
||||||
this.onData(utils.shrinkBuf(strm.output, strm.next_out));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END);
|
|
||||||
|
|
||||||
// Finalize on the last chunk.
|
|
||||||
if (_mode === Z_FINISH) {
|
|
||||||
status = zlib_deflate.deflateEnd(this.strm);
|
|
||||||
this.onEnd(status);
|
|
||||||
this.ended = true;
|
|
||||||
return status === Z_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deflate#onData(chunk) -> Void
|
|
||||||
* - chunk (Uint8Array|Array|String): ouput data. Type of array depends
|
|
||||||
* on js engine support. When string output requested, each chunk
|
|
||||||
* will be string.
|
|
||||||
*
|
|
||||||
* By default, stores data blocks in `chunks[]` property and glue
|
|
||||||
* those in `onEnd`. Override this handler, if you need another behaviour.
|
|
||||||
**/
|
|
||||||
Deflate.prototype.onData = function(chunk) {
|
|
||||||
this.chunks.push(chunk);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deflate#onEnd(status) -> Void
|
|
||||||
* - status (Number): deflate status. 0 (Z_OK) on success,
|
|
||||||
* other if not.
|
|
||||||
*
|
|
||||||
* Called once after you tell deflate that input stream complete
|
|
||||||
* or error happenned. By default - join collected chunks,
|
|
||||||
* free memory and fill `results` / `err` properties.
|
|
||||||
**/
|
|
||||||
Deflate.prototype.onEnd = function(status) {
|
|
||||||
// On success - join
|
|
||||||
if (status === Z_OK) {
|
|
||||||
if (this.options.to === 'string') {
|
|
||||||
this.result = this.chunks.join('');
|
|
||||||
} else {
|
|
||||||
this.result = utils.flattenChunks(this.chunks);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.chunks = [];
|
|
||||||
this.err = status;
|
|
||||||
this.msg = this.strm.msg;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* deflate(data[, options]) -> Uint8Array|Array|String
|
|
||||||
* - data (Uint8Array|Array|String): input data to compress.
|
|
||||||
* - options (Object): zlib deflate options.
|
|
||||||
*
|
|
||||||
* Compress `data` with deflate alrorythm and `options`.
|
|
||||||
*
|
|
||||||
* Supported options are:
|
|
||||||
*
|
|
||||||
* - level
|
|
||||||
* - windowBits
|
|
||||||
* - memLevel
|
|
||||||
* - strategy
|
|
||||||
*
|
|
||||||
* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
|
|
||||||
* for more information on these.
|
|
||||||
*
|
|
||||||
* Sugar (options):
|
|
||||||
*
|
|
||||||
* - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
|
|
||||||
* negative windowBits implicitly.
|
|
||||||
* - `to` (String) - if equal to 'string', then result will be "binary string"
|
|
||||||
* (each char code [0..255])
|
|
||||||
*
|
|
||||||
* ##### Example:
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* var pako = require('pako')
|
|
||||||
* , data = Uint8Array([1,2,3,4,5,6,7,8,9]);
|
|
||||||
*
|
|
||||||
* console.log(pako.deflate(data));
|
|
||||||
* ```
|
|
||||||
**/
|
|
||||||
function deflate(input, options) {
|
|
||||||
var deflator = new Deflate(options);
|
|
||||||
|
|
||||||
deflator.push(input, true);
|
|
||||||
|
|
||||||
// That will never happens, if you don't cheat with options :)
|
|
||||||
if (deflator.err) { throw deflator.msg; }
|
|
||||||
|
|
||||||
return deflator.result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* deflateRaw(data[, options]) -> Uint8Array|Array|String
|
|
||||||
* - data (Uint8Array|Array|String): input data to compress.
|
|
||||||
* - options (Object): zlib deflate options.
|
|
||||||
*
|
|
||||||
* The same as [[deflate]], but creates raw data, without wrapper
|
|
||||||
* (header and adler32 crc).
|
|
||||||
**/
|
|
||||||
function deflateRaw(input, options) {
|
|
||||||
options = options || {};
|
|
||||||
options.raw = true;
|
|
||||||
return deflate(input, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gzip(data[, options]) -> Uint8Array|Array|String
|
|
||||||
* - data (Uint8Array|Array|String): input data to compress.
|
|
||||||
* - options (Object): zlib deflate options.
|
|
||||||
*
|
|
||||||
* The same as [[deflate]], but create gzip wrapper instead of
|
|
||||||
* deflate one.
|
|
||||||
**/
|
|
||||||
function gzip(input, options) {
|
|
||||||
options = options || {};
|
|
||||||
options.gzip = true;
|
|
||||||
return deflate(input, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
exports.Deflate = Deflate;
|
|
||||||
exports.deflate = deflate;
|
|
||||||
exports.deflateRaw = deflateRaw;
|
|
||||||
exports.gzip = gzip;
|
|
||||||
},{"./utils/common":2,"./utils/strings":3,"./zlib/deflate.js":6,"./zlib/messages":7,"./zlib/zstream":9}],2:[function(_dereq_,module,exports){
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
@ -463,12 +101,12 @@ exports.setTyped = function (on) {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.setTyped(TYPED_OK);
|
exports.setTyped(TYPED_OK);
|
||||||
},{}],3:[function(_dereq_,module,exports){
|
},{}],2:[function(require,module,exports){
|
||||||
// String encode/decode helpers
|
// String encode/decode helpers
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var utils = _dereq_('./common');
|
var utils = require('./common');
|
||||||
|
|
||||||
|
|
||||||
// Quick check if we can use fast array to bin string conversion
|
// Quick check if we can use fast array to bin string conversion
|
||||||
|
@ -650,7 +288,7 @@ exports.utf8border = function(buf, max) {
|
||||||
return (pos + _utf8len[buf[pos]] > max) ? pos : max;
|
return (pos + _utf8len[buf[pos]] > max) ? pos : max;
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"./common":2}],4:[function(_dereq_,module,exports){
|
},{"./common":1}],3:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Note: adler32 takes 12% for level 0 and 2% for level 6.
|
// Note: adler32 takes 12% for level 0 and 2% for level 6.
|
||||||
|
@ -683,7 +321,7 @@ function adler32(adler, buf, len, pos) {
|
||||||
|
|
||||||
|
|
||||||
module.exports = adler32;
|
module.exports = adler32;
|
||||||
},{}],5:[function(_dereq_,module,exports){
|
},{}],4:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Note: we can't get significant speed boost here.
|
// Note: we can't get significant speed boost here.
|
||||||
|
@ -725,14 +363,14 @@ function crc32(crc, buf, len, pos) {
|
||||||
|
|
||||||
|
|
||||||
module.exports = crc32;
|
module.exports = crc32;
|
||||||
},{}],6:[function(_dereq_,module,exports){
|
},{}],5:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var utils = _dereq_('../utils/common');
|
var utils = require('../utils/common');
|
||||||
var trees = _dereq_('./trees');
|
var trees = require('./trees');
|
||||||
var adler32 = _dereq_('./adler32');
|
var adler32 = require('./adler32');
|
||||||
var crc32 = _dereq_('./crc32');
|
var crc32 = require('./crc32');
|
||||||
var msg = _dereq_('./messages');
|
var msg = require('./messages');
|
||||||
|
|
||||||
/* Public constants ==========================================================*/
|
/* Public constants ==========================================================*/
|
||||||
/* ===========================================================================*/
|
/* ===========================================================================*/
|
||||||
|
@ -2491,7 +2129,7 @@ exports.deflatePending = deflatePending;
|
||||||
exports.deflatePrime = deflatePrime;
|
exports.deflatePrime = deflatePrime;
|
||||||
exports.deflateTune = deflateTune;
|
exports.deflateTune = deflateTune;
|
||||||
*/
|
*/
|
||||||
},{"../utils/common":2,"./adler32":4,"./crc32":5,"./messages":7,"./trees":8}],7:[function(_dereq_,module,exports){
|
},{"../utils/common":1,"./adler32":3,"./crc32":4,"./messages":6,"./trees":7}],6:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -2505,11 +2143,11 @@ module.exports = {
|
||||||
'-5': 'buffer error', /* Z_BUF_ERROR (-5) */
|
'-5': 'buffer error', /* Z_BUF_ERROR (-5) */
|
||||||
'-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */
|
'-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */
|
||||||
};
|
};
|
||||||
},{}],8:[function(_dereq_,module,exports){
|
},{}],7:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var utils = _dereq_('../utils/common');
|
var utils = require('../utils/common');
|
||||||
|
|
||||||
/* Public constants ==========================================================*/
|
/* Public constants ==========================================================*/
|
||||||
/* ===========================================================================*/
|
/* ===========================================================================*/
|
||||||
|
@ -3705,7 +3343,7 @@ exports._tr_stored_block = _tr_stored_block;
|
||||||
exports._tr_flush_block = _tr_flush_block;
|
exports._tr_flush_block = _tr_flush_block;
|
||||||
exports._tr_tally = _tr_tally;
|
exports._tr_tally = _tr_tally;
|
||||||
exports._tr_align = _tr_align;
|
exports._tr_align = _tr_align;
|
||||||
},{"../utils/common":2}],9:[function(_dereq_,module,exports){
|
},{"../utils/common":1}],8:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
@ -3735,6 +3373,370 @@ function ZStream() {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ZStream;
|
module.exports = ZStream;
|
||||||
},{}]},{},[1])
|
},{}],"/lib/deflate.js":[function(require,module,exports){
|
||||||
(1)
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
var zlib_deflate = require('./zlib/deflate.js');
|
||||||
|
var utils = require('./utils/common');
|
||||||
|
var strings = require('./utils/strings');
|
||||||
|
var msg = require('./zlib/messages');
|
||||||
|
var zstream = require('./zlib/zstream');
|
||||||
|
|
||||||
|
var toString = Object.prototype.toString;
|
||||||
|
|
||||||
|
/* Public constants ==========================================================*/
|
||||||
|
/* ===========================================================================*/
|
||||||
|
|
||||||
|
var Z_NO_FLUSH = 0;
|
||||||
|
var Z_FINISH = 4;
|
||||||
|
|
||||||
|
var Z_OK = 0;
|
||||||
|
var Z_STREAM_END = 1;
|
||||||
|
|
||||||
|
var Z_DEFAULT_COMPRESSION = -1;
|
||||||
|
|
||||||
|
var Z_DEFAULT_STRATEGY = 0;
|
||||||
|
|
||||||
|
var Z_DEFLATED = 8;
|
||||||
|
|
||||||
|
/* ===========================================================================*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class Deflate
|
||||||
|
*
|
||||||
|
* Generic JS-style wrapper for zlib calls. If you don't need
|
||||||
|
* streaming behaviour - use more simple functions: [[deflate]],
|
||||||
|
* [[deflateRaw]] and [[gzip]].
|
||||||
|
**/
|
||||||
|
|
||||||
|
/* internal
|
||||||
|
* Deflate.chunks -> Array
|
||||||
|
*
|
||||||
|
* Chunks of output data, if [[Deflate#onData]] not overriden.
|
||||||
|
**/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deflate.result -> Uint8Array|Array
|
||||||
|
*
|
||||||
|
* Compressed result, generated by default [[Deflate#onData]]
|
||||||
|
* and [[Deflate#onEnd]] handlers. Filled after you push last chunk
|
||||||
|
* (call [[Deflate#push]] with `Z_FINISH` / `true` param).
|
||||||
|
**/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deflate.err -> Number
|
||||||
|
*
|
||||||
|
* Error code after deflate finished. 0 (Z_OK) on success.
|
||||||
|
* You will not need it in real life, because deflate errors
|
||||||
|
* are possible only on wrong options or bad `onData` / `onEnd`
|
||||||
|
* custom handlers.
|
||||||
|
**/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deflate.msg -> String
|
||||||
|
*
|
||||||
|
* Error message, if [[Deflate.err]] != 0
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* new Deflate(options)
|
||||||
|
* - options (Object): zlib deflate options.
|
||||||
|
*
|
||||||
|
* Creates new deflator instance with specified params. Throws exception
|
||||||
|
* on bad params. Supported options:
|
||||||
|
*
|
||||||
|
* - `level`
|
||||||
|
* - `windowBits`
|
||||||
|
* - `memLevel`
|
||||||
|
* - `strategy`
|
||||||
|
*
|
||||||
|
* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
|
||||||
|
* for more information on these.
|
||||||
|
*
|
||||||
|
* Additional options, for internal needs:
|
||||||
|
*
|
||||||
|
* - `chunkSize` - size of generated data chunks (16K by default)
|
||||||
|
* - `raw` (Boolean) - do raw deflate
|
||||||
|
* - `gzip` (Boolean) - create gzip wrapper
|
||||||
|
* - `to` (String) - if equal to 'string', then result will be "binary string"
|
||||||
|
* (each char code [0..255])
|
||||||
|
* - `header` (Object) - custom header for gzip
|
||||||
|
* - `text` (Boolean) - true if compressed data believed to be text
|
||||||
|
* - `time` (Number) - modification time, unix timestamp
|
||||||
|
* - `os` (Number) - operation system code
|
||||||
|
* - `extra` (Array) - array of bytes with extra data (max 65536)
|
||||||
|
* - `name` (String) - file name (binary string)
|
||||||
|
* - `comment` (String) - comment (binary string)
|
||||||
|
* - `hcrc` (Boolean) - true if header crc should be added
|
||||||
|
*
|
||||||
|
* ##### Example:
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* var pako = require('pako')
|
||||||
|
* , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
|
||||||
|
* , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
|
||||||
|
*
|
||||||
|
* var deflate = new pako.Deflate({ level: 3});
|
||||||
|
*
|
||||||
|
* deflate.push(chunk1, false);
|
||||||
|
* deflate.push(chunk2, true); // true -> last chunk
|
||||||
|
*
|
||||||
|
* if (deflate.err) { throw new Error(deflate.err); }
|
||||||
|
*
|
||||||
|
* console.log(deflate.result);
|
||||||
|
* ```
|
||||||
|
**/
|
||||||
|
var Deflate = function(options) {
|
||||||
|
|
||||||
|
this.options = utils.assign({
|
||||||
|
level: Z_DEFAULT_COMPRESSION,
|
||||||
|
method: Z_DEFLATED,
|
||||||
|
chunkSize: 16384,
|
||||||
|
windowBits: 15,
|
||||||
|
memLevel: 8,
|
||||||
|
strategy: Z_DEFAULT_STRATEGY,
|
||||||
|
to: ''
|
||||||
|
}, options || {});
|
||||||
|
|
||||||
|
var opt = this.options;
|
||||||
|
|
||||||
|
if (opt.raw && (opt.windowBits > 0)) {
|
||||||
|
opt.windowBits = -opt.windowBits;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (opt.gzip && (opt.windowBits > 0) && (opt.windowBits < 16)) {
|
||||||
|
opt.windowBits += 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.err = 0; // error code, if happens (0 = Z_OK)
|
||||||
|
this.msg = ''; // error message
|
||||||
|
this.ended = false; // used to avoid multiple onEnd() calls
|
||||||
|
this.chunks = []; // chunks of compressed data
|
||||||
|
|
||||||
|
this.strm = new zstream();
|
||||||
|
this.strm.avail_out = 0;
|
||||||
|
|
||||||
|
var status = zlib_deflate.deflateInit2(
|
||||||
|
this.strm,
|
||||||
|
opt.level,
|
||||||
|
opt.method,
|
||||||
|
opt.windowBits,
|
||||||
|
opt.memLevel,
|
||||||
|
opt.strategy
|
||||||
|
);
|
||||||
|
|
||||||
|
if (status !== Z_OK) {
|
||||||
|
throw new Error(msg[status]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opt.header) {
|
||||||
|
zlib_deflate.deflateSetHeader(this.strm, opt.header);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deflate#push(data[, mode]) -> Boolean
|
||||||
|
* - data (Uint8Array|Array|ArrayBuffer|String): input data. Strings will be
|
||||||
|
* converted to utf8 byte sequence.
|
||||||
|
* - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
|
||||||
|
* See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.
|
||||||
|
*
|
||||||
|
* Sends input data to deflate pipe, generating [[Deflate#onData]] calls with
|
||||||
|
* new compressed chunks. Returns `true` on success. The last data block must have
|
||||||
|
* mode Z_FINISH (or `true`). That flush internal pending buffers and call
|
||||||
|
* [[Deflate#onEnd]].
|
||||||
|
*
|
||||||
|
* On fail call [[Deflate#onEnd]] with error code and return false.
|
||||||
|
*
|
||||||
|
* We strongly recommend to use `Uint8Array` on input for best speed (output
|
||||||
|
* array format is detected automatically). Also, don't skip last param and always
|
||||||
|
* use the same type in your code (boolean or number). That will improve JS speed.
|
||||||
|
*
|
||||||
|
* For regular `Array`-s make sure all elements are [0..255].
|
||||||
|
*
|
||||||
|
* ##### Example
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* push(chunk, false); // push one of data chunks
|
||||||
|
* ...
|
||||||
|
* push(chunk, true); // push last chunk
|
||||||
|
* ```
|
||||||
|
**/
|
||||||
|
Deflate.prototype.push = function(data, mode) {
|
||||||
|
var strm = this.strm;
|
||||||
|
var chunkSize = this.options.chunkSize;
|
||||||
|
var status, _mode;
|
||||||
|
|
||||||
|
if (this.ended) { return false; }
|
||||||
|
|
||||||
|
_mode = (mode === ~~mode) ? mode : ((mode === true) ? Z_FINISH : Z_NO_FLUSH);
|
||||||
|
|
||||||
|
// Convert data if needed
|
||||||
|
if (typeof data === 'string') {
|
||||||
|
// If we need to compress text, change encoding to utf8.
|
||||||
|
strm.input = strings.string2buf(data);
|
||||||
|
} else if (toString.call(data) === '[object ArrayBuffer]') {
|
||||||
|
strm.input = new Uint8Array(data);
|
||||||
|
} else {
|
||||||
|
strm.input = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
strm.next_in = 0;
|
||||||
|
strm.avail_in = strm.input.length;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (strm.avail_out === 0) {
|
||||||
|
strm.output = new utils.Buf8(chunkSize);
|
||||||
|
strm.next_out = 0;
|
||||||
|
strm.avail_out = chunkSize;
|
||||||
|
}
|
||||||
|
status = zlib_deflate.deflate(strm, _mode); /* no bad return value */
|
||||||
|
|
||||||
|
if (status !== Z_STREAM_END && status !== Z_OK) {
|
||||||
|
this.onEnd(status);
|
||||||
|
this.ended = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (strm.avail_out === 0 || (strm.avail_in === 0 && _mode === Z_FINISH)) {
|
||||||
|
if (this.options.to === 'string') {
|
||||||
|
this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out)));
|
||||||
|
} else {
|
||||||
|
this.onData(utils.shrinkBuf(strm.output, strm.next_out));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END);
|
||||||
|
|
||||||
|
// Finalize on the last chunk.
|
||||||
|
if (_mode === Z_FINISH) {
|
||||||
|
status = zlib_deflate.deflateEnd(this.strm);
|
||||||
|
this.onEnd(status);
|
||||||
|
this.ended = true;
|
||||||
|
return status === Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deflate#onData(chunk) -> Void
|
||||||
|
* - chunk (Uint8Array|Array|String): ouput data. Type of array depends
|
||||||
|
* on js engine support. When string output requested, each chunk
|
||||||
|
* will be string.
|
||||||
|
*
|
||||||
|
* By default, stores data blocks in `chunks[]` property and glue
|
||||||
|
* those in `onEnd`. Override this handler, if you need another behaviour.
|
||||||
|
**/
|
||||||
|
Deflate.prototype.onData = function(chunk) {
|
||||||
|
this.chunks.push(chunk);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deflate#onEnd(status) -> Void
|
||||||
|
* - status (Number): deflate status. 0 (Z_OK) on success,
|
||||||
|
* other if not.
|
||||||
|
*
|
||||||
|
* Called once after you tell deflate that input stream complete
|
||||||
|
* or error happenned. By default - join collected chunks,
|
||||||
|
* free memory and fill `results` / `err` properties.
|
||||||
|
**/
|
||||||
|
Deflate.prototype.onEnd = function(status) {
|
||||||
|
// On success - join
|
||||||
|
if (status === Z_OK) {
|
||||||
|
if (this.options.to === 'string') {
|
||||||
|
this.result = this.chunks.join('');
|
||||||
|
} else {
|
||||||
|
this.result = utils.flattenChunks(this.chunks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.chunks = [];
|
||||||
|
this.err = status;
|
||||||
|
this.msg = this.strm.msg;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deflate(data[, options]) -> Uint8Array|Array|String
|
||||||
|
* - data (Uint8Array|Array|String): input data to compress.
|
||||||
|
* - options (Object): zlib deflate options.
|
||||||
|
*
|
||||||
|
* Compress `data` with deflate alrorythm and `options`.
|
||||||
|
*
|
||||||
|
* Supported options are:
|
||||||
|
*
|
||||||
|
* - level
|
||||||
|
* - windowBits
|
||||||
|
* - memLevel
|
||||||
|
* - strategy
|
||||||
|
*
|
||||||
|
* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
|
||||||
|
* for more information on these.
|
||||||
|
*
|
||||||
|
* Sugar (options):
|
||||||
|
*
|
||||||
|
* - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
|
||||||
|
* negative windowBits implicitly.
|
||||||
|
* - `to` (String) - if equal to 'string', then result will be "binary string"
|
||||||
|
* (each char code [0..255])
|
||||||
|
*
|
||||||
|
* ##### Example:
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* var pako = require('pako')
|
||||||
|
* , data = Uint8Array([1,2,3,4,5,6,7,8,9]);
|
||||||
|
*
|
||||||
|
* console.log(pako.deflate(data));
|
||||||
|
* ```
|
||||||
|
**/
|
||||||
|
function deflate(input, options) {
|
||||||
|
var deflator = new Deflate(options);
|
||||||
|
|
||||||
|
deflator.push(input, true);
|
||||||
|
|
||||||
|
// That will never happens, if you don't cheat with options :)
|
||||||
|
if (deflator.err) { throw deflator.msg; }
|
||||||
|
|
||||||
|
return deflator.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deflateRaw(data[, options]) -> Uint8Array|Array|String
|
||||||
|
* - data (Uint8Array|Array|String): input data to compress.
|
||||||
|
* - options (Object): zlib deflate options.
|
||||||
|
*
|
||||||
|
* The same as [[deflate]], but creates raw data, without wrapper
|
||||||
|
* (header and adler32 crc).
|
||||||
|
**/
|
||||||
|
function deflateRaw(input, options) {
|
||||||
|
options = options || {};
|
||||||
|
options.raw = true;
|
||||||
|
return deflate(input, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gzip(data[, options]) -> Uint8Array|Array|String
|
||||||
|
* - data (Uint8Array|Array|String): input data to compress.
|
||||||
|
* - options (Object): zlib deflate options.
|
||||||
|
*
|
||||||
|
* The same as [[deflate]], but create gzip wrapper instead of
|
||||||
|
* deflate one.
|
||||||
|
**/
|
||||||
|
function gzip(input, options) {
|
||||||
|
options = options || {};
|
||||||
|
options.gzip = true;
|
||||||
|
return deflate(input, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
exports.Deflate = Deflate;
|
||||||
|
exports.deflate = deflate;
|
||||||
|
exports.deflateRaw = deflateRaw;
|
||||||
|
exports.gzip = gzip;
|
||||||
|
},{"./utils/common":1,"./utils/strings":2,"./zlib/deflate.js":5,"./zlib/messages":6,"./zlib/zstream":8}]},{},[])("/lib/deflate.js")
|
||||||
});
|
});
|
4
dist/pako_deflate.min.js
vendored
4
dist/pako_deflate.min.js
vendored
File diff suppressed because one or more lines are too long
774
dist/pako_inflate.js
vendored
774
dist/pako_inflate.js
vendored
|
@ -1,370 +1,4 @@
|
||||||
/* pako 0.2.5 nodeca/pako */!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.pako=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){
|
/* pako 0.2.6 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||||||
'use strict';
|
|
||||||
|
|
||||||
|
|
||||||
var zlib_inflate = _dereq_('./zlib/inflate.js');
|
|
||||||
var utils = _dereq_('./utils/common');
|
|
||||||
var strings = _dereq_('./utils/strings');
|
|
||||||
var c = _dereq_('./zlib/constants');
|
|
||||||
var msg = _dereq_('./zlib/messages');
|
|
||||||
var zstream = _dereq_('./zlib/zstream');
|
|
||||||
var gzheader = _dereq_('./zlib/gzheader');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* class Inflate
|
|
||||||
*
|
|
||||||
* Generic JS-style wrapper for zlib calls. If you don't need
|
|
||||||
* streaming behaviour - use more simple functions: [[inflate]]
|
|
||||||
* and [[inflateRaw]].
|
|
||||||
**/
|
|
||||||
|
|
||||||
/* internal
|
|
||||||
* inflate.chunks -> Array
|
|
||||||
*
|
|
||||||
* Chunks of output data, if [[Inflate#onData]] not overriden.
|
|
||||||
**/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inflate.result -> Uint8Array|Array|String
|
|
||||||
*
|
|
||||||
* Uncompressed result, generated by default [[Inflate#onData]]
|
|
||||||
* and [[Inflate#onEnd]] handlers. Filled after you push last chunk
|
|
||||||
* (call [[Inflate#push]] with `Z_FINISH` / `true` param).
|
|
||||||
**/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inflate.err -> Number
|
|
||||||
*
|
|
||||||
* Error code after inflate finished. 0 (Z_OK) on success.
|
|
||||||
* Should be checked if broken data possible.
|
|
||||||
**/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inflate.msg -> String
|
|
||||||
*
|
|
||||||
* Error message, if [[Inflate.err]] != 0
|
|
||||||
**/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* new Inflate(options)
|
|
||||||
* - options (Object): zlib inflate options.
|
|
||||||
*
|
|
||||||
* Creates new inflator instance with specified params. Throws exception
|
|
||||||
* on bad params. Supported options:
|
|
||||||
*
|
|
||||||
* - `windowBits`
|
|
||||||
*
|
|
||||||
* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
|
|
||||||
* for more information on these.
|
|
||||||
*
|
|
||||||
* Additional options, for internal needs:
|
|
||||||
*
|
|
||||||
* - `chunkSize` - size of generated data chunks (16K by default)
|
|
||||||
* - `raw` (Boolean) - do raw inflate
|
|
||||||
* - `to` (String) - if equal to 'string', then result will be converted
|
|
||||||
* from utf8 to utf16 (javascript) string. When string output requested,
|
|
||||||
* chunk length can differ from `chunkSize`, depending on content.
|
|
||||||
*
|
|
||||||
* By default, when no options set, autodetect deflate/gzip data format via
|
|
||||||
* wrapper header.
|
|
||||||
*
|
|
||||||
* ##### Example:
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* var pako = require('pako')
|
|
||||||
* , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
|
|
||||||
* , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
|
|
||||||
*
|
|
||||||
* var inflate = new pako.Inflate({ level: 3});
|
|
||||||
*
|
|
||||||
* inflate.push(chunk1, false);
|
|
||||||
* inflate.push(chunk2, true); // true -> last chunk
|
|
||||||
*
|
|
||||||
* if (inflate.err) { throw new Error(inflate.err); }
|
|
||||||
*
|
|
||||||
* console.log(inflate.result);
|
|
||||||
* ```
|
|
||||||
**/
|
|
||||||
var Inflate = function(options) {
|
|
||||||
|
|
||||||
this.options = utils.assign({
|
|
||||||
chunkSize: 16384,
|
|
||||||
windowBits: 0,
|
|
||||||
to: ''
|
|
||||||
}, options || {});
|
|
||||||
|
|
||||||
var opt = this.options;
|
|
||||||
|
|
||||||
// Force window size for `raw` data, if not set directly,
|
|
||||||
// because we have no header for autodetect.
|
|
||||||
if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {
|
|
||||||
opt.windowBits = -opt.windowBits;
|
|
||||||
if (opt.windowBits === 0) { opt.windowBits = -15; }
|
|
||||||
}
|
|
||||||
|
|
||||||
// If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
|
|
||||||
if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&
|
|
||||||
!(options && options.windowBits)) {
|
|
||||||
opt.windowBits += 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gzip header has no info about windows size, we can do autodetect only
|
|
||||||
// for deflate. So, if window size not set, force it to max when gzip possible
|
|
||||||
if ((opt.windowBits > 15) && (opt.windowBits < 48)) {
|
|
||||||
// bit 3 (16) -> gzipped data
|
|
||||||
// bit 4 (32) -> autodetect gzip/deflate
|
|
||||||
if ((opt.windowBits & 15) === 0) {
|
|
||||||
opt.windowBits |= 15;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.err = 0; // error code, if happens (0 = Z_OK)
|
|
||||||
this.msg = ''; // error message
|
|
||||||
this.ended = false; // used to avoid multiple onEnd() calls
|
|
||||||
this.chunks = []; // chunks of compressed data
|
|
||||||
|
|
||||||
this.strm = new zstream();
|
|
||||||
this.strm.avail_out = 0;
|
|
||||||
|
|
||||||
var status = zlib_inflate.inflateInit2(
|
|
||||||
this.strm,
|
|
||||||
opt.windowBits
|
|
||||||
);
|
|
||||||
|
|
||||||
if (status !== c.Z_OK) {
|
|
||||||
throw new Error(msg[status]);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.header = new gzheader();
|
|
||||||
|
|
||||||
zlib_inflate.inflateGetHeader(this.strm, this.header);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inflate#push(data[, mode]) -> Boolean
|
|
||||||
* - data (Uint8Array|Array|String): input data
|
|
||||||
* - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
|
|
||||||
* See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.
|
|
||||||
*
|
|
||||||
* Sends input data to inflate pipe, generating [[Inflate#onData]] calls with
|
|
||||||
* new output chunks. Returns `true` on success. The last data block must have
|
|
||||||
* mode Z_FINISH (or `true`). That flush internal pending buffers and call
|
|
||||||
* [[Inflate#onEnd]].
|
|
||||||
*
|
|
||||||
* On fail call [[Inflate#onEnd]] with error code and return false.
|
|
||||||
*
|
|
||||||
* We strongly recommend to use `Uint8Array` on input for best speed (output
|
|
||||||
* format is detected automatically). Also, don't skip last param and always
|
|
||||||
* use the same type in your code (boolean or number). That will improve JS speed.
|
|
||||||
*
|
|
||||||
* For regular `Array`-s make sure all elements are [0..255].
|
|
||||||
*
|
|
||||||
* ##### Example
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* push(chunk, false); // push one of data chunks
|
|
||||||
* ...
|
|
||||||
* push(chunk, true); // push last chunk
|
|
||||||
* ```
|
|
||||||
**/
|
|
||||||
Inflate.prototype.push = function(data, mode) {
|
|
||||||
var strm = this.strm;
|
|
||||||
var chunkSize = this.options.chunkSize;
|
|
||||||
var status, _mode;
|
|
||||||
var next_out_utf8, tail, utf8str;
|
|
||||||
|
|
||||||
if (this.ended) { return false; }
|
|
||||||
_mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH);
|
|
||||||
|
|
||||||
// Convert data if needed
|
|
||||||
if (typeof data === 'string') {
|
|
||||||
// Only binary strings can be decompressed on practice
|
|
||||||
strm.input = strings.binstring2buf(data);
|
|
||||||
} else {
|
|
||||||
strm.input = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
strm.next_in = 0;
|
|
||||||
strm.avail_in = strm.input.length;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (strm.avail_out === 0) {
|
|
||||||
strm.output = new utils.Buf8(chunkSize);
|
|
||||||
strm.next_out = 0;
|
|
||||||
strm.avail_out = chunkSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH); /* no bad return value */
|
|
||||||
|
|
||||||
if (status !== c.Z_STREAM_END && status !== c.Z_OK) {
|
|
||||||
this.onEnd(status);
|
|
||||||
this.ended = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strm.next_out) {
|
|
||||||
if (strm.avail_out === 0 || status === c.Z_STREAM_END || (strm.avail_in === 0 && _mode === c.Z_FINISH)) {
|
|
||||||
|
|
||||||
if (this.options.to === 'string') {
|
|
||||||
|
|
||||||
next_out_utf8 = strings.utf8border(strm.output, strm.next_out);
|
|
||||||
|
|
||||||
tail = strm.next_out - next_out_utf8;
|
|
||||||
utf8str = strings.buf2string(strm.output, next_out_utf8);
|
|
||||||
|
|
||||||
// move tail
|
|
||||||
strm.next_out = tail;
|
|
||||||
strm.avail_out = chunkSize - tail;
|
|
||||||
if (tail) { utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0); }
|
|
||||||
|
|
||||||
this.onData(utf8str);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this.onData(utils.shrinkBuf(strm.output, strm.next_out));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while ((strm.avail_in > 0) && status !== c.Z_STREAM_END);
|
|
||||||
|
|
||||||
if (status === c.Z_STREAM_END) {
|
|
||||||
_mode = c.Z_FINISH;
|
|
||||||
}
|
|
||||||
// Finalize on the last chunk.
|
|
||||||
if (_mode === c.Z_FINISH) {
|
|
||||||
status = zlib_inflate.inflateEnd(this.strm);
|
|
||||||
this.onEnd(status);
|
|
||||||
this.ended = true;
|
|
||||||
return status === c.Z_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inflate#onData(chunk) -> Void
|
|
||||||
* - chunk (Uint8Array|Array|String): ouput data. Type of array depends
|
|
||||||
* on js engine support. When string output requested, each chunk
|
|
||||||
* will be string.
|
|
||||||
*
|
|
||||||
* By default, stores data blocks in `chunks[]` property and glue
|
|
||||||
* those in `onEnd`. Override this handler, if you need another behaviour.
|
|
||||||
**/
|
|
||||||
Inflate.prototype.onData = function(chunk) {
|
|
||||||
this.chunks.push(chunk);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inflate#onEnd(status) -> Void
|
|
||||||
* - status (Number): inflate status. 0 (Z_OK) on success,
|
|
||||||
* other if not.
|
|
||||||
*
|
|
||||||
* Called once after you tell inflate that input stream complete
|
|
||||||
* or error happenned. By default - join collected chunks,
|
|
||||||
* free memory and fill `results` / `err` properties.
|
|
||||||
**/
|
|
||||||
Inflate.prototype.onEnd = function(status) {
|
|
||||||
// On success - join
|
|
||||||
if (status === c.Z_OK) {
|
|
||||||
if (this.options.to === 'string') {
|
|
||||||
// Glue & convert here, until we teach pako to send
|
|
||||||
// utf8 alligned strings to onData
|
|
||||||
this.result = this.chunks.join('');
|
|
||||||
} else {
|
|
||||||
this.result = utils.flattenChunks(this.chunks);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.chunks = [];
|
|
||||||
this.err = status;
|
|
||||||
this.msg = this.strm.msg;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* inflate(data[, options]) -> Uint8Array|Array|String
|
|
||||||
* - data (Uint8Array|Array|String): input data to decompress.
|
|
||||||
* - options (Object): zlib inflate options.
|
|
||||||
*
|
|
||||||
* Decompress `data` with inflate/ungzip and `options`. Autodetect
|
|
||||||
* format via wrapper header by default. That's why we don't provide
|
|
||||||
* separate `ungzip` method.
|
|
||||||
*
|
|
||||||
* Supported options are:
|
|
||||||
*
|
|
||||||
* - windowBits
|
|
||||||
*
|
|
||||||
* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
|
|
||||||
* for more information.
|
|
||||||
*
|
|
||||||
* Sugar (options):
|
|
||||||
*
|
|
||||||
* - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
|
|
||||||
* negative windowBits implicitly.
|
|
||||||
* - `to` (String) - if equal to 'string', then result will be converted
|
|
||||||
* from utf8 to utf16 (javascript) string. When string output requested,
|
|
||||||
* chunk length can differ from `chunkSize`, depending on content.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* ##### Example:
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* var pako = require('pako')
|
|
||||||
* , input = pako.deflate([1,2,3,4,5,6,7,8,9])
|
|
||||||
* , output;
|
|
||||||
*
|
|
||||||
* try {
|
|
||||||
* output = pako.inflate(input);
|
|
||||||
* } catch (err)
|
|
||||||
* console.log(err);
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
**/
|
|
||||||
function inflate(input, options) {
|
|
||||||
var inflator = new Inflate(options);
|
|
||||||
|
|
||||||
inflator.push(input, true);
|
|
||||||
|
|
||||||
// That will never happens, if you don't cheat with options :)
|
|
||||||
if (inflator.err) { throw inflator.msg; }
|
|
||||||
|
|
||||||
return inflator.result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* inflateRaw(data[, options]) -> Uint8Array|Array|String
|
|
||||||
* - data (Uint8Array|Array|String): input data to decompress.
|
|
||||||
* - options (Object): zlib inflate options.
|
|
||||||
*
|
|
||||||
* The same as [[inflate]], but creates raw data, without wrapper
|
|
||||||
* (header and adler32 crc).
|
|
||||||
**/
|
|
||||||
function inflateRaw(input, options) {
|
|
||||||
options = options || {};
|
|
||||||
options.raw = true;
|
|
||||||
return inflate(input, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ungzip(data[, options]) -> Uint8Array|Array|String
|
|
||||||
* - data (Uint8Array|Array|String): input data to decompress.
|
|
||||||
* - options (Object): zlib inflate options.
|
|
||||||
*
|
|
||||||
* Just shortcut to [[inflate]], because it autodetects format
|
|
||||||
* by header.content. Done for convenience.
|
|
||||||
**/
|
|
||||||
|
|
||||||
|
|
||||||
exports.Inflate = Inflate;
|
|
||||||
exports.inflate = inflate;
|
|
||||||
exports.inflateRaw = inflateRaw;
|
|
||||||
exports.ungzip = inflate;
|
|
||||||
|
|
||||||
},{"./utils/common":2,"./utils/strings":3,"./zlib/constants":5,"./zlib/gzheader":7,"./zlib/inflate.js":9,"./zlib/messages":11,"./zlib/zstream":12}],2:[function(_dereq_,module,exports){
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
@ -467,12 +101,12 @@ exports.setTyped = function (on) {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.setTyped(TYPED_OK);
|
exports.setTyped(TYPED_OK);
|
||||||
},{}],3:[function(_dereq_,module,exports){
|
},{}],2:[function(require,module,exports){
|
||||||
// String encode/decode helpers
|
// String encode/decode helpers
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var utils = _dereq_('./common');
|
var utils = require('./common');
|
||||||
|
|
||||||
|
|
||||||
// Quick check if we can use fast array to bin string conversion
|
// Quick check if we can use fast array to bin string conversion
|
||||||
|
@ -654,7 +288,7 @@ exports.utf8border = function(buf, max) {
|
||||||
return (pos + _utf8len[buf[pos]] > max) ? pos : max;
|
return (pos + _utf8len[buf[pos]] > max) ? pos : max;
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"./common":2}],4:[function(_dereq_,module,exports){
|
},{"./common":1}],3:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Note: adler32 takes 12% for level 0 and 2% for level 6.
|
// Note: adler32 takes 12% for level 0 and 2% for level 6.
|
||||||
|
@ -687,7 +321,7 @@ function adler32(adler, buf, len, pos) {
|
||||||
|
|
||||||
|
|
||||||
module.exports = adler32;
|
module.exports = adler32;
|
||||||
},{}],5:[function(_dereq_,module,exports){
|
},{}],4:[function(require,module,exports){
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
/* Allowed flush values; see deflate() and inflate() below for details */
|
/* Allowed flush values; see deflate() and inflate() below for details */
|
||||||
|
@ -735,7 +369,7 @@ module.exports = {
|
||||||
Z_DEFLATED: 8
|
Z_DEFLATED: 8
|
||||||
//Z_NULL: null // Use -1 or null inline, depending on var type
|
//Z_NULL: null // Use -1 or null inline, depending on var type
|
||||||
};
|
};
|
||||||
},{}],6:[function(_dereq_,module,exports){
|
},{}],5:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Note: we can't get significant speed boost here.
|
// Note: we can't get significant speed boost here.
|
||||||
|
@ -777,7 +411,7 @@ function crc32(crc, buf, len, pos) {
|
||||||
|
|
||||||
|
|
||||||
module.exports = crc32;
|
module.exports = crc32;
|
||||||
},{}],7:[function(_dereq_,module,exports){
|
},{}],6:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
@ -818,7 +452,7 @@ function GZheader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = GZheader;
|
module.exports = GZheader;
|
||||||
},{}],8:[function(_dereq_,module,exports){
|
},{}],7:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// See state defs from inflate.js
|
// See state defs from inflate.js
|
||||||
|
@ -1145,15 +779,15 @@ module.exports = function inflate_fast(strm, start) {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
},{}],9:[function(_dereq_,module,exports){
|
},{}],8:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var utils = _dereq_('../utils/common');
|
var utils = require('../utils/common');
|
||||||
var adler32 = _dereq_('./adler32');
|
var adler32 = require('./adler32');
|
||||||
var crc32 = _dereq_('./crc32');
|
var crc32 = require('./crc32');
|
||||||
var inflate_fast = _dereq_('./inffast');
|
var inflate_fast = require('./inffast');
|
||||||
var inflate_table = _dereq_('./inftrees');
|
var inflate_table = require('./inftrees');
|
||||||
|
|
||||||
var CODES = 0;
|
var CODES = 0;
|
||||||
var LENS = 1;
|
var LENS = 1;
|
||||||
|
@ -2649,11 +2283,11 @@ exports.inflateSync = inflateSync;
|
||||||
exports.inflateSyncPoint = inflateSyncPoint;
|
exports.inflateSyncPoint = inflateSyncPoint;
|
||||||
exports.inflateUndermine = inflateUndermine;
|
exports.inflateUndermine = inflateUndermine;
|
||||||
*/
|
*/
|
||||||
},{"../utils/common":2,"./adler32":4,"./crc32":6,"./inffast":8,"./inftrees":10}],10:[function(_dereq_,module,exports){
|
},{"../utils/common":1,"./adler32":3,"./crc32":5,"./inffast":7,"./inftrees":9}],9:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var utils = _dereq_('../utils/common');
|
var utils = require('../utils/common');
|
||||||
|
|
||||||
var MAXBITS = 15;
|
var MAXBITS = 15;
|
||||||
var ENOUGH_LENS = 852;
|
var ENOUGH_LENS = 852;
|
||||||
|
@ -2976,7 +2610,7 @@ module.exports = function inflate_table(type, lens, lens_index, codes, table, ta
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"../utils/common":2}],11:[function(_dereq_,module,exports){
|
},{"../utils/common":1}],10:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -2990,7 +2624,7 @@ module.exports = {
|
||||||
'-5': 'buffer error', /* Z_BUF_ERROR (-5) */
|
'-5': 'buffer error', /* Z_BUF_ERROR (-5) */
|
||||||
'-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */
|
'-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */
|
||||||
};
|
};
|
||||||
},{}],12:[function(_dereq_,module,exports){
|
},{}],11:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
@ -3020,6 +2654,374 @@ function ZStream() {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ZStream;
|
module.exports = ZStream;
|
||||||
},{}]},{},[1])
|
},{}],"/lib/inflate.js":[function(require,module,exports){
|
||||||
(1)
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
var zlib_inflate = require('./zlib/inflate.js');
|
||||||
|
var utils = require('./utils/common');
|
||||||
|
var strings = require('./utils/strings');
|
||||||
|
var c = require('./zlib/constants');
|
||||||
|
var msg = require('./zlib/messages');
|
||||||
|
var zstream = require('./zlib/zstream');
|
||||||
|
var gzheader = require('./zlib/gzheader');
|
||||||
|
|
||||||
|
var toString = Object.prototype.toString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class Inflate
|
||||||
|
*
|
||||||
|
* Generic JS-style wrapper for zlib calls. If you don't need
|
||||||
|
* streaming behaviour - use more simple functions: [[inflate]]
|
||||||
|
* and [[inflateRaw]].
|
||||||
|
**/
|
||||||
|
|
||||||
|
/* internal
|
||||||
|
* inflate.chunks -> Array
|
||||||
|
*
|
||||||
|
* Chunks of output data, if [[Inflate#onData]] not overriden.
|
||||||
|
**/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inflate.result -> Uint8Array|Array|String
|
||||||
|
*
|
||||||
|
* Uncompressed result, generated by default [[Inflate#onData]]
|
||||||
|
* and [[Inflate#onEnd]] handlers. Filled after you push last chunk
|
||||||
|
* (call [[Inflate#push]] with `Z_FINISH` / `true` param).
|
||||||
|
**/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inflate.err -> Number
|
||||||
|
*
|
||||||
|
* Error code after inflate finished. 0 (Z_OK) on success.
|
||||||
|
* Should be checked if broken data possible.
|
||||||
|
**/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inflate.msg -> String
|
||||||
|
*
|
||||||
|
* Error message, if [[Inflate.err]] != 0
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* new Inflate(options)
|
||||||
|
* - options (Object): zlib inflate options.
|
||||||
|
*
|
||||||
|
* Creates new inflator instance with specified params. Throws exception
|
||||||
|
* on bad params. Supported options:
|
||||||
|
*
|
||||||
|
* - `windowBits`
|
||||||
|
*
|
||||||
|
* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
|
||||||
|
* for more information on these.
|
||||||
|
*
|
||||||
|
* Additional options, for internal needs:
|
||||||
|
*
|
||||||
|
* - `chunkSize` - size of generated data chunks (16K by default)
|
||||||
|
* - `raw` (Boolean) - do raw inflate
|
||||||
|
* - `to` (String) - if equal to 'string', then result will be converted
|
||||||
|
* from utf8 to utf16 (javascript) string. When string output requested,
|
||||||
|
* chunk length can differ from `chunkSize`, depending on content.
|
||||||
|
*
|
||||||
|
* By default, when no options set, autodetect deflate/gzip data format via
|
||||||
|
* wrapper header.
|
||||||
|
*
|
||||||
|
* ##### Example:
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* var pako = require('pako')
|
||||||
|
* , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
|
||||||
|
* , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
|
||||||
|
*
|
||||||
|
* var inflate = new pako.Inflate({ level: 3});
|
||||||
|
*
|
||||||
|
* inflate.push(chunk1, false);
|
||||||
|
* inflate.push(chunk2, true); // true -> last chunk
|
||||||
|
*
|
||||||
|
* if (inflate.err) { throw new Error(inflate.err); }
|
||||||
|
*
|
||||||
|
* console.log(inflate.result);
|
||||||
|
* ```
|
||||||
|
**/
|
||||||
|
var Inflate = function(options) {
|
||||||
|
|
||||||
|
this.options = utils.assign({
|
||||||
|
chunkSize: 16384,
|
||||||
|
windowBits: 0,
|
||||||
|
to: ''
|
||||||
|
}, options || {});
|
||||||
|
|
||||||
|
var opt = this.options;
|
||||||
|
|
||||||
|
// Force window size for `raw` data, if not set directly,
|
||||||
|
// because we have no header for autodetect.
|
||||||
|
if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {
|
||||||
|
opt.windowBits = -opt.windowBits;
|
||||||
|
if (opt.windowBits === 0) { opt.windowBits = -15; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
|
||||||
|
if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&
|
||||||
|
!(options && options.windowBits)) {
|
||||||
|
opt.windowBits += 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gzip header has no info about windows size, we can do autodetect only
|
||||||
|
// for deflate. So, if window size not set, force it to max when gzip possible
|
||||||
|
if ((opt.windowBits > 15) && (opt.windowBits < 48)) {
|
||||||
|
// bit 3 (16) -> gzipped data
|
||||||
|
// bit 4 (32) -> autodetect gzip/deflate
|
||||||
|
if ((opt.windowBits & 15) === 0) {
|
||||||
|
opt.windowBits |= 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.err = 0; // error code, if happens (0 = Z_OK)
|
||||||
|
this.msg = ''; // error message
|
||||||
|
this.ended = false; // used to avoid multiple onEnd() calls
|
||||||
|
this.chunks = []; // chunks of compressed data
|
||||||
|
|
||||||
|
this.strm = new zstream();
|
||||||
|
this.strm.avail_out = 0;
|
||||||
|
|
||||||
|
var status = zlib_inflate.inflateInit2(
|
||||||
|
this.strm,
|
||||||
|
opt.windowBits
|
||||||
|
);
|
||||||
|
|
||||||
|
if (status !== c.Z_OK) {
|
||||||
|
throw new Error(msg[status]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.header = new gzheader();
|
||||||
|
|
||||||
|
zlib_inflate.inflateGetHeader(this.strm, this.header);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inflate#push(data[, mode]) -> Boolean
|
||||||
|
* - data (Uint8Array|Array|ArrayBuffer|String): input data
|
||||||
|
* - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
|
||||||
|
* See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.
|
||||||
|
*
|
||||||
|
* Sends input data to inflate pipe, generating [[Inflate#onData]] calls with
|
||||||
|
* new output chunks. Returns `true` on success. The last data block must have
|
||||||
|
* mode Z_FINISH (or `true`). That flush internal pending buffers and call
|
||||||
|
* [[Inflate#onEnd]].
|
||||||
|
*
|
||||||
|
* On fail call [[Inflate#onEnd]] with error code and return false.
|
||||||
|
*
|
||||||
|
* We strongly recommend to use `Uint8Array` on input for best speed (output
|
||||||
|
* format is detected automatically). Also, don't skip last param and always
|
||||||
|
* use the same type in your code (boolean or number). That will improve JS speed.
|
||||||
|
*
|
||||||
|
* For regular `Array`-s make sure all elements are [0..255].
|
||||||
|
*
|
||||||
|
* ##### Example
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* push(chunk, false); // push one of data chunks
|
||||||
|
* ...
|
||||||
|
* push(chunk, true); // push last chunk
|
||||||
|
* ```
|
||||||
|
**/
|
||||||
|
Inflate.prototype.push = function(data, mode) {
|
||||||
|
var strm = this.strm;
|
||||||
|
var chunkSize = this.options.chunkSize;
|
||||||
|
var status, _mode;
|
||||||
|
var next_out_utf8, tail, utf8str;
|
||||||
|
|
||||||
|
if (this.ended) { return false; }
|
||||||
|
_mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH);
|
||||||
|
|
||||||
|
// Convert data if needed
|
||||||
|
if (typeof data === 'string') {
|
||||||
|
// Only binary strings can be decompressed on practice
|
||||||
|
strm.input = strings.binstring2buf(data);
|
||||||
|
} else if (toString.call(data) === '[object ArrayBuffer]') {
|
||||||
|
strm.input = new Uint8Array(data);
|
||||||
|
} else {
|
||||||
|
strm.input = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
strm.next_in = 0;
|
||||||
|
strm.avail_in = strm.input.length;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (strm.avail_out === 0) {
|
||||||
|
strm.output = new utils.Buf8(chunkSize);
|
||||||
|
strm.next_out = 0;
|
||||||
|
strm.avail_out = chunkSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH); /* no bad return value */
|
||||||
|
|
||||||
|
if (status !== c.Z_STREAM_END && status !== c.Z_OK) {
|
||||||
|
this.onEnd(status);
|
||||||
|
this.ended = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strm.next_out) {
|
||||||
|
if (strm.avail_out === 0 || status === c.Z_STREAM_END || (strm.avail_in === 0 && _mode === c.Z_FINISH)) {
|
||||||
|
|
||||||
|
if (this.options.to === 'string') {
|
||||||
|
|
||||||
|
next_out_utf8 = strings.utf8border(strm.output, strm.next_out);
|
||||||
|
|
||||||
|
tail = strm.next_out - next_out_utf8;
|
||||||
|
utf8str = strings.buf2string(strm.output, next_out_utf8);
|
||||||
|
|
||||||
|
// move tail
|
||||||
|
strm.next_out = tail;
|
||||||
|
strm.avail_out = chunkSize - tail;
|
||||||
|
if (tail) { utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0); }
|
||||||
|
|
||||||
|
this.onData(utf8str);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this.onData(utils.shrinkBuf(strm.output, strm.next_out));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while ((strm.avail_in > 0) && status !== c.Z_STREAM_END);
|
||||||
|
|
||||||
|
if (status === c.Z_STREAM_END) {
|
||||||
|
_mode = c.Z_FINISH;
|
||||||
|
}
|
||||||
|
// Finalize on the last chunk.
|
||||||
|
if (_mode === c.Z_FINISH) {
|
||||||
|
status = zlib_inflate.inflateEnd(this.strm);
|
||||||
|
this.onEnd(status);
|
||||||
|
this.ended = true;
|
||||||
|
return status === c.Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inflate#onData(chunk) -> Void
|
||||||
|
* - chunk (Uint8Array|Array|String): ouput data. Type of array depends
|
||||||
|
* on js engine support. When string output requested, each chunk
|
||||||
|
* will be string.
|
||||||
|
*
|
||||||
|
* By default, stores data blocks in `chunks[]` property and glue
|
||||||
|
* those in `onEnd`. Override this handler, if you need another behaviour.
|
||||||
|
**/
|
||||||
|
Inflate.prototype.onData = function(chunk) {
|
||||||
|
this.chunks.push(chunk);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inflate#onEnd(status) -> Void
|
||||||
|
* - status (Number): inflate status. 0 (Z_OK) on success,
|
||||||
|
* other if not.
|
||||||
|
*
|
||||||
|
* Called once after you tell inflate that input stream complete
|
||||||
|
* or error happenned. By default - join collected chunks,
|
||||||
|
* free memory and fill `results` / `err` properties.
|
||||||
|
**/
|
||||||
|
Inflate.prototype.onEnd = function(status) {
|
||||||
|
// On success - join
|
||||||
|
if (status === c.Z_OK) {
|
||||||
|
if (this.options.to === 'string') {
|
||||||
|
// Glue & convert here, until we teach pako to send
|
||||||
|
// utf8 alligned strings to onData
|
||||||
|
this.result = this.chunks.join('');
|
||||||
|
} else {
|
||||||
|
this.result = utils.flattenChunks(this.chunks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.chunks = [];
|
||||||
|
this.err = status;
|
||||||
|
this.msg = this.strm.msg;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inflate(data[, options]) -> Uint8Array|Array|String
|
||||||
|
* - data (Uint8Array|Array|String): input data to decompress.
|
||||||
|
* - options (Object): zlib inflate options.
|
||||||
|
*
|
||||||
|
* Decompress `data` with inflate/ungzip and `options`. Autodetect
|
||||||
|
* format via wrapper header by default. That's why we don't provide
|
||||||
|
* separate `ungzip` method.
|
||||||
|
*
|
||||||
|
* Supported options are:
|
||||||
|
*
|
||||||
|
* - windowBits
|
||||||
|
*
|
||||||
|
* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
|
||||||
|
* for more information.
|
||||||
|
*
|
||||||
|
* Sugar (options):
|
||||||
|
*
|
||||||
|
* - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
|
||||||
|
* negative windowBits implicitly.
|
||||||
|
* - `to` (String) - if equal to 'string', then result will be converted
|
||||||
|
* from utf8 to utf16 (javascript) string. When string output requested,
|
||||||
|
* chunk length can differ from `chunkSize`, depending on content.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* ##### Example:
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* var pako = require('pako')
|
||||||
|
* , input = pako.deflate([1,2,3,4,5,6,7,8,9])
|
||||||
|
* , output;
|
||||||
|
*
|
||||||
|
* try {
|
||||||
|
* output = pako.inflate(input);
|
||||||
|
* } catch (err)
|
||||||
|
* console.log(err);
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
**/
|
||||||
|
function inflate(input, options) {
|
||||||
|
var inflator = new Inflate(options);
|
||||||
|
|
||||||
|
inflator.push(input, true);
|
||||||
|
|
||||||
|
// That will never happens, if you don't cheat with options :)
|
||||||
|
if (inflator.err) { throw inflator.msg; }
|
||||||
|
|
||||||
|
return inflator.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inflateRaw(data[, options]) -> Uint8Array|Array|String
|
||||||
|
* - data (Uint8Array|Array|String): input data to decompress.
|
||||||
|
* - options (Object): zlib inflate options.
|
||||||
|
*
|
||||||
|
* The same as [[inflate]], but creates raw data, without wrapper
|
||||||
|
* (header and adler32 crc).
|
||||||
|
**/
|
||||||
|
function inflateRaw(input, options) {
|
||||||
|
options = options || {};
|
||||||
|
options.raw = true;
|
||||||
|
return inflate(input, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ungzip(data[, options]) -> Uint8Array|Array|String
|
||||||
|
* - data (Uint8Array|Array|String): input data to decompress.
|
||||||
|
* - options (Object): zlib inflate options.
|
||||||
|
*
|
||||||
|
* Just shortcut to [[inflate]], because it autodetects format
|
||||||
|
* by header.content. Done for convenience.
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
exports.Inflate = Inflate;
|
||||||
|
exports.inflate = inflate;
|
||||||
|
exports.inflateRaw = inflateRaw;
|
||||||
|
exports.ungzip = inflate;
|
||||||
|
|
||||||
|
},{"./utils/common":1,"./utils/strings":2,"./zlib/constants":4,"./zlib/gzheader":6,"./zlib/inflate.js":8,"./zlib/messages":10,"./zlib/zstream":11}]},{},[])("/lib/inflate.js")
|
||||||
});
|
});
|
4
dist/pako_inflate.min.js
vendored
4
dist/pako_inflate.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue