@leofcoin/chain 1.10.2 → 1.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/exports/browser/{browser-BOiH47em-CNA0837Q.js → browser-D-r0O9Qn-BUd-PxvP.js} +2 -2
- package/exports/browser/{browser-BuaFyOQj-BCgu_5S8.js → browser-_hiyXwPp-CeZtoaRo.js} +2 -2
- package/exports/browser/chain.js +10 -10
- package/exports/browser/{client-B2wkkpij-CXdxWu9W.js → client-U5AYtQje-DAQ00fHP.js} +4 -4
- package/exports/browser/{constants-CUoFxEp2.js → constants-CVkCJ-VS.js} +490 -221
- package/exports/browser/{index-s61gSKAd-DUkaInec.js → index-BD0Anx7_-D-zybnw-.js} +2 -2
- package/exports/browser/{messages-CZ-3jxiD-BQAqB9Vv.js → messages-Dr5w-bq6-D-moQFGj.js} +2 -2
- package/exports/browser/{node-browser-Cveo6mdM.js → node-browser-D5TgXCwx.js} +11 -7
- package/exports/browser/node-browser.js +2 -2
- package/exports/browser/workers/block-worker.js +1 -1
- package/exports/browser/workers/machine-worker.js +9 -9
- package/exports/browser/workers/{worker-jeGMMCte-BwFbyiks.js → worker-CZqErLI7-BxofVJAn.js} +490 -221
- package/exports/workers/block-worker.js +1 -1
- package/exports/workers/machine-worker.js +9 -9
- package/exports/workers/{worker-jeGMMCte-BwFbyiks.js → worker-CZqErLI7-BxofVJAn.js} +490 -221
- package/package.json +13 -13
|
@@ -1,144 +1,341 @@
|
|
|
1
|
-
// base-x encoding / decoding
|
|
2
|
-
// Copyright (c) 2018 base-x contributors
|
|
3
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
1
|
+
// base-x encoding / decoding
|
|
2
|
+
// Copyright (c) 2018 base-x contributors
|
|
3
|
+
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
4
|
+
// Copyright (c) 2026 Vandeuren Glenn
|
|
5
|
+
// Distributed under the MIT software license, see the accompanying
|
|
6
|
+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
7
|
+
const base = (ALPHABET, options = {}) => {
|
|
8
|
+
if (ALPHABET.length >= 255) {
|
|
9
|
+
throw new TypeError("Alphabet too long");
|
|
10
|
+
}
|
|
11
|
+
const BASE_MAP = new Uint8Array(256);
|
|
12
|
+
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
13
|
+
BASE_MAP[j] = 255;
|
|
14
|
+
}
|
|
15
|
+
for (let i = 0; i < ALPHABET.length; i++) {
|
|
16
|
+
const x = ALPHABET.charAt(i);
|
|
17
|
+
const xc = x.charCodeAt(0);
|
|
18
|
+
if (BASE_MAP[xc] !== 255) {
|
|
19
|
+
throw new TypeError(x + " is ambiguous");
|
|
20
|
+
}
|
|
21
|
+
BASE_MAP[xc] = i;
|
|
22
|
+
}
|
|
23
|
+
const BASE = ALPHABET.length;
|
|
24
|
+
const LEADER = ALPHABET.charAt(0);
|
|
25
|
+
const LEADER_CODE = ALPHABET.charCodeAt(0);
|
|
26
|
+
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
27
|
+
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
28
|
+
// Optimization: If BASE is a power of 2, we can use bitwise operations
|
|
29
|
+
// This is much faster than the generic algorithm (approx 10x-20x)
|
|
30
|
+
const isPowerOfTwo = (BASE & (BASE - 1)) === 0;
|
|
31
|
+
if (isPowerOfTwo) {
|
|
32
|
+
const k = Math.log2(BASE);
|
|
33
|
+
const mask = (1 << k) - 1;
|
|
34
|
+
if (options.rfc4648) {
|
|
35
|
+
// RFC 4648 Mode
|
|
36
|
+
const encode = (source) => {
|
|
37
|
+
if (source instanceof Uint8Array) ;
|
|
38
|
+
else if (ArrayBuffer.isView(source)) {
|
|
39
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
40
|
+
}
|
|
41
|
+
else if (Array.isArray(source)) {
|
|
42
|
+
source = Uint8Array.from(source);
|
|
43
|
+
}
|
|
44
|
+
if (!(source instanceof Uint8Array)) {
|
|
45
|
+
throw new TypeError("Expected Uint8Array");
|
|
46
|
+
}
|
|
47
|
+
if (source.length === 0) {
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
let str = "";
|
|
51
|
+
let currentValue = 0;
|
|
52
|
+
let currentBits = 0;
|
|
53
|
+
for (let i = 0; i < source.length; i++) {
|
|
54
|
+
currentValue = (currentValue << 8) | source[i];
|
|
55
|
+
currentBits += 8;
|
|
56
|
+
while (currentBits >= k) {
|
|
57
|
+
currentBits -= k;
|
|
58
|
+
str += ALPHABET.charAt((currentValue >>> currentBits) & mask);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Leftover bits (padding logic for the last character)
|
|
62
|
+
if (currentBits > 0) {
|
|
63
|
+
str += ALPHABET.charAt((currentValue << (k - currentBits)) & mask);
|
|
64
|
+
}
|
|
65
|
+
// Add padding chars '=' if required
|
|
66
|
+
while ((str.length * k) % 8 !== 0) {
|
|
67
|
+
str += "=";
|
|
68
|
+
}
|
|
69
|
+
return str;
|
|
70
|
+
};
|
|
71
|
+
const decodeUnsafe = (source) => {
|
|
72
|
+
if (typeof source !== "string") {
|
|
73
|
+
throw new TypeError("Expected String");
|
|
74
|
+
}
|
|
75
|
+
if (source.length === 0) {
|
|
76
|
+
return new Uint8Array();
|
|
77
|
+
}
|
|
78
|
+
// Strip padding
|
|
79
|
+
let end = source.length;
|
|
80
|
+
while (end > 0 && source[end - 1] === "=") {
|
|
81
|
+
end--;
|
|
82
|
+
}
|
|
83
|
+
source = source.substring(0, end);
|
|
84
|
+
let currentValue = 0;
|
|
85
|
+
let currentBits = 0;
|
|
86
|
+
// Estimate size: source.length * k / 8
|
|
87
|
+
const buffer = new Uint8Array((source.length * k) >>> 3);
|
|
88
|
+
let ptr = 0;
|
|
89
|
+
for (let i = 0; i < source.length; i++) {
|
|
90
|
+
const char = source.charCodeAt(i);
|
|
91
|
+
const val = BASE_MAP[char];
|
|
92
|
+
if (val === 255)
|
|
93
|
+
return undefined;
|
|
94
|
+
currentValue = (currentValue << k) | val;
|
|
95
|
+
currentBits += k;
|
|
96
|
+
if (currentBits >= 8) {
|
|
97
|
+
currentBits -= 8;
|
|
98
|
+
buffer[ptr++] = (currentValue >>> currentBits) & 0xff;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return buffer;
|
|
102
|
+
};
|
|
103
|
+
const decode = (string) => {
|
|
104
|
+
const buffer = decodeUnsafe(string);
|
|
105
|
+
if (buffer)
|
|
106
|
+
return buffer;
|
|
107
|
+
throw new Error("Non-base" + BASE + " character");
|
|
108
|
+
};
|
|
109
|
+
return { encode, decodeUnsafe, decode };
|
|
110
|
+
}
|
|
111
|
+
// Standard Mode (Bitwise)
|
|
112
|
+
const encode = (source) => {
|
|
113
|
+
if (source instanceof Uint8Array) ;
|
|
114
|
+
else if (ArrayBuffer.isView(source)) {
|
|
115
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
116
|
+
}
|
|
117
|
+
else if (Array.isArray(source)) {
|
|
118
|
+
source = Uint8Array.from(source);
|
|
119
|
+
}
|
|
120
|
+
if (!(source instanceof Uint8Array)) {
|
|
121
|
+
throw new TypeError("Expected Uint8Array");
|
|
122
|
+
}
|
|
123
|
+
if (source.length === 0) {
|
|
124
|
+
return "";
|
|
125
|
+
}
|
|
126
|
+
let zeroes = 0;
|
|
127
|
+
let pbegin = 0;
|
|
128
|
+
const pend = source.length;
|
|
129
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
130
|
+
pbegin++;
|
|
131
|
+
zeroes++;
|
|
132
|
+
}
|
|
133
|
+
let str = LEADER.repeat(zeroes);
|
|
134
|
+
if (pbegin === pend)
|
|
135
|
+
return str;
|
|
136
|
+
// Bitwise conversion
|
|
137
|
+
let currentValue = 0;
|
|
138
|
+
let currentBits = 0;
|
|
139
|
+
const totalBits = (pend - pbegin) * 8;
|
|
140
|
+
let remainder = totalBits % k;
|
|
141
|
+
// Handling the initial alignment to the most significant bits
|
|
142
|
+
// If total bits isn't divisible by k, the first digit uses 'remainder' bits
|
|
143
|
+
if (remainder === 0)
|
|
144
|
+
remainder = k; // effectively divisible, treating first k bits normally
|
|
145
|
+
let seenNonZero = false;
|
|
146
|
+
let firstChunk = true;
|
|
147
|
+
for (let i = pbegin; i < pend; i++) {
|
|
148
|
+
currentValue = (currentValue << 8) | source[i];
|
|
149
|
+
currentBits += 8;
|
|
150
|
+
while (currentBits >= k || (firstChunk && currentBits >= remainder)) {
|
|
151
|
+
let bitsToExtract = k;
|
|
152
|
+
if (firstChunk) {
|
|
153
|
+
if (totalBits % k !== 0) {
|
|
154
|
+
bitsToExtract = totalBits % k;
|
|
155
|
+
}
|
|
156
|
+
firstChunk = false;
|
|
157
|
+
}
|
|
158
|
+
const shift = currentBits - bitsToExtract;
|
|
159
|
+
const digit = (currentValue >>> shift) & ((1 << bitsToExtract) - 1);
|
|
160
|
+
currentBits -= bitsToExtract;
|
|
161
|
+
if (seenNonZero || digit !== 0) {
|
|
162
|
+
str += ALPHABET.charAt(digit);
|
|
163
|
+
seenNonZero = true;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return str;
|
|
168
|
+
};
|
|
169
|
+
const decodeUnsafe = (source) => {
|
|
170
|
+
if (typeof source !== "string") {
|
|
171
|
+
throw new TypeError("Expected String");
|
|
172
|
+
}
|
|
173
|
+
if (source.length === 0) {
|
|
174
|
+
return new Uint8Array();
|
|
175
|
+
}
|
|
176
|
+
let psz = 0;
|
|
177
|
+
let zeroes = 0;
|
|
178
|
+
while (source.charCodeAt(psz) === LEADER_CODE) {
|
|
179
|
+
zeroes++;
|
|
180
|
+
psz++;
|
|
181
|
+
}
|
|
182
|
+
// Accumulate bits
|
|
183
|
+
// We must handle alignment.
|
|
184
|
+
const length = source.length - psz;
|
|
185
|
+
const totalBits = length * k;
|
|
186
|
+
let currentBits = (8 - (totalBits % 8)) % 8; // align to byte boundary
|
|
187
|
+
const result = new Uint8Array((totalBits + 7) >>> 3); // (totalBits + 7) / 8
|
|
188
|
+
let rIdx = 0;
|
|
189
|
+
let currentValue = 0;
|
|
190
|
+
for (let i = psz; i < source.length; i++) {
|
|
191
|
+
const char = source.charCodeAt(i);
|
|
192
|
+
const val = BASE_MAP[char];
|
|
193
|
+
if (val === 255)
|
|
194
|
+
return;
|
|
195
|
+
currentValue = (currentValue << k) | val;
|
|
196
|
+
currentBits += k;
|
|
197
|
+
if (currentBits >= 8) {
|
|
198
|
+
const shift = currentBits - 8;
|
|
199
|
+
result[rIdx++] = (currentValue >>> shift) & 0xff;
|
|
200
|
+
currentBits -= 8;
|
|
201
|
+
// Keep only the remaining bits to avoid overflow
|
|
202
|
+
currentValue &= (1 << currentBits) - 1;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Skip leading zeroes in result buffer
|
|
206
|
+
let skip = 0;
|
|
207
|
+
while (skip < rIdx && result[skip] === 0) {
|
|
208
|
+
skip++;
|
|
209
|
+
}
|
|
210
|
+
// Combine with zeroes
|
|
211
|
+
const final = new Uint8Array(zeroes + (rIdx - skip));
|
|
212
|
+
// zeroes are 0, so just copy result
|
|
213
|
+
final.set(result.subarray(skip, rIdx), zeroes);
|
|
214
|
+
return final;
|
|
215
|
+
};
|
|
216
|
+
const decode = (string) => {
|
|
217
|
+
const buffer = decodeUnsafe(string);
|
|
218
|
+
if (buffer)
|
|
219
|
+
return buffer;
|
|
220
|
+
throw new Error("Non-base" + BASE + " character");
|
|
221
|
+
};
|
|
222
|
+
return { encode, decodeUnsafe, decode };
|
|
223
|
+
}
|
|
224
|
+
const encode = (source) => {
|
|
225
|
+
if (source instanceof Uint8Array) ;
|
|
226
|
+
else if (ArrayBuffer.isView(source)) {
|
|
227
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
228
|
+
}
|
|
229
|
+
else if (Array.isArray(source)) {
|
|
230
|
+
source = Uint8Array.from(source);
|
|
231
|
+
}
|
|
232
|
+
if (!(source instanceof Uint8Array)) {
|
|
233
|
+
throw new TypeError("Expected Uint8Array");
|
|
234
|
+
}
|
|
235
|
+
if (source.length === 0) {
|
|
236
|
+
return "";
|
|
237
|
+
}
|
|
238
|
+
// Skip & count leading zeroes.
|
|
239
|
+
let zeroes = 0;
|
|
240
|
+
let length = 0;
|
|
241
|
+
let pbegin = 0;
|
|
242
|
+
const pend = source.length;
|
|
243
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
244
|
+
pbegin++;
|
|
245
|
+
zeroes++;
|
|
246
|
+
}
|
|
247
|
+
// Allocate enough space in big-endian base58 representation.
|
|
248
|
+
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
249
|
+
const b58 = new Uint8Array(size);
|
|
250
|
+
// Process the bytes.
|
|
251
|
+
while (pbegin !== pend) {
|
|
252
|
+
let carry = source[pbegin];
|
|
253
|
+
// Apply "b58 = b58 * 256 + ch".
|
|
254
|
+
let i = 0;
|
|
255
|
+
for (let it1 = size - 1; (carry !== 0 || i < length) && it1 !== -1; it1--, i++) {
|
|
256
|
+
carry += (b58[it1] << 8) >>> 0;
|
|
257
|
+
b58[it1] = (carry % BASE) >>> 0;
|
|
258
|
+
carry = (carry / BASE) >>> 0;
|
|
259
|
+
}
|
|
260
|
+
if (carry !== 0) {
|
|
261
|
+
throw new Error("Non-zero carry");
|
|
262
|
+
}
|
|
263
|
+
length = i;
|
|
264
|
+
pbegin++;
|
|
265
|
+
}
|
|
266
|
+
// Skip leading zeroes in base58 result.
|
|
267
|
+
let it2 = size - length;
|
|
268
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
269
|
+
it2++;
|
|
270
|
+
}
|
|
271
|
+
// Translate the result into a string.
|
|
272
|
+
let str = LEADER.repeat(zeroes);
|
|
273
|
+
for (; it2 < size; ++it2) {
|
|
274
|
+
str += ALPHABET.charAt(b58[it2]);
|
|
275
|
+
}
|
|
276
|
+
return str;
|
|
277
|
+
};
|
|
278
|
+
const decodeUnsafe = (source) => {
|
|
279
|
+
if (typeof source !== "string") {
|
|
280
|
+
throw new TypeError("Expected String");
|
|
281
|
+
}
|
|
282
|
+
if (source.length === 0) {
|
|
283
|
+
return new Uint8Array();
|
|
284
|
+
}
|
|
285
|
+
let psz = 0;
|
|
286
|
+
// Skip and count leading '1's.
|
|
287
|
+
let zeroes = 0;
|
|
288
|
+
let length = 0;
|
|
289
|
+
while (source.charCodeAt(psz) === LEADER_CODE) {
|
|
290
|
+
zeroes++;
|
|
291
|
+
psz++;
|
|
292
|
+
}
|
|
293
|
+
// Allocate enough space in big-endian base256 representation.
|
|
294
|
+
const size = ((source.length - psz) * FACTOR + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
295
|
+
let b256 = new Uint8Array(size);
|
|
296
|
+
// Process the characters.
|
|
297
|
+
for (; psz < source.length; psz++) {
|
|
298
|
+
// Decode character
|
|
299
|
+
let carry = BASE_MAP[source.charCodeAt(psz)];
|
|
300
|
+
// Invalid character
|
|
301
|
+
if (carry === 255) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
let i = 0;
|
|
305
|
+
for (let it3 = size - 1; (carry !== 0 || i < length) && it3 !== -1; it3--, i++) {
|
|
306
|
+
carry += (BASE * b256[it3]) >>> 0;
|
|
307
|
+
b256[it3] = (carry & 0xff) >>> 0;
|
|
308
|
+
carry = (carry >> 8) >>> 0;
|
|
309
|
+
}
|
|
310
|
+
if (carry !== 0) {
|
|
311
|
+
throw new Error("Non-zero carry");
|
|
312
|
+
}
|
|
313
|
+
length = i;
|
|
314
|
+
}
|
|
315
|
+
// Skip leading zeroes in b256.
|
|
316
|
+
let it4 = size - length;
|
|
317
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
318
|
+
it4++;
|
|
319
|
+
}
|
|
320
|
+
let vch = new Uint8Array(zeroes + (size - it4));
|
|
321
|
+
let j = zeroes;
|
|
322
|
+
while (it4 !== size) {
|
|
323
|
+
vch[j++] = b256[it4++];
|
|
324
|
+
}
|
|
325
|
+
return vch;
|
|
326
|
+
};
|
|
327
|
+
const decode = (string) => {
|
|
328
|
+
const buffer = decodeUnsafe(string);
|
|
329
|
+
if (buffer) {
|
|
330
|
+
return buffer;
|
|
331
|
+
}
|
|
332
|
+
throw new Error("Non-base" + BASE + " character");
|
|
333
|
+
};
|
|
334
|
+
return {
|
|
335
|
+
encode,
|
|
336
|
+
decodeUnsafe,
|
|
337
|
+
decode,
|
|
338
|
+
};
|
|
142
339
|
};
|
|
143
340
|
|
|
144
341
|
const ALPHABET$3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
@@ -325,7 +522,7 @@ var index$3 = (input, prefix) => {
|
|
|
325
522
|
return typedArray;
|
|
326
523
|
};
|
|
327
524
|
|
|
328
|
-
/*! pako 2.
|
|
525
|
+
/*! pako 2.2.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */
|
|
329
526
|
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
|
|
330
527
|
// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
|
|
331
528
|
//
|
|
@@ -1747,7 +1944,7 @@ const { _tr_init, _tr_stored_block, _tr_flush_block, _tr_tally, _tr_align } = tr
|
|
|
1747
1944
|
|
|
1748
1945
|
const {
|
|
1749
1946
|
Z_NO_FLUSH: Z_NO_FLUSH$2, Z_PARTIAL_FLUSH, Z_FULL_FLUSH: Z_FULL_FLUSH$1, Z_FINISH: Z_FINISH$3, Z_BLOCK: Z_BLOCK$1,
|
|
1750
|
-
Z_OK: Z_OK$3, Z_STREAM_END: Z_STREAM_END$3, Z_STREAM_ERROR: Z_STREAM_ERROR$2, Z_DATA_ERROR: Z_DATA_ERROR$2, Z_BUF_ERROR: Z_BUF_ERROR$
|
|
1947
|
+
Z_OK: Z_OK$3, Z_STREAM_END: Z_STREAM_END$3, Z_STREAM_ERROR: Z_STREAM_ERROR$2, Z_DATA_ERROR: Z_DATA_ERROR$2, Z_BUF_ERROR: Z_BUF_ERROR$2,
|
|
1751
1948
|
Z_DEFAULT_COMPRESSION: Z_DEFAULT_COMPRESSION$1,
|
|
1752
1949
|
Z_FILTERED, Z_HUFFMAN_ONLY, Z_RLE, Z_FIXED, Z_DEFAULT_STRATEGY: Z_DEFAULT_STRATEGY$1,
|
|
1753
1950
|
Z_UNKNOWN,
|
|
@@ -1846,11 +2043,35 @@ const slide_hash = (s) => {
|
|
|
1846
2043
|
};
|
|
1847
2044
|
|
|
1848
2045
|
/* eslint-disable new-cap */
|
|
1849
|
-
let
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
2046
|
+
let HASH = (s, prev, data) => ((prev << s.hash_shift) ^ data) & s.hash_mask;
|
|
2047
|
+
|
|
2048
|
+
|
|
2049
|
+
/* ===========================================================================
|
|
2050
|
+
* Insert string str in the dictionary and set match_head to the previous head
|
|
2051
|
+
* of the hash chain (the most recent string with same hash key). Return
|
|
2052
|
+
* the previous length of the hash chain.
|
|
2053
|
+
* IN assertion: all calls to INSERT_STRING are made with consecutive input
|
|
2054
|
+
* characters and the first MIN_MATCH bytes of str are valid (except for
|
|
2055
|
+
* the last MIN_MATCH-1 bytes of the input file).
|
|
2056
|
+
*/
|
|
2057
|
+
const INSERT_STRING = (s, str) => {
|
|
2058
|
+
let h;
|
|
2059
|
+
if (s.legacy_hash) {
|
|
2060
|
+
/* UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]); */
|
|
2061
|
+
h = s.ins_h = HASH(s, s.ins_h, s.window[str + MIN_MATCH - 1]);
|
|
2062
|
+
} else {
|
|
2063
|
+
// ANZAC++ hash: reads 4 bytes, matches node.js zlib output (legacyHash
|
|
2064
|
+
// restores classic zlib hash). Faster, with fewer collisions.
|
|
2065
|
+
const w = s.window;
|
|
2066
|
+
// Read 4 bytes little-endian. Math.imul reproduces C uint32 overflow in
|
|
2067
|
+
// `(value * 66521 + 66521) >> 16` exactly.
|
|
2068
|
+
const value = w[str] | (w[str + 1] << 8) | (w[str + 2] << 16) | (w[str + 3] << 24);
|
|
2069
|
+
h = s.ins_h = ((Math.imul(value, 66521) + 66521) >>> 16) & s.hash_mask;
|
|
2070
|
+
}
|
|
2071
|
+
const hash_head = s.prev[str & s.w_mask] = s.head[h];
|
|
2072
|
+
s.head[h] = str;
|
|
2073
|
+
return hash_head;
|
|
2074
|
+
};
|
|
1854
2075
|
|
|
1855
2076
|
|
|
1856
2077
|
/* =========================================================================
|
|
@@ -2124,7 +2345,20 @@ const fill_window = (s) => {
|
|
|
2124
2345
|
s.lookahead += n;
|
|
2125
2346
|
|
|
2126
2347
|
/* Initialize the hash value now that we have some input: */
|
|
2127
|
-
if (s.
|
|
2348
|
+
if (!s.legacy_hash) {
|
|
2349
|
+
/* The 4-byte hash reads one extra byte, so it needs one more available. */
|
|
2350
|
+
if (s.lookahead + s.insert > MIN_MATCH) {
|
|
2351
|
+
str = s.strstart - s.insert;
|
|
2352
|
+
while (s.insert) {
|
|
2353
|
+
INSERT_STRING(s, str);
|
|
2354
|
+
str++;
|
|
2355
|
+
s.insert--;
|
|
2356
|
+
if (s.lookahead + s.insert <= MIN_MATCH) {
|
|
2357
|
+
break;
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
} else if (s.lookahead + s.insert >= MIN_MATCH) {
|
|
2128
2362
|
str = s.strstart - s.insert;
|
|
2129
2363
|
s.ins_h = s.window[str];
|
|
2130
2364
|
|
|
@@ -2134,11 +2368,7 @@ const fill_window = (s) => {
|
|
|
2134
2368
|
// Call update_hash() MIN_MATCH-3 more times
|
|
2135
2369
|
//#endif
|
|
2136
2370
|
while (s.insert) {
|
|
2137
|
-
|
|
2138
|
-
s.ins_h = HASH(s, s.ins_h, s.window[str + MIN_MATCH - 1]);
|
|
2139
|
-
|
|
2140
|
-
s.prev[str & s.w_mask] = s.head[s.ins_h];
|
|
2141
|
-
s.head[s.ins_h] = str;
|
|
2371
|
+
INSERT_STRING(s, str);
|
|
2142
2372
|
str++;
|
|
2143
2373
|
s.insert--;
|
|
2144
2374
|
if (s.lookahead + s.insert < MIN_MATCH) {
|
|
@@ -2436,11 +2666,7 @@ const deflate_fast = (s, flush) => {
|
|
|
2436
2666
|
*/
|
|
2437
2667
|
hash_head = 0/*NIL*/;
|
|
2438
2668
|
if (s.lookahead >= MIN_MATCH) {
|
|
2439
|
-
|
|
2440
|
-
s.ins_h = HASH(s, s.ins_h, s.window[s.strstart + MIN_MATCH - 1]);
|
|
2441
|
-
hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
|
|
2442
|
-
s.head[s.ins_h] = s.strstart;
|
|
2443
|
-
/***/
|
|
2669
|
+
hash_head = INSERT_STRING(s, s.strstart);
|
|
2444
2670
|
}
|
|
2445
2671
|
|
|
2446
2672
|
/* Find the longest match, discarding those <= prev_length.
|
|
@@ -2470,11 +2696,7 @@ const deflate_fast = (s, flush) => {
|
|
|
2470
2696
|
s.match_length--; /* string at strstart already in table */
|
|
2471
2697
|
do {
|
|
2472
2698
|
s.strstart++;
|
|
2473
|
-
|
|
2474
|
-
s.ins_h = HASH(s, s.ins_h, s.window[s.strstart + MIN_MATCH - 1]);
|
|
2475
|
-
hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
|
|
2476
|
-
s.head[s.ins_h] = s.strstart;
|
|
2477
|
-
/***/
|
|
2699
|
+
hash_head = INSERT_STRING(s, s.strstart);
|
|
2478
2700
|
/* strstart never exceeds WSIZE-MAX_MATCH, so there are
|
|
2479
2701
|
* always MIN_MATCH bytes ahead.
|
|
2480
2702
|
*/
|
|
@@ -2484,16 +2706,18 @@ const deflate_fast = (s, flush) => {
|
|
|
2484
2706
|
{
|
|
2485
2707
|
s.strstart += s.match_length;
|
|
2486
2708
|
s.match_length = 0;
|
|
2487
|
-
s.
|
|
2488
|
-
|
|
2489
|
-
|
|
2709
|
+
if (s.legacy_hash) {
|
|
2710
|
+
s.ins_h = s.window[s.strstart];
|
|
2711
|
+
/* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */
|
|
2712
|
+
s.ins_h = HASH(s, s.ins_h, s.window[s.strstart + 1]);
|
|
2490
2713
|
|
|
2491
2714
|
//#if MIN_MATCH != 3
|
|
2492
2715
|
// Call UPDATE_HASH() MIN_MATCH-3 more times
|
|
2493
2716
|
//#endif
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2717
|
+
/* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
|
|
2718
|
+
* matter since it will be recomputed at next deflate call.
|
|
2719
|
+
*/
|
|
2720
|
+
}
|
|
2497
2721
|
}
|
|
2498
2722
|
} else {
|
|
2499
2723
|
/* No match, output a literal byte */
|
|
@@ -2566,11 +2790,7 @@ const deflate_slow = (s, flush) => {
|
|
|
2566
2790
|
*/
|
|
2567
2791
|
hash_head = 0/*NIL*/;
|
|
2568
2792
|
if (s.lookahead >= MIN_MATCH) {
|
|
2569
|
-
|
|
2570
|
-
s.ins_h = HASH(s, s.ins_h, s.window[s.strstart + MIN_MATCH - 1]);
|
|
2571
|
-
hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
|
|
2572
|
-
s.head[s.ins_h] = s.strstart;
|
|
2573
|
-
/***/
|
|
2793
|
+
hash_head = INSERT_STRING(s, s.strstart);
|
|
2574
2794
|
}
|
|
2575
2795
|
|
|
2576
2796
|
/* Find the longest match, discarding those <= prev_length.
|
|
@@ -2618,11 +2838,7 @@ const deflate_slow = (s, flush) => {
|
|
|
2618
2838
|
s.prev_length -= 2;
|
|
2619
2839
|
do {
|
|
2620
2840
|
if (++s.strstart <= max_insert) {
|
|
2621
|
-
|
|
2622
|
-
s.ins_h = HASH(s, s.ins_h, s.window[s.strstart + MIN_MATCH - 1]);
|
|
2623
|
-
hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
|
|
2624
|
-
s.head[s.ins_h] = s.strstart;
|
|
2625
|
-
/***/
|
|
2841
|
+
hash_head = INSERT_STRING(s, s.strstart);
|
|
2626
2842
|
}
|
|
2627
2843
|
} while (--s.prev_length !== 0);
|
|
2628
2844
|
s.match_available = 0;
|
|
@@ -2947,6 +3163,7 @@ function DeflateState() {
|
|
|
2947
3163
|
this.head = null; /* Heads of the hash chains or NIL. */
|
|
2948
3164
|
|
|
2949
3165
|
this.ins_h = 0; /* hash index of string to be inserted */
|
|
3166
|
+
this.legacy_hash = 0; /* use classic zlib hash instead of default ANZAC++ */
|
|
2950
3167
|
this.hash_size = 0; /* number of elements in hash table */
|
|
2951
3168
|
this.hash_bits = 0; /* log2(hash_size) */
|
|
2952
3169
|
this.hash_mask = 0; /* hash_size-1 */
|
|
@@ -3169,7 +3386,7 @@ const deflateSetHeader = (strm, head) => {
|
|
|
3169
3386
|
};
|
|
3170
3387
|
|
|
3171
3388
|
|
|
3172
|
-
const deflateInit2 = (strm, level, method, windowBits, memLevel, strategy) => {
|
|
3389
|
+
const deflateInit2 = (strm, level, method, windowBits, memLevel, strategy, legacyHash) => {
|
|
3173
3390
|
|
|
3174
3391
|
if (!strm) { // === Z_NULL
|
|
3175
3392
|
return Z_STREAM_ERROR$2;
|
|
@@ -3215,7 +3432,13 @@ const deflateInit2 = (strm, level, method, windowBits, memLevel, strategy) => {
|
|
|
3215
3432
|
s.w_size = 1 << s.w_bits;
|
|
3216
3433
|
s.w_mask = s.w_size - 1;
|
|
3217
3434
|
|
|
3435
|
+
s.legacy_hash = legacyHash ? 1 : 0;
|
|
3436
|
+
|
|
3218
3437
|
s.hash_bits = memLevel + 7;
|
|
3438
|
+
/* ANZAC++ hash needs >= 15 hash bits to span its 4 read bytes. */
|
|
3439
|
+
if (!s.legacy_hash && s.hash_bits < 15) {
|
|
3440
|
+
s.hash_bits = 15;
|
|
3441
|
+
}
|
|
3219
3442
|
s.hash_size = 1 << s.hash_bits;
|
|
3220
3443
|
s.hash_mask = s.hash_size - 1;
|
|
3221
3444
|
s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH);
|
|
@@ -3307,7 +3530,7 @@ const deflate$2 = (strm, flush) => {
|
|
|
3307
3530
|
if (!strm.output ||
|
|
3308
3531
|
(strm.avail_in !== 0 && !strm.input) ||
|
|
3309
3532
|
(s.status === FINISH_STATE && flush !== Z_FINISH$3)) {
|
|
3310
|
-
return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR$
|
|
3533
|
+
return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR$2 : Z_STREAM_ERROR$2);
|
|
3311
3534
|
}
|
|
3312
3535
|
|
|
3313
3536
|
const old_flush = s.last_flush;
|
|
@@ -3333,12 +3556,12 @@ const deflate$2 = (strm, flush) => {
|
|
|
3333
3556
|
*/
|
|
3334
3557
|
} else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) &&
|
|
3335
3558
|
flush !== Z_FINISH$3) {
|
|
3336
|
-
return err(strm, Z_BUF_ERROR$
|
|
3559
|
+
return err(strm, Z_BUF_ERROR$2);
|
|
3337
3560
|
}
|
|
3338
3561
|
|
|
3339
3562
|
/* User must not provide more input after the first FINISH: */
|
|
3340
3563
|
if (s.status === FINISH_STATE && strm.avail_in !== 0) {
|
|
3341
|
-
return err(strm, Z_BUF_ERROR$
|
|
3564
|
+
return err(strm, Z_BUF_ERROR$2);
|
|
3342
3565
|
}
|
|
3343
3566
|
|
|
3344
3567
|
/* Write the header */
|
|
@@ -3719,12 +3942,7 @@ const deflateSetDictionary = (strm, dictionary) => {
|
|
|
3719
3942
|
let str = s.strstart;
|
|
3720
3943
|
let n = s.lookahead - (MIN_MATCH - 1);
|
|
3721
3944
|
do {
|
|
3722
|
-
|
|
3723
|
-
s.ins_h = HASH(s, s.ins_h, s.window[str + MIN_MATCH - 1]);
|
|
3724
|
-
|
|
3725
|
-
s.prev[str & s.w_mask] = s.head[s.ins_h];
|
|
3726
|
-
|
|
3727
|
-
s.head[s.ins_h] = str;
|
|
3945
|
+
INSERT_STRING(s, str);
|
|
3728
3946
|
str++;
|
|
3729
3947
|
} while (--n);
|
|
3730
3948
|
s.strstart = str;
|
|
@@ -3848,7 +4066,7 @@ const _utf8len = new Uint8Array(256);
|
|
|
3848
4066
|
for (let q = 0; q < 256; q++) {
|
|
3849
4067
|
_utf8len[q] = (q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1);
|
|
3850
4068
|
}
|
|
3851
|
-
_utf8len[254] = _utf8len[
|
|
4069
|
+
_utf8len[254] = _utf8len[255] = 1; // Invalid sequence start
|
|
3852
4070
|
|
|
3853
4071
|
|
|
3854
4072
|
// convert string to array (typed, when possible)
|
|
@@ -4069,6 +4287,15 @@ const {
|
|
|
4069
4287
|
|
|
4070
4288
|
/* ===========================================================================*/
|
|
4071
4289
|
|
|
4290
|
+
const defaultOptions$1 = {
|
|
4291
|
+
level: Z_DEFAULT_COMPRESSION,
|
|
4292
|
+
method: Z_DEFLATED$1,
|
|
4293
|
+
chunkSize: 16384,
|
|
4294
|
+
windowBits: 15,
|
|
4295
|
+
memLevel: 8,
|
|
4296
|
+
strategy: Z_DEFAULT_STRATEGY,
|
|
4297
|
+
legacyHash: true
|
|
4298
|
+
};
|
|
4072
4299
|
|
|
4073
4300
|
/**
|
|
4074
4301
|
* class Deflate
|
|
@@ -4124,6 +4351,10 @@ const {
|
|
|
4124
4351
|
* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
|
|
4125
4352
|
* for more information on these.
|
|
4126
4353
|
*
|
|
4354
|
+
* - `legacyHash` (Boolean) - use the classic zlib hash (default), which matches
|
|
4355
|
+
* canonical zlib output byte-for-byte. Set to `false` to use the faster
|
|
4356
|
+
* ANZAC++ hash, which matches recent (chromium) node.js output instead.
|
|
4357
|
+
*
|
|
4127
4358
|
* Additional options, for internal needs:
|
|
4128
4359
|
*
|
|
4129
4360
|
* - `chunkSize` - size of generated data chunks (16K by default)
|
|
@@ -4156,14 +4387,7 @@ const {
|
|
|
4156
4387
|
* ```
|
|
4157
4388
|
**/
|
|
4158
4389
|
function Deflate$1(options) {
|
|
4159
|
-
this.options = common.assign({
|
|
4160
|
-
level: Z_DEFAULT_COMPRESSION,
|
|
4161
|
-
method: Z_DEFLATED$1,
|
|
4162
|
-
chunkSize: 16384,
|
|
4163
|
-
windowBits: 15,
|
|
4164
|
-
memLevel: 8,
|
|
4165
|
-
strategy: Z_DEFAULT_STRATEGY
|
|
4166
|
-
}, options || {});
|
|
4390
|
+
this.options = common.assign({}, defaultOptions$1, options || {});
|
|
4167
4391
|
|
|
4168
4392
|
let opt = this.options;
|
|
4169
4393
|
|
|
@@ -4189,7 +4413,8 @@ function Deflate$1(options) {
|
|
|
4189
4413
|
opt.method,
|
|
4190
4414
|
opt.windowBits,
|
|
4191
4415
|
opt.memLevel,
|
|
4192
|
-
opt.strategy
|
|
4416
|
+
opt.strategy,
|
|
4417
|
+
opt.legacyHash
|
|
4193
4418
|
);
|
|
4194
4419
|
|
|
4195
4420
|
if (status !== Z_OK$2) {
|
|
@@ -4809,7 +5034,7 @@ const lbase = new Uint16Array([ /* Length codes 257..285 base */
|
|
|
4809
5034
|
|
|
4810
5035
|
const lext = new Uint8Array([ /* Length codes 257..285 extra */
|
|
4811
5036
|
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
|
|
4812
|
-
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16,
|
|
5037
|
+
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 199, 75
|
|
4813
5038
|
]);
|
|
4814
5039
|
|
|
4815
5040
|
const dbase = new Uint16Array([ /* Distance codes 0..29 base */
|
|
@@ -5146,7 +5371,7 @@ const DISTS = 2;
|
|
|
5146
5371
|
|
|
5147
5372
|
const {
|
|
5148
5373
|
Z_FINISH: Z_FINISH$1, Z_BLOCK, Z_TREES,
|
|
5149
|
-
Z_OK: Z_OK$1, Z_STREAM_END: Z_STREAM_END$1, Z_NEED_DICT: Z_NEED_DICT$1, Z_STREAM_ERROR: Z_STREAM_ERROR$1, Z_DATA_ERROR: Z_DATA_ERROR$1, Z_MEM_ERROR: Z_MEM_ERROR$1, Z_BUF_ERROR,
|
|
5374
|
+
Z_OK: Z_OK$1, Z_STREAM_END: Z_STREAM_END$1, Z_NEED_DICT: Z_NEED_DICT$1, Z_STREAM_ERROR: Z_STREAM_ERROR$1, Z_DATA_ERROR: Z_DATA_ERROR$1, Z_MEM_ERROR: Z_MEM_ERROR$1, Z_BUF_ERROR: Z_BUF_ERROR$1,
|
|
5150
5375
|
Z_DEFLATED
|
|
5151
5376
|
} = constants$2;
|
|
5152
5377
|
|
|
@@ -5456,11 +5681,14 @@ const updatewindow = (strm, src, end, copy) => {
|
|
|
5456
5681
|
|
|
5457
5682
|
/* if it hasn't been done already, allocate space for the window */
|
|
5458
5683
|
if (state.window === null) {
|
|
5684
|
+
state.window = new Uint8Array(1 << state.wbits);
|
|
5685
|
+
}
|
|
5686
|
+
|
|
5687
|
+
/* if window not in use yet, initialize */
|
|
5688
|
+
if (state.wsize === 0) {
|
|
5459
5689
|
state.wsize = 1 << state.wbits;
|
|
5460
5690
|
state.wnext = 0;
|
|
5461
5691
|
state.whave = 0;
|
|
5462
|
-
|
|
5463
|
-
state.window = new Uint8Array(state.wsize);
|
|
5464
5692
|
}
|
|
5465
5693
|
|
|
5466
5694
|
/* copy state->wsize or less output bytes into the circular window */
|
|
@@ -6586,7 +6814,7 @@ const inflate$2 = (strm, flush) => {
|
|
|
6586
6814
|
(state.mode === TYPE ? 128 : 0) +
|
|
6587
6815
|
(state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);
|
|
6588
6816
|
if (((_in === 0 && _out === 0) || flush === Z_FINISH$1) && ret === Z_OK$1) {
|
|
6589
|
-
ret = Z_BUF_ERROR;
|
|
6817
|
+
ret = Z_BUF_ERROR$1;
|
|
6590
6818
|
}
|
|
6591
6819
|
return ret;
|
|
6592
6820
|
};
|
|
@@ -6758,11 +6986,16 @@ const toString$2 = Object.prototype.toString;
|
|
|
6758
6986
|
|
|
6759
6987
|
const {
|
|
6760
6988
|
Z_NO_FLUSH, Z_FINISH,
|
|
6761
|
-
Z_OK, Z_STREAM_END, Z_NEED_DICT, Z_STREAM_ERROR, Z_DATA_ERROR, Z_MEM_ERROR
|
|
6989
|
+
Z_OK, Z_STREAM_END, Z_NEED_DICT, Z_STREAM_ERROR, Z_DATA_ERROR, Z_MEM_ERROR, Z_BUF_ERROR
|
|
6762
6990
|
} = constants$2;
|
|
6763
6991
|
|
|
6764
6992
|
/* ===========================================================================*/
|
|
6765
6993
|
|
|
6994
|
+
const defaultOptions = {
|
|
6995
|
+
chunkSize: 1024 * 64,
|
|
6996
|
+
windowBits: 15,
|
|
6997
|
+
to: ''
|
|
6998
|
+
};
|
|
6766
6999
|
|
|
6767
7000
|
/**
|
|
6768
7001
|
* class Inflate
|
|
@@ -6842,11 +7075,7 @@ const {
|
|
|
6842
7075
|
* ```
|
|
6843
7076
|
**/
|
|
6844
7077
|
function Inflate$1(options) {
|
|
6845
|
-
this.options = common.assign({
|
|
6846
|
-
chunkSize: 1024 * 64,
|
|
6847
|
-
windowBits: 15,
|
|
6848
|
-
to: ''
|
|
6849
|
-
}, options || {});
|
|
7078
|
+
this.options = common.assign({}, defaultOptions, options || {});
|
|
6850
7079
|
|
|
6851
7080
|
const opt = this.options;
|
|
6852
7081
|
|
|
@@ -6977,11 +7206,19 @@ Inflate$1.prototype.push = function (data, flush_mode) {
|
|
|
6977
7206
|
}
|
|
6978
7207
|
}
|
|
6979
7208
|
|
|
6980
|
-
//
|
|
7209
|
+
// Only the gzip format defines concatenated members (RFC 1952: a gzip file
|
|
7210
|
+
// is "a series of members"). A zlib stream (RFC 1950) ends after its
|
|
7211
|
+
// ADLER32, and a raw DEFLATE stream (RFC 1951) ends after its final block -
|
|
7212
|
+
// neither format allows anything to follow, so bytes after the end are not
|
|
7213
|
+
// ours to interpret and must be left in the input. Restart decoding only
|
|
7214
|
+
// for a gzip member: `state.flags` is non-zero only once a gzip header has
|
|
7215
|
+
// actually been decoded (it stays 0 for a zlib member, even when the format
|
|
7216
|
+
// was auto-detected and the gzip bit of `wrap` is set). A trailing zero
|
|
7217
|
+
// byte is padding, not the start of a member (no member can begin with 0).
|
|
6981
7218
|
while (strm.avail_in > 0 &&
|
|
6982
7219
|
status === Z_STREAM_END &&
|
|
6983
|
-
strm.state.wrap
|
|
6984
|
-
|
|
7220
|
+
(strm.state.wrap & 2) && strm.state.flags !== 0 &&
|
|
7221
|
+
strm.input[strm.next_in] !== 0)
|
|
6985
7222
|
{
|
|
6986
7223
|
inflate_1$2.inflateReset(strm);
|
|
6987
7224
|
status = inflate_1$2.inflate(strm, _flush_mode);
|
|
@@ -7002,7 +7239,9 @@ Inflate$1.prototype.push = function (data, flush_mode) {
|
|
|
7002
7239
|
last_avail_out = strm.avail_out;
|
|
7003
7240
|
|
|
7004
7241
|
if (strm.next_out) {
|
|
7005
|
-
if
|
|
7242
|
+
// Flush output if buffer is full, stream ended, or an explicit flush was
|
|
7243
|
+
// requested (e.g. Z_SYNC_FLUSH) - to push out the tail, same as node's zlib.
|
|
7244
|
+
if (strm.avail_out === 0 || status === Z_STREAM_END || _flush_mode > 0) {
|
|
7006
7245
|
|
|
7007
7246
|
if (this.options.to === 'string') {
|
|
7008
7247
|
|
|
@@ -7020,12 +7259,22 @@ Inflate$1.prototype.push = function (data, flush_mode) {
|
|
|
7020
7259
|
|
|
7021
7260
|
} else {
|
|
7022
7261
|
this.onData(strm.output.length === strm.next_out ? strm.output : strm.output.subarray(0, strm.next_out));
|
|
7262
|
+
|
|
7263
|
+
// Force a fresh output buffer on next iteration / next push, so the
|
|
7264
|
+
// already emitted tail is not sent again.
|
|
7265
|
+
strm.avail_out = 0;
|
|
7266
|
+
strm.next_out = 0;
|
|
7023
7267
|
}
|
|
7024
7268
|
}
|
|
7025
7269
|
}
|
|
7026
7270
|
|
|
7027
|
-
//
|
|
7028
|
-
|
|
7271
|
+
// A full output buffer means there may be more to produce - allocate a new
|
|
7272
|
+
// one and call inflate again. The status depends on the flush mode: with
|
|
7273
|
+
// Z_NO_FLUSH a full buffer is reported as Z_OK, but with Z_FINISH the same
|
|
7274
|
+
// situation is reported as Z_BUF_ERROR ("could not make progress now",
|
|
7275
|
+
// non-fatal) even though output is still pending. Both must continue; the
|
|
7276
|
+
// distinction that matters is purely "was the output buffer exhausted".
|
|
7277
|
+
if ((status === Z_OK || status === Z_BUF_ERROR) && last_avail_out === 0) continue;
|
|
7029
7278
|
|
|
7030
7279
|
// Finalize if end of stream reached.
|
|
7031
7280
|
if (status === Z_STREAM_END) {
|
|
@@ -7035,7 +7284,23 @@ Inflate$1.prototype.push = function (data, flush_mode) {
|
|
|
7035
7284
|
return true;
|
|
7036
7285
|
}
|
|
7037
7286
|
|
|
7038
|
-
if (strm.avail_in === 0)
|
|
7287
|
+
if (strm.avail_in === 0) {
|
|
7288
|
+
// Input is exhausted. If the caller declared this the end of the stream
|
|
7289
|
+
// (Z_FINISH) but we never saw Z_STREAM_END, the compressed data ended
|
|
7290
|
+
// before its terminating marker - i.e. it is truncated/incomplete. That
|
|
7291
|
+
// is an error: returning the partial output as success would be
|
|
7292
|
+
// indistinguishable from a complete decode, hiding the data loss. Report
|
|
7293
|
+
// it via Z_BUF_ERROR. (Reached only when the output buffer still had room
|
|
7294
|
+
// - a full buffer is handled by the `continue` above - so this genuinely
|
|
7295
|
+
// means "ran out of input", not "ran out of output".)
|
|
7296
|
+
if (_flush_mode === Z_FINISH) {
|
|
7297
|
+
status = inflate_1$2.inflateEnd(this.strm);
|
|
7298
|
+
this.onEnd(status === Z_OK ? Z_BUF_ERROR : status);
|
|
7299
|
+
this.ended = true;
|
|
7300
|
+
return false;
|
|
7301
|
+
}
|
|
7302
|
+
break;
|
|
7303
|
+
}
|
|
7039
7304
|
}
|
|
7040
7305
|
|
|
7041
7306
|
return true;
|
|
@@ -7121,7 +7386,7 @@ Inflate$1.prototype.onEnd = function (status) {
|
|
|
7121
7386
|
function inflate$1(input, options) {
|
|
7122
7387
|
const inflator = new Inflate$1(options);
|
|
7123
7388
|
|
|
7124
|
-
inflator.push(input);
|
|
7389
|
+
inflator.push(input, true);
|
|
7125
7390
|
|
|
7126
7391
|
// That will never happens, if you don't cheat with options :)
|
|
7127
7392
|
if (inflator.err) throw inflator.msg || messages[inflator.err];
|
|
@@ -7271,10 +7536,14 @@ var index$2 = (typedArray, prefix) => {
|
|
|
7271
7536
|
};
|
|
7272
7537
|
|
|
7273
7538
|
const ALPHABET$1 = '0123456789ABCDEF';
|
|
7274
|
-
base(ALPHABET$1);
|
|
7539
|
+
const base16 = base(ALPHABET$1);
|
|
7540
|
+
base16.decode;
|
|
7541
|
+
base16.encode;
|
|
7275
7542
|
|
|
7276
7543
|
const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
7277
|
-
base(ALPHABET);
|
|
7544
|
+
const base64 = base(ALPHABET);
|
|
7545
|
+
base64.decode;
|
|
7546
|
+
base64.encode;
|
|
7278
7547
|
|
|
7279
7548
|
/**
|
|
7280
7549
|
* Returns a Uint8Array as String
|