ry-vue-map 0.6.13 → 0.6.14

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