101arrowz / fflate

High performance (de)compression in an 8kB package
https://101arrowz.github.io/fflate
MIT License
2.27k stars 79 forks source link

DEFLATE `level` parameters compared to zlib #86

Closed SheetJSDev closed 3 years ago

SheetJSDev commented 3 years ago

deo is described in source as:

// deflate options (nice << 13) | chain
const deo = /*#__PURE__*/ new u32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);

If nice and chain are understood to be the tunable nice_length and max_chain parameters as defined in zlib, the constants look different from expectations. For example:

local const config configuration_table[10] = {
/*      good lazy nice chain */
/* 0 */ {0,    0,  0,    0, deflate_stored},  /* store only */
/* 1 */ {4,    4,  8,    4, deflate_fast}, /* max speed, no lazy matches */
/* 2 */ {4,    5, 16,    8, deflate_fast},
/* 3 */ {4,    6, 32,   32, deflate_fast},

/* 4 */ {4,    4, 16,   16, deflate_slow},  /* lazy matches */
/* 5 */ {8,   16, 32,   32, deflate_slow},
/* 6 */ {8,   16, 128, 128, deflate_slow},
/* 7 */ {8,   32, 128, 256, deflate_slow},
/* 8 */ {32, 128, 258, 1024, deflate_slow},
/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */

Since deo is indexed at level - 1, it would seem that deo[2] should be (32 << 13) | 32 (262176). The array would be unsorted in this case since the next level is (16 << 13) | 16 (131088)

101arrowz commented 3 years ago

Since fflate has no concept of deflate_fast vs. deflate_slow, so I used the modified parameters from uzip for these.