mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-21 20:34:04 +01:00
Cleanup & comments
This commit is contained in:
parent
195e40c0df
commit
20b0318601
6 changed files with 43 additions and 37 deletions
|
@ -15,12 +15,12 @@ module.exports = {
|
||||||
Z_OK: 0,
|
Z_OK: 0,
|
||||||
Z_STREAM_END: 1,
|
Z_STREAM_END: 1,
|
||||||
Z_NEED_DICT: 2,
|
Z_NEED_DICT: 2,
|
||||||
Z_ERRNO: (-1),
|
Z_ERRNO: -1,
|
||||||
Z_STREAM_ERROR: (-2),
|
Z_STREAM_ERROR: -2,
|
||||||
Z_DATA_ERROR: (-3),
|
Z_DATA_ERROR: -3,
|
||||||
//Z_MEM_ERROR: (-4),
|
//Z_MEM_ERROR: -4,
|
||||||
Z_BUF_ERROR: (-5),
|
Z_BUF_ERROR: -5,
|
||||||
//Z_VERSION_ERROR: (-6),
|
//Z_VERSION_ERROR: -6,
|
||||||
|
|
||||||
/* compression levels */
|
/* compression levels */
|
||||||
Z_NO_COMPRESSION: 0,
|
Z_NO_COMPRESSION: 0,
|
||||||
|
@ -43,5 +43,5 @@ module.exports = {
|
||||||
|
|
||||||
/* The deflate compression method */
|
/* The deflate compression method */
|
||||||
Z_DEFLATED: 8
|
Z_DEFLATED: 8
|
||||||
//Z_NULL: null // Use -1 or null, depending on var type
|
//Z_NULL: null // Use -1 or null inline, depending on var type
|
||||||
};
|
};
|
|
@ -112,7 +112,7 @@ function rank(f) {
|
||||||
return ((f) << 1) - ((f) > 4 ? 9 : 0);
|
return ((f) << 1) - ((f) > 4 ? 9 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function zero(buf) { var len = buf.length; while (--len) { buf[len] = 0; } }
|
function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
|
||||||
|
|
||||||
|
|
||||||
/* =========================================================================
|
/* =========================================================================
|
||||||
|
@ -330,6 +330,7 @@ function fill_window(s) {
|
||||||
do {
|
do {
|
||||||
more = s.window_size - s.lookahead - s.strstart;
|
more = s.window_size - s.lookahead - s.strstart;
|
||||||
|
|
||||||
|
// JS ints have 32 bit, block below not needed
|
||||||
/* Deal with !@#$% 64K limit: */
|
/* Deal with !@#$% 64K limit: */
|
||||||
//if (sizeof(int) <= 2) {
|
//if (sizeof(int) <= 2) {
|
||||||
// if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
|
// if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
|
||||||
|
@ -1253,7 +1254,9 @@ function DeflateState() {
|
||||||
* are always zero.
|
* are always zero.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.high_water = 0;
|
// Used for window memory init. We safely ignore it for JS. That makes
|
||||||
|
// sense only for pointers and memory check tools.
|
||||||
|
//this.high_water = 0;
|
||||||
/* High water mark offset in window for initialized bytes -- bytes above
|
/* High water mark offset in window for initialized bytes -- bytes above
|
||||||
* this are set to zero in order to avoid memory check warnings when
|
* this are set to zero in order to avoid memory check warnings when
|
||||||
* longest match routines access bytes past the input. This is then
|
* longest match routines access bytes past the input. This is then
|
||||||
|
@ -1350,7 +1353,8 @@ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
|
||||||
s.head = new utils.Buf16(s.hash_size);
|
s.head = new utils.Buf16(s.hash_size);
|
||||||
s.prev = new utils.Buf16(s.w_size);
|
s.prev = new utils.Buf16(s.w_size);
|
||||||
|
|
||||||
s.high_water = 0; /* nothing written to s->window yet */
|
// Don't need mem init magic for JS.
|
||||||
|
//s.high_water = 0; /* nothing written to s->window yet */
|
||||||
|
|
||||||
s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
|
s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
|
||||||
|
|
||||||
|
@ -1560,7 +1564,13 @@ function deflate(strm, flush) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function deflateEnd(strm) {
|
function deflateEnd(strm) {
|
||||||
var status = strm.state.status;
|
var status;
|
||||||
|
|
||||||
|
if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = strm.state.status;
|
||||||
if (status !== INIT_STATE &&
|
if (status !== INIT_STATE &&
|
||||||
status !== EXTRA_STATE &&
|
status !== EXTRA_STATE &&
|
||||||
status !== NAME_STATE &&
|
status !== NAME_STATE &&
|
||||||
|
|
|
@ -183,7 +183,6 @@ module.exports = function inflate_fast(strm, start) {
|
||||||
|
|
||||||
// (!) This block is disabled in zlib defailts,
|
// (!) This block is disabled in zlib defailts,
|
||||||
// don't enable it for binary compatibility
|
// don't enable it for binary compatibility
|
||||||
|
|
||||||
//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
||||||
// if (len <= op - whave) {
|
// if (len <= op - whave) {
|
||||||
// do {
|
// do {
|
||||||
|
|
|
@ -149,7 +149,6 @@ function InflateState() {
|
||||||
this.lens = new utils.Buf16(320); /* temporary storage for code lengths */
|
this.lens = new utils.Buf16(320); /* temporary storage for code lengths */
|
||||||
this.work = new utils.Buf16(288); /* work area for code table building */
|
this.work = new utils.Buf16(288); /* work area for code table building */
|
||||||
|
|
||||||
// TODO: 8 or 16 bits?
|
|
||||||
this.codes = new utils.Buf32(ENOUGH); /* space for code tables */
|
this.codes = new utils.Buf32(ENOUGH); /* space for code tables */
|
||||||
this.sane = 0; /* if false, allow invalid distance too far */
|
this.sane = 0; /* if false, allow invalid distance too far */
|
||||||
this.back = 0; /* bits back of last unprocessed length/lit */
|
this.back = 0; /* bits back of last unprocessed length/lit */
|
||||||
|
@ -162,7 +161,7 @@ function inflateResetKeep(strm) {
|
||||||
if (!strm || !strm.state) { return Z_STREAM_ERROR; }
|
if (!strm || !strm.state) { return Z_STREAM_ERROR; }
|
||||||
state = strm.state;
|
state = strm.state;
|
||||||
strm.total_in = strm.total_out = state.total = 0;
|
strm.total_in = strm.total_out = state.total = 0;
|
||||||
//strm.msg = Z_NULL;
|
strm.msg = ''; /*Z_NULL*/
|
||||||
if (state.wrap) { /* to support ill-conceived Java test suite */
|
if (state.wrap) { /* to support ill-conceived Java test suite */
|
||||||
strm.adler = state.wrap & 1;
|
strm.adler = state.wrap & 1;
|
||||||
}
|
}
|
||||||
|
@ -170,13 +169,10 @@ function inflateResetKeep(strm) {
|
||||||
state.last = 0;
|
state.last = 0;
|
||||||
state.havedict = 0;
|
state.havedict = 0;
|
||||||
state.dmax = 32768;
|
state.dmax = 32768;
|
||||||
// TODO: may be {}
|
|
||||||
state.head = null/*Z_NULL*/;
|
state.head = null/*Z_NULL*/;
|
||||||
state.hold = 0;
|
state.hold = 0;
|
||||||
state.bits = 0;
|
state.bits = 0;
|
||||||
//state.lencode = state.distcode = state.next = state.codes;
|
//state.lencode = state.distcode = state.next = state.codes;
|
||||||
//utils.arraySet(state.lencode,state.codes,0,state.codes.length,0);
|
|
||||||
//utils.arraySet(state.distcode,state.codes,0,state.codes.length,0);
|
|
||||||
state.lencode = new utils.Buf32(ENOUGH);
|
state.lencode = new utils.Buf32(ENOUGH);
|
||||||
state.distcode = new utils.Buf32(ENOUGH);
|
state.distcode = new utils.Buf32(ENOUGH);
|
||||||
|
|
||||||
|
@ -269,8 +265,6 @@ function inflateInit(strm) {
|
||||||
*/
|
*/
|
||||||
var virgin = true;
|
var virgin = true;
|
||||||
|
|
||||||
// TODO: check if we can use single array forbetter CPU cache use
|
|
||||||
// That will require to pass offset, when operating with distance tables.
|
|
||||||
var lenfix, distfix; // We have no pointers in JS, so keep tables separate
|
var lenfix, distfix; // We have no pointers in JS, so keep tables separate
|
||||||
|
|
||||||
function fixedtables(state) {
|
function fixedtables(state) {
|
||||||
|
@ -376,9 +370,9 @@ function inflate(strm, flush) {
|
||||||
var from; /* where to copy match bytes from */
|
var from; /* where to copy match bytes from */
|
||||||
var from_source;
|
var from_source;
|
||||||
var here = 0; /* current decoding table entry */
|
var here = 0; /* current decoding table entry */
|
||||||
var here_bits, here_op, here_val;
|
var here_bits, here_op, here_val; // paked "here" denormalized (JS specific)
|
||||||
//var last; /* parent table entry */
|
//var last; /* parent table entry */
|
||||||
var last_bits, last_op, last_val; // paked "last" denormalized
|
var last_bits, last_op, last_val; // paked "last" denormalized (JS specific)
|
||||||
var len; /* length to copy for repeats, bits to drop */
|
var len; /* length to copy for repeats, bits to drop */
|
||||||
var ret; /* return code */
|
var ret; /* return code */
|
||||||
var hbuf = new utils.Buf8(4); /* buffer for gzip header crc calculation */
|
var hbuf = new utils.Buf8(4); /* buffer for gzip header crc calculation */
|
||||||
|
@ -905,10 +899,9 @@ function inflate(strm, flush) {
|
||||||
while (state.have < 19) {
|
while (state.have < 19) {
|
||||||
state.lens[order[state.have++]] = 0;
|
state.lens[order[state.have++]] = 0;
|
||||||
}
|
}
|
||||||
|
// We have separate tables & no pointers. 2 commented lines below not needed.
|
||||||
//state.next = state.codes;
|
//state.next = state.codes;
|
||||||
// TODO:
|
|
||||||
//state.lencode = state.next;
|
//state.lencode = state.next;
|
||||||
//state.lencode.copy(state.codes);
|
|
||||||
utils.arraySet(state.lencode, state.codes, 0, state.codes.length, 0);
|
utils.arraySet(state.lencode, state.codes, 0, state.codes.length, 0);
|
||||||
state.lenbits = 7;
|
state.lenbits = 7;
|
||||||
|
|
||||||
|
@ -1047,9 +1040,10 @@ function inflate(strm, flush) {
|
||||||
|
|
||||||
opts = {bits: state.lenbits};
|
opts = {bits: state.lenbits};
|
||||||
ret = inflate_table(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts);
|
ret = inflate_table(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts);
|
||||||
// state.next_index = opts.table_index;
|
// We have separate tables & no pointers. 2 commented lines below not needed.
|
||||||
|
// state.next_index = opts.table_index;
|
||||||
state.lenbits = opts.bits;
|
state.lenbits = opts.bits;
|
||||||
// state.lencode = state.next;
|
// state.lencode = state.next;
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
strm.msg = 'invalid literal/lengths set';
|
strm.msg = 'invalid literal/lengths set';
|
||||||
|
@ -1062,9 +1056,10 @@ function inflate(strm, flush) {
|
||||||
utils.arraySet(state.distcode, state.codes, 0, state.codes.length, 0);
|
utils.arraySet(state.distcode, state.codes, 0, state.codes.length, 0);
|
||||||
opts = {bits: state.distbits};
|
opts = {bits: state.distbits};
|
||||||
ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts);
|
ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts);
|
||||||
// state.next_index = opts.table_index;
|
// We have separate tables & no pointers. 2 commented lines below not needed.
|
||||||
|
// state.next_index = opts.table_index;
|
||||||
state.distbits = opts.bits;
|
state.distbits = opts.bits;
|
||||||
// state.distcode = state.next;
|
// state.distcode = state.next;
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
strm.msg = 'invalid distances set';
|
strm.msg = 'invalid distances set';
|
||||||
|
@ -1287,8 +1282,10 @@ function inflate(strm, flush) {
|
||||||
state.mode = BAD;
|
state.mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// (!) This block is disabled in zlib defailts,
|
||||||
|
// don't enable it for binary compatibility
|
||||||
//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
||||||
//Trace((stderr, "inflate.c too far\n"));
|
// Trace((stderr, "inflate.c too far\n"));
|
||||||
// copy -= state.whave;
|
// copy -= state.whave;
|
||||||
// if (copy > state.length) { copy = state.length; }
|
// if (copy > state.length) { copy = state.length; }
|
||||||
// if (copy > left) { copy = left; }
|
// if (copy > left) { copy = left; }
|
||||||
|
|
|
@ -305,7 +305,7 @@ module.exports = function inflate_table(type, lens, lens_index, codes, table, ta
|
||||||
/*table.op[low] = curr;
|
/*table.op[low] = curr;
|
||||||
table.bits[low] = root;
|
table.bits[low] = root;
|
||||||
table.val[low] = next - opts.table_index;*/
|
table.val[low] = next - opts.table_index;*/
|
||||||
table[low] = (root << 24) | (curr << 16) | (next - table_index);
|
table[low] = (root << 24) | (curr << 16) | (next - table_index) |0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ module.exports = function inflate_table(type, lens, lens_index, codes, table, ta
|
||||||
//table.op[next + huff] = 64; /* invalid code marker */
|
//table.op[next + huff] = 64; /* invalid code marker */
|
||||||
//table.bits[next + huff] = len - drop;
|
//table.bits[next + huff] = len - drop;
|
||||||
//table.val[next + huff] = 0;
|
//table.val[next + huff] = 0;
|
||||||
table[next + huff] = ((len - drop) << 24) | (64 << 16) | 0;
|
table[next + huff] = ((len - drop) << 24) | (64 << 16) |0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set return parameters */
|
/* set return parameters */
|
||||||
|
|
|
@ -22,7 +22,7 @@ var Z_UNKNOWN = 2;
|
||||||
/*============================================================================*/
|
/*============================================================================*/
|
||||||
|
|
||||||
|
|
||||||
function zero(buf) { var len = buf.length; while (--len) { buf[len] = 0; } }
|
function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
|
||||||
|
|
||||||
// From zutil.h
|
// From zutil.h
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue