1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222 |
- 'use strict';
- var utils = require('../utils/common');
- var Z_FIXED = 4;
- var Z_BINARY = 0;
- var Z_TEXT = 1;
- var Z_UNKNOWN = 2;
- function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
- var STORED_BLOCK = 0;
- var STATIC_TREES = 1;
- var DYN_TREES = 2;
- var MIN_MATCH = 3;
- var MAX_MATCH = 258;
- var LENGTH_CODES = 29;
- var LITERALS = 256;
- var L_CODES = LITERALS + 1 + LENGTH_CODES;
- var D_CODES = 30;
- var BL_CODES = 19;
- var HEAP_SIZE = 2 * L_CODES + 1;
- var MAX_BITS = 15;
- var Buf_size = 16;
- var MAX_BL_BITS = 7;
- var END_BLOCK = 256;
- var REP_3_6 = 16;
- var REPZ_3_10 = 17;
- var REPZ_11_138 = 18;
- var extra_lbits =
- [0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0];
- var extra_dbits =
- [0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];
- var extra_blbits =
- [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7];
- var bl_order =
- [16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];
- var DIST_CODE_LEN = 512;
- var static_ltree = new Array((L_CODES + 2) * 2);
- zero(static_ltree);
- var static_dtree = new Array(D_CODES * 2);
- zero(static_dtree);
- var _dist_code = new Array(DIST_CODE_LEN);
- zero(_dist_code);
- var _length_code = new Array(MAX_MATCH - MIN_MATCH + 1);
- zero(_length_code);
- var base_length = new Array(LENGTH_CODES);
- zero(base_length);
- var base_dist = new Array(D_CODES);
- zero(base_dist);
- function StaticTreeDesc(static_tree, extra_bits, extra_base, elems, max_length) {
- this.static_tree = static_tree;
- this.extra_bits = extra_bits;
- this.extra_base = extra_base;
- this.elems = elems;
- this.max_length = max_length;
-
- this.has_stree = static_tree && static_tree.length;
- }
- var static_l_desc;
- var static_d_desc;
- var static_bl_desc;
- function TreeDesc(dyn_tree, stat_desc) {
- this.dyn_tree = dyn_tree;
- this.max_code = 0;
- this.stat_desc = stat_desc;
- }
- function d_code(dist) {
- return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];
- }
- function put_short(s, w) {
- s.pending_buf[s.pending++] = (w) & 0xff;
- s.pending_buf[s.pending++] = (w >>> 8) & 0xff;
- }
- function send_bits(s, value, length) {
- if (s.bi_valid > (Buf_size - length)) {
- s.bi_buf |= (value << s.bi_valid) & 0xffff;
- put_short(s, s.bi_buf);
- s.bi_buf = value >> (Buf_size - s.bi_valid);
- s.bi_valid += length - Buf_size;
- } else {
- s.bi_buf |= (value << s.bi_valid) & 0xffff;
- s.bi_valid += length;
- }
- }
- function send_code(s, c, tree) {
- send_bits(s, tree[c * 2], tree[c * 2 + 1]);
- }
- function bi_reverse(code, len) {
- var res = 0;
- do {
- res |= code & 1;
- code >>>= 1;
- res <<= 1;
- } while (--len > 0);
- return res >>> 1;
- }
- function bi_flush(s) {
- if (s.bi_valid === 16) {
- put_short(s, s.bi_buf);
- s.bi_buf = 0;
- s.bi_valid = 0;
- } else if (s.bi_valid >= 8) {
- s.pending_buf[s.pending++] = s.bi_buf & 0xff;
- s.bi_buf >>= 8;
- s.bi_valid -= 8;
- }
- }
- function gen_bitlen(s, desc)
- // deflate_state *s;
- // tree_desc *desc; /* the tree descriptor */
- {
- var tree = desc.dyn_tree;
- var max_code = desc.max_code;
- var stree = desc.stat_desc.static_tree;
- var has_stree = desc.stat_desc.has_stree;
- var extra = desc.stat_desc.extra_bits;
- var base = desc.stat_desc.extra_base;
- var max_length = desc.stat_desc.max_length;
- var h;
- var n, m;
- var bits;
- var xbits;
- var f;
- var overflow = 0;
- for (bits = 0; bits <= MAX_BITS; bits++) {
- s.bl_count[bits] = 0;
- }
-
- tree[s.heap[s.heap_max] * 2 + 1] = 0;
- for (h = s.heap_max + 1; h < HEAP_SIZE; h++) {
- n = s.heap[h];
- bits = tree[tree[n * 2 + 1] * 2 + 1] + 1;
- if (bits > max_length) {
- bits = max_length;
- overflow++;
- }
- tree[n * 2 + 1] = bits;
-
- if (n > max_code) { continue; }
- s.bl_count[bits]++;
- xbits = 0;
- if (n >= base) {
- xbits = extra[n - base];
- }
- f = tree[n * 2];
- s.opt_len += f * (bits + xbits);
- if (has_stree) {
- s.static_len += f * (stree[n * 2 + 1] + xbits);
- }
- }
- if (overflow === 0) { return; }
-
-
-
- do {
- bits = max_length - 1;
- while (s.bl_count[bits] === 0) { bits--; }
- s.bl_count[bits]--;
- s.bl_count[bits + 1] += 2;
- s.bl_count[max_length]--;
-
- overflow -= 2;
- } while (overflow > 0);
-
- for (bits = max_length; bits !== 0; bits--) {
- n = s.bl_count[bits];
- while (n !== 0) {
- m = s.heap[--h];
- if (m > max_code) { continue; }
- if (tree[m * 2 + 1] !== bits) {
-
- s.opt_len += (bits - tree[m * 2 + 1]) * tree[m * 2];
- tree[m * 2 + 1] = bits;
- }
- n--;
- }
- }
- }
- function gen_codes(tree, max_code, bl_count)
- // ct_data *tree; /* the tree to decorate */
- // int max_code; /* largest code with non zero frequency */
- // ushf *bl_count; /* number of codes at each bit length */
- {
- var next_code = new Array(MAX_BITS + 1);
- var code = 0;
- var bits;
- var n;
-
- for (bits = 1; bits <= MAX_BITS; bits++) {
- next_code[bits] = code = (code + bl_count[bits - 1]) << 1;
- }
-
-
-
-
- for (n = 0; n <= max_code; n++) {
- var len = tree[n * 2 + 1];
- if (len === 0) { continue; }
-
- tree[n * 2] = bi_reverse(next_code[len]++, len);
-
-
- }
- }
- function tr_static_init() {
- var n;
- var bits;
- var length;
- var code;
- var dist;
- var bl_count = new Array(MAX_BITS + 1);
-
-
-
-
-
- length = 0;
- for (code = 0; code < LENGTH_CODES - 1; code++) {
- base_length[code] = length;
- for (n = 0; n < (1 << extra_lbits[code]); n++) {
- _length_code[length++] = code;
- }
- }
-
-
- _length_code[length - 1] = code;
-
- dist = 0;
- for (code = 0; code < 16; code++) {
- base_dist[code] = dist;
- for (n = 0; n < (1 << extra_dbits[code]); n++) {
- _dist_code[dist++] = code;
- }
- }
-
- dist >>= 7;
- for (; code < D_CODES; code++) {
- base_dist[code] = dist << 7;
- for (n = 0; n < (1 << (extra_dbits[code] - 7)); n++) {
- _dist_code[256 + dist++] = code;
- }
- }
-
-
- for (bits = 0; bits <= MAX_BITS; bits++) {
- bl_count[bits] = 0;
- }
- n = 0;
- while (n <= 143) {
- static_ltree[n * 2 + 1] = 8;
- n++;
- bl_count[8]++;
- }
- while (n <= 255) {
- static_ltree[n * 2 + 1] = 9;
- n++;
- bl_count[9]++;
- }
- while (n <= 279) {
- static_ltree[n * 2 + 1] = 7;
- n++;
- bl_count[7]++;
- }
- while (n <= 287) {
- static_ltree[n * 2 + 1] = 8;
- n++;
- bl_count[8]++;
- }
-
- gen_codes(static_ltree, L_CODES + 1, bl_count);
-
- for (n = 0; n < D_CODES; n++) {
- static_dtree[n * 2 + 1] = 5;
- static_dtree[n * 2] = bi_reverse(n, 5);
- }
-
- static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS + 1, L_CODES, MAX_BITS);
- static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS);
- static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS);
-
- }
- function init_block(s) {
- var n;
-
- for (n = 0; n < L_CODES; n++) { s.dyn_ltree[n * 2] = 0; }
- for (n = 0; n < D_CODES; n++) { s.dyn_dtree[n * 2] = 0; }
- for (n = 0; n < BL_CODES; n++) { s.bl_tree[n * 2] = 0; }
- s.dyn_ltree[END_BLOCK * 2] = 1;
- s.opt_len = s.static_len = 0;
- s.last_lit = s.matches = 0;
- }
- function bi_windup(s)
- {
- if (s.bi_valid > 8) {
- put_short(s, s.bi_buf);
- } else if (s.bi_valid > 0) {
-
- s.pending_buf[s.pending++] = s.bi_buf;
- }
- s.bi_buf = 0;
- s.bi_valid = 0;
- }
- function copy_block(s, buf, len, header)
- //DeflateState *s;
- //charf *buf; /* the input data */
- //unsigned len; /* its length */
- //int header; /* true if block header must be written */
- {
- bi_windup(s);
- if (header) {
- put_short(s, len);
- put_short(s, ~len);
- }
- utils.arraySet(s.pending_buf, s.window, buf, len, s.pending);
- s.pending += len;
- }
- function smaller(tree, n, m, depth) {
- var _n2 = n * 2;
- var _m2 = m * 2;
- return (tree[_n2] < tree[_m2] ||
- (tree[_n2] === tree[_m2] && depth[n] <= depth[m]));
- }
- function pqdownheap(s, tree, k)
- // deflate_state *s;
- // ct_data *tree; /* the tree to restore */
- // int k; /* node to move down */
- {
- var v = s.heap[k];
- var j = k << 1;
- while (j <= s.heap_len) {
-
- if (j < s.heap_len &&
- smaller(tree, s.heap[j + 1], s.heap[j], s.depth)) {
- j++;
- }
-
- if (smaller(tree, v, s.heap[j], s.depth)) { break; }
-
- s.heap[k] = s.heap[j];
- k = j;
-
- j <<= 1;
- }
- s.heap[k] = v;
- }
- function compress_block(s, ltree, dtree)
- // deflate_state *s;
- // const ct_data *ltree; /* literal tree */
- // const ct_data *dtree; /* distance tree */
- {
- var dist;
- var lc;
- var lx = 0;
- var code;
- var extra;
- if (s.last_lit !== 0) {
- do {
- dist = (s.pending_buf[s.d_buf + lx * 2] << 8) | (s.pending_buf[s.d_buf + lx * 2 + 1]);
- lc = s.pending_buf[s.l_buf + lx];
- lx++;
- if (dist === 0) {
- send_code(s, lc, ltree);
-
- } else {
-
- code = _length_code[lc];
- send_code(s, code + LITERALS + 1, ltree);
- extra = extra_lbits[code];
- if (extra !== 0) {
- lc -= base_length[code];
- send_bits(s, lc, extra);
- }
- dist--;
- code = d_code(dist);
-
- send_code(s, code, dtree);
- extra = extra_dbits[code];
- if (extra !== 0) {
- dist -= base_dist[code];
- send_bits(s, dist, extra);
- }
- }
-
-
-
- } while (lx < s.last_lit);
- }
- send_code(s, END_BLOCK, ltree);
- }
- function build_tree(s, desc)
- // deflate_state *s;
- // tree_desc *desc; /* the tree descriptor */
- {
- var tree = desc.dyn_tree;
- var stree = desc.stat_desc.static_tree;
- var has_stree = desc.stat_desc.has_stree;
- var elems = desc.stat_desc.elems;
- var n, m;
- var max_code = -1;
- var node;
-
- s.heap_len = 0;
- s.heap_max = HEAP_SIZE;
- for (n = 0; n < elems; n++) {
- if (tree[n * 2] !== 0) {
- s.heap[++s.heap_len] = max_code = n;
- s.depth[n] = 0;
- } else {
- tree[n * 2 + 1] = 0;
- }
- }
-
- while (s.heap_len < 2) {
- node = s.heap[++s.heap_len] = (max_code < 2 ? ++max_code : 0);
- tree[node * 2] = 1;
- s.depth[node] = 0;
- s.opt_len--;
- if (has_stree) {
- s.static_len -= stree[node * 2 + 1];
- }
-
- }
- desc.max_code = max_code;
-
- for (n = (s.heap_len >> 1); n >= 1; n--) { pqdownheap(s, tree, n); }
-
- node = elems;
- do {
-
-
- n = s.heap[1];
- s.heap[1] = s.heap[s.heap_len--];
- pqdownheap(s, tree, 1);
-
- m = s.heap[1];
- s.heap[--s.heap_max] = n;
- s.heap[--s.heap_max] = m;
-
- tree[node * 2] = tree[n * 2] + tree[m * 2];
- s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;
- tree[n * 2 + 1] = tree[m * 2 + 1] = node;
-
- s.heap[1] = node++;
- pqdownheap(s, tree, 1);
- } while (s.heap_len >= 2);
- s.heap[--s.heap_max] = s.heap[1];
-
- gen_bitlen(s, desc);
-
- gen_codes(tree, max_code, s.bl_count);
- }
- function scan_tree(s, tree, max_code)
- // deflate_state *s;
- // ct_data *tree; /* the tree to be scanned */
- // int max_code; /* and its largest code of non zero frequency */
- {
- var n;
- var prevlen = -1;
- var curlen;
- var nextlen = tree[0 * 2 + 1];
- var count = 0;
- var max_count = 7;
- var min_count = 4;
- if (nextlen === 0) {
- max_count = 138;
- min_count = 3;
- }
- tree[(max_code + 1) * 2 + 1] = 0xffff;
- for (n = 0; n <= max_code; n++) {
- curlen = nextlen;
- nextlen = tree[(n + 1) * 2 + 1];
- if (++count < max_count && curlen === nextlen) {
- continue;
- } else if (count < min_count) {
- s.bl_tree[curlen * 2] += count;
- } else if (curlen !== 0) {
- if (curlen !== prevlen) { s.bl_tree[curlen * 2]++; }
- s.bl_tree[REP_3_6 * 2]++;
- } else if (count <= 10) {
- s.bl_tree[REPZ_3_10 * 2]++;
- } else {
- s.bl_tree[REPZ_11_138 * 2]++;
- }
- count = 0;
- prevlen = curlen;
- if (nextlen === 0) {
- max_count = 138;
- min_count = 3;
- } else if (curlen === nextlen) {
- max_count = 6;
- min_count = 3;
- } else {
- max_count = 7;
- min_count = 4;
- }
- }
- }
- function send_tree(s, tree, max_code)
- // deflate_state *s;
- // ct_data *tree; /* the tree to be scanned */
- // int max_code; /* and its largest code of non zero frequency */
- {
- var n;
- var prevlen = -1;
- var curlen;
- var nextlen = tree[0 * 2 + 1];
- var count = 0;
- var max_count = 7;
- var min_count = 4;
-
- if (nextlen === 0) {
- max_count = 138;
- min_count = 3;
- }
- for (n = 0; n <= max_code; n++) {
- curlen = nextlen;
- nextlen = tree[(n + 1) * 2 + 1];
- if (++count < max_count && curlen === nextlen) {
- continue;
- } else if (count < min_count) {
- do { send_code(s, curlen, s.bl_tree); } while (--count !== 0);
- } else if (curlen !== 0) {
- if (curlen !== prevlen) {
- send_code(s, curlen, s.bl_tree);
- count--;
- }
-
- send_code(s, REP_3_6, s.bl_tree);
- send_bits(s, count - 3, 2);
- } else if (count <= 10) {
- send_code(s, REPZ_3_10, s.bl_tree);
- send_bits(s, count - 3, 3);
- } else {
- send_code(s, REPZ_11_138, s.bl_tree);
- send_bits(s, count - 11, 7);
- }
- count = 0;
- prevlen = curlen;
- if (nextlen === 0) {
- max_count = 138;
- min_count = 3;
- } else if (curlen === nextlen) {
- max_count = 6;
- min_count = 3;
- } else {
- max_count = 7;
- min_count = 4;
- }
- }
- }
- function build_bl_tree(s) {
- var max_blindex;
-
- scan_tree(s, s.dyn_ltree, s.l_desc.max_code);
- scan_tree(s, s.dyn_dtree, s.d_desc.max_code);
-
- build_tree(s, s.bl_desc);
-
-
- for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) {
- if (s.bl_tree[bl_order[max_blindex] * 2 + 1] !== 0) {
- break;
- }
- }
-
- s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
-
-
- return max_blindex;
- }
- function send_all_trees(s, lcodes, dcodes, blcodes)
- // deflate_state *s;
- // int lcodes, dcodes, blcodes; /* number of codes for each tree */
- {
- var rank;
-
-
-
-
- send_bits(s, lcodes - 257, 5);
- send_bits(s, dcodes - 1, 5);
- send_bits(s, blcodes - 4, 4);
- for (rank = 0; rank < blcodes; rank++) {
-
- send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1], 3);
- }
-
- send_tree(s, s.dyn_ltree, lcodes - 1);
-
- send_tree(s, s.dyn_dtree, dcodes - 1);
-
- }
- function detect_data_type(s) {
-
- var black_mask = 0xf3ffc07f;
- var n;
-
- for (n = 0; n <= 31; n++, black_mask >>>= 1) {
- if ((black_mask & 1) && (s.dyn_ltree[n * 2] !== 0)) {
- return Z_BINARY;
- }
- }
-
- if (s.dyn_ltree[9 * 2] !== 0 || s.dyn_ltree[10 * 2] !== 0 ||
- s.dyn_ltree[13 * 2] !== 0) {
- return Z_TEXT;
- }
- for (n = 32; n < LITERALS; n++) {
- if (s.dyn_ltree[n * 2] !== 0) {
- return Z_TEXT;
- }
- }
-
- return Z_BINARY;
- }
- var static_init_done = false;
- function _tr_init(s)
- {
- if (!static_init_done) {
- tr_static_init();
- static_init_done = true;
- }
- s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc);
- s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc);
- s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc);
- s.bi_buf = 0;
- s.bi_valid = 0;
-
- init_block(s);
- }
- function _tr_stored_block(s, buf, stored_len, last)
- //DeflateState *s;
- //charf *buf; /* input block */
- //ulg stored_len; /* length of input block */
- //int last; /* one if this is the last block for a file */
- {
- send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3);
- copy_block(s, buf, stored_len, true);
- }
- function _tr_align(s) {
- send_bits(s, STATIC_TREES << 1, 3);
- send_code(s, END_BLOCK, static_ltree);
- bi_flush(s);
- }
- function _tr_flush_block(s, buf, stored_len, last)
- //DeflateState *s;
- //charf *buf; /* input block, or NULL if too old */
- //ulg stored_len; /* length of input block */
- //int last; /* one if this is the last block for a file */
- {
- var opt_lenb, static_lenb;
- var max_blindex = 0;
-
- if (s.level > 0) {
-
- if (s.strm.data_type === Z_UNKNOWN) {
- s.strm.data_type = detect_data_type(s);
- }
-
- build_tree(s, s.l_desc);
-
-
- build_tree(s, s.d_desc);
-
-
-
-
- max_blindex = build_bl_tree(s);
-
- opt_lenb = (s.opt_len + 3 + 7) >>> 3;
- static_lenb = (s.static_len + 3 + 7) >>> 3;
-
-
-
- if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }
- } else {
-
- opt_lenb = static_lenb = stored_len + 5;
- }
- if ((stored_len + 4 <= opt_lenb) && (buf !== -1)) {
-
-
- _tr_stored_block(s, buf, stored_len, last);
- } else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) {
- send_bits(s, (STATIC_TREES << 1) + (last ? 1 : 0), 3);
- compress_block(s, static_ltree, static_dtree);
- } else {
- send_bits(s, (DYN_TREES << 1) + (last ? 1 : 0), 3);
- send_all_trees(s, s.l_desc.max_code + 1, s.d_desc.max_code + 1, max_blindex + 1);
- compress_block(s, s.dyn_ltree, s.dyn_dtree);
- }
-
-
- init_block(s);
- if (last) {
- bi_windup(s);
- }
-
-
- }
- function _tr_tally(s, dist, lc)
- // deflate_state *s;
- // unsigned dist; /* distance of matched string */
- // unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
- {
-
- s.pending_buf[s.d_buf + s.last_lit * 2] = (dist >>> 8) & 0xff;
- s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff;
- s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff;
- s.last_lit++;
- if (dist === 0) {
-
- s.dyn_ltree[lc * 2]++;
- } else {
- s.matches++;
-
- dist--;
-
-
-
- s.dyn_ltree[(_length_code[lc] + LITERALS + 1) * 2]++;
- s.dyn_dtree[d_code(dist) * 2]++;
- }
- return (s.last_lit === s.lit_bufsize - 1);
-
- }
- exports._tr_init = _tr_init;
- exports._tr_stored_block = _tr_stored_block;
- exports._tr_flush_block = _tr_flush_block;
- exports._tr_tally = _tr_tally;
- exports._tr_align = _tr_align;
|