@leofcoin/peernet 0.14.19 → 0.14.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/pako.js +670 -501
- package/dist/browser/pako.mjs +670 -501
- package/dist/browser/peernet-swarm.js +5 -11
- package/dist/browser/peernet-swarm.mjs +5 -11
- package/dist/browser/peernet.js +2 -12
- package/dist/browser/peernet.mjs +2 -12
- package/dist/commonjs/peernet.js +1 -10
- package/dist/module/peernet.js +1 -10
- package/package.json +2 -2
- package/src/peernet.js +1 -10
package/dist/browser/pako.js
CHANGED
|
@@ -18,7 +18,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
18
18
|
/* harmony export */ "ungzip": function() { return /* binding */ ungzip_1; }
|
|
19
19
|
/* harmony export */ });
|
|
20
20
|
|
|
21
|
-
/*! pako 2.0
|
|
21
|
+
/*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */
|
|
22
22
|
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
|
|
23
23
|
// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
|
|
24
24
|
//
|
|
@@ -295,10 +295,10 @@ const bi_flush = (s) => {
|
|
|
295
295
|
* The length opt_len is updated; static_len is also updated if stree is
|
|
296
296
|
* not null.
|
|
297
297
|
*/
|
|
298
|
-
const gen_bitlen = (s, desc) =>
|
|
298
|
+
const gen_bitlen = (s, desc) => {
|
|
299
299
|
// deflate_state *s;
|
|
300
300
|
// tree_desc *desc; /* the tree descriptor */
|
|
301
|
-
|
|
301
|
+
|
|
302
302
|
const tree = desc.dyn_tree;
|
|
303
303
|
const max_code = desc.max_code;
|
|
304
304
|
const stree = desc.stat_desc.static_tree;
|
|
@@ -347,7 +347,7 @@ const gen_bitlen = (s, desc) =>
|
|
|
347
347
|
}
|
|
348
348
|
if (overflow === 0) { return; }
|
|
349
349
|
|
|
350
|
-
//
|
|
350
|
+
// Tracev((stderr,"\nbit length overflow\n"));
|
|
351
351
|
/* This happens for example on obj2 and pic of the Calgary corpus */
|
|
352
352
|
|
|
353
353
|
/* Find the first bit length which could increase: */
|
|
@@ -374,7 +374,7 @@ const gen_bitlen = (s, desc) =>
|
|
|
374
374
|
m = s.heap[--h];
|
|
375
375
|
if (m > max_code) { continue; }
|
|
376
376
|
if (tree[m * 2 + 1]/*.Len*/ !== bits) {
|
|
377
|
-
//
|
|
377
|
+
// Tracev((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
|
|
378
378
|
s.opt_len += (bits - tree[m * 2 + 1]/*.Len*/) * tree[m * 2]/*.Freq*/;
|
|
379
379
|
tree[m * 2 + 1]/*.Len*/ = bits;
|
|
380
380
|
}
|
|
@@ -392,11 +392,11 @@ const gen_bitlen = (s, desc) =>
|
|
|
392
392
|
* OUT assertion: the field code is set for all tree elements of non
|
|
393
393
|
* zero code length.
|
|
394
394
|
*/
|
|
395
|
-
const gen_codes = (tree, max_code, bl_count) =>
|
|
395
|
+
const gen_codes = (tree, max_code, bl_count) => {
|
|
396
396
|
// ct_data *tree; /* the tree to decorate */
|
|
397
397
|
// int max_code; /* largest code with non zero frequency */
|
|
398
398
|
// ushf *bl_count; /* number of codes at each bit length */
|
|
399
|
-
|
|
399
|
+
|
|
400
400
|
const next_code = new Array(MAX_BITS$1 + 1); /* next code value for each bit length */
|
|
401
401
|
let code = 0; /* running code value */
|
|
402
402
|
let bits; /* bit index */
|
|
@@ -406,7 +406,8 @@ const gen_codes = (tree, max_code, bl_count) =>
|
|
|
406
406
|
* without bit reversal.
|
|
407
407
|
*/
|
|
408
408
|
for (bits = 1; bits <= MAX_BITS$1; bits++) {
|
|
409
|
-
|
|
409
|
+
code = (code + bl_count[bits - 1]) << 1;
|
|
410
|
+
next_code[bits] = code;
|
|
410
411
|
}
|
|
411
412
|
/* Check that the bit counts in bl_count are consistent. The last code
|
|
412
413
|
* must be all ones.
|
|
@@ -546,7 +547,7 @@ const init_block = (s) => {
|
|
|
546
547
|
|
|
547
548
|
s.dyn_ltree[END_BLOCK * 2]/*.Freq*/ = 1;
|
|
548
549
|
s.opt_len = s.static_len = 0;
|
|
549
|
-
s.
|
|
550
|
+
s.sym_next = s.matches = 0;
|
|
550
551
|
};
|
|
551
552
|
|
|
552
553
|
|
|
@@ -565,29 +566,6 @@ const bi_windup = (s) =>
|
|
|
565
566
|
s.bi_valid = 0;
|
|
566
567
|
};
|
|
567
568
|
|
|
568
|
-
/* ===========================================================================
|
|
569
|
-
* Copy a stored block, storing first the length and its
|
|
570
|
-
* one's complement if requested.
|
|
571
|
-
*/
|
|
572
|
-
const copy_block = (s, buf, len, header) =>
|
|
573
|
-
//DeflateState *s;
|
|
574
|
-
//charf *buf; /* the input data */
|
|
575
|
-
//unsigned len; /* its length */
|
|
576
|
-
//int header; /* true if block header must be written */
|
|
577
|
-
{
|
|
578
|
-
bi_windup(s); /* align on byte boundary */
|
|
579
|
-
|
|
580
|
-
if (header) {
|
|
581
|
-
put_short(s, len);
|
|
582
|
-
put_short(s, ~len);
|
|
583
|
-
}
|
|
584
|
-
// while (len--) {
|
|
585
|
-
// put_byte(s, *buf++);
|
|
586
|
-
// }
|
|
587
|
-
s.pending_buf.set(s.window.subarray(buf, buf + len), s.pending);
|
|
588
|
-
s.pending += len;
|
|
589
|
-
};
|
|
590
|
-
|
|
591
569
|
/* ===========================================================================
|
|
592
570
|
* Compares to subtrees, using the tree depth as tie breaker when
|
|
593
571
|
* the subtrees have equal frequency. This minimizes the worst case length.
|
|
@@ -606,11 +584,11 @@ const smaller = (tree, n, m, depth) => {
|
|
|
606
584
|
* when the heap property is re-established (each father smaller than its
|
|
607
585
|
* two sons).
|
|
608
586
|
*/
|
|
609
|
-
const pqdownheap = (s, tree, k) =>
|
|
587
|
+
const pqdownheap = (s, tree, k) => {
|
|
610
588
|
// deflate_state *s;
|
|
611
589
|
// ct_data *tree; /* the tree to restore */
|
|
612
590
|
// int k; /* node to move down */
|
|
613
|
-
|
|
591
|
+
|
|
614
592
|
const v = s.heap[k];
|
|
615
593
|
let j = k << 1; /* left son of k */
|
|
616
594
|
while (j <= s.heap_len) {
|
|
@@ -639,23 +617,22 @@ const pqdownheap = (s, tree, k) =>
|
|
|
639
617
|
/* ===========================================================================
|
|
640
618
|
* Send the block data compressed using the given Huffman trees
|
|
641
619
|
*/
|
|
642
|
-
const compress_block = (s, ltree, dtree) =>
|
|
620
|
+
const compress_block = (s, ltree, dtree) => {
|
|
643
621
|
// deflate_state *s;
|
|
644
622
|
// const ct_data *ltree; /* literal tree */
|
|
645
623
|
// const ct_data *dtree; /* distance tree */
|
|
646
|
-
|
|
624
|
+
|
|
647
625
|
let dist; /* distance of matched string */
|
|
648
626
|
let lc; /* match length or unmatched char (if dist == 0) */
|
|
649
|
-
let
|
|
627
|
+
let sx = 0; /* running index in sym_buf */
|
|
650
628
|
let code; /* the code to send */
|
|
651
629
|
let extra; /* number of extra bits to send */
|
|
652
630
|
|
|
653
|
-
if (s.
|
|
631
|
+
if (s.sym_next !== 0) {
|
|
654
632
|
do {
|
|
655
|
-
dist =
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
633
|
+
dist = s.pending_buf[s.sym_buf + sx++] & 0xff;
|
|
634
|
+
dist += (s.pending_buf[s.sym_buf + sx++] & 0xff) << 8;
|
|
635
|
+
lc = s.pending_buf[s.sym_buf + sx++];
|
|
659
636
|
if (dist === 0) {
|
|
660
637
|
send_code(s, lc, ltree); /* send a literal byte */
|
|
661
638
|
//Tracecv(isgraph(lc), (stderr," '%c' ", lc));
|
|
@@ -680,11 +657,10 @@ const compress_block = (s, ltree, dtree) =>
|
|
|
680
657
|
}
|
|
681
658
|
} /* literal or match pair ? */
|
|
682
659
|
|
|
683
|
-
/* Check that the overlay between pending_buf and
|
|
684
|
-
//Assert(
|
|
685
|
-
// "pendingBuf overflow");
|
|
660
|
+
/* Check that the overlay between pending_buf and sym_buf is ok: */
|
|
661
|
+
//Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow");
|
|
686
662
|
|
|
687
|
-
} while (
|
|
663
|
+
} while (sx < s.sym_next);
|
|
688
664
|
}
|
|
689
665
|
|
|
690
666
|
send_code(s, END_BLOCK, ltree);
|
|
@@ -699,10 +675,10 @@ const compress_block = (s, ltree, dtree) =>
|
|
|
699
675
|
* and corresponding code. The length opt_len is updated; static_len is
|
|
700
676
|
* also updated if stree is not null. The field max_code is set.
|
|
701
677
|
*/
|
|
702
|
-
const build_tree = (s, desc) =>
|
|
678
|
+
const build_tree = (s, desc) => {
|
|
703
679
|
// deflate_state *s;
|
|
704
680
|
// tree_desc *desc; /* the tree descriptor */
|
|
705
|
-
|
|
681
|
+
|
|
706
682
|
const tree = desc.dyn_tree;
|
|
707
683
|
const stree = desc.stat_desc.static_tree;
|
|
708
684
|
const has_stree = desc.stat_desc.has_stree;
|
|
@@ -795,11 +771,11 @@ const build_tree = (s, desc) =>
|
|
|
795
771
|
* Scan a literal or distance tree to determine the frequencies of the codes
|
|
796
772
|
* in the bit length tree.
|
|
797
773
|
*/
|
|
798
|
-
const scan_tree = (s, tree, max_code) =>
|
|
774
|
+
const scan_tree = (s, tree, max_code) => {
|
|
799
775
|
// deflate_state *s;
|
|
800
776
|
// ct_data *tree; /* the tree to be scanned */
|
|
801
777
|
// int max_code; /* and its largest code of non zero frequency */
|
|
802
|
-
|
|
778
|
+
|
|
803
779
|
let n; /* iterates over all tree elements */
|
|
804
780
|
let prevlen = -1; /* last emitted length */
|
|
805
781
|
let curlen; /* length of current code */
|
|
@@ -861,11 +837,11 @@ const scan_tree = (s, tree, max_code) =>
|
|
|
861
837
|
* Send a literal or distance tree in compressed form, using the codes in
|
|
862
838
|
* bl_tree.
|
|
863
839
|
*/
|
|
864
|
-
const send_tree = (s, tree, max_code) =>
|
|
840
|
+
const send_tree = (s, tree, max_code) => {
|
|
865
841
|
// deflate_state *s;
|
|
866
842
|
// ct_data *tree; /* the tree to be scanned */
|
|
867
843
|
// int max_code; /* and its largest code of non zero frequency */
|
|
868
|
-
|
|
844
|
+
|
|
869
845
|
let n; /* iterates over all tree elements */
|
|
870
846
|
let prevlen = -1; /* last emitted length */
|
|
871
847
|
let curlen; /* length of current code */
|
|
@@ -969,10 +945,10 @@ const build_bl_tree = (s) => {
|
|
|
969
945
|
* lengths of the bit length codes, the literal tree and the distance tree.
|
|
970
946
|
* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
|
|
971
947
|
*/
|
|
972
|
-
const send_all_trees = (s, lcodes, dcodes, blcodes) =>
|
|
948
|
+
const send_all_trees = (s, lcodes, dcodes, blcodes) => {
|
|
973
949
|
// deflate_state *s;
|
|
974
950
|
// int lcodes, dcodes, blcodes; /* number of codes for each tree */
|
|
975
|
-
|
|
951
|
+
|
|
976
952
|
let rank; /* index in bl_order */
|
|
977
953
|
|
|
978
954
|
//Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
|
|
@@ -1000,9 +976,9 @@ const send_all_trees = (s, lcodes, dcodes, blcodes) =>
|
|
|
1000
976
|
* Check if the data type is TEXT or BINARY, using the following algorithm:
|
|
1001
977
|
* - TEXT if the two conditions below are satisfied:
|
|
1002
978
|
* a) There are no non-portable control characters belonging to the
|
|
1003
|
-
* "
|
|
979
|
+
* "block list" (0..6, 14..25, 28..31).
|
|
1004
980
|
* b) There is at least one printable character belonging to the
|
|
1005
|
-
* "
|
|
981
|
+
* "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
|
|
1006
982
|
* - BINARY otherwise.
|
|
1007
983
|
* - The following partially-portable control characters form a
|
|
1008
984
|
* "gray list" that is ignored in this detection algorithm:
|
|
@@ -1010,21 +986,21 @@ const send_all_trees = (s, lcodes, dcodes, blcodes) =>
|
|
|
1010
986
|
* IN assertion: the fields Freq of dyn_ltree are set.
|
|
1011
987
|
*/
|
|
1012
988
|
const detect_data_type = (s) => {
|
|
1013
|
-
/*
|
|
989
|
+
/* block_mask is the bit mask of block-listed bytes
|
|
1014
990
|
* set bits 0..6, 14..25, and 28..31
|
|
1015
991
|
* 0xf3ffc07f = binary 11110011111111111100000001111111
|
|
1016
992
|
*/
|
|
1017
|
-
let
|
|
993
|
+
let block_mask = 0xf3ffc07f;
|
|
1018
994
|
let n;
|
|
1019
995
|
|
|
1020
|
-
/* Check for non-textual ("
|
|
1021
|
-
for (n = 0; n <= 31; n++,
|
|
1022
|
-
if ((
|
|
996
|
+
/* Check for non-textual ("block-listed") bytes. */
|
|
997
|
+
for (n = 0; n <= 31; n++, block_mask >>>= 1) {
|
|
998
|
+
if ((block_mask & 1) && (s.dyn_ltree[n * 2]/*.Freq*/ !== 0)) {
|
|
1023
999
|
return Z_BINARY;
|
|
1024
1000
|
}
|
|
1025
1001
|
}
|
|
1026
1002
|
|
|
1027
|
-
/* Check for textual ("
|
|
1003
|
+
/* Check for textual ("allow-listed") bytes. */
|
|
1028
1004
|
if (s.dyn_ltree[9 * 2]/*.Freq*/ !== 0 || s.dyn_ltree[10 * 2]/*.Freq*/ !== 0 ||
|
|
1029
1005
|
s.dyn_ltree[13 * 2]/*.Freq*/ !== 0) {
|
|
1030
1006
|
return Z_TEXT;
|
|
@@ -1035,7 +1011,7 @@ const detect_data_type = (s) => {
|
|
|
1035
1011
|
}
|
|
1036
1012
|
}
|
|
1037
1013
|
|
|
1038
|
-
/* There are no "
|
|
1014
|
+
/* There are no "block-listed" or "allow-listed" bytes:
|
|
1039
1015
|
* this stream either is empty or has tolerated ("gray-listed") bytes only.
|
|
1040
1016
|
*/
|
|
1041
1017
|
return Z_BINARY;
|
|
@@ -1070,14 +1046,20 @@ const _tr_init$1 = (s) =>
|
|
|
1070
1046
|
/* ===========================================================================
|
|
1071
1047
|
* Send a stored block
|
|
1072
1048
|
*/
|
|
1073
|
-
const _tr_stored_block$1 = (s, buf, stored_len, last) =>
|
|
1049
|
+
const _tr_stored_block$1 = (s, buf, stored_len, last) => {
|
|
1074
1050
|
//DeflateState *s;
|
|
1075
1051
|
//charf *buf; /* input block */
|
|
1076
1052
|
//ulg stored_len; /* length of input block */
|
|
1077
1053
|
//int last; /* one if this is the last block for a file */
|
|
1078
|
-
|
|
1054
|
+
|
|
1079
1055
|
send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3); /* send block type */
|
|
1080
|
-
|
|
1056
|
+
bi_windup(s); /* align on byte boundary */
|
|
1057
|
+
put_short(s, stored_len);
|
|
1058
|
+
put_short(s, ~stored_len);
|
|
1059
|
+
if (stored_len) {
|
|
1060
|
+
s.pending_buf.set(s.window.subarray(buf, buf + stored_len), s.pending);
|
|
1061
|
+
}
|
|
1062
|
+
s.pending += stored_len;
|
|
1081
1063
|
};
|
|
1082
1064
|
|
|
1083
1065
|
|
|
@@ -1094,14 +1076,14 @@ const _tr_align$1 = (s) => {
|
|
|
1094
1076
|
|
|
1095
1077
|
/* ===========================================================================
|
|
1096
1078
|
* Determine the best encoding for the current block: dynamic trees, static
|
|
1097
|
-
* trees or store, and
|
|
1079
|
+
* trees or store, and write out the encoded block.
|
|
1098
1080
|
*/
|
|
1099
|
-
const _tr_flush_block$1 = (s, buf, stored_len, last) =>
|
|
1081
|
+
const _tr_flush_block$1 = (s, buf, stored_len, last) => {
|
|
1100
1082
|
//DeflateState *s;
|
|
1101
1083
|
//charf *buf; /* input block, or NULL if too old */
|
|
1102
1084
|
//ulg stored_len; /* length of input block */
|
|
1103
1085
|
//int last; /* one if this is the last block for a file */
|
|
1104
|
-
|
|
1086
|
+
|
|
1105
1087
|
let opt_lenb, static_lenb; /* opt_len and static_len in bytes */
|
|
1106
1088
|
let max_blindex = 0; /* index of last bit length code of non zero freq */
|
|
1107
1089
|
|
|
@@ -1136,7 +1118,7 @@ const _tr_flush_block$1 = (s, buf, stored_len, last) =>
|
|
|
1136
1118
|
|
|
1137
1119
|
// Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
|
|
1138
1120
|
// opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
|
|
1139
|
-
// s->
|
|
1121
|
+
// s->sym_next / 3));
|
|
1140
1122
|
|
|
1141
1123
|
if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }
|
|
1142
1124
|
|
|
@@ -1183,19 +1165,14 @@ const _tr_flush_block$1 = (s, buf, stored_len, last) =>
|
|
|
1183
1165
|
* Save the match info and tally the frequency counts. Return true if
|
|
1184
1166
|
* the current block must be flushed.
|
|
1185
1167
|
*/
|
|
1186
|
-
const _tr_tally$1 = (s, dist, lc) =>
|
|
1168
|
+
const _tr_tally$1 = (s, dist, lc) => {
|
|
1187
1169
|
// deflate_state *s;
|
|
1188
1170
|
// unsigned dist; /* distance of matched string */
|
|
1189
1171
|
// unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
|
|
1190
|
-
{
|
|
1191
|
-
//let out_length, in_length, dcode;
|
|
1192
|
-
|
|
1193
|
-
s.pending_buf[s.d_buf + s.last_lit * 2] = (dist >>> 8) & 0xff;
|
|
1194
|
-
s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff;
|
|
1195
|
-
|
|
1196
|
-
s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff;
|
|
1197
|
-
s.last_lit++;
|
|
1198
1172
|
|
|
1173
|
+
s.pending_buf[s.sym_buf + s.sym_next++] = dist;
|
|
1174
|
+
s.pending_buf[s.sym_buf + s.sym_next++] = dist >> 8;
|
|
1175
|
+
s.pending_buf[s.sym_buf + s.sym_next++] = lc;
|
|
1199
1176
|
if (dist === 0) {
|
|
1200
1177
|
/* lc is the unmatched char */
|
|
1201
1178
|
s.dyn_ltree[lc * 2]/*.Freq*/++;
|
|
@@ -1211,34 +1188,7 @@ const _tr_tally$1 = (s, dist, lc) =>
|
|
|
1211
1188
|
s.dyn_dtree[d_code(dist) * 2]/*.Freq*/++;
|
|
1212
1189
|
}
|
|
1213
1190
|
|
|
1214
|
-
|
|
1215
|
-
// don't enable it for binary compatibility
|
|
1216
|
-
|
|
1217
|
-
//#ifdef TRUNCATE_BLOCK
|
|
1218
|
-
// /* Try to guess if it is profitable to stop the current block here */
|
|
1219
|
-
// if ((s.last_lit & 0x1fff) === 0 && s.level > 2) {
|
|
1220
|
-
// /* Compute an upper bound for the compressed length */
|
|
1221
|
-
// out_length = s.last_lit*8;
|
|
1222
|
-
// in_length = s.strstart - s.block_start;
|
|
1223
|
-
//
|
|
1224
|
-
// for (dcode = 0; dcode < D_CODES; dcode++) {
|
|
1225
|
-
// out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]);
|
|
1226
|
-
// }
|
|
1227
|
-
// out_length >>>= 3;
|
|
1228
|
-
// //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
|
|
1229
|
-
// // s->last_lit, in_length, out_length,
|
|
1230
|
-
// // 100L - out_length*100L/in_length));
|
|
1231
|
-
// if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) {
|
|
1232
|
-
// return true;
|
|
1233
|
-
// }
|
|
1234
|
-
// }
|
|
1235
|
-
//#endif
|
|
1236
|
-
|
|
1237
|
-
return (s.last_lit === s.lit_bufsize - 1);
|
|
1238
|
-
/* We avoid equality with lit_bufsize because of wraparound at 64K
|
|
1239
|
-
* on 16 bit machines and because stored blocks are restricted to
|
|
1240
|
-
* 64K-1 bytes.
|
|
1241
|
-
*/
|
|
1191
|
+
return (s.sym_next === s.sym_end);
|
|
1242
1192
|
};
|
|
1243
1193
|
|
|
1244
1194
|
var _tr_init_1 = _tr_init$1;
|
|
@@ -1528,13 +1478,16 @@ const MIN_LOOKAHEAD = (MAX_MATCH + MIN_MATCH + 1);
|
|
|
1528
1478
|
|
|
1529
1479
|
const PRESET_DICT = 0x20;
|
|
1530
1480
|
|
|
1531
|
-
const INIT_STATE
|
|
1532
|
-
|
|
1533
|
-
const
|
|
1534
|
-
|
|
1535
|
-
const
|
|
1536
|
-
const
|
|
1537
|
-
const
|
|
1481
|
+
const INIT_STATE = 42; /* zlib header -> BUSY_STATE */
|
|
1482
|
+
//#ifdef GZIP
|
|
1483
|
+
const GZIP_STATE = 57; /* gzip header -> BUSY_STATE | EXTRA_STATE */
|
|
1484
|
+
//#endif
|
|
1485
|
+
const EXTRA_STATE = 69; /* gzip extra block -> NAME_STATE */
|
|
1486
|
+
const NAME_STATE = 73; /* gzip file name -> COMMENT_STATE */
|
|
1487
|
+
const COMMENT_STATE = 91; /* gzip comment -> HCRC_STATE */
|
|
1488
|
+
const HCRC_STATE = 103; /* gzip header CRC -> BUSY_STATE */
|
|
1489
|
+
const BUSY_STATE = 113; /* deflate -> FINISH_STATE */
|
|
1490
|
+
const FINISH_STATE = 666; /* stream complete */
|
|
1538
1491
|
|
|
1539
1492
|
const BS_NEED_MORE = 1; /* block not completed, need more input or more output */
|
|
1540
1493
|
const BS_BLOCK_DONE = 2; /* block flush performed */
|
|
@@ -1549,13 +1502,41 @@ const err = (strm, errorCode) => {
|
|
|
1549
1502
|
};
|
|
1550
1503
|
|
|
1551
1504
|
const rank = (f) => {
|
|
1552
|
-
return ((f)
|
|
1505
|
+
return ((f) * 2) - ((f) > 4 ? 9 : 0);
|
|
1553
1506
|
};
|
|
1554
1507
|
|
|
1555
1508
|
const zero = (buf) => {
|
|
1556
1509
|
let len = buf.length; while (--len >= 0) { buf[len] = 0; }
|
|
1557
1510
|
};
|
|
1558
1511
|
|
|
1512
|
+
/* ===========================================================================
|
|
1513
|
+
* Slide the hash table when sliding the window down (could be avoided with 32
|
|
1514
|
+
* bit values at the expense of memory usage). We slide even when level == 0 to
|
|
1515
|
+
* keep the hash table consistent if we switch back to level > 0 later.
|
|
1516
|
+
*/
|
|
1517
|
+
const slide_hash = (s) => {
|
|
1518
|
+
let n, m;
|
|
1519
|
+
let p;
|
|
1520
|
+
let wsize = s.w_size;
|
|
1521
|
+
|
|
1522
|
+
n = s.hash_size;
|
|
1523
|
+
p = n;
|
|
1524
|
+
do {
|
|
1525
|
+
m = s.head[--p];
|
|
1526
|
+
s.head[p] = (m >= wsize ? m - wsize : 0);
|
|
1527
|
+
} while (--n);
|
|
1528
|
+
n = wsize;
|
|
1529
|
+
//#ifndef FASTEST
|
|
1530
|
+
p = n;
|
|
1531
|
+
do {
|
|
1532
|
+
m = s.prev[--p];
|
|
1533
|
+
s.prev[p] = (m >= wsize ? m - wsize : 0);
|
|
1534
|
+
/* If n is not on any hash chain, prev[n] is garbage but
|
|
1535
|
+
* its value will never be used.
|
|
1536
|
+
*/
|
|
1537
|
+
} while (--n);
|
|
1538
|
+
//#endif
|
|
1539
|
+
};
|
|
1559
1540
|
|
|
1560
1541
|
/* eslint-disable new-cap */
|
|
1561
1542
|
let HASH_ZLIB = (s, prev, data) => ((prev << s.hash_shift) ^ data) & s.hash_mask;
|
|
@@ -1564,11 +1545,12 @@ let HASH_ZLIB = (s, prev, data) => ((prev << s.hash_shift) ^ data) & s.hash_mask
|
|
|
1564
1545
|
//let HASH_FAST = (s, prev, data) => ((prev << 8) + (prev >> 8) + (data << 4)) & s.hash_mask;
|
|
1565
1546
|
let HASH = HASH_ZLIB;
|
|
1566
1547
|
|
|
1548
|
+
|
|
1567
1549
|
/* =========================================================================
|
|
1568
|
-
* Flush as much pending output as possible. All deflate() output
|
|
1569
|
-
* through this function so some
|
|
1570
|
-
*
|
|
1571
|
-
* (See also read_buf()).
|
|
1550
|
+
* Flush as much pending output as possible. All deflate() output, except for
|
|
1551
|
+
* some deflate_stored() output, goes through this function so some
|
|
1552
|
+
* applications may wish to modify it to avoid allocating a large
|
|
1553
|
+
* strm->next_out buffer and copying into it. (See also read_buf()).
|
|
1572
1554
|
*/
|
|
1573
1555
|
const flush_pending = (strm) => {
|
|
1574
1556
|
const s = strm.state;
|
|
@@ -1581,11 +1563,11 @@ const flush_pending = (strm) => {
|
|
|
1581
1563
|
if (len === 0) { return; }
|
|
1582
1564
|
|
|
1583
1565
|
strm.output.set(s.pending_buf.subarray(s.pending_out, s.pending_out + len), strm.next_out);
|
|
1584
|
-
strm.next_out
|
|
1585
|
-
s.pending_out
|
|
1566
|
+
strm.next_out += len;
|
|
1567
|
+
s.pending_out += len;
|
|
1586
1568
|
strm.total_out += len;
|
|
1587
1569
|
strm.avail_out -= len;
|
|
1588
|
-
s.pending
|
|
1570
|
+
s.pending -= len;
|
|
1589
1571
|
if (s.pending === 0) {
|
|
1590
1572
|
s.pending_out = 0;
|
|
1591
1573
|
}
|
|
@@ -1777,7 +1759,7 @@ const longest_match = (s, cur_match) => {
|
|
|
1777
1759
|
const fill_window = (s) => {
|
|
1778
1760
|
|
|
1779
1761
|
const _w_size = s.w_size;
|
|
1780
|
-
let
|
|
1762
|
+
let n, more, str;
|
|
1781
1763
|
|
|
1782
1764
|
//Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
|
|
1783
1765
|
|
|
@@ -1804,38 +1786,15 @@ const fill_window = (s) => {
|
|
|
1804
1786
|
*/
|
|
1805
1787
|
if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {
|
|
1806
1788
|
|
|
1807
|
-
s.window.set(s.window.subarray(_w_size, _w_size + _w_size), 0);
|
|
1789
|
+
s.window.set(s.window.subarray(_w_size, _w_size + _w_size - more), 0);
|
|
1808
1790
|
s.match_start -= _w_size;
|
|
1809
1791
|
s.strstart -= _w_size;
|
|
1810
1792
|
/* we now have strstart >= MAX_DIST */
|
|
1811
1793
|
s.block_start -= _w_size;
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
later. (Using level 0 permanently is not an optimal usage of
|
|
1817
|
-
zlib, so we don't care about this pathological case.)
|
|
1818
|
-
*/
|
|
1819
|
-
|
|
1820
|
-
n = s.hash_size;
|
|
1821
|
-
p = n;
|
|
1822
|
-
|
|
1823
|
-
do {
|
|
1824
|
-
m = s.head[--p];
|
|
1825
|
-
s.head[p] = (m >= _w_size ? m - _w_size : 0);
|
|
1826
|
-
} while (--n);
|
|
1827
|
-
|
|
1828
|
-
n = _w_size;
|
|
1829
|
-
p = n;
|
|
1830
|
-
|
|
1831
|
-
do {
|
|
1832
|
-
m = s.prev[--p];
|
|
1833
|
-
s.prev[p] = (m >= _w_size ? m - _w_size : 0);
|
|
1834
|
-
/* If n is not on any hash chain, prev[n] is garbage but
|
|
1835
|
-
* its value will never be used.
|
|
1836
|
-
*/
|
|
1837
|
-
} while (--n);
|
|
1838
|
-
|
|
1794
|
+
if (s.insert > s.strstart) {
|
|
1795
|
+
s.insert = s.strstart;
|
|
1796
|
+
}
|
|
1797
|
+
slide_hash(s);
|
|
1839
1798
|
more += _w_size;
|
|
1840
1799
|
}
|
|
1841
1800
|
if (s.strm.avail_in === 0) {
|
|
@@ -1927,104 +1886,216 @@ const fill_window = (s) => {
|
|
|
1927
1886
|
/* ===========================================================================
|
|
1928
1887
|
* Copy without compression as much as possible from the input stream, return
|
|
1929
1888
|
* the current block state.
|
|
1930
|
-
*
|
|
1931
|
-
*
|
|
1932
|
-
*
|
|
1933
|
-
*
|
|
1934
|
-
*
|
|
1889
|
+
*
|
|
1890
|
+
* In case deflateParams() is used to later switch to a non-zero compression
|
|
1891
|
+
* level, s->matches (otherwise unused when storing) keeps track of the number
|
|
1892
|
+
* of hash table slides to perform. If s->matches is 1, then one hash table
|
|
1893
|
+
* slide will be done when switching. If s->matches is 2, the maximum value
|
|
1894
|
+
* allowed here, then the hash table will be cleared, since two or more slides
|
|
1895
|
+
* is the same as a clear.
|
|
1896
|
+
*
|
|
1897
|
+
* deflate_stored() is written to minimize the number of times an input byte is
|
|
1898
|
+
* copied. It is most efficient with large input and output buffers, which
|
|
1899
|
+
* maximizes the opportunites to have a single copy from next_in to next_out.
|
|
1935
1900
|
*/
|
|
1936
1901
|
const deflate_stored = (s, flush) => {
|
|
1937
1902
|
|
|
1938
|
-
/*
|
|
1939
|
-
*
|
|
1903
|
+
/* Smallest worthy block size when not flushing or finishing. By default
|
|
1904
|
+
* this is 32K. This can be as small as 507 bytes for memLevel == 1. For
|
|
1905
|
+
* large input and output buffers, the stored block size will be larger.
|
|
1940
1906
|
*/
|
|
1941
|
-
let
|
|
1942
|
-
|
|
1943
|
-
if (max_block_size > s.pending_buf_size - 5) {
|
|
1944
|
-
max_block_size = s.pending_buf_size - 5;
|
|
1945
|
-
}
|
|
1907
|
+
let min_block = s.pending_buf_size - 5 > s.w_size ? s.w_size : s.pending_buf_size - 5;
|
|
1946
1908
|
|
|
1947
|
-
/* Copy as
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
/*
|
|
1909
|
+
/* Copy as many min_block or larger stored blocks directly to next_out as
|
|
1910
|
+
* possible. If flushing, copy the remaining available input to next_out as
|
|
1911
|
+
* stored blocks, if there is enough space.
|
|
1912
|
+
*/
|
|
1913
|
+
let len, left, have, last = 0;
|
|
1914
|
+
let used = s.strm.avail_in;
|
|
1915
|
+
do {
|
|
1916
|
+
/* Set len to the maximum size block that we can copy directly with the
|
|
1917
|
+
* available input data and output space. Set left to how much of that
|
|
1918
|
+
* would be copied from what's left in the window.
|
|
1919
|
+
*/
|
|
1920
|
+
len = 65535/* MAX_STORED */; /* maximum deflate stored block length */
|
|
1921
|
+
have = (s.bi_valid + 42) >> 3; /* number of header bytes */
|
|
1922
|
+
if (s.strm.avail_out < have) { /* need room for header */
|
|
1923
|
+
break;
|
|
1924
|
+
}
|
|
1925
|
+
/* maximum stored block length that will fit in avail_out: */
|
|
1926
|
+
have = s.strm.avail_out - have;
|
|
1927
|
+
left = s.strstart - s.block_start; /* bytes left in window */
|
|
1928
|
+
if (len > left + s.strm.avail_in) {
|
|
1929
|
+
len = left + s.strm.avail_in; /* limit len to the input */
|
|
1930
|
+
}
|
|
1931
|
+
if (len > have) {
|
|
1932
|
+
len = have; /* limit len to the output */
|
|
1968
1933
|
}
|
|
1969
|
-
//Assert(s->block_start >= 0L, "block gone");
|
|
1970
|
-
// if (s.block_start < 0) throw new Error("block gone");
|
|
1971
1934
|
|
|
1972
|
-
|
|
1973
|
-
|
|
1935
|
+
/* If the stored block would be less than min_block in length, or if
|
|
1936
|
+
* unable to copy all of the available input when flushing, then try
|
|
1937
|
+
* copying to the window and the pending buffer instead. Also don't
|
|
1938
|
+
* write an empty block when flushing -- deflate() does that.
|
|
1939
|
+
*/
|
|
1940
|
+
if (len < min_block && ((len === 0 && flush !== Z_FINISH$3) ||
|
|
1941
|
+
flush === Z_NO_FLUSH$2 ||
|
|
1942
|
+
len !== left + s.strm.avail_in)) {
|
|
1943
|
+
break;
|
|
1944
|
+
}
|
|
1974
1945
|
|
|
1975
|
-
/*
|
|
1976
|
-
|
|
1946
|
+
/* Make a dummy stored block in pending to get the header bytes,
|
|
1947
|
+
* including any pending bits. This also updates the debugging counts.
|
|
1948
|
+
*/
|
|
1949
|
+
last = flush === Z_FINISH$3 && len === left + s.strm.avail_in ? 1 : 0;
|
|
1950
|
+
_tr_stored_block(s, 0, 0, last);
|
|
1951
|
+
|
|
1952
|
+
/* Replace the lengths in the dummy stored block with len. */
|
|
1953
|
+
s.pending_buf[s.pending - 4] = len;
|
|
1954
|
+
s.pending_buf[s.pending - 3] = len >> 8;
|
|
1955
|
+
s.pending_buf[s.pending - 2] = ~len;
|
|
1956
|
+
s.pending_buf[s.pending - 1] = ~len >> 8;
|
|
1957
|
+
|
|
1958
|
+
/* Write the stored block header bytes. */
|
|
1959
|
+
flush_pending(s.strm);
|
|
1960
|
+
|
|
1961
|
+
//#ifdef ZLIB_DEBUG
|
|
1962
|
+
// /* Update debugging counts for the data about to be copied. */
|
|
1963
|
+
// s->compressed_len += len << 3;
|
|
1964
|
+
// s->bits_sent += len << 3;
|
|
1965
|
+
//#endif
|
|
1977
1966
|
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
/*** FLUSH_BLOCK(s, 0); ***/
|
|
1983
|
-
flush_block_only(s, false);
|
|
1984
|
-
if (s.strm.avail_out === 0) {
|
|
1985
|
-
return BS_NEED_MORE;
|
|
1967
|
+
/* Copy uncompressed bytes from the window to next_out. */
|
|
1968
|
+
if (left) {
|
|
1969
|
+
if (left > len) {
|
|
1970
|
+
left = len;
|
|
1986
1971
|
}
|
|
1987
|
-
|
|
1988
|
-
|
|
1972
|
+
//zmemcpy(s->strm->next_out, s->window + s->block_start, left);
|
|
1973
|
+
s.strm.output.set(s.window.subarray(s.block_start, s.block_start + left), s.strm.next_out);
|
|
1974
|
+
s.strm.next_out += left;
|
|
1975
|
+
s.strm.avail_out -= left;
|
|
1976
|
+
s.strm.total_out += left;
|
|
1977
|
+
s.block_start += left;
|
|
1978
|
+
len -= left;
|
|
1979
|
+
}
|
|
1989
1980
|
|
|
1981
|
+
/* Copy uncompressed bytes directly from next_in to next_out, updating
|
|
1982
|
+
* the check value.
|
|
1983
|
+
*/
|
|
1984
|
+
if (len) {
|
|
1985
|
+
read_buf(s.strm, s.strm.output, s.strm.next_out, len);
|
|
1986
|
+
s.strm.next_out += len;
|
|
1987
|
+
s.strm.avail_out -= len;
|
|
1988
|
+
s.strm.total_out += len;
|
|
1990
1989
|
}
|
|
1991
|
-
|
|
1992
|
-
|
|
1990
|
+
} while (last === 0);
|
|
1991
|
+
|
|
1992
|
+
/* Update the sliding window with the last s->w_size bytes of the copied
|
|
1993
|
+
* data, or append all of the copied data to the existing window if less
|
|
1994
|
+
* than s->w_size bytes were copied. Also update the number of bytes to
|
|
1995
|
+
* insert in the hash tables, in the event that deflateParams() switches to
|
|
1996
|
+
* a non-zero compression level.
|
|
1997
|
+
*/
|
|
1998
|
+
used -= s.strm.avail_in; /* number of input bytes directly copied */
|
|
1999
|
+
if (used) {
|
|
2000
|
+
/* If any input was used, then no unused input remains in the window,
|
|
2001
|
+
* therefore s->block_start == s->strstart.
|
|
1993
2002
|
*/
|
|
1994
|
-
if (
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
2003
|
+
if (used >= s.w_size) { /* supplant the previous history */
|
|
2004
|
+
s.matches = 2; /* clear hash */
|
|
2005
|
+
//zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
|
|
2006
|
+
s.window.set(s.strm.input.subarray(s.strm.next_in - s.w_size, s.strm.next_in), 0);
|
|
2007
|
+
s.strstart = s.w_size;
|
|
2008
|
+
s.insert = s.strstart;
|
|
2009
|
+
}
|
|
2010
|
+
else {
|
|
2011
|
+
if (s.window_size - s.strstart <= used) {
|
|
2012
|
+
/* Slide the window down. */
|
|
2013
|
+
s.strstart -= s.w_size;
|
|
2014
|
+
//zmemcpy(s->window, s->window + s->w_size, s->strstart);
|
|
2015
|
+
s.window.set(s.window.subarray(s.w_size, s.w_size + s.strstart), 0);
|
|
2016
|
+
if (s.matches < 2) {
|
|
2017
|
+
s.matches++; /* add a pending slide_hash() */
|
|
2018
|
+
}
|
|
2019
|
+
if (s.insert > s.strstart) {
|
|
2020
|
+
s.insert = s.strstart;
|
|
2021
|
+
}
|
|
1999
2022
|
}
|
|
2000
|
-
|
|
2023
|
+
//zmemcpy(s->window + s->strstart, s->strm->next_in - used, used);
|
|
2024
|
+
s.window.set(s.strm.input.subarray(s.strm.next_in - used, s.strm.next_in), s.strstart);
|
|
2025
|
+
s.strstart += used;
|
|
2026
|
+
s.insert += used > s.w_size - s.insert ? s.w_size - s.insert : used;
|
|
2001
2027
|
}
|
|
2028
|
+
s.block_start = s.strstart;
|
|
2029
|
+
}
|
|
2030
|
+
if (s.high_water < s.strstart) {
|
|
2031
|
+
s.high_water = s.strstart;
|
|
2002
2032
|
}
|
|
2003
2033
|
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
if (flush === Z_FINISH$3) {
|
|
2007
|
-
/*** FLUSH_BLOCK(s, 1); ***/
|
|
2008
|
-
flush_block_only(s, true);
|
|
2009
|
-
if (s.strm.avail_out === 0) {
|
|
2010
|
-
return BS_FINISH_STARTED;
|
|
2011
|
-
}
|
|
2012
|
-
/***/
|
|
2034
|
+
/* If the last block was written to next_out, then done. */
|
|
2035
|
+
if (last) {
|
|
2013
2036
|
return BS_FINISH_DONE;
|
|
2014
2037
|
}
|
|
2015
2038
|
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2039
|
+
/* If flushing and all input has been consumed, then done. */
|
|
2040
|
+
if (flush !== Z_NO_FLUSH$2 && flush !== Z_FINISH$3 &&
|
|
2041
|
+
s.strm.avail_in === 0 && s.strstart === s.block_start) {
|
|
2042
|
+
return BS_BLOCK_DONE;
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
/* Fill the window with any remaining input. */
|
|
2046
|
+
have = s.window_size - s.strstart;
|
|
2047
|
+
if (s.strm.avail_in > have && s.block_start >= s.w_size) {
|
|
2048
|
+
/* Slide the window down. */
|
|
2049
|
+
s.block_start -= s.w_size;
|
|
2050
|
+
s.strstart -= s.w_size;
|
|
2051
|
+
//zmemcpy(s->window, s->window + s->w_size, s->strstart);
|
|
2052
|
+
s.window.set(s.window.subarray(s.w_size, s.w_size + s.strstart), 0);
|
|
2053
|
+
if (s.matches < 2) {
|
|
2054
|
+
s.matches++; /* add a pending slide_hash() */
|
|
2021
2055
|
}
|
|
2022
|
-
|
|
2056
|
+
have += s.w_size; /* more space now */
|
|
2057
|
+
if (s.insert > s.strstart) {
|
|
2058
|
+
s.insert = s.strstart;
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
if (have > s.strm.avail_in) {
|
|
2062
|
+
have = s.strm.avail_in;
|
|
2063
|
+
}
|
|
2064
|
+
if (have) {
|
|
2065
|
+
read_buf(s.strm, s.window, s.strstart, have);
|
|
2066
|
+
s.strstart += have;
|
|
2067
|
+
s.insert += have > s.w_size - s.insert ? s.w_size - s.insert : have;
|
|
2068
|
+
}
|
|
2069
|
+
if (s.high_water < s.strstart) {
|
|
2070
|
+
s.high_water = s.strstart;
|
|
2023
2071
|
}
|
|
2024
2072
|
|
|
2025
|
-
|
|
2073
|
+
/* There was not enough avail_out to write a complete worthy or flushed
|
|
2074
|
+
* stored block to next_out. Write a stored block to pending instead, if we
|
|
2075
|
+
* have enough input for a worthy block, or if flushing and there is enough
|
|
2076
|
+
* room for the remaining input as a stored block in the pending buffer.
|
|
2077
|
+
*/
|
|
2078
|
+
have = (s.bi_valid + 42) >> 3; /* number of header bytes */
|
|
2079
|
+
/* maximum stored block length that will fit in pending: */
|
|
2080
|
+
have = s.pending_buf_size - have > 65535/* MAX_STORED */ ? 65535/* MAX_STORED */ : s.pending_buf_size - have;
|
|
2081
|
+
min_block = have > s.w_size ? s.w_size : have;
|
|
2082
|
+
left = s.strstart - s.block_start;
|
|
2083
|
+
if (left >= min_block ||
|
|
2084
|
+
((left || flush === Z_FINISH$3) && flush !== Z_NO_FLUSH$2 &&
|
|
2085
|
+
s.strm.avail_in === 0 && left <= have)) {
|
|
2086
|
+
len = left > have ? have : left;
|
|
2087
|
+
last = flush === Z_FINISH$3 && s.strm.avail_in === 0 &&
|
|
2088
|
+
len === left ? 1 : 0;
|
|
2089
|
+
_tr_stored_block(s, s.block_start, len, last);
|
|
2090
|
+
s.block_start += len;
|
|
2091
|
+
flush_pending(s.strm);
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
/* We've done all we can with the available input and output. */
|
|
2095
|
+
return last ? BS_FINISH_STARTED : BS_NEED_MORE;
|
|
2026
2096
|
};
|
|
2027
2097
|
|
|
2098
|
+
|
|
2028
2099
|
/* ===========================================================================
|
|
2029
2100
|
* Compress as much as possible from the input stream, return the current
|
|
2030
2101
|
* block state.
|
|
@@ -2145,7 +2216,7 @@ const deflate_fast = (s, flush) => {
|
|
|
2145
2216
|
/***/
|
|
2146
2217
|
return BS_FINISH_DONE;
|
|
2147
2218
|
}
|
|
2148
|
-
if (s.
|
|
2219
|
+
if (s.sym_next) {
|
|
2149
2220
|
/*** FLUSH_BLOCK(s, 0); ***/
|
|
2150
2221
|
flush_block_only(s, false);
|
|
2151
2222
|
if (s.strm.avail_out === 0) {
|
|
@@ -2306,7 +2377,7 @@ const deflate_slow = (s, flush) => {
|
|
|
2306
2377
|
/***/
|
|
2307
2378
|
return BS_FINISH_DONE;
|
|
2308
2379
|
}
|
|
2309
|
-
if (s.
|
|
2380
|
+
if (s.sym_next) {
|
|
2310
2381
|
/*** FLUSH_BLOCK(s, 0); ***/
|
|
2311
2382
|
flush_block_only(s, false);
|
|
2312
2383
|
if (s.strm.avail_out === 0) {
|
|
@@ -2405,7 +2476,7 @@ const deflate_rle = (s, flush) => {
|
|
|
2405
2476
|
/***/
|
|
2406
2477
|
return BS_FINISH_DONE;
|
|
2407
2478
|
}
|
|
2408
|
-
if (s.
|
|
2479
|
+
if (s.sym_next) {
|
|
2409
2480
|
/*** FLUSH_BLOCK(s, 0); ***/
|
|
2410
2481
|
flush_block_only(s, false);
|
|
2411
2482
|
if (s.strm.avail_out === 0) {
|
|
@@ -2462,7 +2533,7 @@ const deflate_huff = (s, flush) => {
|
|
|
2462
2533
|
/***/
|
|
2463
2534
|
return BS_FINISH_DONE;
|
|
2464
2535
|
}
|
|
2465
|
-
if (s.
|
|
2536
|
+
if (s.sym_next) {
|
|
2466
2537
|
/*** FLUSH_BLOCK(s, 0); ***/
|
|
2467
2538
|
flush_block_only(s, false);
|
|
2468
2539
|
if (s.strm.avail_out === 0) {
|
|
@@ -2663,7 +2734,7 @@ function DeflateState() {
|
|
|
2663
2734
|
/* Depth of each subtree used as tie breaker for trees of equal frequency
|
|
2664
2735
|
*/
|
|
2665
2736
|
|
|
2666
|
-
this.
|
|
2737
|
+
this.sym_buf = 0; /* buffer for distances and literals/lengths */
|
|
2667
2738
|
|
|
2668
2739
|
this.lit_bufsize = 0;
|
|
2669
2740
|
/* Size of match buffer for literals/lengths. There are 4 reasons for
|
|
@@ -2685,13 +2756,8 @@ function DeflateState() {
|
|
|
2685
2756
|
* - I can't count above 4
|
|
2686
2757
|
*/
|
|
2687
2758
|
|
|
2688
|
-
this.
|
|
2689
|
-
|
|
2690
|
-
this.d_buf = 0;
|
|
2691
|
-
/* Buffer index for distances. To simplify the code, d_buf and l_buf have
|
|
2692
|
-
* the same number of elements. To use different lengths, an extra flag
|
|
2693
|
-
* array would be necessary.
|
|
2694
|
-
*/
|
|
2759
|
+
this.sym_next = 0; /* running index in sym_buf */
|
|
2760
|
+
this.sym_end = 0; /* symbol table full when sym_next reaches this */
|
|
2695
2761
|
|
|
2696
2762
|
this.opt_len = 0; /* bit length of current block with optimal trees */
|
|
2697
2763
|
this.static_len = 0; /* bit length of current block with static trees */
|
|
@@ -2719,9 +2785,34 @@ function DeflateState() {
|
|
|
2719
2785
|
}
|
|
2720
2786
|
|
|
2721
2787
|
|
|
2788
|
+
/* =========================================================================
|
|
2789
|
+
* Check for a valid deflate stream state. Return 0 if ok, 1 if not.
|
|
2790
|
+
*/
|
|
2791
|
+
const deflateStateCheck = (strm) => {
|
|
2792
|
+
|
|
2793
|
+
if (!strm) {
|
|
2794
|
+
return 1;
|
|
2795
|
+
}
|
|
2796
|
+
const s = strm.state;
|
|
2797
|
+
if (!s || s.strm !== strm || (s.status !== INIT_STATE &&
|
|
2798
|
+
//#ifdef GZIP
|
|
2799
|
+
s.status !== GZIP_STATE &&
|
|
2800
|
+
//#endif
|
|
2801
|
+
s.status !== EXTRA_STATE &&
|
|
2802
|
+
s.status !== NAME_STATE &&
|
|
2803
|
+
s.status !== COMMENT_STATE &&
|
|
2804
|
+
s.status !== HCRC_STATE &&
|
|
2805
|
+
s.status !== BUSY_STATE &&
|
|
2806
|
+
s.status !== FINISH_STATE)) {
|
|
2807
|
+
return 1;
|
|
2808
|
+
}
|
|
2809
|
+
return 0;
|
|
2810
|
+
};
|
|
2811
|
+
|
|
2812
|
+
|
|
2722
2813
|
const deflateResetKeep = (strm) => {
|
|
2723
2814
|
|
|
2724
|
-
if (
|
|
2815
|
+
if (deflateStateCheck(strm)) {
|
|
2725
2816
|
return err(strm, Z_STREAM_ERROR$2);
|
|
2726
2817
|
}
|
|
2727
2818
|
|
|
@@ -2736,12 +2827,16 @@ const deflateResetKeep = (strm) => {
|
|
|
2736
2827
|
s.wrap = -s.wrap;
|
|
2737
2828
|
/* was made negative by deflate(..., Z_FINISH); */
|
|
2738
2829
|
}
|
|
2739
|
-
s.status =
|
|
2830
|
+
s.status =
|
|
2831
|
+
//#ifdef GZIP
|
|
2832
|
+
s.wrap === 2 ? GZIP_STATE :
|
|
2833
|
+
//#endif
|
|
2834
|
+
s.wrap ? INIT_STATE : BUSY_STATE;
|
|
2740
2835
|
strm.adler = (s.wrap === 2) ?
|
|
2741
2836
|
0 // crc32(0, Z_NULL, 0)
|
|
2742
2837
|
:
|
|
2743
2838
|
1; // adler32(0, Z_NULL, 0)
|
|
2744
|
-
s.last_flush =
|
|
2839
|
+
s.last_flush = -2;
|
|
2745
2840
|
_tr_init(s);
|
|
2746
2841
|
return Z_OK$3;
|
|
2747
2842
|
};
|
|
@@ -2759,8 +2854,9 @@ const deflateReset = (strm) => {
|
|
|
2759
2854
|
|
|
2760
2855
|
const deflateSetHeader = (strm, head) => {
|
|
2761
2856
|
|
|
2762
|
-
if (
|
|
2763
|
-
|
|
2857
|
+
if (deflateStateCheck(strm) || strm.state.wrap !== 2) {
|
|
2858
|
+
return Z_STREAM_ERROR$2;
|
|
2859
|
+
}
|
|
2764
2860
|
strm.state.gzhead = head;
|
|
2765
2861
|
return Z_OK$3;
|
|
2766
2862
|
};
|
|
@@ -2790,7 +2886,7 @@ const deflateInit2 = (strm, level, method, windowBits, memLevel, strategy) => {
|
|
|
2790
2886
|
|
|
2791
2887
|
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED$2 ||
|
|
2792
2888
|
windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
|
|
2793
|
-
strategy < 0 || strategy > Z_FIXED) {
|
|
2889
|
+
strategy < 0 || strategy > Z_FIXED || (windowBits === 8 && wrap !== 1)) {
|
|
2794
2890
|
return err(strm, Z_STREAM_ERROR$2);
|
|
2795
2891
|
}
|
|
2796
2892
|
|
|
@@ -2804,6 +2900,7 @@ const deflateInit2 = (strm, level, method, windowBits, memLevel, strategy) => {
|
|
|
2804
2900
|
|
|
2805
2901
|
strm.state = s;
|
|
2806
2902
|
s.strm = strm;
|
|
2903
|
+
s.status = INIT_STATE; /* to pass state test in deflateReset() */
|
|
2807
2904
|
|
|
2808
2905
|
s.wrap = wrap;
|
|
2809
2906
|
s.gzhead = null;
|
|
@@ -2825,18 +2922,58 @@ const deflateInit2 = (strm, level, method, windowBits, memLevel, strategy) => {
|
|
|
2825
2922
|
|
|
2826
2923
|
s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
|
|
2827
2924
|
|
|
2828
|
-
|
|
2925
|
+
/* We overlay pending_buf and sym_buf. This works since the average size
|
|
2926
|
+
* for length/distance pairs over any compressed block is assured to be 31
|
|
2927
|
+
* bits or less.
|
|
2928
|
+
*
|
|
2929
|
+
* Analysis: The longest fixed codes are a length code of 8 bits plus 5
|
|
2930
|
+
* extra bits, for lengths 131 to 257. The longest fixed distance codes are
|
|
2931
|
+
* 5 bits plus 13 extra bits, for distances 16385 to 32768. The longest
|
|
2932
|
+
* possible fixed-codes length/distance pair is then 31 bits total.
|
|
2933
|
+
*
|
|
2934
|
+
* sym_buf starts one-fourth of the way into pending_buf. So there are
|
|
2935
|
+
* three bytes in sym_buf for every four bytes in pending_buf. Each symbol
|
|
2936
|
+
* in sym_buf is three bytes -- two for the distance and one for the
|
|
2937
|
+
* literal/length. As each symbol is consumed, the pointer to the next
|
|
2938
|
+
* sym_buf value to read moves forward three bytes. From that symbol, up to
|
|
2939
|
+
* 31 bits are written to pending_buf. The closest the written pending_buf
|
|
2940
|
+
* bits gets to the next sym_buf symbol to read is just before the last
|
|
2941
|
+
* code is written. At that time, 31*(n-2) bits have been written, just
|
|
2942
|
+
* after 24*(n-2) bits have been consumed from sym_buf. sym_buf starts at
|
|
2943
|
+
* 8*n bits into pending_buf. (Note that the symbol buffer fills when n-1
|
|
2944
|
+
* symbols are written.) The closest the writing gets to what is unread is
|
|
2945
|
+
* then n+14 bits. Here n is lit_bufsize, which is 16384 by default, and
|
|
2946
|
+
* can range from 128 to 32768.
|
|
2947
|
+
*
|
|
2948
|
+
* Therefore, at a minimum, there are 142 bits of space between what is
|
|
2949
|
+
* written and what is read in the overlain buffers, so the symbols cannot
|
|
2950
|
+
* be overwritten by the compressed data. That space is actually 139 bits,
|
|
2951
|
+
* due to the three-bit fixed-code block header.
|
|
2952
|
+
*
|
|
2953
|
+
* That covers the case where either Z_FIXED is specified, forcing fixed
|
|
2954
|
+
* codes, or when the use of fixed codes is chosen, because that choice
|
|
2955
|
+
* results in a smaller compressed block than dynamic codes. That latter
|
|
2956
|
+
* condition then assures that the above analysis also covers all dynamic
|
|
2957
|
+
* blocks. A dynamic-code block will only be chosen to be emitted if it has
|
|
2958
|
+
* fewer bits than a fixed-code block would for the same set of symbols.
|
|
2959
|
+
* Therefore its average symbol length is assured to be less than 31. So
|
|
2960
|
+
* the compressed data for a dynamic block also cannot overwrite the
|
|
2961
|
+
* symbols from which it is being constructed.
|
|
2962
|
+
*/
|
|
2829
2963
|
|
|
2830
|
-
|
|
2831
|
-
//s->pending_buf = (uchf *) overlay;
|
|
2964
|
+
s.pending_buf_size = s.lit_bufsize * 4;
|
|
2832
2965
|
s.pending_buf = new Uint8Array(s.pending_buf_size);
|
|
2833
2966
|
|
|
2834
2967
|
// It is offset from `s.pending_buf` (size is `s.lit_bufsize * 2`)
|
|
2835
|
-
//s->
|
|
2836
|
-
s.
|
|
2968
|
+
//s->sym_buf = s->pending_buf + s->lit_bufsize;
|
|
2969
|
+
s.sym_buf = s.lit_bufsize;
|
|
2837
2970
|
|
|
2838
|
-
//s->
|
|
2839
|
-
s.
|
|
2971
|
+
//s->sym_end = (s->lit_bufsize - 1) * 3;
|
|
2972
|
+
s.sym_end = (s.lit_bufsize - 1) * 3;
|
|
2973
|
+
/* We avoid equality with lit_bufsize*3 because of wraparound at 64K
|
|
2974
|
+
* on 16 bit machines and because stored blocks are restricted to
|
|
2975
|
+
* 64K-1 bytes.
|
|
2976
|
+
*/
|
|
2840
2977
|
|
|
2841
2978
|
s.level = level;
|
|
2842
2979
|
s.strategy = strategy;
|
|
@@ -2851,150 +2988,200 @@ const deflateInit = (strm, level) => {
|
|
|
2851
2988
|
};
|
|
2852
2989
|
|
|
2853
2990
|
|
|
2991
|
+
/* ========================================================================= */
|
|
2854
2992
|
const deflate$2 = (strm, flush) => {
|
|
2855
2993
|
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
if (!strm || !strm.state ||
|
|
2859
|
-
flush > Z_BLOCK$1 || flush < 0) {
|
|
2994
|
+
if (deflateStateCheck(strm) || flush > Z_BLOCK$1 || flush < 0) {
|
|
2860
2995
|
return strm ? err(strm, Z_STREAM_ERROR$2) : Z_STREAM_ERROR$2;
|
|
2861
2996
|
}
|
|
2862
2997
|
|
|
2863
2998
|
const s = strm.state;
|
|
2864
2999
|
|
|
2865
3000
|
if (!strm.output ||
|
|
2866
|
-
(
|
|
3001
|
+
(strm.avail_in !== 0 && !strm.input) ||
|
|
2867
3002
|
(s.status === FINISH_STATE && flush !== Z_FINISH$3)) {
|
|
2868
3003
|
return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR$1 : Z_STREAM_ERROR$2);
|
|
2869
3004
|
}
|
|
2870
3005
|
|
|
2871
|
-
s.strm = strm; /* just in case */
|
|
2872
3006
|
const old_flush = s.last_flush;
|
|
2873
3007
|
s.last_flush = flush;
|
|
2874
3008
|
|
|
3009
|
+
/* Flush as much pending output as possible */
|
|
3010
|
+
if (s.pending !== 0) {
|
|
3011
|
+
flush_pending(strm);
|
|
3012
|
+
if (strm.avail_out === 0) {
|
|
3013
|
+
/* Since avail_out is 0, deflate will be called again with
|
|
3014
|
+
* more output space, but possibly with both pending and
|
|
3015
|
+
* avail_in equal to zero. There won't be anything to do,
|
|
3016
|
+
* but this is not an error situation so make sure we
|
|
3017
|
+
* return OK instead of BUF_ERROR at next call of deflate:
|
|
3018
|
+
*/
|
|
3019
|
+
s.last_flush = -1;
|
|
3020
|
+
return Z_OK$3;
|
|
3021
|
+
}
|
|
3022
|
+
|
|
3023
|
+
/* Make sure there is something to do and avoid duplicate consecutive
|
|
3024
|
+
* flushes. For repeated and useless calls with Z_FINISH, we keep
|
|
3025
|
+
* returning Z_STREAM_END instead of Z_BUF_ERROR.
|
|
3026
|
+
*/
|
|
3027
|
+
} else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) &&
|
|
3028
|
+
flush !== Z_FINISH$3) {
|
|
3029
|
+
return err(strm, Z_BUF_ERROR$1);
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
/* User must not provide more input after the first FINISH: */
|
|
3033
|
+
if (s.status === FINISH_STATE && strm.avail_in !== 0) {
|
|
3034
|
+
return err(strm, Z_BUF_ERROR$1);
|
|
3035
|
+
}
|
|
3036
|
+
|
|
2875
3037
|
/* Write the header */
|
|
3038
|
+
if (s.status === INIT_STATE && s.wrap === 0) {
|
|
3039
|
+
s.status = BUSY_STATE;
|
|
3040
|
+
}
|
|
2876
3041
|
if (s.status === INIT_STATE) {
|
|
3042
|
+
/* zlib header */
|
|
3043
|
+
let header = (Z_DEFLATED$2 + ((s.w_bits - 8) << 4)) << 8;
|
|
3044
|
+
let level_flags = -1;
|
|
3045
|
+
|
|
3046
|
+
if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) {
|
|
3047
|
+
level_flags = 0;
|
|
3048
|
+
} else if (s.level < 6) {
|
|
3049
|
+
level_flags = 1;
|
|
3050
|
+
} else if (s.level === 6) {
|
|
3051
|
+
level_flags = 2;
|
|
3052
|
+
} else {
|
|
3053
|
+
level_flags = 3;
|
|
3054
|
+
}
|
|
3055
|
+
header |= (level_flags << 6);
|
|
3056
|
+
if (s.strstart !== 0) { header |= PRESET_DICT; }
|
|
3057
|
+
header += 31 - (header % 31);
|
|
2877
3058
|
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
put_byte(s, 0);
|
|
2885
|
-
put_byte(s, 0);
|
|
2886
|
-
put_byte(s, 0);
|
|
2887
|
-
put_byte(s, 0);
|
|
2888
|
-
put_byte(s, 0);
|
|
2889
|
-
put_byte(s, s.level === 9 ? 2 :
|
|
2890
|
-
(s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?
|
|
2891
|
-
4 : 0));
|
|
2892
|
-
put_byte(s, OS_CODE);
|
|
2893
|
-
s.status = BUSY_STATE;
|
|
2894
|
-
}
|
|
2895
|
-
else {
|
|
2896
|
-
put_byte(s, (s.gzhead.text ? 1 : 0) +
|
|
2897
|
-
(s.gzhead.hcrc ? 2 : 0) +
|
|
2898
|
-
(!s.gzhead.extra ? 0 : 4) +
|
|
2899
|
-
(!s.gzhead.name ? 0 : 8) +
|
|
2900
|
-
(!s.gzhead.comment ? 0 : 16)
|
|
2901
|
-
);
|
|
2902
|
-
put_byte(s, s.gzhead.time & 0xff);
|
|
2903
|
-
put_byte(s, (s.gzhead.time >> 8) & 0xff);
|
|
2904
|
-
put_byte(s, (s.gzhead.time >> 16) & 0xff);
|
|
2905
|
-
put_byte(s, (s.gzhead.time >> 24) & 0xff);
|
|
2906
|
-
put_byte(s, s.level === 9 ? 2 :
|
|
2907
|
-
(s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?
|
|
2908
|
-
4 : 0));
|
|
2909
|
-
put_byte(s, s.gzhead.os & 0xff);
|
|
2910
|
-
if (s.gzhead.extra && s.gzhead.extra.length) {
|
|
2911
|
-
put_byte(s, s.gzhead.extra.length & 0xff);
|
|
2912
|
-
put_byte(s, (s.gzhead.extra.length >> 8) & 0xff);
|
|
2913
|
-
}
|
|
2914
|
-
if (s.gzhead.hcrc) {
|
|
2915
|
-
strm.adler = crc32_1(strm.adler, s.pending_buf, s.pending, 0);
|
|
2916
|
-
}
|
|
2917
|
-
s.gzindex = 0;
|
|
2918
|
-
s.status = EXTRA_STATE;
|
|
2919
|
-
}
|
|
3059
|
+
putShortMSB(s, header);
|
|
3060
|
+
|
|
3061
|
+
/* Save the adler32 of the preset dictionary: */
|
|
3062
|
+
if (s.strstart !== 0) {
|
|
3063
|
+
putShortMSB(s, strm.adler >>> 16);
|
|
3064
|
+
putShortMSB(s, strm.adler & 0xffff);
|
|
2920
3065
|
}
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
let header = (Z_DEFLATED$2 + ((s.w_bits - 8) << 4)) << 8;
|
|
2924
|
-
let level_flags = -1;
|
|
2925
|
-
|
|
2926
|
-
if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) {
|
|
2927
|
-
level_flags = 0;
|
|
2928
|
-
} else if (s.level < 6) {
|
|
2929
|
-
level_flags = 1;
|
|
2930
|
-
} else if (s.level === 6) {
|
|
2931
|
-
level_flags = 2;
|
|
2932
|
-
} else {
|
|
2933
|
-
level_flags = 3;
|
|
2934
|
-
}
|
|
2935
|
-
header |= (level_flags << 6);
|
|
2936
|
-
if (s.strstart !== 0) { header |= PRESET_DICT; }
|
|
2937
|
-
header += 31 - (header % 31);
|
|
3066
|
+
strm.adler = 1; // adler32(0L, Z_NULL, 0);
|
|
3067
|
+
s.status = BUSY_STATE;
|
|
2938
3068
|
|
|
3069
|
+
/* Compression must start with an empty pending buffer */
|
|
3070
|
+
flush_pending(strm);
|
|
3071
|
+
if (s.pending !== 0) {
|
|
3072
|
+
s.last_flush = -1;
|
|
3073
|
+
return Z_OK$3;
|
|
3074
|
+
}
|
|
3075
|
+
}
|
|
3076
|
+
//#ifdef GZIP
|
|
3077
|
+
if (s.status === GZIP_STATE) {
|
|
3078
|
+
/* gzip header */
|
|
3079
|
+
strm.adler = 0; //crc32(0L, Z_NULL, 0);
|
|
3080
|
+
put_byte(s, 31);
|
|
3081
|
+
put_byte(s, 139);
|
|
3082
|
+
put_byte(s, 8);
|
|
3083
|
+
if (!s.gzhead) { // s->gzhead == Z_NULL
|
|
3084
|
+
put_byte(s, 0);
|
|
3085
|
+
put_byte(s, 0);
|
|
3086
|
+
put_byte(s, 0);
|
|
3087
|
+
put_byte(s, 0);
|
|
3088
|
+
put_byte(s, 0);
|
|
3089
|
+
put_byte(s, s.level === 9 ? 2 :
|
|
3090
|
+
(s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?
|
|
3091
|
+
4 : 0));
|
|
3092
|
+
put_byte(s, OS_CODE);
|
|
2939
3093
|
s.status = BUSY_STATE;
|
|
2940
|
-
putShortMSB(s, header);
|
|
2941
3094
|
|
|
2942
|
-
/*
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
3095
|
+
/* Compression must start with an empty pending buffer */
|
|
3096
|
+
flush_pending(strm);
|
|
3097
|
+
if (s.pending !== 0) {
|
|
3098
|
+
s.last_flush = -1;
|
|
3099
|
+
return Z_OK$3;
|
|
3100
|
+
}
|
|
3101
|
+
}
|
|
3102
|
+
else {
|
|
3103
|
+
put_byte(s, (s.gzhead.text ? 1 : 0) +
|
|
3104
|
+
(s.gzhead.hcrc ? 2 : 0) +
|
|
3105
|
+
(!s.gzhead.extra ? 0 : 4) +
|
|
3106
|
+
(!s.gzhead.name ? 0 : 8) +
|
|
3107
|
+
(!s.gzhead.comment ? 0 : 16)
|
|
3108
|
+
);
|
|
3109
|
+
put_byte(s, s.gzhead.time & 0xff);
|
|
3110
|
+
put_byte(s, (s.gzhead.time >> 8) & 0xff);
|
|
3111
|
+
put_byte(s, (s.gzhead.time >> 16) & 0xff);
|
|
3112
|
+
put_byte(s, (s.gzhead.time >> 24) & 0xff);
|
|
3113
|
+
put_byte(s, s.level === 9 ? 2 :
|
|
3114
|
+
(s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?
|
|
3115
|
+
4 : 0));
|
|
3116
|
+
put_byte(s, s.gzhead.os & 0xff);
|
|
3117
|
+
if (s.gzhead.extra && s.gzhead.extra.length) {
|
|
3118
|
+
put_byte(s, s.gzhead.extra.length & 0xff);
|
|
3119
|
+
put_byte(s, (s.gzhead.extra.length >> 8) & 0xff);
|
|
3120
|
+
}
|
|
3121
|
+
if (s.gzhead.hcrc) {
|
|
3122
|
+
strm.adler = crc32_1(strm.adler, s.pending_buf, s.pending, 0);
|
|
2946
3123
|
}
|
|
2947
|
-
|
|
3124
|
+
s.gzindex = 0;
|
|
3125
|
+
s.status = EXTRA_STATE;
|
|
2948
3126
|
}
|
|
2949
3127
|
}
|
|
2950
|
-
|
|
2951
|
-
//#ifdef GZIP
|
|
2952
3128
|
if (s.status === EXTRA_STATE) {
|
|
2953
3129
|
if (s.gzhead.extra/* != Z_NULL*/) {
|
|
2954
|
-
beg = s.pending;
|
|
2955
|
-
|
|
2956
|
-
while (s.
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
}
|
|
3130
|
+
let beg = s.pending; /* start of bytes to update crc */
|
|
3131
|
+
let left = (s.gzhead.extra.length & 0xffff) - s.gzindex;
|
|
3132
|
+
while (s.pending + left > s.pending_buf_size) {
|
|
3133
|
+
let copy = s.pending_buf_size - s.pending;
|
|
3134
|
+
// zmemcpy(s.pending_buf + s.pending,
|
|
3135
|
+
// s.gzhead.extra + s.gzindex, copy);
|
|
3136
|
+
s.pending_buf.set(s.gzhead.extra.subarray(s.gzindex, s.gzindex + copy), s.pending);
|
|
3137
|
+
s.pending = s.pending_buf_size;
|
|
3138
|
+
//--- HCRC_UPDATE(beg) ---//
|
|
3139
|
+
if (s.gzhead.hcrc && s.pending > beg) {
|
|
3140
|
+
strm.adler = crc32_1(strm.adler, s.pending_buf, s.pending - beg, beg);
|
|
2966
3141
|
}
|
|
2967
|
-
|
|
2968
|
-
s.gzindex
|
|
3142
|
+
//---//
|
|
3143
|
+
s.gzindex += copy;
|
|
3144
|
+
flush_pending(strm);
|
|
3145
|
+
if (s.pending !== 0) {
|
|
3146
|
+
s.last_flush = -1;
|
|
3147
|
+
return Z_OK$3;
|
|
3148
|
+
}
|
|
3149
|
+
beg = 0;
|
|
3150
|
+
left -= copy;
|
|
2969
3151
|
}
|
|
3152
|
+
// JS specific: s.gzhead.extra may be TypedArray or Array for backward compatibility
|
|
3153
|
+
// TypedArray.slice and TypedArray.from don't exist in IE10-IE11
|
|
3154
|
+
let gzhead_extra = new Uint8Array(s.gzhead.extra);
|
|
3155
|
+
// zmemcpy(s->pending_buf + s->pending,
|
|
3156
|
+
// s->gzhead->extra + s->gzindex, left);
|
|
3157
|
+
s.pending_buf.set(gzhead_extra.subarray(s.gzindex, s.gzindex + left), s.pending);
|
|
3158
|
+
s.pending += left;
|
|
3159
|
+
//--- HCRC_UPDATE(beg) ---//
|
|
2970
3160
|
if (s.gzhead.hcrc && s.pending > beg) {
|
|
2971
3161
|
strm.adler = crc32_1(strm.adler, s.pending_buf, s.pending - beg, beg);
|
|
2972
3162
|
}
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
s.status = NAME_STATE;
|
|
2976
|
-
}
|
|
2977
|
-
}
|
|
2978
|
-
else {
|
|
2979
|
-
s.status = NAME_STATE;
|
|
3163
|
+
//---//
|
|
3164
|
+
s.gzindex = 0;
|
|
2980
3165
|
}
|
|
3166
|
+
s.status = NAME_STATE;
|
|
2981
3167
|
}
|
|
2982
3168
|
if (s.status === NAME_STATE) {
|
|
2983
3169
|
if (s.gzhead.name/* != Z_NULL*/) {
|
|
2984
|
-
beg = s.pending;
|
|
2985
|
-
|
|
2986
|
-
|
|
3170
|
+
let beg = s.pending; /* start of bytes to update crc */
|
|
3171
|
+
let val;
|
|
2987
3172
|
do {
|
|
2988
3173
|
if (s.pending === s.pending_buf_size) {
|
|
3174
|
+
//--- HCRC_UPDATE(beg) ---//
|
|
2989
3175
|
if (s.gzhead.hcrc && s.pending > beg) {
|
|
2990
3176
|
strm.adler = crc32_1(strm.adler, s.pending_buf, s.pending - beg, beg);
|
|
2991
3177
|
}
|
|
3178
|
+
//---//
|
|
2992
3179
|
flush_pending(strm);
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
break;
|
|
3180
|
+
if (s.pending !== 0) {
|
|
3181
|
+
s.last_flush = -1;
|
|
3182
|
+
return Z_OK$3;
|
|
2997
3183
|
}
|
|
3184
|
+
beg = 0;
|
|
2998
3185
|
}
|
|
2999
3186
|
// JS specific: little magic to add zero terminator to end of string
|
|
3000
3187
|
if (s.gzindex < s.gzhead.name.length) {
|
|
@@ -3004,35 +3191,32 @@ const deflate$2 = (strm, flush) => {
|
|
|
3004
3191
|
}
|
|
3005
3192
|
put_byte(s, val);
|
|
3006
3193
|
} while (val !== 0);
|
|
3007
|
-
|
|
3194
|
+
//--- HCRC_UPDATE(beg) ---//
|
|
3008
3195
|
if (s.gzhead.hcrc && s.pending > beg) {
|
|
3009
3196
|
strm.adler = crc32_1(strm.adler, s.pending_buf, s.pending - beg, beg);
|
|
3010
3197
|
}
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
s.status = COMMENT_STATE;
|
|
3014
|
-
}
|
|
3015
|
-
}
|
|
3016
|
-
else {
|
|
3017
|
-
s.status = COMMENT_STATE;
|
|
3198
|
+
//---//
|
|
3199
|
+
s.gzindex = 0;
|
|
3018
3200
|
}
|
|
3201
|
+
s.status = COMMENT_STATE;
|
|
3019
3202
|
}
|
|
3020
3203
|
if (s.status === COMMENT_STATE) {
|
|
3021
3204
|
if (s.gzhead.comment/* != Z_NULL*/) {
|
|
3022
|
-
beg = s.pending;
|
|
3023
|
-
|
|
3024
|
-
|
|
3205
|
+
let beg = s.pending; /* start of bytes to update crc */
|
|
3206
|
+
let val;
|
|
3025
3207
|
do {
|
|
3026
3208
|
if (s.pending === s.pending_buf_size) {
|
|
3209
|
+
//--- HCRC_UPDATE(beg) ---//
|
|
3027
3210
|
if (s.gzhead.hcrc && s.pending > beg) {
|
|
3028
3211
|
strm.adler = crc32_1(strm.adler, s.pending_buf, s.pending - beg, beg);
|
|
3029
3212
|
}
|
|
3213
|
+
//---//
|
|
3030
3214
|
flush_pending(strm);
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
break;
|
|
3215
|
+
if (s.pending !== 0) {
|
|
3216
|
+
s.last_flush = -1;
|
|
3217
|
+
return Z_OK$3;
|
|
3035
3218
|
}
|
|
3219
|
+
beg = 0;
|
|
3036
3220
|
}
|
|
3037
3221
|
// JS specific: little magic to add zero terminator to end of string
|
|
3038
3222
|
if (s.gzindex < s.gzhead.comment.length) {
|
|
@@ -3042,71 +3226,46 @@ const deflate$2 = (strm, flush) => {
|
|
|
3042
3226
|
}
|
|
3043
3227
|
put_byte(s, val);
|
|
3044
3228
|
} while (val !== 0);
|
|
3045
|
-
|
|
3229
|
+
//--- HCRC_UPDATE(beg) ---//
|
|
3046
3230
|
if (s.gzhead.hcrc && s.pending > beg) {
|
|
3047
3231
|
strm.adler = crc32_1(strm.adler, s.pending_buf, s.pending - beg, beg);
|
|
3048
3232
|
}
|
|
3049
|
-
|
|
3050
|
-
s.status = HCRC_STATE;
|
|
3051
|
-
}
|
|
3052
|
-
}
|
|
3053
|
-
else {
|
|
3054
|
-
s.status = HCRC_STATE;
|
|
3233
|
+
//---//
|
|
3055
3234
|
}
|
|
3235
|
+
s.status = HCRC_STATE;
|
|
3056
3236
|
}
|
|
3057
3237
|
if (s.status === HCRC_STATE) {
|
|
3058
3238
|
if (s.gzhead.hcrc) {
|
|
3059
3239
|
if (s.pending + 2 > s.pending_buf_size) {
|
|
3060
3240
|
flush_pending(strm);
|
|
3241
|
+
if (s.pending !== 0) {
|
|
3242
|
+
s.last_flush = -1;
|
|
3243
|
+
return Z_OK$3;
|
|
3244
|
+
}
|
|
3061
3245
|
}
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
strm.adler = 0; //crc32(0L, Z_NULL, 0);
|
|
3066
|
-
s.status = BUSY_STATE;
|
|
3067
|
-
}
|
|
3246
|
+
put_byte(s, strm.adler & 0xff);
|
|
3247
|
+
put_byte(s, (strm.adler >> 8) & 0xff);
|
|
3248
|
+
strm.adler = 0; //crc32(0L, Z_NULL, 0);
|
|
3068
3249
|
}
|
|
3069
|
-
|
|
3070
|
-
s.status = BUSY_STATE;
|
|
3071
|
-
}
|
|
3072
|
-
}
|
|
3073
|
-
//#endif
|
|
3250
|
+
s.status = BUSY_STATE;
|
|
3074
3251
|
|
|
3075
|
-
|
|
3076
|
-
if (s.pending !== 0) {
|
|
3252
|
+
/* Compression must start with an empty pending buffer */
|
|
3077
3253
|
flush_pending(strm);
|
|
3078
|
-
if (
|
|
3079
|
-
/* Since avail_out is 0, deflate will be called again with
|
|
3080
|
-
* more output space, but possibly with both pending and
|
|
3081
|
-
* avail_in equal to zero. There won't be anything to do,
|
|
3082
|
-
* but this is not an error situation so make sure we
|
|
3083
|
-
* return OK instead of BUF_ERROR at next call of deflate:
|
|
3084
|
-
*/
|
|
3254
|
+
if (s.pending !== 0) {
|
|
3085
3255
|
s.last_flush = -1;
|
|
3086
3256
|
return Z_OK$3;
|
|
3087
3257
|
}
|
|
3088
|
-
|
|
3089
|
-
/* Make sure there is something to do and avoid duplicate consecutive
|
|
3090
|
-
* flushes. For repeated and useless calls with Z_FINISH, we keep
|
|
3091
|
-
* returning Z_STREAM_END instead of Z_BUF_ERROR.
|
|
3092
|
-
*/
|
|
3093
|
-
} else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) &&
|
|
3094
|
-
flush !== Z_FINISH$3) {
|
|
3095
|
-
return err(strm, Z_BUF_ERROR$1);
|
|
3096
|
-
}
|
|
3097
|
-
|
|
3098
|
-
/* User must not provide more input after the first FINISH: */
|
|
3099
|
-
if (s.status === FINISH_STATE && strm.avail_in !== 0) {
|
|
3100
|
-
return err(strm, Z_BUF_ERROR$1);
|
|
3101
3258
|
}
|
|
3259
|
+
//#endif
|
|
3102
3260
|
|
|
3103
3261
|
/* Start a new block or continue the current one.
|
|
3104
3262
|
*/
|
|
3105
3263
|
if (strm.avail_in !== 0 || s.lookahead !== 0 ||
|
|
3106
3264
|
(flush !== Z_NO_FLUSH$2 && s.status !== FINISH_STATE)) {
|
|
3107
|
-
let bstate =
|
|
3108
|
-
|
|
3109
|
-
|
|
3265
|
+
let bstate = s.level === 0 ? deflate_stored(s, flush) :
|
|
3266
|
+
s.strategy === Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
|
|
3267
|
+
s.strategy === Z_RLE ? deflate_rle(s, flush) :
|
|
3268
|
+
configuration_table[s.level].func(s, flush);
|
|
3110
3269
|
|
|
3111
3270
|
if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) {
|
|
3112
3271
|
s.status = FINISH_STATE;
|
|
@@ -3153,8 +3312,6 @@ const deflate$2 = (strm, flush) => {
|
|
|
3153
3312
|
}
|
|
3154
3313
|
}
|
|
3155
3314
|
}
|
|
3156
|
-
//Assert(strm->avail_out > 0, "bug2");
|
|
3157
|
-
//if (strm.avail_out <= 0) { throw new Error("bug2");}
|
|
3158
3315
|
|
|
3159
3316
|
if (flush !== Z_FINISH$3) { return Z_OK$3; }
|
|
3160
3317
|
if (s.wrap <= 0) { return Z_STREAM_END$3; }
|
|
@@ -3188,21 +3345,11 @@ const deflate$2 = (strm, flush) => {
|
|
|
3188
3345
|
|
|
3189
3346
|
const deflateEnd = (strm) => {
|
|
3190
3347
|
|
|
3191
|
-
if (
|
|
3348
|
+
if (deflateStateCheck(strm)) {
|
|
3192
3349
|
return Z_STREAM_ERROR$2;
|
|
3193
3350
|
}
|
|
3194
3351
|
|
|
3195
3352
|
const status = strm.state.status;
|
|
3196
|
-
if (status !== INIT_STATE &&
|
|
3197
|
-
status !== EXTRA_STATE &&
|
|
3198
|
-
status !== NAME_STATE &&
|
|
3199
|
-
status !== COMMENT_STATE &&
|
|
3200
|
-
status !== HCRC_STATE &&
|
|
3201
|
-
status !== BUSY_STATE &&
|
|
3202
|
-
status !== FINISH_STATE
|
|
3203
|
-
) {
|
|
3204
|
-
return err(strm, Z_STREAM_ERROR$2);
|
|
3205
|
-
}
|
|
3206
3353
|
|
|
3207
3354
|
strm.state = null;
|
|
3208
3355
|
|
|
@@ -3218,7 +3365,7 @@ const deflateSetDictionary = (strm, dictionary) => {
|
|
|
3218
3365
|
|
|
3219
3366
|
let dictLength = dictionary.length;
|
|
3220
3367
|
|
|
3221
|
-
if (
|
|
3368
|
+
if (deflateStateCheck(strm)) {
|
|
3222
3369
|
return Z_STREAM_ERROR$2;
|
|
3223
3370
|
}
|
|
3224
3371
|
|
|
@@ -3304,6 +3451,7 @@ var deflateInfo = 'pako deflate (from Nodeca project)';
|
|
|
3304
3451
|
/* Not implemented
|
|
3305
3452
|
module.exports.deflateBound = deflateBound;
|
|
3306
3453
|
module.exports.deflateCopy = deflateCopy;
|
|
3454
|
+
module.exports.deflateGetDictionary = deflateGetDictionary;
|
|
3307
3455
|
module.exports.deflateParams = deflateParams;
|
|
3308
3456
|
module.exports.deflatePending = deflatePending;
|
|
3309
3457
|
module.exports.deflatePrime = deflatePrime;
|
|
@@ -3893,7 +4041,7 @@ Deflate$1.prototype.onEnd = function (status) {
|
|
|
3893
4041
|
|
|
3894
4042
|
/**
|
|
3895
4043
|
* deflate(data[, options]) -> Uint8Array
|
|
3896
|
-
* - data (Uint8Array|String): input data to compress.
|
|
4044
|
+
* - data (Uint8Array|ArrayBuffer|String): input data to compress.
|
|
3897
4045
|
* - options (Object): zlib deflate options.
|
|
3898
4046
|
*
|
|
3899
4047
|
* Compress `data` with deflate algorithm and `options`.
|
|
@@ -3937,7 +4085,7 @@ function deflate$1(input, options) {
|
|
|
3937
4085
|
|
|
3938
4086
|
/**
|
|
3939
4087
|
* deflateRaw(data[, options]) -> Uint8Array
|
|
3940
|
-
* - data (Uint8Array|String): input data to compress.
|
|
4088
|
+
* - data (Uint8Array|ArrayBuffer|String): input data to compress.
|
|
3941
4089
|
* - options (Object): zlib deflate options.
|
|
3942
4090
|
*
|
|
3943
4091
|
* The same as [[deflate]], but creates raw data, without wrapper
|
|
@@ -3952,7 +4100,7 @@ function deflateRaw$1(input, options) {
|
|
|
3952
4100
|
|
|
3953
4101
|
/**
|
|
3954
4102
|
* gzip(data[, options]) -> Uint8Array
|
|
3955
|
-
* - data (Uint8Array|String): input data to compress.
|
|
4103
|
+
* - data (Uint8Array|ArrayBuffer|String): input data to compress.
|
|
3956
4104
|
* - options (Object): zlib deflate options.
|
|
3957
4105
|
*
|
|
3958
4106
|
* The same as [[deflate]], but create gzip wrapper instead of
|
|
@@ -3999,8 +4147,8 @@ var deflate_1$1 = {
|
|
|
3999
4147
|
// 3. This notice may not be removed or altered from any source distribution.
|
|
4000
4148
|
|
|
4001
4149
|
// See state defs from inflate.js
|
|
4002
|
-
const BAD$1 =
|
|
4003
|
-
const TYPE$1 =
|
|
4150
|
+
const BAD$1 = 16209; /* got a data error -- remain here until reset */
|
|
4151
|
+
const TYPE$1 = 16191; /* i: waiting for type bits, including last-flag bit */
|
|
4004
4152
|
|
|
4005
4153
|
/*
|
|
4006
4154
|
Decode literal, length, and distance codes and write out the resulting
|
|
@@ -4392,13 +4540,11 @@ const inflate_table = (type, lens, lens_index, codes, table, table_index, work,
|
|
|
4392
4540
|
let mask; /* mask for low root bits */
|
|
4393
4541
|
let next; /* next available space in table */
|
|
4394
4542
|
let base = null; /* base value table to use */
|
|
4395
|
-
let base_index = 0;
|
|
4396
4543
|
// let shoextra; /* extra bits table to use */
|
|
4397
|
-
let
|
|
4544
|
+
let match; /* use base and extra for symbol >= match */
|
|
4398
4545
|
const count = new Uint16Array(MAXBITS + 1); //[MAXBITS+1]; /* number of codes of each length */
|
|
4399
4546
|
const offs = new Uint16Array(MAXBITS + 1); //[MAXBITS+1]; /* offsets in table for each length */
|
|
4400
4547
|
let extra = null;
|
|
4401
|
-
let extra_index = 0;
|
|
4402
4548
|
|
|
4403
4549
|
let here_bits, here_op, here_val;
|
|
4404
4550
|
|
|
@@ -4533,19 +4679,17 @@ const inflate_table = (type, lens, lens_index, codes, table, table_index, work,
|
|
|
4533
4679
|
// to avoid deopts in old v8
|
|
4534
4680
|
if (type === CODES$1) {
|
|
4535
4681
|
base = extra = work; /* dummy value--not used */
|
|
4536
|
-
|
|
4682
|
+
match = 20;
|
|
4537
4683
|
|
|
4538
4684
|
} else if (type === LENS$1) {
|
|
4539
4685
|
base = lbase;
|
|
4540
|
-
base_index -= 257;
|
|
4541
4686
|
extra = lext;
|
|
4542
|
-
|
|
4543
|
-
end = 256;
|
|
4687
|
+
match = 257;
|
|
4544
4688
|
|
|
4545
4689
|
} else { /* DISTS */
|
|
4546
4690
|
base = dbase;
|
|
4547
4691
|
extra = dext;
|
|
4548
|
-
|
|
4692
|
+
match = 0;
|
|
4549
4693
|
}
|
|
4550
4694
|
|
|
4551
4695
|
/* initialize opts for loop */
|
|
@@ -4569,13 +4713,13 @@ const inflate_table = (type, lens, lens_index, codes, table, table_index, work,
|
|
|
4569
4713
|
for (;;) {
|
|
4570
4714
|
/* create table entry */
|
|
4571
4715
|
here_bits = len - drop;
|
|
4572
|
-
if (work[sym] <
|
|
4716
|
+
if (work[sym] + 1 < match) {
|
|
4573
4717
|
here_op = 0;
|
|
4574
4718
|
here_val = work[sym];
|
|
4575
4719
|
}
|
|
4576
|
-
else if (work[sym]
|
|
4577
|
-
here_op = extra[
|
|
4578
|
-
here_val = base[
|
|
4720
|
+
else if (work[sym] >= match) {
|
|
4721
|
+
here_op = extra[work[sym] - match];
|
|
4722
|
+
here_val = base[work[sym] - match];
|
|
4579
4723
|
}
|
|
4580
4724
|
else {
|
|
4581
4725
|
here_op = 32 + 64; /* end of block */
|
|
@@ -4707,38 +4851,38 @@ const {
|
|
|
4707
4851
|
/* ===========================================================================*/
|
|
4708
4852
|
|
|
4709
4853
|
|
|
4710
|
-
const HEAD =
|
|
4711
|
-
const FLAGS =
|
|
4712
|
-
const TIME =
|
|
4713
|
-
const OS =
|
|
4714
|
-
const EXLEN =
|
|
4715
|
-
const EXTRA =
|
|
4716
|
-
const NAME =
|
|
4717
|
-
const COMMENT =
|
|
4718
|
-
const HCRC =
|
|
4719
|
-
const DICTID =
|
|
4720
|
-
const DICT =
|
|
4721
|
-
const TYPE =
|
|
4722
|
-
const TYPEDO =
|
|
4723
|
-
const STORED =
|
|
4724
|
-
const COPY_ =
|
|
4725
|
-
const COPY =
|
|
4726
|
-
const TABLE =
|
|
4727
|
-
const LENLENS =
|
|
4728
|
-
const CODELENS =
|
|
4729
|
-
const LEN_ =
|
|
4730
|
-
const LEN =
|
|
4731
|
-
const LENEXT =
|
|
4732
|
-
const DIST =
|
|
4733
|
-
const DISTEXT =
|
|
4734
|
-
const MATCH =
|
|
4735
|
-
const LIT =
|
|
4736
|
-
const CHECK =
|
|
4737
|
-
const LENGTH =
|
|
4738
|
-
const DONE =
|
|
4739
|
-
const BAD =
|
|
4740
|
-
const MEM =
|
|
4741
|
-
const SYNC =
|
|
4854
|
+
const HEAD = 16180; /* i: waiting for magic header */
|
|
4855
|
+
const FLAGS = 16181; /* i: waiting for method and flags (gzip) */
|
|
4856
|
+
const TIME = 16182; /* i: waiting for modification time (gzip) */
|
|
4857
|
+
const OS = 16183; /* i: waiting for extra flags and operating system (gzip) */
|
|
4858
|
+
const EXLEN = 16184; /* i: waiting for extra length (gzip) */
|
|
4859
|
+
const EXTRA = 16185; /* i: waiting for extra bytes (gzip) */
|
|
4860
|
+
const NAME = 16186; /* i: waiting for end of file name (gzip) */
|
|
4861
|
+
const COMMENT = 16187; /* i: waiting for end of comment (gzip) */
|
|
4862
|
+
const HCRC = 16188; /* i: waiting for header crc (gzip) */
|
|
4863
|
+
const DICTID = 16189; /* i: waiting for dictionary check value */
|
|
4864
|
+
const DICT = 16190; /* waiting for inflateSetDictionary() call */
|
|
4865
|
+
const TYPE = 16191; /* i: waiting for type bits, including last-flag bit */
|
|
4866
|
+
const TYPEDO = 16192; /* i: same, but skip check to exit inflate on new block */
|
|
4867
|
+
const STORED = 16193; /* i: waiting for stored size (length and complement) */
|
|
4868
|
+
const COPY_ = 16194; /* i/o: same as COPY below, but only first time in */
|
|
4869
|
+
const COPY = 16195; /* i/o: waiting for input or output to copy stored block */
|
|
4870
|
+
const TABLE = 16196; /* i: waiting for dynamic block table lengths */
|
|
4871
|
+
const LENLENS = 16197; /* i: waiting for code length code lengths */
|
|
4872
|
+
const CODELENS = 16198; /* i: waiting for length/lit and distance code lengths */
|
|
4873
|
+
const LEN_ = 16199; /* i: same as LEN below, but only first time in */
|
|
4874
|
+
const LEN = 16200; /* i: waiting for length/lit/eob code */
|
|
4875
|
+
const LENEXT = 16201; /* i: waiting for length extra bits */
|
|
4876
|
+
const DIST = 16202; /* i: waiting for distance code */
|
|
4877
|
+
const DISTEXT = 16203; /* i: waiting for distance extra bits */
|
|
4878
|
+
const MATCH = 16204; /* o: waiting for output space to copy string */
|
|
4879
|
+
const LIT = 16205; /* o: waiting for output space to write literal */
|
|
4880
|
+
const CHECK = 16206; /* i: waiting for 32-bit check value */
|
|
4881
|
+
const LENGTH = 16207; /* i: waiting for 32-bit length (gzip) */
|
|
4882
|
+
const DONE = 16208; /* finished check, done -- remain here until reset */
|
|
4883
|
+
const BAD = 16209; /* got a data error -- remain here until reset */
|
|
4884
|
+
const MEM = 16210; /* got an inflate() memory error -- remain here until reset */
|
|
4885
|
+
const SYNC = 16211; /* looking for synchronization bytes to restart inflate() */
|
|
4742
4886
|
|
|
4743
4887
|
/* ===========================================================================*/
|
|
4744
4888
|
|
|
@@ -4763,11 +4907,14 @@ const zswap32 = (q) => {
|
|
|
4763
4907
|
|
|
4764
4908
|
|
|
4765
4909
|
function InflateState() {
|
|
4766
|
-
this.
|
|
4910
|
+
this.strm = null; /* pointer back to this zlib stream */
|
|
4911
|
+
this.mode = 0; /* current inflate mode */
|
|
4767
4912
|
this.last = false; /* true if processing last block */
|
|
4768
|
-
this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip
|
|
4913
|
+
this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip,
|
|
4914
|
+
bit 2 true to validate check value */
|
|
4769
4915
|
this.havedict = false; /* true if dictionary provided */
|
|
4770
|
-
this.flags = 0; /* gzip header method and flags (0 if zlib)
|
|
4916
|
+
this.flags = 0; /* gzip header method and flags (0 if zlib), or
|
|
4917
|
+
-1 if raw or no header yet */
|
|
4771
4918
|
this.dmax = 0; /* zlib header max distance (INFLATE_STRICT) */
|
|
4772
4919
|
this.check = 0; /* protected copy of check value */
|
|
4773
4920
|
this.total = 0; /* protected copy of output count */
|
|
@@ -4821,9 +4968,23 @@ function InflateState() {
|
|
|
4821
4968
|
}
|
|
4822
4969
|
|
|
4823
4970
|
|
|
4971
|
+
const inflateStateCheck = (strm) => {
|
|
4972
|
+
|
|
4973
|
+
if (!strm) {
|
|
4974
|
+
return 1;
|
|
4975
|
+
}
|
|
4976
|
+
const state = strm.state;
|
|
4977
|
+
if (!state || state.strm !== strm ||
|
|
4978
|
+
state.mode < HEAD || state.mode > SYNC) {
|
|
4979
|
+
return 1;
|
|
4980
|
+
}
|
|
4981
|
+
return 0;
|
|
4982
|
+
};
|
|
4983
|
+
|
|
4984
|
+
|
|
4824
4985
|
const inflateResetKeep = (strm) => {
|
|
4825
4986
|
|
|
4826
|
-
if (
|
|
4987
|
+
if (inflateStateCheck(strm)) { return Z_STREAM_ERROR$1; }
|
|
4827
4988
|
const state = strm.state;
|
|
4828
4989
|
strm.total_in = strm.total_out = state.total = 0;
|
|
4829
4990
|
strm.msg = ''; /*Z_NULL*/
|
|
@@ -4833,6 +4994,7 @@ const inflateResetKeep = (strm) => {
|
|
|
4833
4994
|
state.mode = HEAD;
|
|
4834
4995
|
state.last = 0;
|
|
4835
4996
|
state.havedict = 0;
|
|
4997
|
+
state.flags = -1;
|
|
4836
4998
|
state.dmax = 32768;
|
|
4837
4999
|
state.head = null/*Z_NULL*/;
|
|
4838
5000
|
state.hold = 0;
|
|
@@ -4850,7 +5012,7 @@ const inflateResetKeep = (strm) => {
|
|
|
4850
5012
|
|
|
4851
5013
|
const inflateReset = (strm) => {
|
|
4852
5014
|
|
|
4853
|
-
if (
|
|
5015
|
+
if (inflateStateCheck(strm)) { return Z_STREAM_ERROR$1; }
|
|
4854
5016
|
const state = strm.state;
|
|
4855
5017
|
state.wsize = 0;
|
|
4856
5018
|
state.whave = 0;
|
|
@@ -4864,7 +5026,7 @@ const inflateReset2 = (strm, windowBits) => {
|
|
|
4864
5026
|
let wrap;
|
|
4865
5027
|
|
|
4866
5028
|
/* get the state */
|
|
4867
|
-
if (
|
|
5029
|
+
if (inflateStateCheck(strm)) { return Z_STREAM_ERROR$1; }
|
|
4868
5030
|
const state = strm.state;
|
|
4869
5031
|
|
|
4870
5032
|
/* extract wrap request from windowBits parameter */
|
|
@@ -4873,7 +5035,7 @@ const inflateReset2 = (strm, windowBits) => {
|
|
|
4873
5035
|
windowBits = -windowBits;
|
|
4874
5036
|
}
|
|
4875
5037
|
else {
|
|
4876
|
-
wrap = (windowBits >> 4) +
|
|
5038
|
+
wrap = (windowBits >> 4) + 5;
|
|
4877
5039
|
if (windowBits < 48) {
|
|
4878
5040
|
windowBits &= 15;
|
|
4879
5041
|
}
|
|
@@ -4904,7 +5066,9 @@ const inflateInit2 = (strm, windowBits) => {
|
|
|
4904
5066
|
//if (state === Z_NULL) return Z_MEM_ERROR;
|
|
4905
5067
|
//Tracev((stderr, "inflate: allocated\n"));
|
|
4906
5068
|
strm.state = state;
|
|
5069
|
+
state.strm = strm;
|
|
4907
5070
|
state.window = null/*Z_NULL*/;
|
|
5071
|
+
state.mode = HEAD; /* to pass state test in inflateReset2() */
|
|
4908
5072
|
const ret = inflateReset2(strm, windowBits);
|
|
4909
5073
|
if (ret !== Z_OK$1) {
|
|
4910
5074
|
strm.state = null/*Z_NULL*/;
|
|
@@ -5053,7 +5217,7 @@ const inflate$2 = (strm, flush) => {
|
|
|
5053
5217
|
new Uint8Array([ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 ]);
|
|
5054
5218
|
|
|
5055
5219
|
|
|
5056
|
-
if (
|
|
5220
|
+
if (inflateStateCheck(strm) || !strm.output ||
|
|
5057
5221
|
(!strm.input && strm.avail_in !== 0)) {
|
|
5058
5222
|
return Z_STREAM_ERROR$1;
|
|
5059
5223
|
}
|
|
@@ -5094,6 +5258,9 @@ const inflate$2 = (strm, flush) => {
|
|
|
5094
5258
|
}
|
|
5095
5259
|
//===//
|
|
5096
5260
|
if ((state.wrap & 2) && hold === 0x8b1f) { /* gzip header */
|
|
5261
|
+
if (state.wbits === 0) {
|
|
5262
|
+
state.wbits = 15;
|
|
5263
|
+
}
|
|
5097
5264
|
state.check = 0/*crc32(0L, Z_NULL, 0)*/;
|
|
5098
5265
|
//=== CRC2(state.check, hold);
|
|
5099
5266
|
hbuf[0] = hold & 0xff;
|
|
@@ -5108,7 +5275,6 @@ const inflate$2 = (strm, flush) => {
|
|
|
5108
5275
|
state.mode = FLAGS;
|
|
5109
5276
|
break;
|
|
5110
5277
|
}
|
|
5111
|
-
state.flags = 0; /* expect zlib header */
|
|
5112
5278
|
if (state.head) {
|
|
5113
5279
|
state.head.done = false;
|
|
5114
5280
|
}
|
|
@@ -5131,7 +5297,7 @@ const inflate$2 = (strm, flush) => {
|
|
|
5131
5297
|
if (state.wbits === 0) {
|
|
5132
5298
|
state.wbits = len;
|
|
5133
5299
|
}
|
|
5134
|
-
|
|
5300
|
+
if (len > 15 || len > state.wbits) {
|
|
5135
5301
|
strm.msg = 'invalid window size';
|
|
5136
5302
|
state.mode = BAD;
|
|
5137
5303
|
break;
|
|
@@ -5142,6 +5308,7 @@ const inflate$2 = (strm, flush) => {
|
|
|
5142
5308
|
state.dmax = 1 << state.wbits;
|
|
5143
5309
|
//state.dmax = 1 << len;
|
|
5144
5310
|
|
|
5311
|
+
state.flags = 0; /* indicate zlib header */
|
|
5145
5312
|
//Tracev((stderr, "inflate: zlib header ok\n"));
|
|
5146
5313
|
strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
|
|
5147
5314
|
state.mode = hold & 0x200 ? DICTID : TYPE;
|
|
@@ -5173,7 +5340,7 @@ const inflate$2 = (strm, flush) => {
|
|
|
5173
5340
|
if (state.head) {
|
|
5174
5341
|
state.head.text = ((hold >> 8) & 1);
|
|
5175
5342
|
}
|
|
5176
|
-
if (state.flags & 0x0200) {
|
|
5343
|
+
if ((state.flags & 0x0200) && (state.wrap & 4)) {
|
|
5177
5344
|
//=== CRC2(state.check, hold);
|
|
5178
5345
|
hbuf[0] = hold & 0xff;
|
|
5179
5346
|
hbuf[1] = (hold >>> 8) & 0xff;
|
|
@@ -5198,7 +5365,7 @@ const inflate$2 = (strm, flush) => {
|
|
|
5198
5365
|
if (state.head) {
|
|
5199
5366
|
state.head.time = hold;
|
|
5200
5367
|
}
|
|
5201
|
-
if (state.flags & 0x0200) {
|
|
5368
|
+
if ((state.flags & 0x0200) && (state.wrap & 4)) {
|
|
5202
5369
|
//=== CRC4(state.check, hold)
|
|
5203
5370
|
hbuf[0] = hold & 0xff;
|
|
5204
5371
|
hbuf[1] = (hold >>> 8) & 0xff;
|
|
@@ -5226,7 +5393,7 @@ const inflate$2 = (strm, flush) => {
|
|
|
5226
5393
|
state.head.xflags = (hold & 0xff);
|
|
5227
5394
|
state.head.os = (hold >> 8);
|
|
5228
5395
|
}
|
|
5229
|
-
if (state.flags & 0x0200) {
|
|
5396
|
+
if ((state.flags & 0x0200) && (state.wrap & 4)) {
|
|
5230
5397
|
//=== CRC2(state.check, hold);
|
|
5231
5398
|
hbuf[0] = hold & 0xff;
|
|
5232
5399
|
hbuf[1] = (hold >>> 8) & 0xff;
|
|
@@ -5253,7 +5420,7 @@ const inflate$2 = (strm, flush) => {
|
|
|
5253
5420
|
if (state.head) {
|
|
5254
5421
|
state.head.extra_len = hold;
|
|
5255
5422
|
}
|
|
5256
|
-
if (state.flags & 0x0200) {
|
|
5423
|
+
if ((state.flags & 0x0200) && (state.wrap & 4)) {
|
|
5257
5424
|
//=== CRC2(state.check, hold);
|
|
5258
5425
|
hbuf[0] = hold & 0xff;
|
|
5259
5426
|
hbuf[1] = (hold >>> 8) & 0xff;
|
|
@@ -5295,7 +5462,7 @@ const inflate$2 = (strm, flush) => {
|
|
|
5295
5462
|
// len + copy > state.head.extra_max ?
|
|
5296
5463
|
// state.head.extra_max - len : copy);
|
|
5297
5464
|
}
|
|
5298
|
-
if (state.flags & 0x0200) {
|
|
5465
|
+
if ((state.flags & 0x0200) && (state.wrap & 4)) {
|
|
5299
5466
|
state.check = crc32_1(state.check, input, copy, next);
|
|
5300
5467
|
}
|
|
5301
5468
|
have -= copy;
|
|
@@ -5321,7 +5488,7 @@ const inflate$2 = (strm, flush) => {
|
|
|
5321
5488
|
}
|
|
5322
5489
|
} while (len && copy < have);
|
|
5323
5490
|
|
|
5324
|
-
if (state.flags & 0x0200) {
|
|
5491
|
+
if ((state.flags & 0x0200) && (state.wrap & 4)) {
|
|
5325
5492
|
state.check = crc32_1(state.check, input, copy, next);
|
|
5326
5493
|
}
|
|
5327
5494
|
have -= copy;
|
|
@@ -5346,7 +5513,7 @@ const inflate$2 = (strm, flush) => {
|
|
|
5346
5513
|
state.head.comment += String.fromCharCode(len);
|
|
5347
5514
|
}
|
|
5348
5515
|
} while (len && copy < have);
|
|
5349
|
-
if (state.flags & 0x0200) {
|
|
5516
|
+
if ((state.flags & 0x0200) && (state.wrap & 4)) {
|
|
5350
5517
|
state.check = crc32_1(state.check, input, copy, next);
|
|
5351
5518
|
}
|
|
5352
5519
|
have -= copy;
|
|
@@ -5368,7 +5535,7 @@ const inflate$2 = (strm, flush) => {
|
|
|
5368
5535
|
bits += 8;
|
|
5369
5536
|
}
|
|
5370
5537
|
//===//
|
|
5371
|
-
if (hold !== (state.check & 0xffff)) {
|
|
5538
|
+
if ((state.wrap & 4) && hold !== (state.check & 0xffff)) {
|
|
5372
5539
|
strm.msg = 'header crc mismatch';
|
|
5373
5540
|
state.mode = BAD;
|
|
5374
5541
|
break;
|
|
@@ -6021,15 +6188,15 @@ const inflate$2 = (strm, flush) => {
|
|
|
6021
6188
|
_out -= left;
|
|
6022
6189
|
strm.total_out += _out;
|
|
6023
6190
|
state.total += _out;
|
|
6024
|
-
if (_out) {
|
|
6191
|
+
if ((state.wrap & 4) && _out) {
|
|
6025
6192
|
strm.adler = state.check =
|
|
6026
|
-
/*
|
|
6193
|
+
/*UPDATE_CHECK(state.check, put - _out, _out);*/
|
|
6027
6194
|
(state.flags ? crc32_1(state.check, output, _out, put - _out) : adler32_1(state.check, output, _out, put - _out));
|
|
6028
6195
|
|
|
6029
6196
|
}
|
|
6030
6197
|
_out = left;
|
|
6031
6198
|
// NB: crc32 stored as signed 32-bit int, zswap32 returns signed too
|
|
6032
|
-
if ((state.flags ? hold : zswap32(hold)) !== state.check) {
|
|
6199
|
+
if ((state.wrap & 4) && (state.flags ? hold : zswap32(hold)) !== state.check) {
|
|
6033
6200
|
strm.msg = 'incorrect data check';
|
|
6034
6201
|
state.mode = BAD;
|
|
6035
6202
|
break;
|
|
@@ -6052,7 +6219,7 @@ const inflate$2 = (strm, flush) => {
|
|
|
6052
6219
|
bits += 8;
|
|
6053
6220
|
}
|
|
6054
6221
|
//===//
|
|
6055
|
-
if (hold !== (state.total & 0xffffffff)) {
|
|
6222
|
+
if ((state.wrap & 4) && hold !== (state.total & 0xffffffff)) {
|
|
6056
6223
|
strm.msg = 'incorrect length check';
|
|
6057
6224
|
state.mode = BAD;
|
|
6058
6225
|
break;
|
|
@@ -6107,8 +6274,8 @@ const inflate$2 = (strm, flush) => {
|
|
|
6107
6274
|
strm.total_in += _in;
|
|
6108
6275
|
strm.total_out += _out;
|
|
6109
6276
|
state.total += _out;
|
|
6110
|
-
if (state.wrap && _out) {
|
|
6111
|
-
strm.adler = state.check = /*
|
|
6277
|
+
if ((state.wrap & 4) && _out) {
|
|
6278
|
+
strm.adler = state.check = /*UPDATE_CHECK(state.check, strm.next_out - _out, _out);*/
|
|
6112
6279
|
(state.flags ? crc32_1(state.check, output, _out, strm.next_out - _out) : adler32_1(state.check, output, _out, strm.next_out - _out));
|
|
6113
6280
|
}
|
|
6114
6281
|
strm.data_type = state.bits + (state.last ? 64 : 0) +
|
|
@@ -6123,7 +6290,7 @@ const inflate$2 = (strm, flush) => {
|
|
|
6123
6290
|
|
|
6124
6291
|
const inflateEnd = (strm) => {
|
|
6125
6292
|
|
|
6126
|
-
if (
|
|
6293
|
+
if (inflateStateCheck(strm)) {
|
|
6127
6294
|
return Z_STREAM_ERROR$1;
|
|
6128
6295
|
}
|
|
6129
6296
|
|
|
@@ -6139,7 +6306,7 @@ const inflateEnd = (strm) => {
|
|
|
6139
6306
|
const inflateGetHeader = (strm, head) => {
|
|
6140
6307
|
|
|
6141
6308
|
/* check state */
|
|
6142
|
-
if (
|
|
6309
|
+
if (inflateStateCheck(strm)) { return Z_STREAM_ERROR$1; }
|
|
6143
6310
|
const state = strm.state;
|
|
6144
6311
|
if ((state.wrap & 2) === 0) { return Z_STREAM_ERROR$1; }
|
|
6145
6312
|
|
|
@@ -6158,7 +6325,7 @@ const inflateSetDictionary = (strm, dictionary) => {
|
|
|
6158
6325
|
let ret;
|
|
6159
6326
|
|
|
6160
6327
|
/* check state */
|
|
6161
|
-
if (
|
|
6328
|
+
if (inflateStateCheck(strm)) { return Z_STREAM_ERROR$1; }
|
|
6162
6329
|
state = strm.state;
|
|
6163
6330
|
|
|
6164
6331
|
if (state.wrap !== 0 && state.mode !== DICT) {
|
|
@@ -6199,6 +6366,7 @@ var inflateSetDictionary_1 = inflateSetDictionary;
|
|
|
6199
6366
|
var inflateInfo = 'pako inflate (from Nodeca project)';
|
|
6200
6367
|
|
|
6201
6368
|
/* Not implemented
|
|
6369
|
+
module.exports.inflateCodesUsed = inflateCodesUsed;
|
|
6202
6370
|
module.exports.inflateCopy = inflateCopy;
|
|
6203
6371
|
module.exports.inflateGetDictionary = inflateGetDictionary;
|
|
6204
6372
|
module.exports.inflateMark = inflateMark;
|
|
@@ -6206,6 +6374,7 @@ module.exports.inflatePrime = inflatePrime;
|
|
|
6206
6374
|
module.exports.inflateSync = inflateSync;
|
|
6207
6375
|
module.exports.inflateSyncPoint = inflateSyncPoint;
|
|
6208
6376
|
module.exports.inflateUndermine = inflateUndermine;
|
|
6377
|
+
module.exports.inflateValidate = inflateValidate;
|
|
6209
6378
|
*/
|
|
6210
6379
|
|
|
6211
6380
|
var inflate_1$2 = {
|
|
@@ -6608,7 +6777,7 @@ Inflate$1.prototype.onEnd = function (status) {
|
|
|
6608
6777
|
|
|
6609
6778
|
/**
|
|
6610
6779
|
* inflate(data[, options]) -> Uint8Array|String
|
|
6611
|
-
* - data (Uint8Array): input data to decompress.
|
|
6780
|
+
* - data (Uint8Array|ArrayBuffer): input data to decompress.
|
|
6612
6781
|
* - options (Object): zlib inflate options.
|
|
6613
6782
|
*
|
|
6614
6783
|
* Decompress `data` with inflate/ungzip and `options`. Autodetect
|
|
@@ -6659,7 +6828,7 @@ function inflate$1(input, options) {
|
|
|
6659
6828
|
|
|
6660
6829
|
/**
|
|
6661
6830
|
* inflateRaw(data[, options]) -> Uint8Array|String
|
|
6662
|
-
* - data (Uint8Array): input data to decompress.
|
|
6831
|
+
* - data (Uint8Array|ArrayBuffer): input data to decompress.
|
|
6663
6832
|
* - options (Object): zlib inflate options.
|
|
6664
6833
|
*
|
|
6665
6834
|
* The same as [[inflate]], but creates raw data, without wrapper
|
|
@@ -6674,7 +6843,7 @@ function inflateRaw$1(input, options) {
|
|
|
6674
6843
|
|
|
6675
6844
|
/**
|
|
6676
6845
|
* ungzip(data[, options]) -> Uint8Array|String
|
|
6677
|
-
* - data (Uint8Array): input data to decompress.
|
|
6846
|
+
* - data (Uint8Array|ArrayBuffer): input data to decompress.
|
|
6678
6847
|
* - options (Object): zlib inflate options.
|
|
6679
6848
|
*
|
|
6680
6849
|
* Just shortcut to [[inflate]], because it autodetects format
|