@zip.js/zip.js 2.6.24 → 2.6.26

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.
Files changed (52) hide show
  1. package/README.md +16 -17
  2. package/dist/z-worker-fflate.js +1 -1
  3. package/dist/z-worker-pako.js +1 -1
  4. package/dist/z-worker.js +1 -1
  5. package/dist/zip-fs-full.js +3698 -3693
  6. package/dist/zip-fs-full.min.js +1 -1
  7. package/dist/zip-fs.js +89 -73
  8. package/dist/zip-fs.min.js +1 -1
  9. package/dist/zip-full.js +3675 -3670
  10. package/dist/zip-full.min.js +1 -1
  11. package/dist/zip-no-worker-deflate.min.js +1 -1
  12. package/dist/zip-no-worker-inflate.min.js +1 -1
  13. package/dist/zip-no-worker.min.js +1 -1
  14. package/dist/zip.js +89 -73
  15. package/dist/zip.min.js +1 -1
  16. package/index.d.ts +11 -11
  17. package/index.js +2 -2
  18. package/lib/core/codec-interface.js +36 -19
  19. package/lib/core/codec-pool-worker.js +2 -2
  20. package/lib/core/codec-pool.js +2 -2
  21. package/lib/core/streams/aes-crypto-stream.js +1 -1
  22. package/lib/core/streams/codec-stream.js +3 -1
  23. package/lib/core/streams/codecs/crc32.js +3 -1
  24. package/lib/core/streams/codecs/deflate.js +1792 -1796
  25. package/lib/core/streams/codecs/inflate.js +1828 -1831
  26. package/lib/core/streams/crc32-stream.js +7 -7
  27. package/lib/core/streams/zip-crypto-stream.js +1 -1
  28. package/lib/core/streams/zip-entry-stream.js +2 -2
  29. package/lib/core/util/cp437-decode.js +6 -2
  30. package/lib/core/util/decode-text.js +4 -2
  31. package/lib/core/util/encode-text.js +3 -1
  32. package/lib/core/util/stream-codec-shim.js +6 -2
  33. package/lib/core/zip-entry.js +6 -2
  34. package/lib/core/zip-reader.js +17 -5
  35. package/lib/core/zip-writer.js +27 -10
  36. package/lib/z-worker-bootstrap-fflate.js +1 -1
  37. package/lib/z-worker-bootstrap-pako.js +1 -1
  38. package/lib/z-worker-inline-template.js +9 -7
  39. package/lib/z-worker-inline.js +1 -1
  40. package/lib/z-worker.js +2 -2
  41. package/lib/zip-fflate-shim.js +1 -1
  42. package/lib/zip-fs.js +2 -2
  43. package/lib/zip-full-fflate.js +2 -2
  44. package/lib/zip-full.js +4 -4
  45. package/lib/zip-no-worker-deflate.js +1 -1
  46. package/lib/zip-no-worker-inflate.js +1 -1
  47. package/lib/zip-no-worker.js +2 -2
  48. package/lib/zip.js +2 -2
  49. package/package.json +1 -1
  50. package/tests/all/test-streams.js +29 -0
  51. package/tests/tests-data.js +1 -0
  52. package/lib/z-worker-inline-template-base64.js +0 -36
@@ -37,674 +37,741 @@
37
37
 
38
38
  // Global
39
39
 
40
- const ZipInflate = (() => {
41
-
42
- const MAX_BITS = 15;
43
-
44
- const Z_OK = 0;
45
- const Z_STREAM_END = 1;
46
- const Z_NEED_DICT = 2;
47
- const Z_STREAM_ERROR = -2;
48
- const Z_DATA_ERROR = -3;
49
- const Z_MEM_ERROR = -4;
50
- const Z_BUF_ERROR = -5;
51
-
52
- const inflate_mask = [0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff, 0x000003ff,
53
- 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff];
54
-
55
- const MANY = 1440;
56
-
57
- // JZlib version : "1.0.2"
58
- const Z_NO_FLUSH = 0;
59
- const Z_FINISH = 4;
60
-
61
- // InfTree
62
- const fixed_bl = 9;
63
- const fixed_bd = 5;
64
-
65
- const fixed_tl = [96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 192, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 160, 0, 8, 0,
66
- 0, 8, 128, 0, 8, 64, 0, 9, 224, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 144, 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 208, 81, 7, 17, 0, 8, 104, 0, 8, 40,
67
- 0, 9, 176, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 240, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 200, 81, 7, 13,
68
- 0, 8, 100, 0, 8, 36, 0, 9, 168, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 232, 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 152, 84, 7, 83, 0, 8, 124, 0, 8, 60,
69
- 0, 9, 216, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 184, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 248, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7,
70
- 35, 0, 8, 114, 0, 8, 50, 0, 9, 196, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 164, 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 228, 80, 7, 7, 0, 8, 90, 0, 8,
71
- 26, 0, 9, 148, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 212, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 180, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 244, 80,
72
- 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 204, 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 172, 0, 8, 6, 0, 8, 134, 0,
73
- 8, 70, 0, 9, 236, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 156, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 220, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 188, 0,
74
- 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 252, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 194, 80, 7, 10, 0, 8, 97,
75
- 0, 8, 33, 0, 9, 162, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 226, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 146, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 210,
76
- 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 178, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 242, 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117,
77
- 0, 8, 53, 0, 9, 202, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 170, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 234, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 154,
78
- 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 218, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 186, 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 250, 80, 7, 3, 0, 8, 83,
79
- 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 198, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 166, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 230,
80
- 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 150, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 214, 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 182, 0, 8, 11, 0, 8, 139,
81
- 0, 8, 75, 0, 9, 246, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 206, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 174,
82
- 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 238, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 158, 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 222, 82, 7, 27, 0, 8, 111,
83
- 0, 8, 47, 0, 9, 190, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 254, 96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9,
84
- 193, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 161, 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 225, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 145, 83, 7, 59, 0, 8,
85
- 120, 0, 8, 56, 0, 9, 209, 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 177, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 241, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8,
86
- 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 201, 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 169, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 233, 80, 7, 8, 0, 8,
87
- 92, 0, 8, 28, 0, 9, 153, 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 217, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 185, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9,
88
- 249, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 197, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 165, 0, 8, 2, 0, 8,
89
- 130, 0, 8, 66, 0, 9, 229, 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 149, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 213, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9,
90
- 181, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 245, 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 205, 81, 7, 15, 0, 8,
91
- 102, 0, 8, 38, 0, 9, 173, 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 237, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 157, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9,
92
- 221, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 189, 0, 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 253, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0,
93
- 8, 113, 0, 8, 49, 0, 9, 195, 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 163, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 227, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9,
94
- 147, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 211, 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 179, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 243, 80, 7, 4, 0, 8,
95
- 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 203, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 171, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9,
96
- 235, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 155, 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 219, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 187, 0, 8, 13, 0, 8,
97
- 141, 0, 8, 77, 0, 9, 251, 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 199, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9,
98
- 167, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 231, 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 151, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 215, 82, 7, 19, 0, 8,
99
- 107, 0, 8, 43, 0, 9, 183, 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 247, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9,
100
- 207, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 175, 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 239, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 159, 84, 7, 99, 0, 8,
101
- 127, 0, 8, 63, 0, 9, 223, 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 191, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 255];
102
- const fixed_td = [80, 5, 1, 87, 5, 257, 83, 5, 17, 91, 5, 4097, 81, 5, 5, 89, 5, 1025, 85, 5, 65, 93, 5, 16385, 80, 5, 3, 88, 5, 513, 84, 5, 33, 92, 5,
103
- 8193, 82, 5, 9, 90, 5, 2049, 86, 5, 129, 192, 5, 24577, 80, 5, 2, 87, 5, 385, 83, 5, 25, 91, 5, 6145, 81, 5, 7, 89, 5, 1537, 85, 5, 97, 93, 5,
104
- 24577, 80, 5, 4, 88, 5, 769, 84, 5, 49, 92, 5, 12289, 82, 5, 13, 90, 5, 3073, 86, 5, 193, 192, 5, 24577];
105
-
106
- // Tables for deflate from PKZIP's appnote.txt.
107
- const cplens = [ // Copy lengths for literal codes 257..285
108
- 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0];
109
-
110
- // see note #13 above about 258
111
- const cplext = [ // Extra bits for literal codes 257..285
112
- 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 // 112==invalid
113
- ];
114
-
115
- const cpdist = [ // Copy offsets for distance codes 0..29
116
- 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577];
117
-
118
- const cpdext = [ // Extra bits for distance codes
119
- 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13];
120
-
121
- // If BMAX needs to be larger than 16, then h and x[] should be uLong.
122
- const BMAX = 15; // maximum bit length of any code
123
-
124
- function InfTree() {
125
- const that = this;
126
-
127
- let hn; // hufts used in space
128
- let v; // work area for huft_build
129
- let c; // bit length count table
130
- let r; // table entry for structure assignment
131
- let u; // table stack
132
- let x; // bit offsets, then code stack
133
-
134
- function huft_build(b, // code lengths in bits (all assumed <=
135
- // BMAX)
136
- bindex, n, // number of codes (assumed <= 288)
137
- s, // number of simple-valued codes (0..s-1)
138
- d, // list of base values for non-simple codes
139
- e, // list of extra bits for non-simple codes
140
- t, // result: starting table
141
- m, // maximum lookup bits, returns actual
142
- hp,// space for trees
143
- hn,// hufts used in space
144
- v // working area: values in order of bit length
145
- ) {
146
- // Given a list of code lengths and a maximum table size, make a set of
147
- // tables to decode that set of codes. Return Z_OK on success,
148
- // Z_BUF_ERROR
149
- // if the given code set is incomplete (the tables are still built in
150
- // this
151
- // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set
152
- // of
153
- // lengths), or Z_MEM_ERROR if not enough memory.
154
-
155
- let a; // counter for codes of length k
156
- let f; // i repeats in table every f entries
157
- let g; // maximum code length
158
- let h; // table level
159
- let i; // counter, current code
160
- let j; // counter
161
- let k; // number of bits in current code
162
- let l; // bits per table (returned in m)
163
- let mask; // (1 << w) - 1, to avoid cc -O bug on HP
164
- let p; // pointer into c[], b[], or v[]
165
- let q; // points to current table
166
- let w; // bits before this table == (l * h)
167
- let xp; // pointer into x
168
- let y; // number of dummy codes added
169
- let z; // number of entries in current table
170
-
171
- // Generate counts for each bit length
172
-
173
- p = 0;
174
- i = n;
175
- do {
176
- c[b[bindex + p]]++;
177
- p++;
178
- i--; // assume all entries <= BMAX
179
- } while (i !== 0);
180
-
181
- if (c[0] == n) { // null input--all zero length codes
182
- t[0] = -1;
183
- m[0] = 0;
184
- return Z_OK;
185
- }
40
+ const MAX_BITS = 15;
41
+
42
+ const Z_OK = 0;
43
+ const Z_STREAM_END = 1;
44
+ const Z_NEED_DICT = 2;
45
+ const Z_STREAM_ERROR = -2;
46
+ const Z_DATA_ERROR = -3;
47
+ const Z_MEM_ERROR = -4;
48
+ const Z_BUF_ERROR = -5;
49
+
50
+ const inflate_mask = [0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff, 0x000003ff,
51
+ 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff];
52
+
53
+ const MANY = 1440;
54
+
55
+ // JZlib version : "1.0.2"
56
+ const Z_NO_FLUSH = 0;
57
+ const Z_FINISH = 4;
58
+
59
+ // InfTree
60
+ const fixed_bl = 9;
61
+ const fixed_bd = 5;
62
+
63
+ const fixed_tl = [96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 192, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 160, 0, 8, 0,
64
+ 0, 8, 128, 0, 8, 64, 0, 9, 224, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 144, 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 208, 81, 7, 17, 0, 8, 104, 0, 8, 40,
65
+ 0, 9, 176, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 240, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 200, 81, 7, 13,
66
+ 0, 8, 100, 0, 8, 36, 0, 9, 168, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 232, 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 152, 84, 7, 83, 0, 8, 124, 0, 8, 60,
67
+ 0, 9, 216, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 184, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 248, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7,
68
+ 35, 0, 8, 114, 0, 8, 50, 0, 9, 196, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 164, 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 228, 80, 7, 7, 0, 8, 90, 0, 8,
69
+ 26, 0, 9, 148, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 212, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 180, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 244, 80,
70
+ 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 204, 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 172, 0, 8, 6, 0, 8, 134, 0,
71
+ 8, 70, 0, 9, 236, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 156, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 220, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 188, 0,
72
+ 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 252, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 194, 80, 7, 10, 0, 8, 97,
73
+ 0, 8, 33, 0, 9, 162, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 226, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 146, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 210,
74
+ 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 178, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 242, 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117,
75
+ 0, 8, 53, 0, 9, 202, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 170, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 234, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 154,
76
+ 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 218, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 186, 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 250, 80, 7, 3, 0, 8, 83,
77
+ 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 198, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 166, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 230,
78
+ 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 150, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 214, 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 182, 0, 8, 11, 0, 8, 139,
79
+ 0, 8, 75, 0, 9, 246, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 206, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 174,
80
+ 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 238, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 158, 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 222, 82, 7, 27, 0, 8, 111,
81
+ 0, 8, 47, 0, 9, 190, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 254, 96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9,
82
+ 193, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 161, 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 225, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 145, 83, 7, 59, 0, 8,
83
+ 120, 0, 8, 56, 0, 9, 209, 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 177, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 241, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8,
84
+ 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 201, 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 169, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 233, 80, 7, 8, 0, 8,
85
+ 92, 0, 8, 28, 0, 9, 153, 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 217, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 185, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9,
86
+ 249, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 197, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 165, 0, 8, 2, 0, 8,
87
+ 130, 0, 8, 66, 0, 9, 229, 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 149, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 213, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9,
88
+ 181, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 245, 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 205, 81, 7, 15, 0, 8,
89
+ 102, 0, 8, 38, 0, 9, 173, 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 237, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 157, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9,
90
+ 221, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 189, 0, 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 253, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0,
91
+ 8, 113, 0, 8, 49, 0, 9, 195, 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 163, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 227, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9,
92
+ 147, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 211, 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 179, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 243, 80, 7, 4, 0, 8,
93
+ 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 203, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 171, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9,
94
+ 235, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 155, 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 219, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 187, 0, 8, 13, 0, 8,
95
+ 141, 0, 8, 77, 0, 9, 251, 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 199, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9,
96
+ 167, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 231, 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 151, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 215, 82, 7, 19, 0, 8,
97
+ 107, 0, 8, 43, 0, 9, 183, 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 247, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9,
98
+ 207, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 175, 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 239, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 159, 84, 7, 99, 0, 8,
99
+ 127, 0, 8, 63, 0, 9, 223, 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 191, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 255];
100
+ const fixed_td = [80, 5, 1, 87, 5, 257, 83, 5, 17, 91, 5, 4097, 81, 5, 5, 89, 5, 1025, 85, 5, 65, 93, 5, 16385, 80, 5, 3, 88, 5, 513, 84, 5, 33, 92, 5,
101
+ 8193, 82, 5, 9, 90, 5, 2049, 86, 5, 129, 192, 5, 24577, 80, 5, 2, 87, 5, 385, 83, 5, 25, 91, 5, 6145, 81, 5, 7, 89, 5, 1537, 85, 5, 97, 93, 5,
102
+ 24577, 80, 5, 4, 88, 5, 769, 84, 5, 49, 92, 5, 12289, 82, 5, 13, 90, 5, 3073, 86, 5, 193, 192, 5, 24577];
103
+
104
+ // Tables for deflate from PKZIP's appnote.txt.
105
+ const cplens = [ // Copy lengths for literal codes 257..285
106
+ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0];
107
+
108
+ // see note #13 above about 258
109
+ const cplext = [ // Extra bits for literal codes 257..285
110
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 // 112==invalid
111
+ ];
112
+
113
+ const cpdist = [ // Copy offsets for distance codes 0..29
114
+ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577];
115
+
116
+ const cpdext = [ // Extra bits for distance codes
117
+ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13];
118
+
119
+ // If BMAX needs to be larger than 16, then h and x[] should be uLong.
120
+ const BMAX = 15; // maximum bit length of any code
121
+
122
+ function InfTree() {
123
+ const that = this;
124
+
125
+ let hn; // hufts used in space
126
+ let v; // work area for huft_build
127
+ let c; // bit length count table
128
+ let r; // table entry for structure assignment
129
+ let u; // table stack
130
+ let x; // bit offsets, then code stack
131
+
132
+ function huft_build(b, // code lengths in bits (all assumed <=
133
+ // BMAX)
134
+ bindex, n, // number of codes (assumed <= 288)
135
+ s, // number of simple-valued codes (0..s-1)
136
+ d, // list of base values for non-simple codes
137
+ e, // list of extra bits for non-simple codes
138
+ t, // result: starting table
139
+ m, // maximum lookup bits, returns actual
140
+ hp,// space for trees
141
+ hn,// hufts used in space
142
+ v // working area: values in order of bit length
143
+ ) {
144
+ // Given a list of code lengths and a maximum table size, make a set of
145
+ // tables to decode that set of codes. Return Z_OK on success,
146
+ // Z_BUF_ERROR
147
+ // if the given code set is incomplete (the tables are still built in
148
+ // this
149
+ // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set
150
+ // of
151
+ // lengths), or Z_MEM_ERROR if not enough memory.
152
+
153
+ let a; // counter for codes of length k
154
+ let f; // i repeats in table every f entries
155
+ let g; // maximum code length
156
+ let h; // table level
157
+ let i; // counter, current code
158
+ let j; // counter
159
+ let k; // number of bits in current code
160
+ let l; // bits per table (returned in m)
161
+ let mask; // (1 << w) - 1, to avoid cc -O bug on HP
162
+ let p; // pointer into c[], b[], or v[]
163
+ let q; // points to current table
164
+ let w; // bits before this table == (l * h)
165
+ let xp; // pointer into x
166
+ let y; // number of dummy codes added
167
+ let z; // number of entries in current table
168
+
169
+ // Generate counts for each bit length
170
+
171
+ p = 0;
172
+ i = n;
173
+ do {
174
+ c[b[bindex + p]]++;
175
+ p++;
176
+ i--; // assume all entries <= BMAX
177
+ } while (i !== 0);
178
+
179
+ if (c[0] == n) { // null input--all zero length codes
180
+ t[0] = -1;
181
+ m[0] = 0;
182
+ return Z_OK;
183
+ }
186
184
 
187
- // Find minimum and maximum length, bound *m by those
188
- l = m[0];
189
- for (j = 1; j <= BMAX; j++)
190
- if (c[j] !== 0)
191
- break;
192
- k = j; // minimum code length
193
- if (l < j) {
194
- l = j;
195
- }
196
- for (i = BMAX; i !== 0; i--) {
197
- if (c[i] !== 0)
198
- break;
199
- }
200
- g = i; // maximum code length
201
- if (l > i) {
202
- l = i;
203
- }
204
- m[0] = l;
185
+ // Find minimum and maximum length, bound *m by those
186
+ l = m[0];
187
+ for (j = 1; j <= BMAX; j++)
188
+ if (c[j] !== 0)
189
+ break;
190
+ k = j; // minimum code length
191
+ if (l < j) {
192
+ l = j;
193
+ }
194
+ for (i = BMAX; i !== 0; i--) {
195
+ if (c[i] !== 0)
196
+ break;
197
+ }
198
+ g = i; // maximum code length
199
+ if (l > i) {
200
+ l = i;
201
+ }
202
+ m[0] = l;
205
203
 
206
- // Adjust last length count to fill out codes, if needed
207
- for (y = 1 << j; j < i; j++, y <<= 1) {
208
- if ((y -= c[j]) < 0) {
209
- return Z_DATA_ERROR;
210
- }
211
- }
212
- if ((y -= c[i]) < 0) {
204
+ // Adjust last length count to fill out codes, if needed
205
+ for (y = 1 << j; j < i; j++, y <<= 1) {
206
+ if ((y -= c[j]) < 0) {
213
207
  return Z_DATA_ERROR;
214
208
  }
215
- c[i] += y;
216
-
217
- // Generate starting offsets into the value table for each length
218
- x[1] = j = 0;
219
- p = 1;
220
- xp = 2;
221
- while (--i !== 0) { // note that i == g from above
222
- x[xp] = (j += c[p]);
223
- xp++;
224
- p++;
225
- }
209
+ }
210
+ if ((y -= c[i]) < 0) {
211
+ return Z_DATA_ERROR;
212
+ }
213
+ c[i] += y;
214
+
215
+ // Generate starting offsets into the value table for each length
216
+ x[1] = j = 0;
217
+ p = 1;
218
+ xp = 2;
219
+ while (--i !== 0) { // note that i == g from above
220
+ x[xp] = (j += c[p]);
221
+ xp++;
222
+ p++;
223
+ }
226
224
 
227
- // Make a table of values in order of bit lengths
228
- i = 0;
229
- p = 0;
230
- do {
231
- if ((j = b[bindex + p]) !== 0) {
232
- v[x[j]++] = i;
233
- }
234
- p++;
235
- } while (++i < n);
236
- n = x[g]; // set n to length of v
237
-
238
- // Generate the Huffman codes and for each, make the table entries
239
- x[0] = i = 0; // first Huffman code is zero
240
- p = 0; // grab values in bit order
241
- h = -1; // no tables yet--level -1
242
- w = -l; // bits decoded == (l * h)
243
- u[0] = 0; // just to keep compilers happy
244
- q = 0; // ditto
245
- z = 0; // ditto
246
-
247
- // go through the bit lengths (k already is bits in shortest code)
248
- for (; k <= g; k++) {
249
- a = c[k];
250
- while (a-- !== 0) {
251
- // here i is the Huffman code of length k bits for value *p
252
- // make tables up to required level
253
- while (k > w + l) {
254
- h++;
255
- w += l; // previous table always l bits
256
- // compute minimum size table less than or equal to l bits
257
- z = g - w;
258
- z = (z > l) ? l : z; // table size upper limit
259
- if ((f = 1 << (j = k - w)) > a + 1) { // try a k-w bit table
260
- // too few codes for
261
- // k-w bit table
262
- f -= a + 1; // deduct codes from patterns left
263
- xp = k;
264
- if (j < z) {
265
- while (++j < z) { // try smaller tables up to z bits
266
- if ((f <<= 1) <= c[++xp])
267
- break; // enough codes to use up j bits
268
- f -= c[xp]; // else deduct codes from patterns
269
- }
225
+ // Make a table of values in order of bit lengths
226
+ i = 0;
227
+ p = 0;
228
+ do {
229
+ if ((j = b[bindex + p]) !== 0) {
230
+ v[x[j]++] = i;
231
+ }
232
+ p++;
233
+ } while (++i < n);
234
+ n = x[g]; // set n to length of v
235
+
236
+ // Generate the Huffman codes and for each, make the table entries
237
+ x[0] = i = 0; // first Huffman code is zero
238
+ p = 0; // grab values in bit order
239
+ h = -1; // no tables yet--level -1
240
+ w = -l; // bits decoded == (l * h)
241
+ u[0] = 0; // just to keep compilers happy
242
+ q = 0; // ditto
243
+ z = 0; // ditto
244
+
245
+ // go through the bit lengths (k already is bits in shortest code)
246
+ for (; k <= g; k++) {
247
+ a = c[k];
248
+ while (a-- !== 0) {
249
+ // here i is the Huffman code of length k bits for value *p
250
+ // make tables up to required level
251
+ while (k > w + l) {
252
+ h++;
253
+ w += l; // previous table always l bits
254
+ // compute minimum size table less than or equal to l bits
255
+ z = g - w;
256
+ z = (z > l) ? l : z; // table size upper limit
257
+ if ((f = 1 << (j = k - w)) > a + 1) { // try a k-w bit table
258
+ // too few codes for
259
+ // k-w bit table
260
+ f -= a + 1; // deduct codes from patterns left
261
+ xp = k;
262
+ if (j < z) {
263
+ while (++j < z) { // try smaller tables up to z bits
264
+ if ((f <<= 1) <= c[++xp])
265
+ break; // enough codes to use up j bits
266
+ f -= c[xp]; // else deduct codes from patterns
270
267
  }
271
268
  }
272
- z = 1 << j; // table entries for j-bit table
273
-
274
- // allocate new table
275
- if (hn[0] + z > MANY) { // (note: doesn't matter for fixed)
276
- return Z_DATA_ERROR; // overflow of MANY
277
- }
278
- u[h] = q = /* hp+ */hn[0]; // DEBUG
279
- hn[0] += z;
280
-
281
- // connect to last table, if there is one
282
- if (h !== 0) {
283
- x[h] = i; // save pattern for backing up
284
- r[0] = /* (byte) */j; // bits in this table
285
- r[1] = /* (byte) */l; // bits to dump before this table
286
- j = i >>> (w - l);
287
- r[2] = /* (int) */(q - u[h - 1] - j); // offset to this table
288
- hp.set(r, (u[h - 1] + j) * 3);
289
- // to
290
- // last
291
- // table
292
- } else {
293
- t[0] = q; // first table is returned result
294
- }
295
269
  }
270
+ z = 1 << j; // table entries for j-bit table
296
271
 
297
- // set up table entry in r
298
- r[1] = /* (byte) */(k - w);
299
- if (p >= n) {
300
- r[0] = 128 + 64; // out of values--invalid code
301
- } else if (v[p] < s) {
302
- r[0] = /* (byte) */(v[p] < 256 ? 0 : 32 + 64); // 256 is
303
- // end-of-block
304
- r[2] = v[p++]; // simple code is just the value
272
+ // allocate new table
273
+ if (hn[0] + z > MANY) { // (note: doesn't matter for fixed)
274
+ return Z_DATA_ERROR; // overflow of MANY
275
+ }
276
+ u[h] = q = /* hp+ */hn[0]; // DEBUG
277
+ hn[0] += z;
278
+
279
+ // connect to last table, if there is one
280
+ if (h !== 0) {
281
+ x[h] = i; // save pattern for backing up
282
+ r[0] = /* (byte) */j; // bits in this table
283
+ r[1] = /* (byte) */l; // bits to dump before this table
284
+ j = i >>> (w - l);
285
+ r[2] = /* (int) */(q - u[h - 1] - j); // offset to this table
286
+ hp.set(r, (u[h - 1] + j) * 3);
287
+ // to
288
+ // last
289
+ // table
305
290
  } else {
306
- r[0] = /* (byte) */(e[v[p] - s] + 16 + 64); // non-simple--look
307
- // up in lists
308
- r[2] = d[v[p++] - s];
291
+ t[0] = q; // first table is returned result
309
292
  }
293
+ }
310
294
 
311
- // fill code-like entries with r
312
- f = 1 << (k - w);
313
- for (j = i >>> w; j < z; j += f) {
314
- hp.set(r, (q + j) * 3);
315
- }
295
+ // set up table entry in r
296
+ r[1] = /* (byte) */(k - w);
297
+ if (p >= n) {
298
+ r[0] = 128 + 64; // out of values--invalid code
299
+ } else if (v[p] < s) {
300
+ r[0] = /* (byte) */(v[p] < 256 ? 0 : 32 + 64); // 256 is
301
+ // end-of-block
302
+ r[2] = v[p++]; // simple code is just the value
303
+ } else {
304
+ r[0] = /* (byte) */(e[v[p] - s] + 16 + 64); // non-simple--look
305
+ // up in lists
306
+ r[2] = d[v[p++] - s];
307
+ }
316
308
 
317
- // backwards increment the k-bit code i
318
- for (j = 1 << (k - 1); (i & j) !== 0; j >>>= 1) {
319
- i ^= j;
320
- }
321
- i ^= j;
309
+ // fill code-like entries with r
310
+ f = 1 << (k - w);
311
+ for (j = i >>> w; j < z; j += f) {
312
+ hp.set(r, (q + j) * 3);
313
+ }
322
314
 
323
- // backup over finished tables
324
- mask = (1 << w) - 1; // needed on HP, cc -O bug
325
- while ((i & mask) != x[h]) {
326
- h--; // don't need to update q
327
- w -= l;
328
- mask = (1 << w) - 1;
329
- }
315
+ // backwards increment the k-bit code i
316
+ for (j = 1 << (k - 1); (i & j) !== 0; j >>>= 1) {
317
+ i ^= j;
318
+ }
319
+ i ^= j;
320
+
321
+ // backup over finished tables
322
+ mask = (1 << w) - 1; // needed on HP, cc -O bug
323
+ while ((i & mask) != x[h]) {
324
+ h--; // don't need to update q
325
+ w -= l;
326
+ mask = (1 << w) - 1;
330
327
  }
331
328
  }
332
- // Return Z_BUF_ERROR if we were given an incomplete table
333
- return y !== 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
334
329
  }
330
+ // Return Z_BUF_ERROR if we were given an incomplete table
331
+ return y !== 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
332
+ }
335
333
 
336
- function initWorkArea(vsize) {
337
- let i;
338
- if (!hn) {
339
- hn = []; // []; //new Array(1);
340
- v = []; // new Array(vsize);
341
- c = new Int32Array(BMAX + 1); // new Array(BMAX + 1);
342
- r = []; // new Array(3);
343
- u = new Int32Array(BMAX); // new Array(BMAX);
344
- x = new Int32Array(BMAX + 1); // new Array(BMAX + 1);
345
- }
346
- if (v.length < vsize) {
347
- v = []; // new Array(vsize);
348
- }
349
- for (i = 0; i < vsize; i++) {
350
- v[i] = 0;
351
- }
352
- for (i = 0; i < BMAX + 1; i++) {
353
- c[i] = 0;
354
- }
355
- for (i = 0; i < 3; i++) {
356
- r[i] = 0;
357
- }
358
- // for(int i=0; i<BMAX; i++){u[i]=0;}
359
- u.set(c.subarray(0, BMAX), 0);
360
- // for(int i=0; i<BMAX+1; i++){x[i]=0;}
361
- x.set(c.subarray(0, BMAX + 1), 0);
334
+ function initWorkArea(vsize) {
335
+ let i;
336
+ if (!hn) {
337
+ hn = []; // []; //new Array(1);
338
+ v = []; // new Array(vsize);
339
+ c = new Int32Array(BMAX + 1); // new Array(BMAX + 1);
340
+ r = []; // new Array(3);
341
+ u = new Int32Array(BMAX); // new Array(BMAX);
342
+ x = new Int32Array(BMAX + 1); // new Array(BMAX + 1);
343
+ }
344
+ if (v.length < vsize) {
345
+ v = []; // new Array(vsize);
362
346
  }
347
+ for (i = 0; i < vsize; i++) {
348
+ v[i] = 0;
349
+ }
350
+ for (i = 0; i < BMAX + 1; i++) {
351
+ c[i] = 0;
352
+ }
353
+ for (i = 0; i < 3; i++) {
354
+ r[i] = 0;
355
+ }
356
+ // for(int i=0; i<BMAX; i++){u[i]=0;}
357
+ u.set(c.subarray(0, BMAX), 0);
358
+ // for(int i=0; i<BMAX+1; i++){x[i]=0;}
359
+ x.set(c.subarray(0, BMAX + 1), 0);
360
+ }
361
+
362
+ that.inflate_trees_bits = function (c, // 19 code lengths
363
+ bb, // bits tree desired/actual depth
364
+ tb, // bits tree result
365
+ hp, // space for trees
366
+ z // for messages
367
+ ) {
368
+ let result;
369
+ initWorkArea(19);
370
+ hn[0] = 0;
371
+ result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
372
+
373
+ if (result == Z_DATA_ERROR) {
374
+ z.msg = "oversubscribed dynamic bit lengths tree";
375
+ } else if (result == Z_BUF_ERROR || bb[0] === 0) {
376
+ z.msg = "incomplete dynamic bit lengths tree";
377
+ result = Z_DATA_ERROR;
378
+ }
379
+ return result;
380
+ };
363
381
 
364
- that.inflate_trees_bits = function (c, // 19 code lengths
365
- bb, // bits tree desired/actual depth
366
- tb, // bits tree result
367
- hp, // space for trees
368
- z // for messages
369
- ) {
370
- let result;
371
- initWorkArea(19);
372
- hn[0] = 0;
373
- result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
382
+ that.inflate_trees_dynamic = function (nl, // number of literal/length codes
383
+ nd, // number of distance codes
384
+ c, // that many (total) code lengths
385
+ bl, // literal desired/actual bit depth
386
+ bd, // distance desired/actual bit depth
387
+ tl, // literal/length tree result
388
+ td, // distance tree result
389
+ hp, // space for trees
390
+ z // for messages
391
+ ) {
392
+ let result;
374
393
 
394
+ // build literal/length tree
395
+ initWorkArea(288);
396
+ hn[0] = 0;
397
+ result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
398
+ if (result != Z_OK || bl[0] === 0) {
375
399
  if (result == Z_DATA_ERROR) {
376
- z.msg = "oversubscribed dynamic bit lengths tree";
377
- } else if (result == Z_BUF_ERROR || bb[0] === 0) {
378
- z.msg = "incomplete dynamic bit lengths tree";
400
+ z.msg = "oversubscribed literal/length tree";
401
+ } else if (result != Z_MEM_ERROR) {
402
+ z.msg = "incomplete literal/length tree";
379
403
  result = Z_DATA_ERROR;
380
404
  }
381
405
  return result;
382
- };
383
-
384
- that.inflate_trees_dynamic = function (nl, // number of literal/length codes
385
- nd, // number of distance codes
386
- c, // that many (total) code lengths
387
- bl, // literal desired/actual bit depth
388
- bd, // distance desired/actual bit depth
389
- tl, // literal/length tree result
390
- td, // distance tree result
391
- hp, // space for trees
392
- z // for messages
393
- ) {
394
- let result;
395
-
396
- // build literal/length tree
397
- initWorkArea(288);
398
- hn[0] = 0;
399
- result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
400
- if (result != Z_OK || bl[0] === 0) {
401
- if (result == Z_DATA_ERROR) {
402
- z.msg = "oversubscribed literal/length tree";
403
- } else if (result != Z_MEM_ERROR) {
404
- z.msg = "incomplete literal/length tree";
405
- result = Z_DATA_ERROR;
406
- }
407
- return result;
408
- }
409
-
410
- // build distance tree
411
- initWorkArea(288);
412
- result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
413
-
414
- if (result != Z_OK || (bd[0] === 0 && nl > 257)) {
415
- if (result == Z_DATA_ERROR) {
416
- z.msg = "oversubscribed distance tree";
417
- } else if (result == Z_BUF_ERROR) {
418
- z.msg = "incomplete distance tree";
419
- result = Z_DATA_ERROR;
420
- } else if (result != Z_MEM_ERROR) {
421
- z.msg = "empty distance tree with lengths";
422
- result = Z_DATA_ERROR;
423
- }
424
- return result;
425
- }
406
+ }
426
407
 
427
- return Z_OK;
428
- };
408
+ // build distance tree
409
+ initWorkArea(288);
410
+ result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
429
411
 
430
- }
412
+ if (result != Z_OK || (bd[0] === 0 && nl > 257)) {
413
+ if (result == Z_DATA_ERROR) {
414
+ z.msg = "oversubscribed distance tree";
415
+ } else if (result == Z_BUF_ERROR) {
416
+ z.msg = "incomplete distance tree";
417
+ result = Z_DATA_ERROR;
418
+ } else if (result != Z_MEM_ERROR) {
419
+ z.msg = "empty distance tree with lengths";
420
+ result = Z_DATA_ERROR;
421
+ }
422
+ return result;
423
+ }
431
424
 
432
- InfTree.inflate_trees_fixed = function (bl, // literal desired/actual bit depth
433
- bd, // distance desired/actual bit depth
434
- tl,// literal/length tree result
435
- td// distance tree result
436
- ) {
437
- bl[0] = fixed_bl;
438
- bd[0] = fixed_bd;
439
- tl[0] = fixed_tl;
440
- td[0] = fixed_td;
441
425
  return Z_OK;
442
426
  };
443
427
 
444
- // InfCodes
445
-
446
- // waiting for "i:"=input,
447
- // "o:"=output,
448
- // "x:"=nothing
449
- const START = 0; // x: set up for LEN
450
- const LEN = 1; // i: get length/literal/eob next
451
- const LENEXT = 2; // i: getting length extra (have base)
452
- const DIST = 3; // i: get distance next
453
- const DISTEXT = 4;// i: getting distance extra
454
- const COPY = 5; // o: copying bytes in win, waiting
455
- // for space
456
- const LIT = 6; // o: got literal, waiting for output
457
- // space
458
- const WASH = 7; // o: got eob, possibly still output
459
- // waiting
460
- const END = 8; // x: got eob and all data flushed
461
- const BADCODE = 9;// x: got error
462
-
463
- function InfCodes() {
464
- const that = this;
465
-
466
- let mode; // current inflate_codes mode
467
-
468
- // mode dependent information
469
- let len = 0;
470
-
471
- let tree; // pointer into tree
472
- let tree_index = 0;
473
- let need = 0; // bits needed
474
-
475
- let lit = 0;
476
-
477
- // if EXT or COPY, where and how much
478
- let get = 0; // bits to get for extra
479
- let dist = 0; // distance back to copy from
480
-
481
- let lbits = 0; // ltree bits decoded per branch
482
- let dbits = 0; // dtree bits decoder per branch
483
- let ltree; // literal/length/eob tree
484
- let ltree_index = 0; // literal/length/eob tree
485
- let dtree; // distance tree
486
- let dtree_index = 0; // distance tree
487
-
488
- // Called with number of bytes left to write in win at least 258
489
- // (the maximum string length) and number of input bytes available
490
- // at least ten. The ten bytes are six bytes for the longest length/
491
- // distance pair plus four bytes for overloading the bit buffer.
492
-
493
- function inflate_fast(bl, bd, tl, tl_index, td, td_index, s, z) {
494
- let t; // temporary pointer
495
- let tp; // temporary pointer
496
- let tp_index; // temporary pointer
497
- let e; // extra bits or operation
498
- let b; // bit buffer
499
- let k; // bits in bit buffer
500
- let p; // input data pointer
501
- let n; // bytes available there
502
- let q; // output win write pointer
503
- let m; // bytes to end of win or read pointer
504
- let ml; // mask for literal/length tree
505
- let md; // mask for distance tree
506
- let c; // bytes to copy
507
- let d; // distance back to copy from
508
- let r; // copy source pointer
509
-
510
- let tp_index_t_3; // (tp_index+t)*3
511
-
512
- // load input, output, bit values
513
- p = z.next_in_index;
514
- n = z.avail_in;
515
- b = s.bitb;
516
- k = s.bitk;
517
- q = s.write;
518
- m = q < s.read ? s.read - q - 1 : s.end - q;
519
-
520
- // initialize masks
521
- ml = inflate_mask[bl];
522
- md = inflate_mask[bd];
523
-
524
- // do until not enough input or output space for fast loop
525
- do { // assume called with m >= 258 && n >= 10
526
- // get literal/length code
527
- while (k < (20)) { // max bits for literal/length code
528
- n--;
529
- b |= (z.read_byte(p++) & 0xff) << k;
530
- k += 8;
531
- }
428
+ }
429
+
430
+ InfTree.inflate_trees_fixed = function (bl, // literal desired/actual bit depth
431
+ bd, // distance desired/actual bit depth
432
+ tl,// literal/length tree result
433
+ td// distance tree result
434
+ ) {
435
+ bl[0] = fixed_bl;
436
+ bd[0] = fixed_bd;
437
+ tl[0] = fixed_tl;
438
+ td[0] = fixed_td;
439
+ return Z_OK;
440
+ };
441
+
442
+ // InfCodes
443
+
444
+ // waiting for "i:"=input,
445
+ // "o:"=output,
446
+ // "x:"=nothing
447
+ const START = 0; // x: set up for LEN
448
+ const LEN = 1; // i: get length/literal/eob next
449
+ const LENEXT = 2; // i: getting length extra (have base)
450
+ const DIST = 3; // i: get distance next
451
+ const DISTEXT = 4;// i: getting distance extra
452
+ const COPY = 5; // o: copying bytes in win, waiting
453
+ // for space
454
+ const LIT = 6; // o: got literal, waiting for output
455
+ // space
456
+ const WASH = 7; // o: got eob, possibly still output
457
+ // waiting
458
+ const END = 8; // x: got eob and all data flushed
459
+ const BADCODE = 9;// x: got error
460
+
461
+ function InfCodes() {
462
+ const that = this;
463
+
464
+ let mode; // current inflate_codes mode
465
+
466
+ // mode dependent information
467
+ let len = 0;
468
+
469
+ let tree; // pointer into tree
470
+ let tree_index = 0;
471
+ let need = 0; // bits needed
472
+
473
+ let lit = 0;
474
+
475
+ // if EXT or COPY, where and how much
476
+ let get = 0; // bits to get for extra
477
+ let dist = 0; // distance back to copy from
478
+
479
+ let lbits = 0; // ltree bits decoded per branch
480
+ let dbits = 0; // dtree bits decoder per branch
481
+ let ltree; // literal/length/eob tree
482
+ let ltree_index = 0; // literal/length/eob tree
483
+ let dtree; // distance tree
484
+ let dtree_index = 0; // distance tree
485
+
486
+ // Called with number of bytes left to write in win at least 258
487
+ // (the maximum string length) and number of input bytes available
488
+ // at least ten. The ten bytes are six bytes for the longest length/
489
+ // distance pair plus four bytes for overloading the bit buffer.
490
+
491
+ function inflate_fast(bl, bd, tl, tl_index, td, td_index, s, z) {
492
+ let t; // temporary pointer
493
+ let tp; // temporary pointer
494
+ let tp_index; // temporary pointer
495
+ let e; // extra bits or operation
496
+ let b; // bit buffer
497
+ let k; // bits in bit buffer
498
+ let p; // input data pointer
499
+ let n; // bytes available there
500
+ let q; // output win write pointer
501
+ let m; // bytes to end of win or read pointer
502
+ let ml; // mask for literal/length tree
503
+ let md; // mask for distance tree
504
+ let c; // bytes to copy
505
+ let d; // distance back to copy from
506
+ let r; // copy source pointer
507
+
508
+ let tp_index_t_3; // (tp_index+t)*3
509
+
510
+ // load input, output, bit values
511
+ p = z.next_in_index;
512
+ n = z.avail_in;
513
+ b = s.bitb;
514
+ k = s.bitk;
515
+ q = s.write;
516
+ m = q < s.read ? s.read - q - 1 : s.end - q;
517
+
518
+ // initialize masks
519
+ ml = inflate_mask[bl];
520
+ md = inflate_mask[bd];
521
+
522
+ // do until not enough input or output space for fast loop
523
+ do { // assume called with m >= 258 && n >= 10
524
+ // get literal/length code
525
+ while (k < (20)) { // max bits for literal/length code
526
+ n--;
527
+ b |= (z.read_byte(p++) & 0xff) << k;
528
+ k += 8;
529
+ }
532
530
 
533
- t = b & ml;
534
- tp = tl;
535
- tp_index = tl_index;
536
- tp_index_t_3 = (tp_index + t) * 3;
537
- if ((e = tp[tp_index_t_3]) === 0) {
538
- b >>= (tp[tp_index_t_3 + 1]);
539
- k -= (tp[tp_index_t_3 + 1]);
531
+ t = b & ml;
532
+ tp = tl;
533
+ tp_index = tl_index;
534
+ tp_index_t_3 = (tp_index + t) * 3;
535
+ if ((e = tp[tp_index_t_3]) === 0) {
536
+ b >>= (tp[tp_index_t_3 + 1]);
537
+ k -= (tp[tp_index_t_3 + 1]);
538
+
539
+ s.win[q++] = /* (byte) */tp[tp_index_t_3 + 2];
540
+ m--;
541
+ continue;
542
+ }
543
+ do {
540
544
 
541
- s.win[q++] = /* (byte) */tp[tp_index_t_3 + 2];
542
- m--;
543
- continue;
544
- }
545
- do {
545
+ b >>= (tp[tp_index_t_3 + 1]);
546
+ k -= (tp[tp_index_t_3 + 1]);
546
547
 
547
- b >>= (tp[tp_index_t_3 + 1]);
548
- k -= (tp[tp_index_t_3 + 1]);
548
+ if ((e & 16) !== 0) {
549
+ e &= 15;
550
+ c = tp[tp_index_t_3 + 2] + (/* (int) */b & inflate_mask[e]);
549
551
 
550
- if ((e & 16) !== 0) {
551
- e &= 15;
552
- c = tp[tp_index_t_3 + 2] + (/* (int) */b & inflate_mask[e]);
552
+ b >>= e;
553
+ k -= e;
553
554
 
554
- b >>= e;
555
- k -= e;
555
+ // decode distance base of block to copy
556
+ while (k < (15)) { // max bits for distance code
557
+ n--;
558
+ b |= (z.read_byte(p++) & 0xff) << k;
559
+ k += 8;
560
+ }
556
561
 
557
- // decode distance base of block to copy
558
- while (k < (15)) { // max bits for distance code
559
- n--;
560
- b |= (z.read_byte(p++) & 0xff) << k;
561
- k += 8;
562
- }
562
+ t = b & md;
563
+ tp = td;
564
+ tp_index = td_index;
565
+ tp_index_t_3 = (tp_index + t) * 3;
566
+ e = tp[tp_index_t_3];
563
567
 
564
- t = b & md;
565
- tp = td;
566
- tp_index = td_index;
567
- tp_index_t_3 = (tp_index + t) * 3;
568
- e = tp[tp_index_t_3];
568
+ do {
569
569
 
570
- do {
570
+ b >>= (tp[tp_index_t_3 + 1]);
571
+ k -= (tp[tp_index_t_3 + 1]);
571
572
 
572
- b >>= (tp[tp_index_t_3 + 1]);
573
- k -= (tp[tp_index_t_3 + 1]);
573
+ if ((e & 16) !== 0) {
574
+ // get extra bits to add to distance base
575
+ e &= 15;
576
+ while (k < (e)) { // get extra bits (up to 13)
577
+ n--;
578
+ b |= (z.read_byte(p++) & 0xff) << k;
579
+ k += 8;
580
+ }
574
581
 
575
- if ((e & 16) !== 0) {
576
- // get extra bits to add to distance base
577
- e &= 15;
578
- while (k < (e)) { // get extra bits (up to 13)
579
- n--;
580
- b |= (z.read_byte(p++) & 0xff) << k;
581
- k += 8;
582
+ d = tp[tp_index_t_3 + 2] + (b & inflate_mask[e]);
583
+
584
+ b >>= (e);
585
+ k -= (e);
586
+
587
+ // do the copy
588
+ m -= c;
589
+ if (q >= d) { // offset before dest
590
+ // just copy
591
+ r = q - d;
592
+ if (q - r > 0 && 2 > (q - r)) {
593
+ s.win[q++] = s.win[r++]; // minimum
594
+ // count is
595
+ // three,
596
+ s.win[q++] = s.win[r++]; // so unroll
597
+ // loop a
598
+ // little
599
+ c -= 2;
600
+ } else {
601
+ s.win.set(s.win.subarray(r, r + 2), q);
602
+ q += 2;
603
+ r += 2;
604
+ c -= 2;
582
605
  }
583
-
584
- d = tp[tp_index_t_3 + 2] + (b & inflate_mask[e]);
585
-
586
- b >>= (e);
587
- k -= (e);
588
-
589
- // do the copy
590
- m -= c;
591
- if (q >= d) { // offset before dest
592
- // just copy
593
- r = q - d;
594
- if (q - r > 0 && 2 > (q - r)) {
595
- s.win[q++] = s.win[r++]; // minimum
596
- // count is
597
- // three,
598
- s.win[q++] = s.win[r++]; // so unroll
599
- // loop a
600
- // little
601
- c -= 2;
606
+ } else { // else offset after destination
607
+ r = q - d;
608
+ do {
609
+ r += s.end; // force pointer in win
610
+ } while (r < 0); // covers invalid distances
611
+ e = s.end - r;
612
+ if (c > e) { // if source crosses,
613
+ c -= e; // wrapped copy
614
+ if (q - r > 0 && e > (q - r)) {
615
+ do {
616
+ s.win[q++] = s.win[r++];
617
+ } while (--e !== 0);
602
618
  } else {
603
- s.win.set(s.win.subarray(r, r + 2), q);
604
- q += 2;
605
- r += 2;
606
- c -= 2;
607
- }
608
- } else { // else offset after destination
609
- r = q - d;
610
- do {
611
- r += s.end; // force pointer in win
612
- } while (r < 0); // covers invalid distances
613
- e = s.end - r;
614
- if (c > e) { // if source crosses,
615
- c -= e; // wrapped copy
616
- if (q - r > 0 && e > (q - r)) {
617
- do {
618
- s.win[q++] = s.win[r++];
619
- } while (--e !== 0);
620
- } else {
621
- s.win.set(s.win.subarray(r, r + e), q);
622
- q += e;
623
- r += e;
624
- e = 0;
625
- }
626
- r = 0; // copy rest from start of win
619
+ s.win.set(s.win.subarray(r, r + e), q);
620
+ q += e;
621
+ r += e;
622
+ e = 0;
627
623
  }
628
-
624
+ r = 0; // copy rest from start of win
629
625
  }
630
626
 
631
- // copy all or what's left
632
- if (q - r > 0 && c > (q - r)) {
633
- do {
634
- s.win[q++] = s.win[r++];
635
- } while (--c !== 0);
636
- } else {
637
- s.win.set(s.win.subarray(r, r + c), q);
638
- q += c;
639
- r += c;
640
- c = 0;
641
- }
642
- break;
643
- } else if ((e & 64) === 0) {
644
- t += tp[tp_index_t_3 + 2];
645
- t += (b & inflate_mask[e]);
646
- tp_index_t_3 = (tp_index + t) * 3;
647
- e = tp[tp_index_t_3];
627
+ }
628
+
629
+ // copy all or what's left
630
+ if (q - r > 0 && c > (q - r)) {
631
+ do {
632
+ s.win[q++] = s.win[r++];
633
+ } while (--c !== 0);
648
634
  } else {
649
- z.msg = "invalid distance code";
635
+ s.win.set(s.win.subarray(r, r + c), q);
636
+ q += c;
637
+ r += c;
638
+ c = 0;
639
+ }
640
+ break;
641
+ } else if ((e & 64) === 0) {
642
+ t += tp[tp_index_t_3 + 2];
643
+ t += (b & inflate_mask[e]);
644
+ tp_index_t_3 = (tp_index + t) * 3;
645
+ e = tp[tp_index_t_3];
646
+ } else {
647
+ z.msg = "invalid distance code";
650
648
 
651
- c = z.avail_in - n;
652
- c = (k >> 3) < c ? k >> 3 : c;
653
- n += c;
654
- p -= c;
655
- k -= c << 3;
649
+ c = z.avail_in - n;
650
+ c = (k >> 3) < c ? k >> 3 : c;
651
+ n += c;
652
+ p -= c;
653
+ k -= c << 3;
656
654
 
657
- s.bitb = b;
658
- s.bitk = k;
659
- z.avail_in = n;
660
- z.total_in += p - z.next_in_index;
661
- z.next_in_index = p;
662
- s.write = q;
655
+ s.bitb = b;
656
+ s.bitk = k;
657
+ z.avail_in = n;
658
+ z.total_in += p - z.next_in_index;
659
+ z.next_in_index = p;
660
+ s.write = q;
663
661
 
664
- return Z_DATA_ERROR;
665
- }
666
- // eslint-disable-next-line no-constant-condition
667
- } while (true);
662
+ return Z_DATA_ERROR;
663
+ }
664
+ // eslint-disable-next-line no-constant-condition
665
+ } while (true);
666
+ break;
667
+ }
668
+
669
+ if ((e & 64) === 0) {
670
+ t += tp[tp_index_t_3 + 2];
671
+ t += (b & inflate_mask[e]);
672
+ tp_index_t_3 = (tp_index + t) * 3;
673
+ if ((e = tp[tp_index_t_3]) === 0) {
674
+
675
+ b >>= (tp[tp_index_t_3 + 1]);
676
+ k -= (tp[tp_index_t_3 + 1]);
677
+
678
+ s.win[q++] = /* (byte) */tp[tp_index_t_3 + 2];
679
+ m--;
668
680
  break;
669
681
  }
682
+ } else if ((e & 32) !== 0) {
683
+
684
+ c = z.avail_in - n;
685
+ c = (k >> 3) < c ? k >> 3 : c;
686
+ n += c;
687
+ p -= c;
688
+ k -= c << 3;
689
+
690
+ s.bitb = b;
691
+ s.bitk = k;
692
+ z.avail_in = n;
693
+ z.total_in += p - z.next_in_index;
694
+ z.next_in_index = p;
695
+ s.write = q;
696
+
697
+ return Z_STREAM_END;
698
+ } else {
699
+ z.msg = "invalid literal/length code";
670
700
 
671
- if ((e & 64) === 0) {
672
- t += tp[tp_index_t_3 + 2];
673
- t += (b & inflate_mask[e]);
674
- tp_index_t_3 = (tp_index + t) * 3;
675
- if ((e = tp[tp_index_t_3]) === 0) {
676
-
677
- b >>= (tp[tp_index_t_3 + 1]);
678
- k -= (tp[tp_index_t_3 + 1]);
701
+ c = z.avail_in - n;
702
+ c = (k >> 3) < c ? k >> 3 : c;
703
+ n += c;
704
+ p -= c;
705
+ k -= c << 3;
679
706
 
680
- s.win[q++] = /* (byte) */tp[tp_index_t_3 + 2];
681
- m--;
682
- break;
683
- }
684
- } else if ((e & 32) !== 0) {
707
+ s.bitb = b;
708
+ s.bitk = k;
709
+ z.avail_in = n;
710
+ z.total_in += p - z.next_in_index;
711
+ z.next_in_index = p;
712
+ s.write = q;
685
713
 
686
- c = z.avail_in - n;
687
- c = (k >> 3) < c ? k >> 3 : c;
688
- n += c;
689
- p -= c;
690
- k -= c << 3;
714
+ return Z_DATA_ERROR;
715
+ }
716
+ // eslint-disable-next-line no-constant-condition
717
+ } while (true);
718
+ } while (m >= 258 && n >= 10);
719
+
720
+ // not enough input or output--restore pointers and return
721
+ c = z.avail_in - n;
722
+ c = (k >> 3) < c ? k >> 3 : c;
723
+ n += c;
724
+ p -= c;
725
+ k -= c << 3;
726
+
727
+ s.bitb = b;
728
+ s.bitk = k;
729
+ z.avail_in = n;
730
+ z.total_in += p - z.next_in_index;
731
+ z.next_in_index = p;
732
+ s.write = q;
691
733
 
692
- s.bitb = b;
693
- s.bitk = k;
694
- z.avail_in = n;
695
- z.total_in += p - z.next_in_index;
696
- z.next_in_index = p;
697
- s.write = q;
734
+ return Z_OK;
735
+ }
698
736
 
699
- return Z_STREAM_END;
700
- } else {
701
- z.msg = "invalid literal/length code";
737
+ that.init = function (bl, bd, tl, tl_index, td, td_index) {
738
+ mode = START;
739
+ lbits = /* (byte) */bl;
740
+ dbits = /* (byte) */bd;
741
+ ltree = tl;
742
+ ltree_index = tl_index;
743
+ dtree = td;
744
+ dtree_index = td_index;
745
+ tree = null;
746
+ };
702
747
 
703
- c = z.avail_in - n;
704
- c = (k >> 3) < c ? k >> 3 : c;
705
- n += c;
706
- p -= c;
707
- k -= c << 3;
748
+ that.proc = function (s, z, r) {
749
+ let j; // temporary storage
750
+ let tindex; // temporary pointer
751
+ let e; // extra bits or operation
752
+ let b = 0; // bit buffer
753
+ let k = 0; // bits in bit buffer
754
+ let p = 0; // input data pointer
755
+ let n; // bytes available there
756
+ let q; // output win write pointer
757
+ let m; // bytes to end of win or read pointer
758
+ let f; // pointer to copy strings from
759
+
760
+ // copy input/output information to locals (UPDATE macro restores)
761
+ p = z.next_in_index;
762
+ n = z.avail_in;
763
+ b = s.bitb;
764
+ k = s.bitk;
765
+ q = s.write;
766
+ m = q < s.read ? s.read - q - 1 : s.end - q;
767
+
768
+ // process input and output based on current state
769
+ // eslint-disable-next-line no-constant-condition
770
+ while (true) {
771
+ switch (mode) {
772
+ // waiting for "i:"=input, "o:"=output, "x:"=nothing
773
+ case START: // x: set up for LEN
774
+ if (m >= 258 && n >= 10) {
708
775
 
709
776
  s.bitb = b;
710
777
  s.bitk = k;
@@ -712,68 +779,33 @@ const ZipInflate = (() => {
712
779
  z.total_in += p - z.next_in_index;
713
780
  z.next_in_index = p;
714
781
  s.write = q;
782
+ r = inflate_fast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, s, z);
783
+
784
+ p = z.next_in_index;
785
+ n = z.avail_in;
786
+ b = s.bitb;
787
+ k = s.bitk;
788
+ q = s.write;
789
+ m = q < s.read ? s.read - q - 1 : s.end - q;
715
790
 
716
- return Z_DATA_ERROR;
791
+ if (r != Z_OK) {
792
+ mode = r == Z_STREAM_END ? WASH : BADCODE;
793
+ break;
794
+ }
717
795
  }
718
- // eslint-disable-next-line no-constant-condition
719
- } while (true);
720
- } while (m >= 258 && n >= 10);
721
-
722
- // not enough input or output--restore pointers and return
723
- c = z.avail_in - n;
724
- c = (k >> 3) < c ? k >> 3 : c;
725
- n += c;
726
- p -= c;
727
- k -= c << 3;
728
-
729
- s.bitb = b;
730
- s.bitk = k;
731
- z.avail_in = n;
732
- z.total_in += p - z.next_in_index;
733
- z.next_in_index = p;
734
- s.write = q;
796
+ need = lbits;
797
+ tree = ltree;
798
+ tree_index = ltree_index;
735
799
 
736
- return Z_OK;
737
- }
800
+ mode = LEN;
801
+ /* falls through */
802
+ case LEN: // i: get length/literal/eob next
803
+ j = need;
738
804
 
739
- that.init = function (bl, bd, tl, tl_index, td, td_index) {
740
- mode = START;
741
- lbits = /* (byte) */bl;
742
- dbits = /* (byte) */bd;
743
- ltree = tl;
744
- ltree_index = tl_index;
745
- dtree = td;
746
- dtree_index = td_index;
747
- tree = null;
748
- };
749
-
750
- that.proc = function (s, z, r) {
751
- let j; // temporary storage
752
- let tindex; // temporary pointer
753
- let e; // extra bits or operation
754
- let b = 0; // bit buffer
755
- let k = 0; // bits in bit buffer
756
- let p = 0; // input data pointer
757
- let n; // bytes available there
758
- let q; // output win write pointer
759
- let m; // bytes to end of win or read pointer
760
- let f; // pointer to copy strings from
761
-
762
- // copy input/output information to locals (UPDATE macro restores)
763
- p = z.next_in_index;
764
- n = z.avail_in;
765
- b = s.bitb;
766
- k = s.bitk;
767
- q = s.write;
768
- m = q < s.read ? s.read - q - 1 : s.end - q;
769
-
770
- // process input and output based on current state
771
- // eslint-disable-next-line no-constant-condition
772
- while (true) {
773
- switch (mode) {
774
- // waiting for "i:"=input, "o:"=output, "x:"=nothing
775
- case START: // x: set up for LEN
776
- if (m >= 258 && n >= 10) {
805
+ while (k < (j)) {
806
+ if (n !== 0)
807
+ r = Z_OK;
808
+ else {
777
809
 
778
810
  s.bitb = b;
779
811
  s.bitk = k;
@@ -781,244 +813,172 @@ const ZipInflate = (() => {
781
813
  z.total_in += p - z.next_in_index;
782
814
  z.next_in_index = p;
783
815
  s.write = q;
784
- r = inflate_fast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, s, z);
816
+ return s.inflate_flush(z, r);
817
+ }
818
+ n--;
819
+ b |= (z.read_byte(p++) & 0xff) << k;
820
+ k += 8;
821
+ }
785
822
 
786
- p = z.next_in_index;
787
- n = z.avail_in;
788
- b = s.bitb;
789
- k = s.bitk;
790
- q = s.write;
791
- m = q < s.read ? s.read - q - 1 : s.end - q;
823
+ tindex = (tree_index + (b & inflate_mask[j])) * 3;
792
824
 
793
- if (r != Z_OK) {
794
- mode = r == Z_STREAM_END ? WASH : BADCODE;
795
- break;
796
- }
797
- }
798
- need = lbits;
799
- tree = ltree;
800
- tree_index = ltree_index;
825
+ b >>>= (tree[tindex + 1]);
826
+ k -= (tree[tindex + 1]);
801
827
 
802
- mode = LEN;
803
- /* falls through */
804
- case LEN: // i: get length/literal/eob next
805
- j = need;
828
+ e = tree[tindex];
806
829
 
807
- while (k < (j)) {
808
- if (n !== 0)
809
- r = Z_OK;
810
- else {
830
+ if (e === 0) { // literal
831
+ lit = tree[tindex + 2];
832
+ mode = LIT;
833
+ break;
834
+ }
835
+ if ((e & 16) !== 0) { // length
836
+ get = e & 15;
837
+ len = tree[tindex + 2];
838
+ mode = LENEXT;
839
+ break;
840
+ }
841
+ if ((e & 64) === 0) { // next table
842
+ need = e;
843
+ tree_index = tindex / 3 + tree[tindex + 2];
844
+ break;
845
+ }
846
+ if ((e & 32) !== 0) { // end of block
847
+ mode = WASH;
848
+ break;
849
+ }
850
+ mode = BADCODE; // invalid code
851
+ z.msg = "invalid literal/length code";
852
+ r = Z_DATA_ERROR;
853
+
854
+ s.bitb = b;
855
+ s.bitk = k;
856
+ z.avail_in = n;
857
+ z.total_in += p - z.next_in_index;
858
+ z.next_in_index = p;
859
+ s.write = q;
860
+ return s.inflate_flush(z, r);
861
+
862
+ case LENEXT: // i: getting length extra (have base)
863
+ j = get;
864
+
865
+ while (k < (j)) {
866
+ if (n !== 0)
867
+ r = Z_OK;
868
+ else {
811
869
 
812
- s.bitb = b;
813
- s.bitk = k;
814
- z.avail_in = n;
815
- z.total_in += p - z.next_in_index;
816
- z.next_in_index = p;
817
- s.write = q;
818
- return s.inflate_flush(z, r);
819
- }
820
- n--;
821
- b |= (z.read_byte(p++) & 0xff) << k;
822
- k += 8;
870
+ s.bitb = b;
871
+ s.bitk = k;
872
+ z.avail_in = n;
873
+ z.total_in += p - z.next_in_index;
874
+ z.next_in_index = p;
875
+ s.write = q;
876
+ return s.inflate_flush(z, r);
823
877
  }
878
+ n--;
879
+ b |= (z.read_byte(p++) & 0xff) << k;
880
+ k += 8;
881
+ }
824
882
 
825
- tindex = (tree_index + (b & inflate_mask[j])) * 3;
883
+ len += (b & inflate_mask[j]);
826
884
 
827
- b >>>= (tree[tindex + 1]);
828
- k -= (tree[tindex + 1]);
885
+ b >>= j;
886
+ k -= j;
829
887
 
830
- e = tree[tindex];
888
+ need = dbits;
889
+ tree = dtree;
890
+ tree_index = dtree_index;
891
+ mode = DIST;
892
+ /* falls through */
893
+ case DIST: // i: get distance next
894
+ j = need;
831
895
 
832
- if (e === 0) { // literal
833
- lit = tree[tindex + 2];
834
- mode = LIT;
835
- break;
836
- }
837
- if ((e & 16) !== 0) { // length
838
- get = e & 15;
839
- len = tree[tindex + 2];
840
- mode = LENEXT;
841
- break;
842
- }
843
- if ((e & 64) === 0) { // next table
844
- need = e;
845
- tree_index = tindex / 3 + tree[tindex + 2];
846
- break;
847
- }
848
- if ((e & 32) !== 0) { // end of block
849
- mode = WASH;
850
- break;
896
+ while (k < (j)) {
897
+ if (n !== 0)
898
+ r = Z_OK;
899
+ else {
900
+
901
+ s.bitb = b;
902
+ s.bitk = k;
903
+ z.avail_in = n;
904
+ z.total_in += p - z.next_in_index;
905
+ z.next_in_index = p;
906
+ s.write = q;
907
+ return s.inflate_flush(z, r);
851
908
  }
852
- mode = BADCODE; // invalid code
853
- z.msg = "invalid literal/length code";
854
- r = Z_DATA_ERROR;
909
+ n--;
910
+ b |= (z.read_byte(p++) & 0xff) << k;
911
+ k += 8;
912
+ }
855
913
 
856
- s.bitb = b;
857
- s.bitk = k;
858
- z.avail_in = n;
859
- z.total_in += p - z.next_in_index;
860
- z.next_in_index = p;
861
- s.write = q;
862
- return s.inflate_flush(z, r);
914
+ tindex = (tree_index + (b & inflate_mask[j])) * 3;
863
915
 
864
- case LENEXT: // i: getting length extra (have base)
865
- j = get;
916
+ b >>= tree[tindex + 1];
917
+ k -= tree[tindex + 1];
866
918
 
867
- while (k < (j)) {
868
- if (n !== 0)
869
- r = Z_OK;
870
- else {
919
+ e = (tree[tindex]);
920
+ if ((e & 16) !== 0) { // distance
921
+ get = e & 15;
922
+ dist = tree[tindex + 2];
923
+ mode = DISTEXT;
924
+ break;
925
+ }
926
+ if ((e & 64) === 0) { // next table
927
+ need = e;
928
+ tree_index = tindex / 3 + tree[tindex + 2];
929
+ break;
930
+ }
931
+ mode = BADCODE; // invalid code
932
+ z.msg = "invalid distance code";
933
+ r = Z_DATA_ERROR;
934
+
935
+ s.bitb = b;
936
+ s.bitk = k;
937
+ z.avail_in = n;
938
+ z.total_in += p - z.next_in_index;
939
+ z.next_in_index = p;
940
+ s.write = q;
941
+ return s.inflate_flush(z, r);
942
+
943
+ case DISTEXT: // i: getting distance extra
944
+ j = get;
945
+
946
+ while (k < (j)) {
947
+ if (n !== 0)
948
+ r = Z_OK;
949
+ else {
871
950
 
872
- s.bitb = b;
873
- s.bitk = k;
874
- z.avail_in = n;
875
- z.total_in += p - z.next_in_index;
876
- z.next_in_index = p;
877
- s.write = q;
878
- return s.inflate_flush(z, r);
879
- }
880
- n--;
881
- b |= (z.read_byte(p++) & 0xff) << k;
882
- k += 8;
951
+ s.bitb = b;
952
+ s.bitk = k;
953
+ z.avail_in = n;
954
+ z.total_in += p - z.next_in_index;
955
+ z.next_in_index = p;
956
+ s.write = q;
957
+ return s.inflate_flush(z, r);
883
958
  }
959
+ n--;
960
+ b |= (z.read_byte(p++) & 0xff) << k;
961
+ k += 8;
962
+ }
884
963
 
885
- len += (b & inflate_mask[j]);
886
-
887
- b >>= j;
888
- k -= j;
964
+ dist += (b & inflate_mask[j]);
889
965
 
890
- need = dbits;
891
- tree = dtree;
892
- tree_index = dtree_index;
893
- mode = DIST;
894
- /* falls through */
895
- case DIST: // i: get distance next
896
- j = need;
966
+ b >>= j;
967
+ k -= j;
897
968
 
898
- while (k < (j)) {
899
- if (n !== 0)
900
- r = Z_OK;
901
- else {
969
+ mode = COPY;
970
+ /* falls through */
971
+ case COPY: // o: copying bytes in win, waiting for space
972
+ f = q - dist;
973
+ while (f < 0) { // modulo win size-"while" instead
974
+ f += s.end; // of "if" handles invalid distances
975
+ }
976
+ while (len !== 0) {
902
977
 
903
- s.bitb = b;
904
- s.bitk = k;
905
- z.avail_in = n;
906
- z.total_in += p - z.next_in_index;
907
- z.next_in_index = p;
908
- s.write = q;
909
- return s.inflate_flush(z, r);
910
- }
911
- n--;
912
- b |= (z.read_byte(p++) & 0xff) << k;
913
- k += 8;
914
- }
915
-
916
- tindex = (tree_index + (b & inflate_mask[j])) * 3;
917
-
918
- b >>= tree[tindex + 1];
919
- k -= tree[tindex + 1];
920
-
921
- e = (tree[tindex]);
922
- if ((e & 16) !== 0) { // distance
923
- get = e & 15;
924
- dist = tree[tindex + 2];
925
- mode = DISTEXT;
926
- break;
927
- }
928
- if ((e & 64) === 0) { // next table
929
- need = e;
930
- tree_index = tindex / 3 + tree[tindex + 2];
931
- break;
932
- }
933
- mode = BADCODE; // invalid code
934
- z.msg = "invalid distance code";
935
- r = Z_DATA_ERROR;
936
-
937
- s.bitb = b;
938
- s.bitk = k;
939
- z.avail_in = n;
940
- z.total_in += p - z.next_in_index;
941
- z.next_in_index = p;
942
- s.write = q;
943
- return s.inflate_flush(z, r);
944
-
945
- case DISTEXT: // i: getting distance extra
946
- j = get;
947
-
948
- while (k < (j)) {
949
- if (n !== 0)
950
- r = Z_OK;
951
- else {
952
-
953
- s.bitb = b;
954
- s.bitk = k;
955
- z.avail_in = n;
956
- z.total_in += p - z.next_in_index;
957
- z.next_in_index = p;
958
- s.write = q;
959
- return s.inflate_flush(z, r);
960
- }
961
- n--;
962
- b |= (z.read_byte(p++) & 0xff) << k;
963
- k += 8;
964
- }
965
-
966
- dist += (b & inflate_mask[j]);
967
-
968
- b >>= j;
969
- k -= j;
970
-
971
- mode = COPY;
972
- /* falls through */
973
- case COPY: // o: copying bytes in win, waiting for space
974
- f = q - dist;
975
- while (f < 0) { // modulo win size-"while" instead
976
- f += s.end; // of "if" handles invalid distances
977
- }
978
- while (len !== 0) {
979
-
980
- if (m === 0) {
981
- if (q == s.end && s.read !== 0) {
982
- q = 0;
983
- m = q < s.read ? s.read - q - 1 : s.end - q;
984
- }
985
- if (m === 0) {
986
- s.write = q;
987
- r = s.inflate_flush(z, r);
988
- q = s.write;
989
- m = q < s.read ? s.read - q - 1 : s.end - q;
990
-
991
- if (q == s.end && s.read !== 0) {
992
- q = 0;
993
- m = q < s.read ? s.read - q - 1 : s.end - q;
994
- }
995
-
996
- if (m === 0) {
997
- s.bitb = b;
998
- s.bitk = k;
999
- z.avail_in = n;
1000
- z.total_in += p - z.next_in_index;
1001
- z.next_in_index = p;
1002
- s.write = q;
1003
- return s.inflate_flush(z, r);
1004
- }
1005
- }
1006
- }
1007
-
1008
- s.win[q++] = s.win[f++];
1009
- m--;
1010
-
1011
- if (f == s.end)
1012
- f = 0;
1013
- len--;
1014
- }
1015
- mode = START;
1016
- break;
1017
- case LIT: // o: got literal, waiting for output space
1018
- if (m === 0) {
1019
- if (q == s.end && s.read !== 0) {
1020
- q = 0;
1021
- m = q < s.read ? s.read - q - 1 : s.end - q;
978
+ if (m === 0) {
979
+ if (q == s.end && s.read !== 0) {
980
+ q = 0;
981
+ m = q < s.read ? s.read - q - 1 : s.end - q;
1022
982
  }
1023
983
  if (m === 0) {
1024
984
  s.write = q;
@@ -1030,6 +990,7 @@ const ZipInflate = (() => {
1030
990
  q = 0;
1031
991
  m = q < s.read ? s.read - q - 1 : s.end - q;
1032
992
  }
993
+
1033
994
  if (m === 0) {
1034
995
  s.bitb = b;
1035
996
  s.bitk = k;
@@ -1041,61 +1002,63 @@ const ZipInflate = (() => {
1041
1002
  }
1042
1003
  }
1043
1004
  }
1044
- r = Z_OK;
1045
1005
 
1046
- s.win[q++] = /* (byte) */lit;
1006
+ s.win[q++] = s.win[f++];
1047
1007
  m--;
1048
1008
 
1049
- mode = START;
1050
- break;
1051
- case WASH: // o: got eob, possibly more output
1052
- if (k > 7) { // return unused byte, if any
1053
- k -= 8;
1054
- n++;
1055
- p--; // can always return one
1009
+ if (f == s.end)
1010
+ f = 0;
1011
+ len--;
1012
+ }
1013
+ mode = START;
1014
+ break;
1015
+ case LIT: // o: got literal, waiting for output space
1016
+ if (m === 0) {
1017
+ if (q == s.end && s.read !== 0) {
1018
+ q = 0;
1019
+ m = q < s.read ? s.read - q - 1 : s.end - q;
1056
1020
  }
1057
-
1058
- s.write = q;
1059
- r = s.inflate_flush(z, r);
1060
- q = s.write;
1061
- m = q < s.read ? s.read - q - 1 : s.end - q;
1062
-
1063
- if (s.read != s.write) {
1064
- s.bitb = b;
1065
- s.bitk = k;
1066
- z.avail_in = n;
1067
- z.total_in += p - z.next_in_index;
1068
- z.next_in_index = p;
1021
+ if (m === 0) {
1069
1022
  s.write = q;
1070
- return s.inflate_flush(z, r);
1071
- }
1072
- mode = END;
1073
- /* falls through */
1074
- case END:
1075
- r = Z_STREAM_END;
1076
- s.bitb = b;
1077
- s.bitk = k;
1078
- z.avail_in = n;
1079
- z.total_in += p - z.next_in_index;
1080
- z.next_in_index = p;
1081
- s.write = q;
1082
- return s.inflate_flush(z, r);
1023
+ r = s.inflate_flush(z, r);
1024
+ q = s.write;
1025
+ m = q < s.read ? s.read - q - 1 : s.end - q;
1083
1026
 
1084
- case BADCODE: // x: got error
1027
+ if (q == s.end && s.read !== 0) {
1028
+ q = 0;
1029
+ m = q < s.read ? s.read - q - 1 : s.end - q;
1030
+ }
1031
+ if (m === 0) {
1032
+ s.bitb = b;
1033
+ s.bitk = k;
1034
+ z.avail_in = n;
1035
+ z.total_in += p - z.next_in_index;
1036
+ z.next_in_index = p;
1037
+ s.write = q;
1038
+ return s.inflate_flush(z, r);
1039
+ }
1040
+ }
1041
+ }
1042
+ r = Z_OK;
1085
1043
 
1086
- r = Z_DATA_ERROR;
1044
+ s.win[q++] = /* (byte) */lit;
1045
+ m--;
1087
1046
 
1088
- s.bitb = b;
1089
- s.bitk = k;
1090
- z.avail_in = n;
1091
- z.total_in += p - z.next_in_index;
1092
- z.next_in_index = p;
1093
- s.write = q;
1094
- return s.inflate_flush(z, r);
1047
+ mode = START;
1048
+ break;
1049
+ case WASH: // o: got eob, possibly more output
1050
+ if (k > 7) { // return unused byte, if any
1051
+ k -= 8;
1052
+ n++;
1053
+ p--; // can always return one
1054
+ }
1095
1055
 
1096
- default:
1097
- r = Z_STREAM_ERROR;
1056
+ s.write = q;
1057
+ r = s.inflate_flush(z, r);
1058
+ q = s.write;
1059
+ m = q < s.read ? s.read - q - 1 : s.end - q;
1098
1060
 
1061
+ if (s.read != s.write) {
1099
1062
  s.bitb = b;
1100
1063
  s.bitk = k;
1101
1064
  z.avail_in = n;
@@ -1103,172 +1066,344 @@ const ZipInflate = (() => {
1103
1066
  z.next_in_index = p;
1104
1067
  s.write = q;
1105
1068
  return s.inflate_flush(z, r);
1106
- }
1069
+ }
1070
+ mode = END;
1071
+ /* falls through */
1072
+ case END:
1073
+ r = Z_STREAM_END;
1074
+ s.bitb = b;
1075
+ s.bitk = k;
1076
+ z.avail_in = n;
1077
+ z.total_in += p - z.next_in_index;
1078
+ z.next_in_index = p;
1079
+ s.write = q;
1080
+ return s.inflate_flush(z, r);
1081
+
1082
+ case BADCODE: // x: got error
1083
+
1084
+ r = Z_DATA_ERROR;
1085
+
1086
+ s.bitb = b;
1087
+ s.bitk = k;
1088
+ z.avail_in = n;
1089
+ z.total_in += p - z.next_in_index;
1090
+ z.next_in_index = p;
1091
+ s.write = q;
1092
+ return s.inflate_flush(z, r);
1093
+
1094
+ default:
1095
+ r = Z_STREAM_ERROR;
1096
+
1097
+ s.bitb = b;
1098
+ s.bitk = k;
1099
+ z.avail_in = n;
1100
+ z.total_in += p - z.next_in_index;
1101
+ z.next_in_index = p;
1102
+ s.write = q;
1103
+ return s.inflate_flush(z, r);
1107
1104
  }
1108
- };
1109
-
1110
- that.free = function () {
1111
- // ZFREE(z, c);
1112
- };
1105
+ }
1106
+ };
1113
1107
 
1114
- }
1108
+ that.free = function () {
1109
+ // ZFREE(z, c);
1110
+ };
1115
1111
 
1116
- // InfBlocks
1117
-
1118
- // Table for deflate from PKZIP's appnote.txt.
1119
- const border = [ // Order of the bit length code lengths
1120
- 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
1121
-
1122
- const TYPE = 0; // get type bits (3, including end bit)
1123
- const LENS = 1; // get lengths for stored
1124
- const STORED = 2;// processing stored block
1125
- const TABLE = 3; // get table lengths
1126
- const BTREE = 4; // get bit lengths tree for a dynamic
1127
- // block
1128
- const DTREE = 5; // get length, distance trees for a
1129
- // dynamic block
1130
- const CODES = 6; // processing fixed or dynamic block
1131
- const DRY = 7; // output remaining win bytes
1132
- const DONELOCKS = 8; // finished last block, done
1133
- const BADBLOCKS = 9; // ot a data error--stuck here
1134
-
1135
- function InfBlocks(z, w) {
1136
- const that = this;
1112
+ }
1113
+
1114
+ // InfBlocks
1115
+
1116
+ // Table for deflate from PKZIP's appnote.txt.
1117
+ const border = [ // Order of the bit length code lengths
1118
+ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
1119
+
1120
+ const TYPE = 0; // get type bits (3, including end bit)
1121
+ const LENS = 1; // get lengths for stored
1122
+ const STORED = 2;// processing stored block
1123
+ const TABLE = 3; // get table lengths
1124
+ const BTREE = 4; // get bit lengths tree for a dynamic
1125
+ // block
1126
+ const DTREE = 5; // get length, distance trees for a
1127
+ // dynamic block
1128
+ const CODES = 6; // processing fixed or dynamic block
1129
+ const DRY = 7; // output remaining win bytes
1130
+ const DONELOCKS = 8; // finished last block, done
1131
+ const BADBLOCKS = 9; // ot a data error--stuck here
1132
+
1133
+ function InfBlocks(z, w) {
1134
+ const that = this;
1135
+
1136
+ let mode = TYPE; // current inflate_block mode
1137
+
1138
+ let left = 0; // if STORED, bytes left to copy
1139
+
1140
+ let table = 0; // table lengths (14 bits)
1141
+ let index = 0; // index into blens (or border)
1142
+ let blens; // bit lengths of codes
1143
+ const bb = [0]; // bit length tree depth
1144
+ const tb = [0]; // bit length decoding tree
1145
+
1146
+ const codes = new InfCodes(); // if CODES, current state
1147
+
1148
+ let last = 0; // true if this block is the last block
1149
+
1150
+ let hufts = new Int32Array(MANY * 3); // single malloc for tree space
1151
+ const check = 0; // check on output
1152
+ const inftree = new InfTree();
1153
+
1154
+ that.bitk = 0; // bits in bit buffer
1155
+ that.bitb = 0; // bit buffer
1156
+ that.win = new Uint8Array(w); // sliding win
1157
+ that.end = w; // one byte after sliding win
1158
+ that.read = 0; // win read pointer
1159
+ that.write = 0; // win write pointer
1160
+
1161
+ that.reset = function (z, c) {
1162
+ if (c)
1163
+ c[0] = check;
1164
+ // if (mode == BTREE || mode == DTREE) {
1165
+ // }
1166
+ if (mode == CODES) {
1167
+ codes.free(z);
1168
+ }
1169
+ mode = TYPE;
1170
+ that.bitk = 0;
1171
+ that.bitb = 0;
1172
+ that.read = that.write = 0;
1173
+ };
1137
1174
 
1138
- let mode = TYPE; // current inflate_block mode
1175
+ that.reset(z, null);
1176
+
1177
+ // copy as much as possible from the sliding win to the output area
1178
+ that.inflate_flush = function (z, r) {
1179
+ let n;
1180
+ let p;
1181
+ let q;
1182
+
1183
+ // local copies of source and destination pointers
1184
+ p = z.next_out_index;
1185
+ q = that.read;
1186
+
1187
+ // compute number of bytes to copy as far as end of win
1188
+ n = /* (int) */((q <= that.write ? that.write : that.end) - q);
1189
+ if (n > z.avail_out)
1190
+ n = z.avail_out;
1191
+ if (n !== 0 && r == Z_BUF_ERROR)
1192
+ r = Z_OK;
1193
+
1194
+ // update counters
1195
+ z.avail_out -= n;
1196
+ z.total_out += n;
1197
+
1198
+ // copy as far as end of win
1199
+ z.next_out.set(that.win.subarray(q, q + n), p);
1200
+ p += n;
1201
+ q += n;
1202
+
1203
+ // see if more to copy at beginning of win
1204
+ if (q == that.end) {
1205
+ // wrap pointers
1206
+ q = 0;
1207
+ if (that.write == that.end)
1208
+ that.write = 0;
1209
+
1210
+ // compute bytes to copy
1211
+ n = that.write - q;
1212
+ if (n > z.avail_out)
1213
+ n = z.avail_out;
1214
+ if (n !== 0 && r == Z_BUF_ERROR)
1215
+ r = Z_OK;
1139
1216
 
1140
- let left = 0; // if STORED, bytes left to copy
1217
+ // update counters
1218
+ z.avail_out -= n;
1219
+ z.total_out += n;
1141
1220
 
1142
- let table = 0; // table lengths (14 bits)
1143
- let index = 0; // index into blens (or border)
1144
- let blens; // bit lengths of codes
1145
- const bb = [0]; // bit length tree depth
1146
- const tb = [0]; // bit length decoding tree
1221
+ // copy
1222
+ z.next_out.set(that.win.subarray(q, q + n), p);
1223
+ p += n;
1224
+ q += n;
1225
+ }
1147
1226
 
1148
- const codes = new InfCodes(); // if CODES, current state
1227
+ // update pointers
1228
+ z.next_out_index = p;
1229
+ that.read = q;
1149
1230
 
1150
- let last = 0; // true if this block is the last block
1231
+ // done
1232
+ return r;
1233
+ };
1151
1234
 
1152
- let hufts = new Int32Array(MANY * 3); // single malloc for tree space
1153
- const check = 0; // check on output
1154
- const inftree = new InfTree();
1235
+ that.proc = function (z, r) {
1236
+ let t; // temporary storage
1237
+ let b; // bit buffer
1238
+ let k; // bits in bit buffer
1239
+ let p; // input data pointer
1240
+ let n; // bytes available there
1241
+ let q; // output win write pointer
1242
+ let m; // bytes to end of win or read pointer
1243
+
1244
+ let i;
1245
+
1246
+ // copy input/output information to locals (UPDATE macro restores)
1247
+ // {
1248
+ p = z.next_in_index;
1249
+ n = z.avail_in;
1250
+ b = that.bitb;
1251
+ k = that.bitk;
1252
+ // }
1253
+ // {
1254
+ q = that.write;
1255
+ m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
1256
+ // }
1257
+
1258
+ // process input based on current state
1259
+ // DEBUG dtree
1260
+ // eslint-disable-next-line no-constant-condition
1261
+ while (true) {
1262
+ let bl, bd, tl, td, bl_, bd_, tl_, td_;
1263
+ switch (mode) {
1264
+ case TYPE:
1265
+
1266
+ while (k < (3)) {
1267
+ if (n !== 0) {
1268
+ r = Z_OK;
1269
+ } else {
1270
+ that.bitb = b;
1271
+ that.bitk = k;
1272
+ z.avail_in = n;
1273
+ z.total_in += p - z.next_in_index;
1274
+ z.next_in_index = p;
1275
+ that.write = q;
1276
+ return that.inflate_flush(z, r);
1277
+ }
1278
+ n--;
1279
+ b |= (z.read_byte(p++) & 0xff) << k;
1280
+ k += 8;
1281
+ }
1282
+ t = /* (int) */(b & 7);
1283
+ last = t & 1;
1155
1284
 
1156
- that.bitk = 0; // bits in bit buffer
1157
- that.bitb = 0; // bit buffer
1158
- that.win = new Uint8Array(w); // sliding win
1159
- that.end = w; // one byte after sliding win
1160
- that.read = 0; // win read pointer
1161
- that.write = 0; // win write pointer
1285
+ switch (t >>> 1) {
1286
+ case 0: // stored
1287
+ // {
1288
+ b >>>= (3);
1289
+ k -= (3);
1290
+ // }
1291
+ t = k & 7; // go to byte boundary
1162
1292
 
1163
- that.reset = function (z, c) {
1164
- if (c)
1165
- c[0] = check;
1166
- // if (mode == BTREE || mode == DTREE) {
1167
- // }
1168
- if (mode == CODES) {
1169
- codes.free(z);
1170
- }
1171
- mode = TYPE;
1172
- that.bitk = 0;
1173
- that.bitb = 0;
1174
- that.read = that.write = 0;
1175
- };
1293
+ // {
1294
+ b >>>= (t);
1295
+ k -= (t);
1296
+ // }
1297
+ mode = LENS; // get length of stored block
1298
+ break;
1299
+ case 1: // fixed
1300
+ // {
1301
+ bl = []; // new Array(1);
1302
+ bd = []; // new Array(1);
1303
+ tl = [[]]; // new Array(1);
1304
+ td = [[]]; // new Array(1);
1176
1305
 
1177
- that.reset(z, null);
1306
+ InfTree.inflate_trees_fixed(bl, bd, tl, td);
1307
+ codes.init(bl[0], bd[0], tl[0], 0, td[0], 0);
1308
+ // }
1178
1309
 
1179
- // copy as much as possible from the sliding win to the output area
1180
- that.inflate_flush = function (z, r) {
1181
- let n;
1182
- let p;
1183
- let q;
1310
+ // {
1311
+ b >>>= (3);
1312
+ k -= (3);
1313
+ // }
1184
1314
 
1185
- // local copies of source and destination pointers
1186
- p = z.next_out_index;
1187
- q = that.read;
1315
+ mode = CODES;
1316
+ break;
1317
+ case 2: // dynamic
1188
1318
 
1189
- // compute number of bytes to copy as far as end of win
1190
- n = /* (int) */((q <= that.write ? that.write : that.end) - q);
1191
- if (n > z.avail_out)
1192
- n = z.avail_out;
1193
- if (n !== 0 && r == Z_BUF_ERROR)
1194
- r = Z_OK;
1319
+ // {
1320
+ b >>>= (3);
1321
+ k -= (3);
1322
+ // }
1195
1323
 
1196
- // update counters
1197
- z.avail_out -= n;
1198
- z.total_out += n;
1324
+ mode = TABLE;
1325
+ break;
1326
+ case 3: // illegal
1199
1327
 
1200
- // copy as far as end of win
1201
- z.next_out.set(that.win.subarray(q, q + n), p);
1202
- p += n;
1203
- q += n;
1328
+ // {
1329
+ b >>>= (3);
1330
+ k -= (3);
1331
+ // }
1332
+ mode = BADBLOCKS;
1333
+ z.msg = "invalid block type";
1334
+ r = Z_DATA_ERROR;
1204
1335
 
1205
- // see if more to copy at beginning of win
1206
- if (q == that.end) {
1207
- // wrap pointers
1208
- q = 0;
1209
- if (that.write == that.end)
1210
- that.write = 0;
1211
-
1212
- // compute bytes to copy
1213
- n = that.write - q;
1214
- if (n > z.avail_out)
1215
- n = z.avail_out;
1216
- if (n !== 0 && r == Z_BUF_ERROR)
1217
- r = Z_OK;
1336
+ that.bitb = b;
1337
+ that.bitk = k;
1338
+ z.avail_in = n;
1339
+ z.total_in += p - z.next_in_index;
1340
+ z.next_in_index = p;
1341
+ that.write = q;
1342
+ return that.inflate_flush(z, r);
1343
+ }
1344
+ break;
1345
+ case LENS:
1218
1346
 
1219
- // update counters
1220
- z.avail_out -= n;
1221
- z.total_out += n;
1347
+ while (k < (32)) {
1348
+ if (n !== 0) {
1349
+ r = Z_OK;
1350
+ } else {
1351
+ that.bitb = b;
1352
+ that.bitk = k;
1353
+ z.avail_in = n;
1354
+ z.total_in += p - z.next_in_index;
1355
+ z.next_in_index = p;
1356
+ that.write = q;
1357
+ return that.inflate_flush(z, r);
1358
+ }
1359
+ n--;
1360
+ b |= (z.read_byte(p++) & 0xff) << k;
1361
+ k += 8;
1362
+ }
1222
1363
 
1223
- // copy
1224
- z.next_out.set(that.win.subarray(q, q + n), p);
1225
- p += n;
1226
- q += n;
1227
- }
1364
+ if ((((~b) >>> 16) & 0xffff) != (b & 0xffff)) {
1365
+ mode = BADBLOCKS;
1366
+ z.msg = "invalid stored block lengths";
1367
+ r = Z_DATA_ERROR;
1228
1368
 
1229
- // update pointers
1230
- z.next_out_index = p;
1231
- that.read = q;
1232
-
1233
- // done
1234
- return r;
1235
- };
1236
-
1237
- that.proc = function (z, r) {
1238
- let t; // temporary storage
1239
- let b; // bit buffer
1240
- let k; // bits in bit buffer
1241
- let p; // input data pointer
1242
- let n; // bytes available there
1243
- let q; // output win write pointer
1244
- let m; // bytes to end of win or read pointer
1245
-
1246
- let i;
1247
-
1248
- // copy input/output information to locals (UPDATE macro restores)
1249
- // {
1250
- p = z.next_in_index;
1251
- n = z.avail_in;
1252
- b = that.bitb;
1253
- k = that.bitk;
1254
- // }
1255
- // {
1256
- q = that.write;
1257
- m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
1258
- // }
1259
-
1260
- // process input based on current state
1261
- // DEBUG dtree
1262
- // eslint-disable-next-line no-constant-condition
1263
- while (true) {
1264
- let bl, bd, tl, td, bl_, bd_, tl_, td_;
1265
- switch (mode) {
1266
- case TYPE:
1369
+ that.bitb = b;
1370
+ that.bitk = k;
1371
+ z.avail_in = n;
1372
+ z.total_in += p - z.next_in_index;
1373
+ z.next_in_index = p;
1374
+ that.write = q;
1375
+ return that.inflate_flush(z, r);
1376
+ }
1377
+ left = (b & 0xffff);
1378
+ b = k = 0; // dump bits
1379
+ mode = left !== 0 ? STORED : (last !== 0 ? DRY : TYPE);
1380
+ break;
1381
+ case STORED:
1382
+ if (n === 0) {
1383
+ that.bitb = b;
1384
+ that.bitk = k;
1385
+ z.avail_in = n;
1386
+ z.total_in += p - z.next_in_index;
1387
+ z.next_in_index = p;
1388
+ that.write = q;
1389
+ return that.inflate_flush(z, r);
1390
+ }
1267
1391
 
1268
- while (k < (3)) {
1269
- if (n !== 0) {
1270
- r = Z_OK;
1271
- } else {
1392
+ if (m === 0) {
1393
+ if (q == that.end && that.read !== 0) {
1394
+ q = 0;
1395
+ m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
1396
+ }
1397
+ if (m === 0) {
1398
+ that.write = q;
1399
+ r = that.inflate_flush(z, r);
1400
+ q = that.write;
1401
+ m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
1402
+ if (q == that.end && that.read !== 0) {
1403
+ q = 0;
1404
+ m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
1405
+ }
1406
+ if (m === 0) {
1272
1407
  that.bitb = b;
1273
1408
  that.bitk = k;
1274
1409
  z.avail_in = n;
@@ -1277,76 +1412,78 @@ const ZipInflate = (() => {
1277
1412
  that.write = q;
1278
1413
  return that.inflate_flush(z, r);
1279
1414
  }
1280
- n--;
1281
- b |= (z.read_byte(p++) & 0xff) << k;
1282
- k += 8;
1283
1415
  }
1284
- t = /* (int) */(b & 7);
1285
- last = t & 1;
1286
-
1287
- switch (t >>> 1) {
1288
- case 0: // stored
1289
- // {
1290
- b >>>= (3);
1291
- k -= (3);
1292
- // }
1293
- t = k & 7; // go to byte boundary
1294
-
1295
- // {
1296
- b >>>= (t);
1297
- k -= (t);
1298
- // }
1299
- mode = LENS; // get length of stored block
1300
- break;
1301
- case 1: // fixed
1302
- // {
1303
- bl = []; // new Array(1);
1304
- bd = []; // new Array(1);
1305
- tl = [[]]; // new Array(1);
1306
- td = [[]]; // new Array(1);
1307
-
1308
- InfTree.inflate_trees_fixed(bl, bd, tl, td);
1309
- codes.init(bl[0], bd[0], tl[0], 0, td[0], 0);
1310
- // }
1311
-
1312
- // {
1313
- b >>>= (3);
1314
- k -= (3);
1315
- // }
1316
-
1317
- mode = CODES;
1318
- break;
1319
- case 2: // dynamic
1320
-
1321
- // {
1322
- b >>>= (3);
1323
- k -= (3);
1324
- // }
1325
-
1326
- mode = TABLE;
1327
- break;
1328
- case 3: // illegal
1329
-
1330
- // {
1331
- b >>>= (3);
1332
- k -= (3);
1333
- // }
1334
- mode = BADBLOCKS;
1335
- z.msg = "invalid block type";
1336
- r = Z_DATA_ERROR;
1416
+ }
1417
+ r = Z_OK;
1337
1418
 
1338
- that.bitb = b;
1339
- that.bitk = k;
1340
- z.avail_in = n;
1341
- z.total_in += p - z.next_in_index;
1342
- z.next_in_index = p;
1343
- that.write = q;
1344
- return that.inflate_flush(z, r);
1345
- }
1419
+ t = left;
1420
+ if (t > n)
1421
+ t = n;
1422
+ if (t > m)
1423
+ t = m;
1424
+ that.win.set(z.read_buf(p, t), q);
1425
+ p += t;
1426
+ n -= t;
1427
+ q += t;
1428
+ m -= t;
1429
+ if ((left -= t) !== 0)
1346
1430
  break;
1347
- case LENS:
1431
+ mode = last !== 0 ? DRY : TYPE;
1432
+ break;
1433
+ case TABLE:
1434
+
1435
+ while (k < (14)) {
1436
+ if (n !== 0) {
1437
+ r = Z_OK;
1438
+ } else {
1439
+ that.bitb = b;
1440
+ that.bitk = k;
1441
+ z.avail_in = n;
1442
+ z.total_in += p - z.next_in_index;
1443
+ z.next_in_index = p;
1444
+ that.write = q;
1445
+ return that.inflate_flush(z, r);
1446
+ }
1348
1447
 
1349
- while (k < (32)) {
1448
+ n--;
1449
+ b |= (z.read_byte(p++) & 0xff) << k;
1450
+ k += 8;
1451
+ }
1452
+
1453
+ table = t = (b & 0x3fff);
1454
+ if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) {
1455
+ mode = BADBLOCKS;
1456
+ z.msg = "too many length or distance symbols";
1457
+ r = Z_DATA_ERROR;
1458
+
1459
+ that.bitb = b;
1460
+ that.bitk = k;
1461
+ z.avail_in = n;
1462
+ z.total_in += p - z.next_in_index;
1463
+ z.next_in_index = p;
1464
+ that.write = q;
1465
+ return that.inflate_flush(z, r);
1466
+ }
1467
+ t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
1468
+ if (!blens || blens.length < t) {
1469
+ blens = []; // new Array(t);
1470
+ } else {
1471
+ for (i = 0; i < t; i++) {
1472
+ blens[i] = 0;
1473
+ }
1474
+ }
1475
+
1476
+ // {
1477
+ b >>>= (14);
1478
+ k -= (14);
1479
+ // }
1480
+
1481
+ index = 0;
1482
+ mode = BTREE;
1483
+ /* falls through */
1484
+ case BTREE:
1485
+ while (index < 4 + (table >>> 10)) {
1486
+ while (k < (3)) {
1350
1487
  if (n !== 0) {
1351
1488
  r = Z_OK;
1352
1489
  } else {
@@ -1363,78 +1500,52 @@ const ZipInflate = (() => {
1363
1500
  k += 8;
1364
1501
  }
1365
1502
 
1366
- if ((((~b) >>> 16) & 0xffff) != (b & 0xffff)) {
1367
- mode = BADBLOCKS;
1368
- z.msg = "invalid stored block lengths";
1369
- r = Z_DATA_ERROR;
1503
+ blens[border[index++]] = b & 7;
1370
1504
 
1371
- that.bitb = b;
1372
- that.bitk = k;
1373
- z.avail_in = n;
1374
- z.total_in += p - z.next_in_index;
1375
- z.next_in_index = p;
1376
- that.write = q;
1377
- return that.inflate_flush(z, r);
1378
- }
1379
- left = (b & 0xffff);
1380
- b = k = 0; // dump bits
1381
- mode = left !== 0 ? STORED : (last !== 0 ? DRY : TYPE);
1382
- break;
1383
- case STORED:
1384
- if (n === 0) {
1385
- that.bitb = b;
1386
- that.bitk = k;
1387
- z.avail_in = n;
1388
- z.total_in += p - z.next_in_index;
1389
- z.next_in_index = p;
1390
- that.write = q;
1391
- return that.inflate_flush(z, r);
1392
- }
1505
+ // {
1506
+ b >>>= (3);
1507
+ k -= (3);
1508
+ // }
1509
+ }
1393
1510
 
1394
- if (m === 0) {
1395
- if (q == that.end && that.read !== 0) {
1396
- q = 0;
1397
- m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
1398
- }
1399
- if (m === 0) {
1400
- that.write = q;
1401
- r = that.inflate_flush(z, r);
1402
- q = that.write;
1403
- m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
1404
- if (q == that.end && that.read !== 0) {
1405
- q = 0;
1406
- m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
1407
- }
1408
- if (m === 0) {
1409
- that.bitb = b;
1410
- that.bitk = k;
1411
- z.avail_in = n;
1412
- z.total_in += p - z.next_in_index;
1413
- z.next_in_index = p;
1414
- that.write = q;
1415
- return that.inflate_flush(z, r);
1416
- }
1417
- }
1511
+ while (index < 19) {
1512
+ blens[border[index++]] = 0;
1513
+ }
1514
+
1515
+ bb[0] = 7;
1516
+ t = inftree.inflate_trees_bits(blens, bb, tb, hufts, z);
1517
+ if (t != Z_OK) {
1518
+ r = t;
1519
+ if (r == Z_DATA_ERROR) {
1520
+ blens = null;
1521
+ mode = BADBLOCKS;
1418
1522
  }
1419
- r = Z_OK;
1420
-
1421
- t = left;
1422
- if (t > n)
1423
- t = n;
1424
- if (t > m)
1425
- t = m;
1426
- that.win.set(z.read_buf(p, t), q);
1427
- p += t;
1428
- n -= t;
1429
- q += t;
1430
- m -= t;
1431
- if ((left -= t) !== 0)
1523
+
1524
+ that.bitb = b;
1525
+ that.bitk = k;
1526
+ z.avail_in = n;
1527
+ z.total_in += p - z.next_in_index;
1528
+ z.next_in_index = p;
1529
+ that.write = q;
1530
+ return that.inflate_flush(z, r);
1531
+ }
1532
+
1533
+ index = 0;
1534
+ mode = DTREE;
1535
+ /* falls through */
1536
+ case DTREE:
1537
+ // eslint-disable-next-line no-constant-condition
1538
+ while (true) {
1539
+ t = table;
1540
+ if (index >= 258 + (t & 0x1f) + ((t >> 5) & 0x1f)) {
1432
1541
  break;
1433
- mode = last !== 0 ? DRY : TYPE;
1434
- break;
1435
- case TABLE:
1542
+ }
1543
+
1544
+ let j, c;
1436
1545
 
1437
- while (k < (14)) {
1546
+ t = bb[0];
1547
+
1548
+ while (k < (t)) {
1438
1549
  if (n !== 0) {
1439
1550
  r = Z_OK;
1440
1551
  } else {
@@ -1446,108 +1557,27 @@ const ZipInflate = (() => {
1446
1557
  that.write = q;
1447
1558
  return that.inflate_flush(z, r);
1448
1559
  }
1449
-
1450
1560
  n--;
1451
1561
  b |= (z.read_byte(p++) & 0xff) << k;
1452
1562
  k += 8;
1453
1563
  }
1454
1564
 
1455
- table = t = (b & 0x3fff);
1456
- if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) {
1457
- mode = BADBLOCKS;
1458
- z.msg = "too many length or distance symbols";
1459
- r = Z_DATA_ERROR;
1460
-
1461
- that.bitb = b;
1462
- that.bitk = k;
1463
- z.avail_in = n;
1464
- z.total_in += p - z.next_in_index;
1465
- z.next_in_index = p;
1466
- that.write = q;
1467
- return that.inflate_flush(z, r);
1468
- }
1469
- t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
1470
- if (!blens || blens.length < t) {
1471
- blens = []; // new Array(t);
1472
- } else {
1473
- for (i = 0; i < t; i++) {
1474
- blens[i] = 0;
1475
- }
1476
- }
1477
-
1478
- // {
1479
- b >>>= (14);
1480
- k -= (14);
1565
+ // if (tb[0] == -1) {
1566
+ // System.err.println("null...");
1481
1567
  // }
1482
1568
 
1483
- index = 0;
1484
- mode = BTREE;
1485
- /* falls through */
1486
- case BTREE:
1487
- while (index < 4 + (table >>> 10)) {
1488
- while (k < (3)) {
1489
- if (n !== 0) {
1490
- r = Z_OK;
1491
- } else {
1492
- that.bitb = b;
1493
- that.bitk = k;
1494
- z.avail_in = n;
1495
- z.total_in += p - z.next_in_index;
1496
- z.next_in_index = p;
1497
- that.write = q;
1498
- return that.inflate_flush(z, r);
1499
- }
1500
- n--;
1501
- b |= (z.read_byte(p++) & 0xff) << k;
1502
- k += 8;
1503
- }
1504
-
1505
- blens[border[index++]] = b & 7;
1506
-
1507
- // {
1508
- b >>>= (3);
1509
- k -= (3);
1510
- // }
1511
- }
1512
-
1513
- while (index < 19) {
1514
- blens[border[index++]] = 0;
1515
- }
1516
-
1517
- bb[0] = 7;
1518
- t = inftree.inflate_trees_bits(blens, bb, tb, hufts, z);
1519
- if (t != Z_OK) {
1520
- r = t;
1521
- if (r == Z_DATA_ERROR) {
1522
- blens = null;
1523
- mode = BADBLOCKS;
1524
- }
1525
-
1526
- that.bitb = b;
1527
- that.bitk = k;
1528
- z.avail_in = n;
1529
- z.total_in += p - z.next_in_index;
1530
- z.next_in_index = p;
1531
- that.write = q;
1532
- return that.inflate_flush(z, r);
1533
- }
1534
-
1535
- index = 0;
1536
- mode = DTREE;
1537
- /* falls through */
1538
- case DTREE:
1539
- // eslint-disable-next-line no-constant-condition
1540
- while (true) {
1541
- t = table;
1542
- if (index >= 258 + (t & 0x1f) + ((t >> 5) & 0x1f)) {
1543
- break;
1544
- }
1545
-
1546
- let j, c;
1569
+ t = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 1];
1570
+ c = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 2];
1547
1571
 
1548
- t = bb[0];
1572
+ if (c < 16) {
1573
+ b >>>= (t);
1574
+ k -= (t);
1575
+ blens[index++] = c;
1576
+ } else { // c == 16..18
1577
+ i = c == 18 ? 7 : c - 14;
1578
+ j = c == 18 ? 11 : 3;
1549
1579
 
1550
- while (k < (t)) {
1580
+ while (k < (t + i)) {
1551
1581
  if (n !== 0) {
1552
1582
  r = Z_OK;
1553
1583
  } else {
@@ -1564,147 +1594,57 @@ const ZipInflate = (() => {
1564
1594
  k += 8;
1565
1595
  }
1566
1596
 
1567
- // if (tb[0] == -1) {
1568
- // System.err.println("null...");
1569
- // }
1570
-
1571
- t = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 1];
1572
- c = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 2];
1573
-
1574
- if (c < 16) {
1575
- b >>>= (t);
1576
- k -= (t);
1577
- blens[index++] = c;
1578
- } else { // c == 16..18
1579
- i = c == 18 ? 7 : c - 14;
1580
- j = c == 18 ? 11 : 3;
1581
-
1582
- while (k < (t + i)) {
1583
- if (n !== 0) {
1584
- r = Z_OK;
1585
- } else {
1586
- that.bitb = b;
1587
- that.bitk = k;
1588
- z.avail_in = n;
1589
- z.total_in += p - z.next_in_index;
1590
- z.next_in_index = p;
1591
- that.write = q;
1592
- return that.inflate_flush(z, r);
1593
- }
1594
- n--;
1595
- b |= (z.read_byte(p++) & 0xff) << k;
1596
- k += 8;
1597
- }
1598
-
1599
- b >>>= (t);
1600
- k -= (t);
1601
-
1602
- j += (b & inflate_mask[i]);
1603
-
1604
- b >>>= (i);
1605
- k -= (i);
1606
-
1607
- i = index;
1608
- t = table;
1609
- if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) {
1610
- blens = null;
1611
- mode = BADBLOCKS;
1612
- z.msg = "invalid bit length repeat";
1613
- r = Z_DATA_ERROR;
1614
-
1615
- that.bitb = b;
1616
- that.bitk = k;
1617
- z.avail_in = n;
1618
- z.total_in += p - z.next_in_index;
1619
- z.next_in_index = p;
1620
- that.write = q;
1621
- return that.inflate_flush(z, r);
1622
- }
1597
+ b >>>= (t);
1598
+ k -= (t);
1623
1599
 
1624
- c = c == 16 ? blens[i - 1] : 0;
1625
- do {
1626
- blens[i++] = c;
1627
- } while (--j !== 0);
1628
- index = i;
1629
- }
1630
- }
1631
-
1632
- tb[0] = -1;
1633
- // {
1634
- bl_ = []; // new Array(1);
1635
- bd_ = []; // new Array(1);
1636
- tl_ = []; // new Array(1);
1637
- td_ = []; // new Array(1);
1638
- bl_[0] = 9; // must be <= 9 for lookahead assumptions
1639
- bd_[0] = 6; // must be <= 9 for lookahead assumptions
1600
+ j += (b & inflate_mask[i]);
1640
1601
 
1641
- t = table;
1642
- t = inftree.inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), blens, bl_, bd_, tl_, td_, hufts, z);
1602
+ b >>>= (i);
1603
+ k -= (i);
1643
1604
 
1644
- if (t != Z_OK) {
1645
- if (t == Z_DATA_ERROR) {
1605
+ i = index;
1606
+ t = table;
1607
+ if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) {
1646
1608
  blens = null;
1647
1609
  mode = BADBLOCKS;
1648
- }
1649
- r = t;
1610
+ z.msg = "invalid bit length repeat";
1611
+ r = Z_DATA_ERROR;
1650
1612
 
1651
- that.bitb = b;
1652
- that.bitk = k;
1653
- z.avail_in = n;
1654
- z.total_in += p - z.next_in_index;
1655
- z.next_in_index = p;
1656
- that.write = q;
1657
- return that.inflate_flush(z, r);
1658
- }
1659
- codes.init(bl_[0], bd_[0], hufts, tl_[0], hufts, td_[0]);
1660
- // }
1661
- mode = CODES;
1662
- /* falls through */
1663
- case CODES:
1664
- that.bitb = b;
1665
- that.bitk = k;
1666
- z.avail_in = n;
1667
- z.total_in += p - z.next_in_index;
1668
- z.next_in_index = p;
1669
- that.write = q;
1613
+ that.bitb = b;
1614
+ that.bitk = k;
1615
+ z.avail_in = n;
1616
+ z.total_in += p - z.next_in_index;
1617
+ z.next_in_index = p;
1618
+ that.write = q;
1619
+ return that.inflate_flush(z, r);
1620
+ }
1670
1621
 
1671
- if ((r = codes.proc(that, z, r)) != Z_STREAM_END) {
1672
- return that.inflate_flush(z, r);
1622
+ c = c == 16 ? blens[i - 1] : 0;
1623
+ do {
1624
+ blens[i++] = c;
1625
+ } while (--j !== 0);
1626
+ index = i;
1673
1627
  }
1674
- r = Z_OK;
1675
- codes.free(z);
1676
-
1677
- p = z.next_in_index;
1678
- n = z.avail_in;
1679
- b = that.bitb;
1680
- k = that.bitk;
1681
- q = that.write;
1682
- m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
1628
+ }
1683
1629
 
1684
- if (last === 0) {
1685
- mode = TYPE;
1686
- break;
1687
- }
1688
- mode = DRY;
1689
- /* falls through */
1690
- case DRY:
1691
- that.write = q;
1692
- r = that.inflate_flush(z, r);
1693
- q = that.write;
1694
- m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
1695
- if (that.read != that.write) {
1696
- that.bitb = b;
1697
- that.bitk = k;
1698
- z.avail_in = n;
1699
- z.total_in += p - z.next_in_index;
1700
- z.next_in_index = p;
1701
- that.write = q;
1702
- return that.inflate_flush(z, r);
1630
+ tb[0] = -1;
1631
+ // {
1632
+ bl_ = []; // new Array(1);
1633
+ bd_ = []; // new Array(1);
1634
+ tl_ = []; // new Array(1);
1635
+ td_ = []; // new Array(1);
1636
+ bl_[0] = 9; // must be <= 9 for lookahead assumptions
1637
+ bd_[0] = 6; // must be <= 9 for lookahead assumptions
1638
+
1639
+ t = table;
1640
+ t = inftree.inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), blens, bl_, bd_, tl_, td_, hufts, z);
1641
+
1642
+ if (t != Z_OK) {
1643
+ if (t == Z_DATA_ERROR) {
1644
+ blens = null;
1645
+ mode = BADBLOCKS;
1703
1646
  }
1704
- mode = DONELOCKS;
1705
- /* falls through */
1706
- case DONELOCKS:
1707
- r = Z_STREAM_END;
1647
+ r = t;
1708
1648
 
1709
1649
  that.bitb = b;
1710
1650
  that.bitk = k;
@@ -1713,20 +1653,44 @@ const ZipInflate = (() => {
1713
1653
  z.next_in_index = p;
1714
1654
  that.write = q;
1715
1655
  return that.inflate_flush(z, r);
1716
- case BADBLOCKS:
1717
- r = Z_DATA_ERROR;
1718
-
1719
- that.bitb = b;
1720
- that.bitk = k;
1721
- z.avail_in = n;
1722
- z.total_in += p - z.next_in_index;
1723
- z.next_in_index = p;
1724
- that.write = q;
1656
+ }
1657
+ codes.init(bl_[0], bd_[0], hufts, tl_[0], hufts, td_[0]);
1658
+ // }
1659
+ mode = CODES;
1660
+ /* falls through */
1661
+ case CODES:
1662
+ that.bitb = b;
1663
+ that.bitk = k;
1664
+ z.avail_in = n;
1665
+ z.total_in += p - z.next_in_index;
1666
+ z.next_in_index = p;
1667
+ that.write = q;
1668
+
1669
+ if ((r = codes.proc(that, z, r)) != Z_STREAM_END) {
1725
1670
  return that.inflate_flush(z, r);
1671
+ }
1672
+ r = Z_OK;
1673
+ codes.free(z);
1726
1674
 
1727
- default:
1728
- r = Z_STREAM_ERROR;
1675
+ p = z.next_in_index;
1676
+ n = z.avail_in;
1677
+ b = that.bitb;
1678
+ k = that.bitk;
1679
+ q = that.write;
1680
+ m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
1729
1681
 
1682
+ if (last === 0) {
1683
+ mode = TYPE;
1684
+ break;
1685
+ }
1686
+ mode = DRY;
1687
+ /* falls through */
1688
+ case DRY:
1689
+ that.write = q;
1690
+ r = that.inflate_flush(z, r);
1691
+ q = that.write;
1692
+ m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
1693
+ if (that.read != that.write) {
1730
1694
  that.bitb = b;
1731
1695
  that.bitk = k;
1732
1696
  z.avail_in = n;
@@ -1734,437 +1698,470 @@ const ZipInflate = (() => {
1734
1698
  z.next_in_index = p;
1735
1699
  that.write = q;
1736
1700
  return that.inflate_flush(z, r);
1737
- }
1701
+ }
1702
+ mode = DONELOCKS;
1703
+ /* falls through */
1704
+ case DONELOCKS:
1705
+ r = Z_STREAM_END;
1706
+
1707
+ that.bitb = b;
1708
+ that.bitk = k;
1709
+ z.avail_in = n;
1710
+ z.total_in += p - z.next_in_index;
1711
+ z.next_in_index = p;
1712
+ that.write = q;
1713
+ return that.inflate_flush(z, r);
1714
+ case BADBLOCKS:
1715
+ r = Z_DATA_ERROR;
1716
+
1717
+ that.bitb = b;
1718
+ that.bitk = k;
1719
+ z.avail_in = n;
1720
+ z.total_in += p - z.next_in_index;
1721
+ z.next_in_index = p;
1722
+ that.write = q;
1723
+ return that.inflate_flush(z, r);
1724
+
1725
+ default:
1726
+ r = Z_STREAM_ERROR;
1727
+
1728
+ that.bitb = b;
1729
+ that.bitk = k;
1730
+ z.avail_in = n;
1731
+ z.total_in += p - z.next_in_index;
1732
+ z.next_in_index = p;
1733
+ that.write = q;
1734
+ return that.inflate_flush(z, r);
1738
1735
  }
1739
- };
1740
-
1741
- that.free = function (z) {
1742
- that.reset(z, null);
1743
- that.win = null;
1744
- hufts = null;
1745
- // ZFREE(z, s);
1746
- };
1747
-
1748
- that.set_dictionary = function (d, start, n) {
1749
- that.win.set(d.subarray(start, start + n), 0);
1750
- that.read = that.write = n;
1751
- };
1752
-
1753
- // Returns true if inflate is currently at the end of a block generated
1754
- // by Z_SYNC_FLUSH or Z_FULL_FLUSH.
1755
- that.sync_point = function () {
1756
- return mode == LENS ? 1 : 0;
1757
- };
1758
-
1759
- }
1760
-
1761
- // Inflate
1762
-
1763
- // preset dictionary flag in zlib header
1764
- const PRESET_DICT = 0x20;
1765
-
1766
- const Z_DEFLATED = 8;
1767
-
1768
- const METHOD = 0; // waiting for method byte
1769
- const FLAG = 1; // waiting for flag byte
1770
- const DICT4 = 2; // four dictionary check bytes to go
1771
- const DICT3 = 3; // three dictionary check bytes to go
1772
- const DICT2 = 4; // two dictionary check bytes to go
1773
- const DICT1 = 5; // one dictionary check byte to go
1774
- const DICT0 = 6; // waiting for inflateSetDictionary
1775
- const BLOCKS = 7; // decompressing blocks
1776
- const DONE = 12; // finished check, done
1777
- const BAD = 13; // got an error--stay here
1736
+ }
1737
+ };
1778
1738
 
1779
- const mark = [0, 0, 0xff, 0xff];
1739
+ that.free = function (z) {
1740
+ that.reset(z, null);
1741
+ that.win = null;
1742
+ hufts = null;
1743
+ // ZFREE(z, s);
1744
+ };
1780
1745
 
1781
- function Inflate() {
1782
- const that = this;
1746
+ that.set_dictionary = function (d, start, n) {
1747
+ that.win.set(d.subarray(start, start + n), 0);
1748
+ that.read = that.write = n;
1749
+ };
1783
1750
 
1784
- that.mode = 0; // current inflate mode
1751
+ // Returns true if inflate is currently at the end of a block generated
1752
+ // by Z_SYNC_FLUSH or Z_FULL_FLUSH.
1753
+ that.sync_point = function () {
1754
+ return mode == LENS ? 1 : 0;
1755
+ };
1785
1756
 
1786
- // mode dependent information
1787
- that.method = 0; // if FLAGS, method byte
1757
+ }
1788
1758
 
1789
- // if CHECK, check values to compare
1790
- that.was = [0]; // new Array(1); // computed check value
1791
- that.need = 0; // stream check value
1759
+ // Inflate
1792
1760
 
1793
- // if BAD, inflateSync's marker bytes count
1794
- that.marker = 0;
1761
+ // preset dictionary flag in zlib header
1762
+ const PRESET_DICT = 0x20;
1795
1763
 
1796
- // mode independent information
1797
- that.wbits = 0; // log2(win size) (8..15, defaults to 15)
1764
+ const Z_DEFLATED = 8;
1798
1765
 
1799
- // this.blocks; // current inflate_blocks state
1766
+ const METHOD = 0; // waiting for method byte
1767
+ const FLAG = 1; // waiting for flag byte
1768
+ const DICT4 = 2; // four dictionary check bytes to go
1769
+ const DICT3 = 3; // three dictionary check bytes to go
1770
+ const DICT2 = 4; // two dictionary check bytes to go
1771
+ const DICT1 = 5; // one dictionary check byte to go
1772
+ const DICT0 = 6; // waiting for inflateSetDictionary
1773
+ const BLOCKS = 7; // decompressing blocks
1774
+ const DONE = 12; // finished check, done
1775
+ const BAD = 13; // got an error--stay here
1800
1776
 
1801
- function inflateReset(z) {
1802
- if (!z || !z.istate)
1803
- return Z_STREAM_ERROR;
1777
+ const mark = [0, 0, 0xff, 0xff];
1804
1778
 
1805
- z.total_in = z.total_out = 0;
1806
- z.msg = null;
1807
- z.istate.mode = BLOCKS;
1808
- z.istate.blocks.reset(z, null);
1809
- return Z_OK;
1810
- }
1779
+ function Inflate() {
1780
+ const that = this;
1811
1781
 
1812
- that.inflateEnd = function (z) {
1813
- if (that.blocks)
1814
- that.blocks.free(z);
1815
- that.blocks = null;
1816
- // ZFREE(z, z->state);
1817
- return Z_OK;
1818
- };
1782
+ that.mode = 0; // current inflate mode
1819
1783
 
1820
- that.inflateInit = function (z, w) {
1821
- z.msg = null;
1822
- that.blocks = null;
1784
+ // mode dependent information
1785
+ that.method = 0; // if FLAGS, method byte
1823
1786
 
1824
- // set win size
1825
- if (w < 8 || w > 15) {
1826
- that.inflateEnd(z);
1827
- return Z_STREAM_ERROR;
1828
- }
1829
- that.wbits = w;
1787
+ // if CHECK, check values to compare
1788
+ that.was = [0]; // new Array(1); // computed check value
1789
+ that.need = 0; // stream check value
1830
1790
 
1831
- z.istate.blocks = new InfBlocks(z, 1 << w);
1791
+ // if BAD, inflateSync's marker bytes count
1792
+ that.marker = 0;
1832
1793
 
1833
- // reset state
1834
- inflateReset(z);
1835
- return Z_OK;
1836
- };
1837
-
1838
- that.inflate = function (z, f) {
1839
- let r;
1840
- let b;
1841
-
1842
- if (!z || !z.istate || !z.next_in)
1843
- return Z_STREAM_ERROR;
1844
- const istate = z.istate;
1845
- f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
1846
- r = Z_BUF_ERROR;
1847
- // eslint-disable-next-line no-constant-condition
1848
- while (true) {
1849
- switch (istate.mode) {
1850
- case METHOD:
1851
-
1852
- if (z.avail_in === 0)
1853
- return r;
1854
- r = f;
1794
+ // mode independent information
1795
+ that.wbits = 0; // log2(win size) (8..15, defaults to 15)
1855
1796
 
1856
- z.avail_in--;
1857
- z.total_in++;
1858
- if (((istate.method = z.read_byte(z.next_in_index++)) & 0xf) != Z_DEFLATED) {
1859
- istate.mode = BAD;
1860
- z.msg = "unknown compression method";
1861
- istate.marker = 5; // can't try inflateSync
1862
- break;
1863
- }
1864
- if ((istate.method >> 4) + 8 > istate.wbits) {
1865
- istate.mode = BAD;
1866
- z.msg = "invalid win size";
1867
- istate.marker = 5; // can't try inflateSync
1868
- break;
1869
- }
1870
- istate.mode = FLAG;
1871
- /* falls through */
1872
- case FLAG:
1797
+ // this.blocks; // current inflate_blocks state
1873
1798
 
1874
- if (z.avail_in === 0)
1875
- return r;
1876
- r = f;
1799
+ function inflateReset(z) {
1800
+ if (!z || !z.istate)
1801
+ return Z_STREAM_ERROR;
1877
1802
 
1878
- z.avail_in--;
1879
- z.total_in++;
1880
- b = (z.read_byte(z.next_in_index++)) & 0xff;
1803
+ z.total_in = z.total_out = 0;
1804
+ z.msg = null;
1805
+ z.istate.mode = BLOCKS;
1806
+ z.istate.blocks.reset(z, null);
1807
+ return Z_OK;
1808
+ }
1881
1809
 
1882
- if ((((istate.method << 8) + b) % 31) !== 0) {
1883
- istate.mode = BAD;
1884
- z.msg = "incorrect header check";
1885
- istate.marker = 5; // can't try inflateSync
1886
- break;
1887
- }
1810
+ that.inflateEnd = function (z) {
1811
+ if (that.blocks)
1812
+ that.blocks.free(z);
1813
+ that.blocks = null;
1814
+ // ZFREE(z, z->state);
1815
+ return Z_OK;
1816
+ };
1888
1817
 
1889
- if ((b & PRESET_DICT) === 0) {
1890
- istate.mode = BLOCKS;
1891
- break;
1892
- }
1893
- istate.mode = DICT4;
1894
- /* falls through */
1895
- case DICT4:
1818
+ that.inflateInit = function (z, w) {
1819
+ z.msg = null;
1820
+ that.blocks = null;
1896
1821
 
1897
- if (z.avail_in === 0)
1898
- return r;
1899
- r = f;
1822
+ // set win size
1823
+ if (w < 8 || w > 15) {
1824
+ that.inflateEnd(z);
1825
+ return Z_STREAM_ERROR;
1826
+ }
1827
+ that.wbits = w;
1900
1828
 
1901
- z.avail_in--;
1902
- z.total_in++;
1903
- istate.need = ((z.read_byte(z.next_in_index++) & 0xff) << 24) & 0xff000000;
1904
- istate.mode = DICT3;
1905
- /* falls through */
1906
- case DICT3:
1829
+ z.istate.blocks = new InfBlocks(z, 1 << w);
1907
1830
 
1908
- if (z.avail_in === 0)
1909
- return r;
1910
- r = f;
1831
+ // reset state
1832
+ inflateReset(z);
1833
+ return Z_OK;
1834
+ };
1911
1835
 
1912
- z.avail_in--;
1913
- z.total_in++;
1914
- istate.need += ((z.read_byte(z.next_in_index++) & 0xff) << 16) & 0xff0000;
1915
- istate.mode = DICT2;
1916
- /* falls through */
1917
- case DICT2:
1836
+ that.inflate = function (z, f) {
1837
+ let r;
1838
+ let b;
1839
+
1840
+ if (!z || !z.istate || !z.next_in)
1841
+ return Z_STREAM_ERROR;
1842
+ const istate = z.istate;
1843
+ f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
1844
+ r = Z_BUF_ERROR;
1845
+ // eslint-disable-next-line no-constant-condition
1846
+ while (true) {
1847
+ switch (istate.mode) {
1848
+ case METHOD:
1849
+
1850
+ if (z.avail_in === 0)
1851
+ return r;
1852
+ r = f;
1853
+
1854
+ z.avail_in--;
1855
+ z.total_in++;
1856
+ if (((istate.method = z.read_byte(z.next_in_index++)) & 0xf) != Z_DEFLATED) {
1857
+ istate.mode = BAD;
1858
+ z.msg = "unknown compression method";
1859
+ istate.marker = 5; // can't try inflateSync
1860
+ break;
1861
+ }
1862
+ if ((istate.method >> 4) + 8 > istate.wbits) {
1863
+ istate.mode = BAD;
1864
+ z.msg = "invalid win size";
1865
+ istate.marker = 5; // can't try inflateSync
1866
+ break;
1867
+ }
1868
+ istate.mode = FLAG;
1869
+ /* falls through */
1870
+ case FLAG:
1918
1871
 
1919
- if (z.avail_in === 0)
1920
- return r;
1921
- r = f;
1872
+ if (z.avail_in === 0)
1873
+ return r;
1874
+ r = f;
1922
1875
 
1923
- z.avail_in--;
1924
- z.total_in++;
1925
- istate.need += ((z.read_byte(z.next_in_index++) & 0xff) << 8) & 0xff00;
1926
- istate.mode = DICT1;
1927
- /* falls through */
1928
- case DICT1:
1876
+ z.avail_in--;
1877
+ z.total_in++;
1878
+ b = (z.read_byte(z.next_in_index++)) & 0xff;
1929
1879
 
1930
- if (z.avail_in === 0)
1931
- return r;
1932
- r = f;
1880
+ if ((((istate.method << 8) + b) % 31) !== 0) {
1881
+ istate.mode = BAD;
1882
+ z.msg = "incorrect header check";
1883
+ istate.marker = 5; // can't try inflateSync
1884
+ break;
1885
+ }
1933
1886
 
1934
- z.avail_in--;
1935
- z.total_in++;
1936
- istate.need += (z.read_byte(z.next_in_index++) & 0xff);
1937
- istate.mode = DICT0;
1938
- return Z_NEED_DICT;
1939
- case DICT0:
1887
+ if ((b & PRESET_DICT) === 0) {
1888
+ istate.mode = BLOCKS;
1889
+ break;
1890
+ }
1891
+ istate.mode = DICT4;
1892
+ /* falls through */
1893
+ case DICT4:
1894
+
1895
+ if (z.avail_in === 0)
1896
+ return r;
1897
+ r = f;
1898
+
1899
+ z.avail_in--;
1900
+ z.total_in++;
1901
+ istate.need = ((z.read_byte(z.next_in_index++) & 0xff) << 24) & 0xff000000;
1902
+ istate.mode = DICT3;
1903
+ /* falls through */
1904
+ case DICT3:
1905
+
1906
+ if (z.avail_in === 0)
1907
+ return r;
1908
+ r = f;
1909
+
1910
+ z.avail_in--;
1911
+ z.total_in++;
1912
+ istate.need += ((z.read_byte(z.next_in_index++) & 0xff) << 16) & 0xff0000;
1913
+ istate.mode = DICT2;
1914
+ /* falls through */
1915
+ case DICT2:
1916
+
1917
+ if (z.avail_in === 0)
1918
+ return r;
1919
+ r = f;
1920
+
1921
+ z.avail_in--;
1922
+ z.total_in++;
1923
+ istate.need += ((z.read_byte(z.next_in_index++) & 0xff) << 8) & 0xff00;
1924
+ istate.mode = DICT1;
1925
+ /* falls through */
1926
+ case DICT1:
1927
+
1928
+ if (z.avail_in === 0)
1929
+ return r;
1930
+ r = f;
1931
+
1932
+ z.avail_in--;
1933
+ z.total_in++;
1934
+ istate.need += (z.read_byte(z.next_in_index++) & 0xff);
1935
+ istate.mode = DICT0;
1936
+ return Z_NEED_DICT;
1937
+ case DICT0:
1938
+ istate.mode = BAD;
1939
+ z.msg = "need dictionary";
1940
+ istate.marker = 0; // can try inflateSync
1941
+ return Z_STREAM_ERROR;
1942
+ case BLOCKS:
1943
+
1944
+ r = istate.blocks.proc(z, r);
1945
+ if (r == Z_DATA_ERROR) {
1940
1946
  istate.mode = BAD;
1941
- z.msg = "need dictionary";
1942
1947
  istate.marker = 0; // can try inflateSync
1943
- return Z_STREAM_ERROR;
1944
- case BLOCKS:
1945
-
1946
- r = istate.blocks.proc(z, r);
1947
- if (r == Z_DATA_ERROR) {
1948
- istate.mode = BAD;
1949
- istate.marker = 0; // can try inflateSync
1950
- break;
1951
- }
1952
- if (r == Z_OK) {
1953
- r = f;
1954
- }
1955
- if (r != Z_STREAM_END) {
1956
- return r;
1957
- }
1948
+ break;
1949
+ }
1950
+ if (r == Z_OK) {
1958
1951
  r = f;
1959
- istate.blocks.reset(z, istate.was);
1960
- istate.mode = DONE;
1961
- /* falls through */
1962
- case DONE:
1963
- z.avail_in = 0;
1964
- return Z_STREAM_END;
1965
- case BAD:
1966
- return Z_DATA_ERROR;
1967
- default:
1968
- return Z_STREAM_ERROR;
1969
- }
1970
- }
1971
- };
1972
-
1973
- that.inflateSetDictionary = function (z, dictionary, dictLength) {
1974
- let index = 0, length = dictLength;
1975
- if (!z || !z.istate || z.istate.mode != DICT0)
1976
- return Z_STREAM_ERROR;
1977
- const istate = z.istate;
1978
- if (length >= (1 << istate.wbits)) {
1979
- length = (1 << istate.wbits) - 1;
1980
- index = dictLength - length;
1981
- }
1982
- istate.blocks.set_dictionary(dictionary, index, length);
1983
- istate.mode = BLOCKS;
1984
- return Z_OK;
1985
- };
1986
-
1987
- that.inflateSync = function (z) {
1988
- let n; // number of bytes to look at
1989
- let p; // pointer to bytes
1990
- let m; // number of marker bytes found in a row
1991
- let r, w; // temporaries to save total_in and total_out
1992
-
1993
- // set up
1994
- if (!z || !z.istate)
1995
- return Z_STREAM_ERROR;
1996
- const istate = z.istate;
1997
- if (istate.mode != BAD) {
1998
- istate.mode = BAD;
1999
- istate.marker = 0;
2000
- }
2001
- if ((n = z.avail_in) === 0)
2002
- return Z_BUF_ERROR;
2003
- p = z.next_in_index;
2004
- m = istate.marker;
2005
-
2006
- // search
2007
- while (n !== 0 && m < 4) {
2008
- if (z.read_byte(p) == mark[m]) {
2009
- m++;
2010
- } else if (z.read_byte(p) !== 0) {
2011
- m = 0;
2012
- } else {
2013
- m = 4 - m;
2014
- }
2015
- p++;
2016
- n--;
1952
+ }
1953
+ if (r != Z_STREAM_END) {
1954
+ return r;
1955
+ }
1956
+ r = f;
1957
+ istate.blocks.reset(z, istate.was);
1958
+ istate.mode = DONE;
1959
+ /* falls through */
1960
+ case DONE:
1961
+ z.avail_in = 0;
1962
+ return Z_STREAM_END;
1963
+ case BAD:
1964
+ return Z_DATA_ERROR;
1965
+ default:
1966
+ return Z_STREAM_ERROR;
2017
1967
  }
1968
+ }
1969
+ };
2018
1970
 
2019
- // restore
2020
- z.total_in += p - z.next_in_index;
2021
- z.next_in_index = p;
2022
- z.avail_in = n;
2023
- istate.marker = m;
1971
+ that.inflateSetDictionary = function (z, dictionary, dictLength) {
1972
+ let index = 0, length = dictLength;
1973
+ if (!z || !z.istate || z.istate.mode != DICT0)
1974
+ return Z_STREAM_ERROR;
1975
+ const istate = z.istate;
1976
+ if (length >= (1 << istate.wbits)) {
1977
+ length = (1 << istate.wbits) - 1;
1978
+ index = dictLength - length;
1979
+ }
1980
+ istate.blocks.set_dictionary(dictionary, index, length);
1981
+ istate.mode = BLOCKS;
1982
+ return Z_OK;
1983
+ };
2024
1984
 
2025
- // return no joy or set up to restart on a new block
2026
- if (m != 4) {
2027
- return Z_DATA_ERROR;
1985
+ that.inflateSync = function (z) {
1986
+ let n; // number of bytes to look at
1987
+ let p; // pointer to bytes
1988
+ let m; // number of marker bytes found in a row
1989
+ let r, w; // temporaries to save total_in and total_out
1990
+
1991
+ // set up
1992
+ if (!z || !z.istate)
1993
+ return Z_STREAM_ERROR;
1994
+ const istate = z.istate;
1995
+ if (istate.mode != BAD) {
1996
+ istate.mode = BAD;
1997
+ istate.marker = 0;
1998
+ }
1999
+ if ((n = z.avail_in) === 0)
2000
+ return Z_BUF_ERROR;
2001
+ p = z.next_in_index;
2002
+ m = istate.marker;
2003
+
2004
+ // search
2005
+ while (n !== 0 && m < 4) {
2006
+ if (z.read_byte(p) == mark[m]) {
2007
+ m++;
2008
+ } else if (z.read_byte(p) !== 0) {
2009
+ m = 0;
2010
+ } else {
2011
+ m = 4 - m;
2028
2012
  }
2029
- r = z.total_in;
2030
- w = z.total_out;
2031
- inflateReset(z);
2032
- z.total_in = r;
2033
- z.total_out = w;
2034
- istate.mode = BLOCKS;
2035
- return Z_OK;
2036
- };
2037
-
2038
- // Returns true if inflate is currently at the end of a block generated
2039
- // by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
2040
- // implementation to provide an additional safety check. PPP uses
2041
- // Z_SYNC_FLUSH
2042
- // but removes the length bytes of the resulting empty stored block. When
2043
- // decompressing, PPP checks that at the end of input packet, inflate is
2044
- // waiting for these length bytes.
2045
- that.inflateSyncPoint = function (z) {
2046
- if (!z || !z.istate || !z.istate.blocks)
2047
- return Z_STREAM_ERROR;
2048
- return z.istate.blocks.sync_point();
2049
- };
2050
- }
2051
-
2052
- // ZStream
2013
+ p++;
2014
+ n--;
2015
+ }
2053
2016
 
2054
- function ZStream() {
2055
- }
2017
+ // restore
2018
+ z.total_in += p - z.next_in_index;
2019
+ z.next_in_index = p;
2020
+ z.avail_in = n;
2021
+ istate.marker = m;
2056
2022
 
2057
- ZStream.prototype = {
2058
- inflateInit(bits) {
2059
- const that = this;
2060
- that.istate = new Inflate();
2061
- if (!bits)
2062
- bits = MAX_BITS;
2063
- return that.istate.inflateInit(that, bits);
2064
- },
2065
-
2066
- inflate(f) {
2067
- const that = this;
2068
- if (!that.istate)
2069
- return Z_STREAM_ERROR;
2070
- return that.istate.inflate(that, f);
2071
- },
2072
-
2073
- inflateEnd() {
2074
- const that = this;
2075
- if (!that.istate)
2076
- return Z_STREAM_ERROR;
2077
- const ret = that.istate.inflateEnd(that);
2078
- that.istate = null;
2079
- return ret;
2080
- },
2081
-
2082
- inflateSync() {
2083
- const that = this;
2084
- if (!that.istate)
2085
- return Z_STREAM_ERROR;
2086
- return that.istate.inflateSync(that);
2087
- },
2088
- inflateSetDictionary(dictionary, dictLength) {
2089
- const that = this;
2090
- if (!that.istate)
2091
- return Z_STREAM_ERROR;
2092
- return that.istate.inflateSetDictionary(that, dictionary, dictLength);
2093
- },
2094
- read_byte(start) {
2095
- const that = this;
2096
- return that.next_in[start];
2097
- },
2098
- read_buf(start, size) {
2099
- const that = this;
2100
- return that.next_in.subarray(start, start + size);
2023
+ // return no joy or set up to restart on a new block
2024
+ if (m != 4) {
2025
+ return Z_DATA_ERROR;
2101
2026
  }
2027
+ r = z.total_in;
2028
+ w = z.total_out;
2029
+ inflateReset(z);
2030
+ z.total_in = r;
2031
+ z.total_out = w;
2032
+ istate.mode = BLOCKS;
2033
+ return Z_OK;
2034
+ };
2035
+
2036
+ // Returns true if inflate is currently at the end of a block generated
2037
+ // by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
2038
+ // implementation to provide an additional safety check. PPP uses
2039
+ // Z_SYNC_FLUSH
2040
+ // but removes the length bytes of the resulting empty stored block. When
2041
+ // decompressing, PPP checks that at the end of input packet, inflate is
2042
+ // waiting for these length bytes.
2043
+ that.inflateSyncPoint = function (z) {
2044
+ if (!z || !z.istate || !z.istate.blocks)
2045
+ return Z_STREAM_ERROR;
2046
+ return z.istate.blocks.sync_point();
2102
2047
  };
2048
+ }
2103
2049
 
2104
- // Inflater
2050
+ // ZStream
2105
2051
 
2106
- function ZipInflate(options) {
2052
+ function ZStream() {
2053
+ }
2054
+
2055
+ ZStream.prototype = {
2056
+ inflateInit(bits) {
2107
2057
  const that = this;
2108
- const z = new ZStream();
2109
- const bufsize = options && options.chunkSize ? Math.floor(options.chunkSize * 2) : 128 * 1024;
2110
- const flush = Z_NO_FLUSH;
2111
- const buf = new Uint8Array(bufsize);
2112
- let nomoreinput = false;
2113
-
2114
- z.inflateInit();
2115
- z.next_out = buf;
2116
-
2117
- that.append = function (data, onprogress) {
2118
- const buffers = [];
2119
- let err, array, lastIndex = 0, bufferIndex = 0, bufferSize = 0;
2120
- if (data.length === 0)
2121
- return;
2122
- z.next_in_index = 0;
2123
- z.next_in = data;
2124
- z.avail_in = data.length;
2125
- do {
2126
- z.next_out_index = 0;
2127
- z.avail_out = bufsize;
2128
- if ((z.avail_in === 0) && (!nomoreinput)) { // if buffer is empty and more input is available, refill it
2129
- z.next_in_index = 0;
2130
- nomoreinput = true;
2131
- }
2132
- err = z.inflate(flush);
2133
- if (nomoreinput && (err === Z_BUF_ERROR)) {
2134
- if (z.avail_in !== 0)
2135
- throw new Error("inflating: bad input");
2136
- } else if (err !== Z_OK && err !== Z_STREAM_END)
2137
- throw new Error("inflating: " + z.msg);
2138
- if ((nomoreinput || err === Z_STREAM_END) && (z.avail_in === data.length))
2058
+ that.istate = new Inflate();
2059
+ if (!bits)
2060
+ bits = MAX_BITS;
2061
+ return that.istate.inflateInit(that, bits);
2062
+ },
2063
+
2064
+ inflate(f) {
2065
+ const that = this;
2066
+ if (!that.istate)
2067
+ return Z_STREAM_ERROR;
2068
+ return that.istate.inflate(that, f);
2069
+ },
2070
+
2071
+ inflateEnd() {
2072
+ const that = this;
2073
+ if (!that.istate)
2074
+ return Z_STREAM_ERROR;
2075
+ const ret = that.istate.inflateEnd(that);
2076
+ that.istate = null;
2077
+ return ret;
2078
+ },
2079
+
2080
+ inflateSync() {
2081
+ const that = this;
2082
+ if (!that.istate)
2083
+ return Z_STREAM_ERROR;
2084
+ return that.istate.inflateSync(that);
2085
+ },
2086
+ inflateSetDictionary(dictionary, dictLength) {
2087
+ const that = this;
2088
+ if (!that.istate)
2089
+ return Z_STREAM_ERROR;
2090
+ return that.istate.inflateSetDictionary(that, dictionary, dictLength);
2091
+ },
2092
+ read_byte(start) {
2093
+ const that = this;
2094
+ return that.next_in[start];
2095
+ },
2096
+ read_buf(start, size) {
2097
+ const that = this;
2098
+ return that.next_in.subarray(start, start + size);
2099
+ }
2100
+ };
2101
+
2102
+ // Inflater
2103
+
2104
+ function ZipInflate(options) {
2105
+ const that = this;
2106
+ const z = new ZStream();
2107
+ const bufsize = options && options.chunkSize ? Math.floor(options.chunkSize * 2) : 128 * 1024;
2108
+ const flush = Z_NO_FLUSH;
2109
+ const buf = new Uint8Array(bufsize);
2110
+ let nomoreinput = false;
2111
+
2112
+ z.inflateInit();
2113
+ z.next_out = buf;
2114
+
2115
+ that.append = function (data, onprogress) {
2116
+ const buffers = [];
2117
+ let err, array, lastIndex = 0, bufferIndex = 0, bufferSize = 0;
2118
+ if (data.length === 0)
2119
+ return;
2120
+ z.next_in_index = 0;
2121
+ z.next_in = data;
2122
+ z.avail_in = data.length;
2123
+ do {
2124
+ z.next_out_index = 0;
2125
+ z.avail_out = bufsize;
2126
+ if ((z.avail_in === 0) && (!nomoreinput)) { // if buffer is empty and more input is available, refill it
2127
+ z.next_in_index = 0;
2128
+ nomoreinput = true;
2129
+ }
2130
+ err = z.inflate(flush);
2131
+ if (nomoreinput && (err === Z_BUF_ERROR)) {
2132
+ if (z.avail_in !== 0)
2139
2133
  throw new Error("inflating: bad input");
2140
- if (z.next_out_index)
2141
- if (z.next_out_index === bufsize)
2142
- buffers.push(new Uint8Array(buf));
2143
- else
2144
- buffers.push(buf.slice(0, z.next_out_index));
2145
- bufferSize += z.next_out_index;
2146
- if (onprogress && z.next_in_index > 0 && z.next_in_index != lastIndex) {
2147
- onprogress(z.next_in_index);
2148
- lastIndex = z.next_in_index;
2149
- }
2150
- } while (z.avail_in > 0 || z.avail_out === 0);
2151
- if (buffers.length > 1) {
2152
- array = new Uint8Array(bufferSize);
2153
- buffers.forEach(function (chunk) {
2154
- array.set(chunk, bufferIndex);
2155
- bufferIndex += chunk.length;
2156
- });
2157
- } else {
2158
- array = buffers[0] || new Uint8Array();
2134
+ } else if (err !== Z_OK && err !== Z_STREAM_END)
2135
+ throw new Error("inflating: " + z.msg);
2136
+ if ((nomoreinput || err === Z_STREAM_END) && (z.avail_in === data.length))
2137
+ throw new Error("inflating: bad input");
2138
+ if (z.next_out_index)
2139
+ if (z.next_out_index === bufsize)
2140
+ buffers.push(new Uint8Array(buf));
2141
+ else
2142
+ buffers.push(buf.slice(0, z.next_out_index));
2143
+ bufferSize += z.next_out_index;
2144
+ if (onprogress && z.next_in_index > 0 && z.next_in_index != lastIndex) {
2145
+ onprogress(z.next_in_index);
2146
+ lastIndex = z.next_in_index;
2159
2147
  }
2160
- return array;
2161
- };
2162
- that.flush = function () {
2163
- z.inflateEnd();
2164
- };
2165
- }
2166
- return ZipInflate;
2167
-
2168
- })();
2148
+ } while (z.avail_in > 0 || z.avail_out === 0);
2149
+ if (buffers.length > 1) {
2150
+ array = new Uint8Array(bufferSize);
2151
+ buffers.forEach(function (chunk) {
2152
+ array.set(chunk, bufferIndex);
2153
+ bufferIndex += chunk.length;
2154
+ });
2155
+ } else {
2156
+ array = buffers[0] || new Uint8Array();
2157
+ }
2158
+ return array;
2159
+ };
2160
+ that.flush = function () {
2161
+ z.inflateEnd();
2162
+ };
2163
+ }
2169
2164
 
2170
- export default ZipInflate;
2165
+ export {
2166
+ ZipInflate as Inflate
2167
+ };