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