@zip.js/zip.js 2.8.53 → 2.8.55
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/README.md +1 -1
- package/deno.json +2 -1
- package/dist/zip-core-external.js +737 -491
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +745 -490
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +776 -525
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +738 -510
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +776 -525
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +790 -525
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +791 -526
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +746 -491
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +746 -491
- package/dist/zip-native.min.js +1 -1
- package/dist/zip-web-worker-native.js +1 -1
- package/dist/zip-web-worker.js +1 -1
- package/dist/zip.js +747 -492
- package/dist/zip.min.js +1 -1
- package/eslint.config.mjs +1 -0
- package/index-native.cjs +790 -525
- package/index-native.min.js +1 -1
- package/index.cjs +791 -526
- package/index.d.cts +422 -49
- package/index.d.ts +422 -49
- package/index.min.js +1 -1
- package/lib/core/configuration.js +62 -21
- package/lib/core/constants.js +13 -1
- package/lib/core/io.js +33 -27
- package/lib/core/options.js +44 -2
- package/lib/core/streams/aes-crypto-stream.js +12 -12
- package/lib/core/util/decode-text.js +11 -2
- package/lib/core/web-worker-base.js +3 -2
- package/lib/core/web-worker-inline-native.js +1 -1
- package/lib/core/web-worker-inline-wasm.js +1 -1
- package/lib/core/zip-fs.js +39 -32
- package/lib/core/zip-reader.js +100 -38
- package/lib/core/zip-writer.js +301 -177
- package/lib/core/zlib-streams-inline.js +1 -1
- package/lib/zip-core-base.js +6 -1
- package/lib/zip-core-reader.js +1 -0
- package/lib/zip-core-writer.js +5 -0
- package/package.json +8 -2
package/dist/zip-core.js
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
|
|
46
46
|
const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
|
|
47
47
|
const SPLIT_ZIP_FILE_SIGNATURE = 0x08074b50;
|
|
48
|
+
const TEMPORARY_SPLIT_ZIP_FILE_SIGNATURE = 0x30304b50;
|
|
48
49
|
const DATA_DESCRIPTOR_RECORD_SIGNATURE = SPLIT_ZIP_FILE_SIGNATURE;
|
|
49
50
|
const ARCHIVE_EXTRA_DATA_SIGNATURE = 0x08064b50;
|
|
50
51
|
const DIGITAL_SIGNATURE_RECORD_SIGNATURE = 0x05054b50;
|
|
@@ -61,6 +62,7 @@
|
|
|
61
62
|
const DATA_DESCRIPTOR_RECORD_LENGTH = 12;
|
|
62
63
|
const DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH = 20;
|
|
63
64
|
const DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH = 4;
|
|
65
|
+
const SPLIT_ZIP_FILE_SIGNATURE_LENGTH = 4;
|
|
64
66
|
|
|
65
67
|
const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
|
|
66
68
|
const EXTRAFIELD_TYPE_AES = 0x9901;
|
|
@@ -83,6 +85,7 @@
|
|
|
83
85
|
const BITFLAG_DATA_DESCRIPTOR = 0b1000;
|
|
84
86
|
const BITFLAG_STRONG_ENCRYPTION = 0b1000000;
|
|
85
87
|
const BITFLAG_LANG_ENCODING_FLAG = 0b100000000000;
|
|
88
|
+
const BITFLAG_MASKED_LOCAL_HEADERS = 0b10000000000000;
|
|
86
89
|
const FILE_ATTR_MSDOS_DIR_MASK = 0b10000;
|
|
87
90
|
const FILE_ATTR_MSDOS_READONLY_MASK = 0x01;
|
|
88
91
|
const FILE_ATTR_MSDOS_HIDDEN_MASK = 0x02;
|
|
@@ -112,6 +115,8 @@
|
|
|
112
115
|
const HEADER_OFFSET_SIGNATURE = 10;
|
|
113
116
|
const HEADER_OFFSET_COMPRESSED_SIZE = 14;
|
|
114
117
|
const HEADER_OFFSET_UNCOMPRESSED_SIZE = 18;
|
|
118
|
+
const HEADER_OFFSET_FILENAME_LENGTH = 22;
|
|
119
|
+
const HEADER_OFFSET_EXTRAFIELD_LENGTH = 24;
|
|
115
120
|
const LOCAL_HEADER_COMMON_OFFSET = 4;
|
|
116
121
|
|
|
117
122
|
const MAX_DATE = new Date(2107, 11, 31, 23, 59, 58);
|
|
@@ -124,9 +129,116 @@
|
|
|
124
129
|
const OBJECT_TYPE = "object";
|
|
125
130
|
const STRING_TYPE = "string";
|
|
126
131
|
const NUMBER_TYPE = "number";
|
|
132
|
+
const BOOLEAN_TYPE = "boolean";
|
|
127
133
|
|
|
128
134
|
const EMPTY_UINT8_ARRAY = new Uint8Array();
|
|
129
135
|
|
|
136
|
+
/*
|
|
137
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
138
|
+
|
|
139
|
+
Redistribution and use in source and binary forms, with or without
|
|
140
|
+
modification, are permitted provided that the following conditions are met:
|
|
141
|
+
|
|
142
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
143
|
+
this list of conditions and the following disclaimer.
|
|
144
|
+
|
|
145
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
146
|
+
notice, this list of conditions and the following disclaimer in
|
|
147
|
+
the documentation and/or other materials provided with the distribution.
|
|
148
|
+
|
|
149
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
150
|
+
derived from this software without specific prior written permission.
|
|
151
|
+
|
|
152
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
153
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
154
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
155
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
156
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
157
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
158
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
159
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
160
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
161
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
const OPTION_FILENAME_ENCODING = "filenameEncoding";
|
|
166
|
+
const OPTION_COMMENT_ENCODING = "commentEncoding";
|
|
167
|
+
const OPTION_DECODE_TEXT = "decodeText";
|
|
168
|
+
const OPTION_EXTRACT_PREPENDED_DATA = "extractPrependedData";
|
|
169
|
+
const OPTION_EXTRACT_APPENDED_DATA = "extractAppendedData";
|
|
170
|
+
const OPTION_PASSWORD = "password";
|
|
171
|
+
const OPTION_RAW_PASSWORD = "rawPassword";
|
|
172
|
+
const OPTION_PASS_THROUGH = "passThrough";
|
|
173
|
+
const OPTION_SIGNAL = "signal";
|
|
174
|
+
const OPTION_CHECK_PASSWORD_ONLY = "checkPasswordOnly";
|
|
175
|
+
const OPTION_CHECK_OVERLAPPING_ENTRY_ONLY = "checkOverlappingEntryOnly";
|
|
176
|
+
const OPTION_CHECK_OVERLAPPING_ENTRY = "checkOverlappingEntry";
|
|
177
|
+
const OPTION_CHECK_AMBIGUITY = "checkAmbiguity";
|
|
178
|
+
const OPTION_CHECK_LOCAL_DIRECTORY = "checkLocalDirectory";
|
|
179
|
+
const OPTION_CHECK_SIGNATURE = "checkSignature";
|
|
180
|
+
const OPTION_CHECK_CRC32 = "checkCrc32";
|
|
181
|
+
const OPTION_CHECK_AUTHENTICATION_CODE = "checkAuthenticationCode";
|
|
182
|
+
const OPTION_USE_WEB_WORKERS = "useWebWorkers";
|
|
183
|
+
const OPTION_USE_COMPRESSION_STREAM = "useCompressionStream";
|
|
184
|
+
const OPTION_TRANSFER_STREAMS = "transferStreams";
|
|
185
|
+
const OPTION_PREVENT_CLOSE = "preventClose";
|
|
186
|
+
const OPTION_ENCRYPTION_STRENGTH = "encryptionStrength";
|
|
187
|
+
const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
|
|
188
|
+
const OPTION_NTFS_TIMESTAMP = "ntfsTimestamp";
|
|
189
|
+
const OPTION_KEEP_ORDER = "keepOrder";
|
|
190
|
+
const OPTION_LEVEL = "level";
|
|
191
|
+
const OPTION_BUFFERED_WRITE = "bufferedWrite";
|
|
192
|
+
const OPTION_CREATE_TEMP_STREAM = "createTempStream";
|
|
193
|
+
const OPTION_DATA_DESCRIPTOR_SIGNATURE = "dataDescriptorSignature";
|
|
194
|
+
const OPTION_USE_UNICODE_FILE_NAMES = "useUnicodeFileNames";
|
|
195
|
+
const OPTION_DATA_DESCRIPTOR = "dataDescriptor";
|
|
196
|
+
const OPTION_SUPPORT_ZIP64_SPLIT_FILE = "supportZip64SplitFile";
|
|
197
|
+
const OPTION_ENCODE_TEXT = "encodeText";
|
|
198
|
+
const OPTION_OFFSET = "offset";
|
|
199
|
+
const OPTION_USDZ = "usdz";
|
|
200
|
+
const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
|
|
201
|
+
const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
|
|
202
|
+
const OPTION_STRICTNESS = "strictness";
|
|
203
|
+
const OPTION_FILENAME_VALIDATION = "filenameValidation";
|
|
204
|
+
const OPTION_NORMALIZE_FILENAME = "normalizeFilename";
|
|
205
|
+
const OPTION_MAX_APPENDED_DATA_SIZE = "maxAppendedDataSize";
|
|
206
|
+
const OPTION_DECRYPT_CENTRAL_DIRECTORY = "decryptCentralDirectory";
|
|
207
|
+
const OPTION_SIGN_CENTRAL_DIRECTORY = "signCentralDirectory";
|
|
208
|
+
const TEXT_TYPE_FILENAME = "filename";
|
|
209
|
+
const TEXT_TYPE_COMMENT = "comment";
|
|
210
|
+
const STRICTNESS_STRICT = "strict";
|
|
211
|
+
const STRICTNESS_BALANCED = "balanced";
|
|
212
|
+
const STRICTNESS_TOLERANT = "tolerant";
|
|
213
|
+
|
|
214
|
+
const ERR_INVALID_FUNCTION_OPTION = "Invalid option (must be a function)";
|
|
215
|
+
const ERR_INVALID_SIGNAL = "Invalid signal (must be an AbortSignal instance)";
|
|
216
|
+
const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
|
|
217
|
+
|
|
218
|
+
function checkFunctionOption(value) {
|
|
219
|
+
if (value && typeof value != FUNCTION_TYPE) {
|
|
220
|
+
throw new Error(ERR_INVALID_FUNCTION_OPTION);
|
|
221
|
+
}
|
|
222
|
+
return value;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function checkSignalOption(signal) {
|
|
226
|
+
if (signal && (typeof signal.addEventListener != FUNCTION_TYPE || typeof signal.aborted != BOOLEAN_TYPE)) {
|
|
227
|
+
throw new Error(ERR_INVALID_SIGNAL);
|
|
228
|
+
}
|
|
229
|
+
return signal || UNDEFINED_VALUE;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function checkPasswordOption(password, rawPassword) {
|
|
233
|
+
if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
|
|
234
|
+
throw new Error(ERR_INVALID_PASSWORD_TYPE);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function toNumber(value) {
|
|
239
|
+
return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
|
|
240
|
+
}
|
|
241
|
+
|
|
130
242
|
/*
|
|
131
243
|
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
132
244
|
|
|
@@ -156,7 +268,10 @@
|
|
|
156
268
|
*/
|
|
157
269
|
|
|
158
270
|
|
|
271
|
+
const DEFAULT_CHUNK_SIZE$1 = 64 * 1024;
|
|
159
272
|
const MINIMUM_CHUNK_SIZE = 64;
|
|
273
|
+
const MINIMUM_PROPERTY_VALUE = 1;
|
|
274
|
+
const ERR_INVALID_MAX_WORKERS = "Invalid maxWorkers (must be an integer greater than 0)";
|
|
160
275
|
let maxWorkers = 2;
|
|
161
276
|
try {
|
|
162
277
|
if (typeof navigator != UNDEFINED_TYPE && navigator.hardwareConcurrency) {
|
|
@@ -168,7 +283,7 @@
|
|
|
168
283
|
const DEFAULT_CONFIGURATION = {
|
|
169
284
|
workerURI: "./core/web-worker-wasm.js",
|
|
170
285
|
wasmURI: "./core/streams/zlib-wasm/zlib-streams.wasm",
|
|
171
|
-
chunkSize:
|
|
286
|
+
chunkSize: DEFAULT_CHUNK_SIZE$1,
|
|
172
287
|
maxWorkers,
|
|
173
288
|
terminateWorkerTimeout: 5000,
|
|
174
289
|
workerStarvationTimeout: 5000,
|
|
@@ -180,24 +295,38 @@
|
|
|
180
295
|
DecompressionStream: typeof DecompressionStream != UNDEFINED_TYPE && DecompressionStream
|
|
181
296
|
};
|
|
182
297
|
|
|
183
|
-
const
|
|
298
|
+
const PROPERTY_NAME_MAX_WORKERS = "maxWorkers";
|
|
299
|
+
|
|
300
|
+
const STRING_PROPERTY_NAMES = [
|
|
184
301
|
"baseURI",
|
|
185
302
|
"wasmURI",
|
|
186
|
-
"workerURI"
|
|
187
|
-
|
|
303
|
+
"workerURI"
|
|
304
|
+
];
|
|
305
|
+
const BOOLEAN_PROPERTY_NAMES = [
|
|
306
|
+
"useCompressionStream",
|
|
307
|
+
"useWebWorkers",
|
|
308
|
+
"transferStreams"
|
|
309
|
+
];
|
|
310
|
+
const NUMBER_PROPERTY_NAMES = [
|
|
188
311
|
"chunkSize",
|
|
189
|
-
|
|
312
|
+
PROPERTY_NAME_MAX_WORKERS,
|
|
190
313
|
"terminateWorkerTimeout",
|
|
191
314
|
"workerStarvationTimeout",
|
|
192
|
-
"workerStartupTimeout"
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
"
|
|
315
|
+
"workerStartupTimeout"
|
|
316
|
+
];
|
|
317
|
+
const FUNCTION_PROPERTY_NAMES = [
|
|
318
|
+
"createWorker",
|
|
196
319
|
"CompressionStream",
|
|
197
320
|
"DecompressionStream",
|
|
198
321
|
"CompressionStreamFallback",
|
|
199
322
|
"DecompressionStreamFallback"
|
|
200
323
|
];
|
|
324
|
+
const CONFIGURABLE_PROPERTY_NAMES = [
|
|
325
|
+
...STRING_PROPERTY_NAMES,
|
|
326
|
+
...BOOLEAN_PROPERTY_NAMES,
|
|
327
|
+
...NUMBER_PROPERTY_NAMES,
|
|
328
|
+
...FUNCTION_PROPERTY_NAMES
|
|
329
|
+
];
|
|
201
330
|
|
|
202
331
|
const config = { ...DEFAULT_CONFIGURATION };
|
|
203
332
|
|
|
@@ -206,20 +335,43 @@
|
|
|
206
335
|
}
|
|
207
336
|
|
|
208
337
|
function getChunkSize(config) {
|
|
209
|
-
return
|
|
338
|
+
return normalizeChunkSize(config.chunkSize);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function normalizeChunkSize(chunkSize) {
|
|
342
|
+
chunkSize = toNumber(chunkSize);
|
|
343
|
+
return Number.isInteger(chunkSize) && chunkSize >= MINIMUM_PROPERTY_VALUE ? Math.max(chunkSize, MINIMUM_CHUNK_SIZE) : DEFAULT_CHUNK_SIZE$1;
|
|
210
344
|
}
|
|
211
345
|
|
|
212
346
|
function configure(configuration) {
|
|
213
|
-
|
|
347
|
+
Object.assign(config, checkConfiguration(normalizeConfiguration(configuration)));
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function checkConfiguration(configuration) {
|
|
351
|
+
const checkedConfiguration = {};
|
|
214
352
|
for (const propertyName of CONFIGURABLE_PROPERTY_NAMES) {
|
|
215
353
|
const propertyValue = configuration[propertyName];
|
|
216
354
|
if (propertyValue !== UNDEFINED_VALUE) {
|
|
217
|
-
|
|
355
|
+
checkedConfiguration[propertyName] = checkPropertyValue(propertyName, propertyValue);
|
|
218
356
|
}
|
|
219
357
|
}
|
|
358
|
+
return checkedConfiguration;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function checkPropertyValue(propertyName, propertyValue) {
|
|
362
|
+
if (NUMBER_PROPERTY_NAMES.includes(propertyName)) {
|
|
363
|
+
propertyValue = toNumber(propertyValue);
|
|
364
|
+
if (propertyName == PROPERTY_NAME_MAX_WORKERS && (!Number.isInteger(propertyValue) || propertyValue < MINIMUM_PROPERTY_VALUE)) {
|
|
365
|
+
throw new Error(ERR_INVALID_MAX_WORKERS);
|
|
366
|
+
}
|
|
367
|
+
} else if (FUNCTION_PROPERTY_NAMES.includes(propertyName)) {
|
|
368
|
+
checkFunctionOption(propertyValue);
|
|
369
|
+
}
|
|
370
|
+
return propertyValue;
|
|
220
371
|
}
|
|
221
372
|
|
|
222
373
|
function normalizeConfiguration(configuration) {
|
|
374
|
+
configuration = configuration || {};
|
|
223
375
|
const { CompressionStreamZlib, DecompressionStreamZlib } = configuration;
|
|
224
376
|
if (CompressionStreamZlib === UNDEFINED_VALUE && DecompressionStreamZlib === UNDEFINED_VALUE) {
|
|
225
377
|
return configuration;
|
|
@@ -235,14 +387,9 @@
|
|
|
235
387
|
}
|
|
236
388
|
|
|
237
389
|
function setDefaultConfiguration(configuration) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if (propertyValue !== UNDEFINED_VALUE) {
|
|
242
|
-
DEFAULT_CONFIGURATION[propertyName] = propertyValue;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
configure(configuration);
|
|
390
|
+
const checkedConfiguration = checkConfiguration(normalizeConfiguration(configuration));
|
|
391
|
+
Object.assign(DEFAULT_CONFIGURATION, checkedConfiguration);
|
|
392
|
+
Object.assign(config, checkedConfiguration);
|
|
246
393
|
}
|
|
247
394
|
|
|
248
395
|
function resetConfiguration() {
|
|
@@ -1398,13 +1545,13 @@
|
|
|
1398
1545
|
const {
|
|
1399
1546
|
ctr,
|
|
1400
1547
|
hmac,
|
|
1401
|
-
|
|
1548
|
+
pendingInput,
|
|
1402
1549
|
ready
|
|
1403
1550
|
} = this;
|
|
1404
1551
|
if (hmac && ctr) {
|
|
1405
1552
|
await ready;
|
|
1406
|
-
const chunkToDecrypt = subarray(
|
|
1407
|
-
const originalAuthenticationCode = subarray(
|
|
1553
|
+
const chunkToDecrypt = subarray(pendingInput, 0, pendingInput.length - AUTHENTICATION_CODE_LENGTH);
|
|
1554
|
+
const originalAuthenticationCode = subarray(pendingInput, pendingInput.length - AUTHENTICATION_CODE_LENGTH);
|
|
1408
1555
|
let decryptedChunkArray = EMPTY_UINT8_ARRAY;
|
|
1409
1556
|
if (chunkToDecrypt.length) {
|
|
1410
1557
|
const encryptedChunk = toBits(codecBytes, chunkToDecrypt);
|
|
@@ -1413,7 +1560,7 @@
|
|
|
1413
1560
|
decryptedChunkArray = fromBits(codecBytes, decryptedChunk);
|
|
1414
1561
|
}
|
|
1415
1562
|
const authenticationCode = subarray(fromBits(codecBytes, hmac.digest()), 0, AUTHENTICATION_CODE_LENGTH);
|
|
1416
|
-
let invalidAuthenticationCode =
|
|
1563
|
+
let invalidAuthenticationCode = pendingInput.length < AUTHENTICATION_CODE_LENGTH ? 1 : 0;
|
|
1417
1564
|
for (let indexByte = 0; indexByte < AUTHENTICATION_CODE_LENGTH; indexByte++) {
|
|
1418
1565
|
invalidAuthenticationCode |= authenticationCode[indexByte] ^ originalAuthenticationCode[indexByte];
|
|
1419
1566
|
}
|
|
@@ -1457,14 +1604,14 @@
|
|
|
1457
1604
|
const {
|
|
1458
1605
|
ctr,
|
|
1459
1606
|
hmac,
|
|
1460
|
-
|
|
1607
|
+
pendingInput,
|
|
1461
1608
|
ready
|
|
1462
1609
|
} = this;
|
|
1463
1610
|
if (hmac && ctr) {
|
|
1464
1611
|
await ready;
|
|
1465
1612
|
let encryptedChunkArray = EMPTY_UINT8_ARRAY;
|
|
1466
|
-
if (
|
|
1467
|
-
const encryptedChunk = ctr.update(toBits(codecBytes,
|
|
1613
|
+
if (pendingInput.length) {
|
|
1614
|
+
const encryptedChunk = ctr.update(toBits(codecBytes, pendingInput));
|
|
1468
1615
|
hmac.update(encryptedChunk);
|
|
1469
1616
|
encryptedChunkArray = fromBits(codecBytes, encryptedChunk);
|
|
1470
1617
|
}
|
|
@@ -1481,7 +1628,7 @@
|
|
|
1481
1628
|
ready: new Promise(resolve => aesCrypto.resolveReady = resolve),
|
|
1482
1629
|
password: encodePassword(password, rawPassword),
|
|
1483
1630
|
strength: encryptionStrength - 1,
|
|
1484
|
-
|
|
1631
|
+
pendingInput: EMPTY_UINT8_ARRAY
|
|
1485
1632
|
});
|
|
1486
1633
|
}
|
|
1487
1634
|
|
|
@@ -1489,10 +1636,10 @@
|
|
|
1489
1636
|
const {
|
|
1490
1637
|
ctr,
|
|
1491
1638
|
hmac,
|
|
1492
|
-
|
|
1639
|
+
pendingInput
|
|
1493
1640
|
} = aesCrypto;
|
|
1494
|
-
if (
|
|
1495
|
-
input = concat(
|
|
1641
|
+
if (pendingInput.length) {
|
|
1642
|
+
input = concat(pendingInput, input);
|
|
1496
1643
|
}
|
|
1497
1644
|
const inputLength = input.length - paddingEnd;
|
|
1498
1645
|
output = expand(output, paddingStart + (inputLength - (inputLength % BLOCK_LENGTH)));
|
|
@@ -1508,7 +1655,7 @@
|
|
|
1508
1655
|
}
|
|
1509
1656
|
output.set(fromBits(codecBytes, outputChunk), offset + paddingStart);
|
|
1510
1657
|
}
|
|
1511
|
-
aesCrypto.
|
|
1658
|
+
aesCrypto.pendingInput = subarray(input, offset);
|
|
1512
1659
|
return output;
|
|
1513
1660
|
}
|
|
1514
1661
|
|
|
@@ -3281,6 +3428,96 @@
|
|
|
3281
3428
|
resetWebWorkerSupport();
|
|
3282
3429
|
}
|
|
3283
3430
|
|
|
3431
|
+
/*
|
|
3432
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
3433
|
+
|
|
3434
|
+
Redistribution and use in source and binary forms, with or without
|
|
3435
|
+
modification, are permitted provided that the following conditions are met:
|
|
3436
|
+
|
|
3437
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
3438
|
+
this list of conditions and the following disclaimer.
|
|
3439
|
+
|
|
3440
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
3441
|
+
notice, this list of conditions and the following disclaimer in
|
|
3442
|
+
the documentation and/or other materials provided with the distribution.
|
|
3443
|
+
|
|
3444
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
3445
|
+
derived from this software without specific prior written permission.
|
|
3446
|
+
|
|
3447
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
3448
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
3449
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
3450
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
3451
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
3452
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
3453
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
3454
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
3455
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
3456
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3457
|
+
*/
|
|
3458
|
+
|
|
3459
|
+
/* global TextDecoder */
|
|
3460
|
+
|
|
3461
|
+
const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");
|
|
3462
|
+
const VALID_CP437 = CP437.length == 256;
|
|
3463
|
+
|
|
3464
|
+
function decodeCP437(stringValue) {
|
|
3465
|
+
if (VALID_CP437) {
|
|
3466
|
+
let result = "";
|
|
3467
|
+
for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
|
|
3468
|
+
result += CP437[stringValue[indexCharacter]];
|
|
3469
|
+
}
|
|
3470
|
+
return result;
|
|
3471
|
+
} else {
|
|
3472
|
+
return new TextDecoder().decode(stringValue);
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
|
|
3476
|
+
/*
|
|
3477
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
3478
|
+
|
|
3479
|
+
Redistribution and use in source and binary forms, with or without
|
|
3480
|
+
modification, are permitted provided that the following conditions are met:
|
|
3481
|
+
|
|
3482
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
3483
|
+
this list of conditions and the following disclaimer.
|
|
3484
|
+
|
|
3485
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
3486
|
+
notice, this list of conditions and the following disclaimer in
|
|
3487
|
+
the documentation and/or other materials provided with the distribution.
|
|
3488
|
+
|
|
3489
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
3490
|
+
derived from this software without specific prior written permission.
|
|
3491
|
+
|
|
3492
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
3493
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
3494
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
3495
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
3496
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
3497
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
3498
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
3499
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
3500
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
3501
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3502
|
+
*/
|
|
3503
|
+
|
|
3504
|
+
|
|
3505
|
+
function decodeText(value, encoding) {
|
|
3506
|
+
return decode(value, encoding, true);
|
|
3507
|
+
}
|
|
3508
|
+
|
|
3509
|
+
function decodeTextRemovingBOM(value, encoding) {
|
|
3510
|
+
return decode(value, encoding, false);
|
|
3511
|
+
}
|
|
3512
|
+
|
|
3513
|
+
function decode(value, encoding, ignoreBOM) {
|
|
3514
|
+
if (encoding && encoding.trim().toLowerCase() == "cp437") {
|
|
3515
|
+
return decodeCP437(value);
|
|
3516
|
+
} else {
|
|
3517
|
+
return new TextDecoder(encoding, { ignoreBOM }).decode(value);
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
|
|
3284
3521
|
/*
|
|
3285
3522
|
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
3286
3523
|
|
|
@@ -3353,6 +3590,7 @@
|
|
|
3353
3590
|
createReadable({ offset = 0, size, chunkSize = getChunkSize(getConfiguration()) } = {}) {
|
|
3354
3591
|
const reader = this;
|
|
3355
3592
|
let chunkOffset = 0;
|
|
3593
|
+
chunkSize = normalizeChunkSize(chunkSize);
|
|
3356
3594
|
return new ReadableStream({
|
|
3357
3595
|
async pull(controller) {
|
|
3358
3596
|
const dataSize = size === UNDEFINED_VALUE ? chunkSize : Math.min(chunkSize, size - chunkOffset);
|
|
@@ -3360,7 +3598,7 @@
|
|
|
3360
3598
|
if (data.length) {
|
|
3361
3599
|
controller.enqueue(data);
|
|
3362
3600
|
}
|
|
3363
|
-
if ((chunkOffset + chunkSize >= size) || (
|
|
3601
|
+
if ((chunkOffset + chunkSize >= size) || (!data.length && dataSize)) {
|
|
3364
3602
|
controller.close();
|
|
3365
3603
|
} else {
|
|
3366
3604
|
chunkOffset += chunkSize;
|
|
@@ -3440,31 +3678,31 @@
|
|
|
3440
3678
|
Object.assign(this, {
|
|
3441
3679
|
contentType,
|
|
3442
3680
|
data: "data:" + (contentType || "") + ";base64,",
|
|
3443
|
-
|
|
3681
|
+
pendingCharacters: ""
|
|
3444
3682
|
});
|
|
3445
3683
|
}
|
|
3446
3684
|
|
|
3447
3685
|
writeUint8Array(array) {
|
|
3448
3686
|
const writer = this;
|
|
3449
3687
|
let indexArray;
|
|
3450
|
-
let dataString = writer.
|
|
3451
|
-
const delta = writer.
|
|
3452
|
-
writer.
|
|
3688
|
+
let dataString = writer.pendingCharacters;
|
|
3689
|
+
const delta = writer.pendingCharacters.length;
|
|
3690
|
+
writer.pendingCharacters = "";
|
|
3453
3691
|
for (indexArray = 0; indexArray < (Math.floor((delta + array.length) / 3) * 3) - delta; indexArray++) {
|
|
3454
3692
|
dataString += String.fromCharCode(array[indexArray]);
|
|
3455
3693
|
}
|
|
3456
3694
|
for (; indexArray < array.length; indexArray++) {
|
|
3457
|
-
writer.
|
|
3695
|
+
writer.pendingCharacters += String.fromCharCode(array[indexArray]);
|
|
3458
3696
|
}
|
|
3459
3697
|
if (dataString.length > 2) {
|
|
3460
3698
|
writer.data += btoa(dataString);
|
|
3461
3699
|
} else {
|
|
3462
|
-
writer.
|
|
3700
|
+
writer.pendingCharacters = dataString + writer.pendingCharacters;
|
|
3463
3701
|
}
|
|
3464
3702
|
}
|
|
3465
3703
|
|
|
3466
3704
|
getData() {
|
|
3467
|
-
return this.data + btoa(this.
|
|
3705
|
+
return this.data + btoa(this.pendingCharacters);
|
|
3468
3706
|
}
|
|
3469
3707
|
}
|
|
3470
3708
|
|
|
@@ -3494,7 +3732,7 @@
|
|
|
3494
3732
|
constructor(blob) {
|
|
3495
3733
|
super();
|
|
3496
3734
|
Object.assign(this, {
|
|
3497
|
-
blob,
|
|
3735
|
+
sourceBlob: blob,
|
|
3498
3736
|
size: blob.size
|
|
3499
3737
|
});
|
|
3500
3738
|
if (!blobSliceProbe) {
|
|
@@ -3504,13 +3742,13 @@
|
|
|
3504
3742
|
|
|
3505
3743
|
createReadable(options) {
|
|
3506
3744
|
const reader = this;
|
|
3507
|
-
const {
|
|
3745
|
+
const { sourceBlob, size } = reader;
|
|
3508
3746
|
const { offset = 0, size: readSize = size - offset } = options || {};
|
|
3509
3747
|
if (!offset && readSize >= size) {
|
|
3510
|
-
return toCompatibleReadable(
|
|
3748
|
+
return toCompatibleReadable(sourceBlob.stream());
|
|
3511
3749
|
}
|
|
3512
3750
|
if (blobSliceReliable) {
|
|
3513
|
-
return toCompatibleReadable(
|
|
3751
|
+
return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
|
|
3514
3752
|
}
|
|
3515
3753
|
return super.createReadable(options);
|
|
3516
3754
|
}
|
|
@@ -3519,7 +3757,7 @@
|
|
|
3519
3757
|
const reader = this;
|
|
3520
3758
|
const offsetEnd = offset + length;
|
|
3521
3759
|
const readsWholeBlob = !offset && offsetEnd >= reader.size;
|
|
3522
|
-
const blob = readsWholeBlob ? reader.
|
|
3760
|
+
const blob = readsWholeBlob ? reader.sourceBlob : reader.sourceBlob.slice(offset, offsetEnd);
|
|
3523
3761
|
let arrayBuffer = await blob.arrayBuffer();
|
|
3524
3762
|
const sliceIgnoredByBuggyImplementation = arrayBuffer.byteLength > length;
|
|
3525
3763
|
if (sliceIgnoredByBuggyImplementation) {
|
|
@@ -3541,12 +3779,12 @@
|
|
|
3541
3779
|
}
|
|
3542
3780
|
});
|
|
3543
3781
|
writer.contentType = contentType;
|
|
3544
|
-
writer.
|
|
3545
|
-
writer.
|
|
3782
|
+
writer.blobPromise = streamToBlob(transformStream.readable, contentType);
|
|
3783
|
+
writer.blobPromise.catch(() => { });
|
|
3546
3784
|
}
|
|
3547
3785
|
|
|
3548
3786
|
getData() {
|
|
3549
|
-
return this.
|
|
3787
|
+
return this.blobPromise;
|
|
3550
3788
|
}
|
|
3551
3789
|
}
|
|
3552
3790
|
|
|
@@ -3560,7 +3798,7 @@
|
|
|
3560
3798
|
class TextWriter extends BlobWriter {
|
|
3561
3799
|
|
|
3562
3800
|
constructor(encoding) {
|
|
3563
|
-
super(
|
|
3801
|
+
super();
|
|
3564
3802
|
Object.assign(this, {
|
|
3565
3803
|
encoding,
|
|
3566
3804
|
utf8: !encoding || encoding.toLowerCase() == "utf-8"
|
|
@@ -3576,14 +3814,7 @@
|
|
|
3576
3814
|
if (blob.text && utf8) {
|
|
3577
3815
|
return blob.text();
|
|
3578
3816
|
} else {
|
|
3579
|
-
|
|
3580
|
-
return new Promise((resolve, reject) => {
|
|
3581
|
-
Object.assign(reader, {
|
|
3582
|
-
onload: ({ target }) => resolve(target.result),
|
|
3583
|
-
onerror: () => reject(reader.error)
|
|
3584
|
-
});
|
|
3585
|
-
reader.readAsText(blob, encoding);
|
|
3586
|
-
});
|
|
3817
|
+
return decodeTextRemovingBOM(new Uint8Array(await blob.arrayBuffer()), encoding);
|
|
3587
3818
|
}
|
|
3588
3819
|
}
|
|
3589
3820
|
}
|
|
@@ -4251,85 +4482,13 @@
|
|
|
4251
4482
|
return reader.readUint8Array(offset, size);
|
|
4252
4483
|
}
|
|
4253
4484
|
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
1. Redistributions of source code must retain the above copyright notice,
|
|
4261
|
-
this list of conditions and the following disclaimer.
|
|
4262
|
-
|
|
4263
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
4264
|
-
notice, this list of conditions and the following disclaimer in
|
|
4265
|
-
the documentation and/or other materials provided with the distribution.
|
|
4266
|
-
|
|
4267
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
4268
|
-
derived from this software without specific prior written permission.
|
|
4269
|
-
|
|
4270
|
-
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
4271
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
4272
|
-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
4273
|
-
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
4274
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
4275
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
4276
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
4277
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
4278
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
4279
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
4280
|
-
*/
|
|
4281
|
-
|
|
4282
|
-
/* global TextDecoder */
|
|
4283
|
-
|
|
4284
|
-
const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");
|
|
4285
|
-
const VALID_CP437 = CP437.length == 256;
|
|
4286
|
-
|
|
4287
|
-
function decodeCP437(stringValue) {
|
|
4288
|
-
if (VALID_CP437) {
|
|
4289
|
-
let result = "";
|
|
4290
|
-
for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
|
|
4291
|
-
result += CP437[stringValue[indexCharacter]];
|
|
4292
|
-
}
|
|
4293
|
-
return result;
|
|
4294
|
-
} else {
|
|
4295
|
-
return new TextDecoder().decode(stringValue);
|
|
4296
|
-
}
|
|
4297
|
-
}
|
|
4298
|
-
|
|
4299
|
-
/*
|
|
4300
|
-
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
4301
|
-
|
|
4302
|
-
Redistribution and use in source and binary forms, with or without
|
|
4303
|
-
modification, are permitted provided that the following conditions are met:
|
|
4304
|
-
|
|
4305
|
-
1. Redistributions of source code must retain the above copyright notice,
|
|
4306
|
-
this list of conditions and the following disclaimer.
|
|
4307
|
-
|
|
4308
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
4309
|
-
notice, this list of conditions and the following disclaimer in
|
|
4310
|
-
the documentation and/or other materials provided with the distribution.
|
|
4311
|
-
|
|
4312
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
4313
|
-
derived from this software without specific prior written permission.
|
|
4314
|
-
|
|
4315
|
-
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
4316
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
4317
|
-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
4318
|
-
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
4319
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
4320
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
4321
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
4322
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
4323
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
4324
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
4325
|
-
*/
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
function decodeText(value, encoding) {
|
|
4329
|
-
if (encoding && encoding.trim().toLowerCase() == "cp437") {
|
|
4330
|
-
return decodeCP437(value);
|
|
4485
|
+
function createReadable(reader, options) {
|
|
4486
|
+
if (reader.createReadable) {
|
|
4487
|
+
return reader.createReadable(options);
|
|
4488
|
+
} else if (reader.readUint8Array) {
|
|
4489
|
+
return Reader.prototype.createReadable.call(reader, options);
|
|
4331
4490
|
} else {
|
|
4332
|
-
return
|
|
4491
|
+
return reader.readable;
|
|
4333
4492
|
}
|
|
4334
4493
|
}
|
|
4335
4494
|
|
|
@@ -4489,83 +4648,6 @@
|
|
|
4489
4648
|
|
|
4490
4649
|
}
|
|
4491
4650
|
|
|
4492
|
-
/*
|
|
4493
|
-
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
4494
|
-
|
|
4495
|
-
Redistribution and use in source and binary forms, with or without
|
|
4496
|
-
modification, are permitted provided that the following conditions are met:
|
|
4497
|
-
|
|
4498
|
-
1. Redistributions of source code must retain the above copyright notice,
|
|
4499
|
-
this list of conditions and the following disclaimer.
|
|
4500
|
-
|
|
4501
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
4502
|
-
notice, this list of conditions and the following disclaimer in
|
|
4503
|
-
the documentation and/or other materials provided with the distribution.
|
|
4504
|
-
|
|
4505
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
4506
|
-
derived from this software without specific prior written permission.
|
|
4507
|
-
|
|
4508
|
-
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
4509
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
4510
|
-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
4511
|
-
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
4512
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
4513
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
4514
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
4515
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
4516
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
4517
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
4518
|
-
*/
|
|
4519
|
-
|
|
4520
|
-
const OPTION_FILENAME_ENCODING = "filenameEncoding";
|
|
4521
|
-
const OPTION_COMMENT_ENCODING = "commentEncoding";
|
|
4522
|
-
const OPTION_DECODE_TEXT = "decodeText";
|
|
4523
|
-
const OPTION_EXTRACT_PREPENDED_DATA = "extractPrependedData";
|
|
4524
|
-
const OPTION_EXTRACT_APPENDED_DATA = "extractAppendedData";
|
|
4525
|
-
const OPTION_PASSWORD = "password";
|
|
4526
|
-
const OPTION_RAW_PASSWORD = "rawPassword";
|
|
4527
|
-
const OPTION_PASS_THROUGH = "passThrough";
|
|
4528
|
-
const OPTION_SIGNAL = "signal";
|
|
4529
|
-
const OPTION_CHECK_PASSWORD_ONLY = "checkPasswordOnly";
|
|
4530
|
-
const OPTION_CHECK_OVERLAPPING_ENTRY_ONLY = "checkOverlappingEntryOnly";
|
|
4531
|
-
const OPTION_CHECK_OVERLAPPING_ENTRY = "checkOverlappingEntry";
|
|
4532
|
-
const OPTION_CHECK_AMBIGUITY = "checkAmbiguity";
|
|
4533
|
-
const OPTION_CHECK_LOCAL_DIRECTORY = "checkLocalDirectory";
|
|
4534
|
-
const OPTION_CHECK_SIGNATURE = "checkSignature";
|
|
4535
|
-
const OPTION_CHECK_CRC32 = "checkCrc32";
|
|
4536
|
-
const OPTION_CHECK_AUTHENTICATION_CODE = "checkAuthenticationCode";
|
|
4537
|
-
const OPTION_USE_WEB_WORKERS = "useWebWorkers";
|
|
4538
|
-
const OPTION_USE_COMPRESSION_STREAM = "useCompressionStream";
|
|
4539
|
-
const OPTION_TRANSFER_STREAMS = "transferStreams";
|
|
4540
|
-
const OPTION_PREVENT_CLOSE = "preventClose";
|
|
4541
|
-
const OPTION_ENCRYPTION_STRENGTH = "encryptionStrength";
|
|
4542
|
-
const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
|
|
4543
|
-
const OPTION_NTFS_TIMESTAMP = "ntfsTimestamp";
|
|
4544
|
-
const OPTION_KEEP_ORDER = "keepOrder";
|
|
4545
|
-
const OPTION_LEVEL = "level";
|
|
4546
|
-
const OPTION_BUFFERED_WRITE = "bufferedWrite";
|
|
4547
|
-
const OPTION_CREATE_TEMP_STREAM = "createTempStream";
|
|
4548
|
-
const OPTION_DATA_DESCRIPTOR_SIGNATURE = "dataDescriptorSignature";
|
|
4549
|
-
const OPTION_USE_UNICODE_FILE_NAMES = "useUnicodeFileNames";
|
|
4550
|
-
const OPTION_DATA_DESCRIPTOR = "dataDescriptor";
|
|
4551
|
-
const OPTION_SUPPORT_ZIP64_SPLIT_FILE = "supportZip64SplitFile";
|
|
4552
|
-
const OPTION_ENCODE_TEXT = "encodeText";
|
|
4553
|
-
const OPTION_OFFSET = "offset";
|
|
4554
|
-
const OPTION_USDZ = "usdz";
|
|
4555
|
-
const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
|
|
4556
|
-
const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
|
|
4557
|
-
const OPTION_STRICTNESS = "strictness";
|
|
4558
|
-
const OPTION_FILENAME_VALIDATION = "filenameValidation";
|
|
4559
|
-
const OPTION_NORMALIZE_FILENAME = "normalizeFilename";
|
|
4560
|
-
const OPTION_MAX_APPENDED_DATA_SIZE = "maxAppendedDataSize";
|
|
4561
|
-
const OPTION_DECRYPT_CENTRAL_DIRECTORY = "decryptCentralDirectory";
|
|
4562
|
-
const OPTION_SIGN_CENTRAL_DIRECTORY = "signCentralDirectory";
|
|
4563
|
-
const TEXT_TYPE_FILENAME = "filename";
|
|
4564
|
-
const TEXT_TYPE_COMMENT = "comment";
|
|
4565
|
-
const STRICTNESS_STRICT = "strict";
|
|
4566
|
-
const STRICTNESS_BALANCED = "balanced";
|
|
4567
|
-
const STRICTNESS_TOLERANT = "tolerant";
|
|
4568
|
-
|
|
4569
4651
|
/*
|
|
4570
4652
|
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
4571
4653
|
|
|
@@ -4606,6 +4688,7 @@
|
|
|
4606
4688
|
const ERR_UNSUPPORTED_COMPRESSION$1 = "Compression method not supported";
|
|
4607
4689
|
const ERR_SPLIT_ZIP_FILE = "Split zip file";
|
|
4608
4690
|
const ERR_OVERLAPPING_ENTRY = "Overlapping entry found";
|
|
4691
|
+
const ERR_ENTRY_DATA_OUT_OF_BOUNDS = "Entry data out of bounds";
|
|
4609
4692
|
const ERR_AMBIGUOUS_ARCHIVE = "Ambiguous archive";
|
|
4610
4693
|
const ERR_ENCRYPTED_CENTRAL_DIRECTORY = "Encrypted central directory is not supported";
|
|
4611
4694
|
const ERR_UNSAFE_FILENAME = "Unsafe filename";
|
|
@@ -4626,7 +4709,7 @@
|
|
|
4626
4709
|
];
|
|
4627
4710
|
const ZIP64_EXTRACTION = {
|
|
4628
4711
|
[MAX_16_BITS]: {
|
|
4629
|
-
getValue: getUint32,
|
|
4712
|
+
getValue: getUint32$1,
|
|
4630
4713
|
bytes: 4
|
|
4631
4714
|
},
|
|
4632
4715
|
[MAX_32_BITS]: {
|
|
@@ -4635,6 +4718,7 @@
|
|
|
4635
4718
|
}
|
|
4636
4719
|
};
|
|
4637
4720
|
const MAX_END_OF_CENTRAL_DIR_PROBES = 64;
|
|
4721
|
+
const MAX_DEFLATE_EXPANSION_RATIO = 1032;
|
|
4638
4722
|
const CENTRAL_DIRECTORY_UNREACHABLE = 0;
|
|
4639
4723
|
const CENTRAL_DIRECTORY_PLAUSIBLE = 1;
|
|
4640
4724
|
const CENTRAL_DIRECTORY_REACHABLE = 2;
|
|
@@ -4645,7 +4729,6 @@
|
|
|
4645
4729
|
Object.assign(this, {
|
|
4646
4730
|
reader: new GenericReader(reader),
|
|
4647
4731
|
options,
|
|
4648
|
-
config: getConfiguration(),
|
|
4649
4732
|
readRanges: new Map()
|
|
4650
4733
|
});
|
|
4651
4734
|
}
|
|
@@ -4653,7 +4736,6 @@
|
|
|
4653
4736
|
async* getEntriesGenerator(options = {}) {
|
|
4654
4737
|
const zipReader = this;
|
|
4655
4738
|
let { reader } = zipReader;
|
|
4656
|
-
const { config } = zipReader;
|
|
4657
4739
|
await initStream(reader);
|
|
4658
4740
|
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
4659
4741
|
reader = new BlobReader(await streamToBlob(reader.readable));
|
|
@@ -4670,9 +4752,7 @@
|
|
|
4670
4752
|
const normalizeFilename = getOptionValue$1(zipReader, options, OPTION_NORMALIZE_FILENAME);
|
|
4671
4753
|
const { endOfDirectoryInfo, endOfDirectoryReachingEndCount } = await findEndOfCentralDirectory(reader, rejectAmbiguousEndOfDirectory, maxAppendedDataSize);
|
|
4672
4754
|
if (!endOfDirectoryInfo) {
|
|
4673
|
-
|
|
4674
|
-
const signatureView = getDataView(signatureArray);
|
|
4675
|
-
if (getUint32(signatureView) == SPLIT_ZIP_FILE_SIGNATURE) {
|
|
4755
|
+
if (await startsWithSplitZipSignature$1(reader)) {
|
|
4676
4756
|
throw new Error(ERR_SPLIT_ZIP_FILE);
|
|
4677
4757
|
} else {
|
|
4678
4758
|
throw new Error(ERR_EOCDR_NOT_FOUND);
|
|
@@ -4682,22 +4762,23 @@
|
|
|
4682
4762
|
throwAmbiguousArchive("multiple end of central directory records");
|
|
4683
4763
|
}
|
|
4684
4764
|
const endOfDirectoryView = getDataView(endOfDirectoryInfo);
|
|
4685
|
-
let directoryDataLength = getUint32(endOfDirectoryView, 12);
|
|
4686
|
-
let directoryDataOffset = getUint32(endOfDirectoryView, 16);
|
|
4765
|
+
let directoryDataLength = getUint32$1(endOfDirectoryView, 12);
|
|
4766
|
+
let directoryDataOffset = getUint32$1(endOfDirectoryView, 16);
|
|
4687
4767
|
const commentOffset = endOfDirectoryInfo.offset;
|
|
4688
|
-
const commentLength = getUint16(endOfDirectoryView, 20);
|
|
4768
|
+
const commentLength = getUint16$1(endOfDirectoryView, 20);
|
|
4689
4769
|
const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
|
|
4690
4770
|
if (reader.size - appendedDataOffset > maxAppendedDataSize) {
|
|
4691
4771
|
throwAmbiguousArchive("appended data");
|
|
4692
4772
|
}
|
|
4693
|
-
let lastDiskNumber = getUint16(endOfDirectoryView, 4);
|
|
4773
|
+
let lastDiskNumber = getUint16$1(endOfDirectoryView, 4);
|
|
4694
4774
|
const expectedLastDiskNumber = reader.lastDiskNumber || 0;
|
|
4695
|
-
let diskNumber = getUint16(endOfDirectoryView, 6);
|
|
4696
|
-
let filesLength = getUint16(endOfDirectoryView, 10);
|
|
4775
|
+
let diskNumber = getUint16$1(endOfDirectoryView, 6);
|
|
4776
|
+
let filesLength = getUint16$1(endOfDirectoryView, 10);
|
|
4697
4777
|
let prependedDataLength = 0;
|
|
4698
4778
|
let startOffset;
|
|
4699
4779
|
let zip64EndOfDirectory;
|
|
4700
4780
|
let zip64EndOfDirectoryVersion2;
|
|
4781
|
+
let zip64EndOfDirectoryLength = ZIP64_END_OF_CENTRAL_DIR_LENGTH;
|
|
4701
4782
|
let directoryEncryptionInfo;
|
|
4702
4783
|
const requiresZip64 = directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS || diskNumber == MAX_16_BITS;
|
|
4703
4784
|
if (directoryDataOffset != MAX_32_BITS && diskNumber != MAX_16_BITS) {
|
|
@@ -4709,12 +4790,12 @@
|
|
|
4709
4790
|
EMPTY_UINT8_ARRAY;
|
|
4710
4791
|
const endOfDirectoryLocatorView = getDataView(endOfDirectoryLocatorArray);
|
|
4711
4792
|
if (endOfDirectoryLocatorArray.length == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH &&
|
|
4712
|
-
getUint32(endOfDirectoryLocatorView, 0) == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
|
|
4713
|
-
directoryDataOffset = getDiskOffset$1(reader, getUint32(endOfDirectoryLocatorView, 4)) + getBigUint64(endOfDirectoryLocatorView, 8);
|
|
4793
|
+
getUint32$1(endOfDirectoryLocatorView, 0) == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
|
|
4794
|
+
directoryDataOffset = getDiskOffset$1(reader, getUint32$1(endOfDirectoryLocatorView, 4)) + getBigUint64(endOfDirectoryLocatorView, 8);
|
|
4714
4795
|
let endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
|
|
4715
4796
|
let endOfDirectoryView = getDataView(endOfDirectoryArray);
|
|
4716
4797
|
const expectedDirectoryDataOffset = endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH - ZIP64_END_OF_CENTRAL_DIR_LENGTH;
|
|
4717
|
-
if ((endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) &&
|
|
4798
|
+
if ((endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32$1(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) &&
|
|
4718
4799
|
directoryDataOffset != expectedDirectoryDataOffset && expectedDirectoryDataOffset >= 0) {
|
|
4719
4800
|
const originalDirectoryDataOffset = directoryDataOffset;
|
|
4720
4801
|
directoryDataOffset = expectedDirectoryDataOffset;
|
|
@@ -4724,7 +4805,7 @@
|
|
|
4724
4805
|
endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
|
|
4725
4806
|
endOfDirectoryView = getDataView(endOfDirectoryArray);
|
|
4726
4807
|
}
|
|
4727
|
-
if (endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
|
|
4808
|
+
if (endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32$1(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
|
|
4728
4809
|
throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
|
|
4729
4810
|
}
|
|
4730
4811
|
zip64EndOfDirectory = true;
|
|
@@ -4734,18 +4815,19 @@
|
|
|
4734
4815
|
Number(getBigUint64(endOfDirectoryView, 4)) - (ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12),
|
|
4735
4816
|
reader.size - directoryDataOffset - ZIP64_END_OF_CENTRAL_DIR_LENGTH);
|
|
4736
4817
|
if (extensibleDataLength > 0) {
|
|
4818
|
+
zip64EndOfDirectoryLength += extensibleDataLength;
|
|
4737
4819
|
const rawExtensibleData = await readUint8Array(reader, directoryDataOffset + ZIP64_END_OF_CENTRAL_DIR_LENGTH, extensibleDataLength);
|
|
4738
4820
|
directoryEncryptionInfo = getDirectoryEncryptionInfo(rawExtensibleData);
|
|
4739
4821
|
}
|
|
4740
4822
|
}
|
|
4741
4823
|
if (lastDiskNumber == MAX_16_BITS) {
|
|
4742
|
-
lastDiskNumber = getUint32(endOfDirectoryView, 16);
|
|
4743
|
-
} else if (checkAmbiguity && lastDiskNumber != getUint32(endOfDirectoryView, 16)) {
|
|
4824
|
+
lastDiskNumber = getUint32$1(endOfDirectoryView, 16);
|
|
4825
|
+
} else if (checkAmbiguity && lastDiskNumber != getUint32$1(endOfDirectoryView, 16)) {
|
|
4744
4826
|
throwAmbiguousArchive("mismatched zip64 end of central directory record");
|
|
4745
4827
|
}
|
|
4746
4828
|
if (diskNumber == MAX_16_BITS) {
|
|
4747
|
-
diskNumber = getUint32(endOfDirectoryView, 20);
|
|
4748
|
-
} else if (checkAmbiguity && diskNumber != getUint32(endOfDirectoryView, 20)) {
|
|
4829
|
+
diskNumber = getUint32$1(endOfDirectoryView, 20);
|
|
4830
|
+
} else if (checkAmbiguity && diskNumber != getUint32$1(endOfDirectoryView, 20)) {
|
|
4749
4831
|
throwAmbiguousArchive("mismatched zip64 end of central directory record");
|
|
4750
4832
|
}
|
|
4751
4833
|
if (filesLength == MAX_16_BITS) {
|
|
@@ -4763,7 +4845,7 @@
|
|
|
4763
4845
|
}
|
|
4764
4846
|
let declaredDirectoryDataLength = directoryDataLength;
|
|
4765
4847
|
const centralDirectoryEndOffset = endOfDirectoryInfo.offset -
|
|
4766
|
-
(zip64EndOfDirectory ?
|
|
4848
|
+
(zip64EndOfDirectory ? zip64EndOfDirectoryLength + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH : 0);
|
|
4767
4849
|
if (directoryDataOffset >= reader.size) {
|
|
4768
4850
|
prependedDataLength = reader.size - directoryDataOffset - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
|
|
4769
4851
|
directoryDataOffset = reader.size - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
|
|
@@ -4783,11 +4865,13 @@
|
|
|
4783
4865
|
}
|
|
4784
4866
|
const expectedDirectoryDataOffset = centralDirectoryEndOffset - directoryDataLength;
|
|
4785
4867
|
if (directoryDataOffset != expectedDirectoryDataOffset && diskNumber == lastDiskNumber) {
|
|
4786
|
-
const storedPointsAtDirectory = getUint32(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE
|
|
4868
|
+
const storedPointsAtDirectory = getUint32$1(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE ||
|
|
4869
|
+
Boolean(directoryEncryptionInfo && directoryEncryptionInfo.compressedSize) ||
|
|
4870
|
+
detectEncryptedCentralDirectory(directoryView);
|
|
4787
4871
|
let reconcile = !storedPointsAtDirectory;
|
|
4788
4872
|
if (!reconcile && expectedDirectoryDataOffset >= 0 && expectedDirectoryDataOffset + 4 <= reader.size) {
|
|
4789
4873
|
const expectedSignatureArray = await readUint8Array(reader, expectedDirectoryDataOffset, 4);
|
|
4790
|
-
reconcile = getUint32(getDataView(expectedSignatureArray), 0) == CENTRAL_FILE_HEADER_SIGNATURE;
|
|
4874
|
+
reconcile = getUint32$1(getDataView(expectedSignatureArray), 0) == CENTRAL_FILE_HEADER_SIGNATURE;
|
|
4791
4875
|
}
|
|
4792
4876
|
if (reconcile) {
|
|
4793
4877
|
const originalDirectoryDataOffset = directoryDataOffset;
|
|
@@ -4811,12 +4895,14 @@
|
|
|
4811
4895
|
}
|
|
4812
4896
|
zipReader.directoryOffset = directoryDataOffset;
|
|
4813
4897
|
zipReader.directoryLength = declaredDirectoryDataLength;
|
|
4814
|
-
const decryptCentralDirectory =
|
|
4815
|
-
let decryptedDirectory;
|
|
4898
|
+
const decryptCentralDirectory = getFunctionOptionValue$1(zipReader, options, OPTION_DECRYPT_CENTRAL_DIRECTORY);
|
|
4899
|
+
let decryptedDirectory, dataAfterEncryptedDirectory;
|
|
4816
4900
|
if (decryptCentralDirectory && filesLength && directoryArray.length >= 4 &&
|
|
4817
|
-
getUint32(directoryView, 0) != CENTRAL_FILE_HEADER_SIGNATURE &&
|
|
4901
|
+
getUint32$1(directoryView, 0) != CENTRAL_FILE_HEADER_SIGNATURE &&
|
|
4818
4902
|
(zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
|
|
4819
|
-
|
|
4903
|
+
const encryptedDirectoryDataLength = getEncryptedDirectoryDataLength(directoryEncryptionInfo, declaredDirectoryDataLength, directoryArray.length);
|
|
4904
|
+
dataAfterEncryptedDirectory = directoryArray.subarray(encryptedDirectoryDataLength);
|
|
4905
|
+
directoryArray = await decryptCentralDirectory(directoryArray.subarray(0, encryptedDirectoryDataLength), directoryEncryptionInfo);
|
|
4820
4906
|
directoryView = getDataView(directoryArray);
|
|
4821
4907
|
declaredDirectoryDataLength = directoryArray.length;
|
|
4822
4908
|
decryptedDirectory = true;
|
|
@@ -4827,8 +4913,8 @@
|
|
|
4827
4913
|
const filenames = checkAmbiguity ? new Set() : UNDEFINED_VALUE;
|
|
4828
4914
|
let duplicateFilename;
|
|
4829
4915
|
for (let indexFile = 0; indexFile < filesLength; indexFile++) {
|
|
4830
|
-
const fileEntry = new ZipEntry(reader,
|
|
4831
|
-
if (offset + CENTRAL_FILE_HEADER_LENGTH > directoryArray.length || getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
|
|
4916
|
+
const fileEntry = new ZipEntry(reader, zipReader.options);
|
|
4917
|
+
if (offset + CENTRAL_FILE_HEADER_LENGTH > directoryArray.length || getUint32$1(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
|
|
4832
4918
|
if (indexFile == 0 && !decryptedDirectory && (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
|
|
4833
4919
|
throw new Error(ERR_ENCRYPTED_CENTRAL_DIRECTORY);
|
|
4834
4920
|
}
|
|
@@ -4839,16 +4925,16 @@
|
|
|
4839
4925
|
const filenameOffset = offset + CENTRAL_FILE_HEADER_LENGTH;
|
|
4840
4926
|
const extraFieldOffset = filenameOffset + fileEntry.filenameLength;
|
|
4841
4927
|
const commentOffset = extraFieldOffset + fileEntry.extraFieldLength;
|
|
4842
|
-
const versionMadeBy = getUint16(directoryView, offset + 4);
|
|
4928
|
+
const versionMadeBy = getUint16$1(directoryView, offset + 4);
|
|
4843
4929
|
const msDosCompatible = versionMadeBy >> 8 == 0;
|
|
4844
4930
|
const unixCompatible = versionMadeBy >> 8 == 3;
|
|
4845
4931
|
const rawFilename = directoryArray.subarray(filenameOffset, extraFieldOffset);
|
|
4846
|
-
const commentLength = getUint16(directoryView, offset + 32);
|
|
4932
|
+
const commentLength = getUint16$1(directoryView, offset + 32);
|
|
4847
4933
|
const endOffset = commentOffset + commentLength;
|
|
4848
4934
|
const rawComment = directoryArray.subarray(commentOffset, endOffset);
|
|
4849
4935
|
const filenameUTF8 = languageEncodingFlag;
|
|
4850
4936
|
const commentUTF8 = languageEncodingFlag;
|
|
4851
|
-
const externalFileAttributes = getUint32(directoryView, offset + 38);
|
|
4937
|
+
const externalFileAttributes = getUint32$1(directoryView, offset + 38);
|
|
4852
4938
|
const msdosAttributesRaw = externalFileAttributes & MAX_8_BITS;
|
|
4853
4939
|
const msdosAttributes = {
|
|
4854
4940
|
readOnly: Boolean(msdosAttributesRaw & FILE_ATTR_MSDOS_READONLY_MASK),
|
|
@@ -4857,8 +4943,8 @@
|
|
|
4857
4943
|
directory: Boolean(msdosAttributesRaw & FILE_ATTR_MSDOS_DIR_MASK),
|
|
4858
4944
|
archive: Boolean(msdosAttributesRaw & FILE_ATTR_MSDOS_ARCHIVE_MASK)
|
|
4859
4945
|
};
|
|
4860
|
-
const offsetFileEntry = getUint32(directoryView, offset + 42);
|
|
4861
|
-
const decode =
|
|
4946
|
+
const offsetFileEntry = getUint32$1(directoryView, offset + 42);
|
|
4947
|
+
const decode = getFunctionOptionValue$1(zipReader, options, OPTION_DECODE_TEXT) || decodeText;
|
|
4862
4948
|
const rawFilenameEncoding = filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437;
|
|
4863
4949
|
const rawCommentEncoding = commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437;
|
|
4864
4950
|
let filename = decode(rawFilename, rawFilenameEncoding, TEXT_TYPE_FILENAME);
|
|
@@ -4882,6 +4968,7 @@
|
|
|
4882
4968
|
}
|
|
4883
4969
|
Object.assign(fileEntry, {
|
|
4884
4970
|
index: indexFile,
|
|
4971
|
+
decryptedDirectory,
|
|
4885
4972
|
versionMadeBy,
|
|
4886
4973
|
msDosCompatible,
|
|
4887
4974
|
zip64: false,
|
|
@@ -4889,8 +4976,8 @@
|
|
|
4889
4976
|
uncompressedSize: 0,
|
|
4890
4977
|
commentLength,
|
|
4891
4978
|
offset: offsetFileEntry,
|
|
4892
|
-
diskNumberStart: getUint16(directoryView, offset + 34),
|
|
4893
|
-
internalFileAttributes: getUint16(directoryView, offset + 36),
|
|
4979
|
+
diskNumberStart: getUint16$1(directoryView, offset + 34),
|
|
4980
|
+
internalFileAttributes: getUint16$1(directoryView, offset + 36),
|
|
4894
4981
|
externalFileAttributes,
|
|
4895
4982
|
msdosAttributesRaw,
|
|
4896
4983
|
msdosAttributes,
|
|
@@ -4958,12 +5045,11 @@
|
|
|
4958
5045
|
yield entry;
|
|
4959
5046
|
}
|
|
4960
5047
|
let offsetAfterSignature = offset;
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
}
|
|
5048
|
+
const digitalSignature = readDigitalSignature(directoryArray.subarray(offset)) ||
|
|
5049
|
+
(decryptedDirectory ? readDigitalSignature(dataAfterEncryptedDirectory) : UNDEFINED_VALUE);
|
|
5050
|
+
if (digitalSignature) {
|
|
5051
|
+
zipReader.digitalSignature = digitalSignature;
|
|
5052
|
+
offsetAfterSignature = offset + 6 + digitalSignature.length;
|
|
4967
5053
|
}
|
|
4968
5054
|
if (checkAmbiguity && offset != declaredDirectoryDataLength && offsetAfterSignature != declaredDirectoryDataLength) {
|
|
4969
5055
|
throwAmbiguousArchive("trailing central directory data");
|
|
@@ -4971,13 +5057,17 @@
|
|
|
4971
5057
|
if (duplicateFilename) {
|
|
4972
5058
|
throwAmbiguousArchive("duplicate filename");
|
|
4973
5059
|
}
|
|
4974
|
-
if (checkAmbiguity && (prependedDataLength || (filesLength && startOffset > 0))) {
|
|
4975
|
-
throwAmbiguousArchive("prepended data");
|
|
4976
|
-
}
|
|
4977
5060
|
const extractPrependedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_PREPENDED_DATA);
|
|
4978
5061
|
const extractAppendedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_APPENDED_DATA);
|
|
5062
|
+
const splitZipSignatureLength = (checkAmbiguity || extractPrependedData) && filesLength &&
|
|
5063
|
+
startOffset == SPLIT_ZIP_FILE_SIGNATURE_LENGTH && await startsWithSplitZipMarker(reader) ? SPLIT_ZIP_FILE_SIGNATURE_LENGTH : 0;
|
|
5064
|
+
if (checkAmbiguity && (prependedDataLength || (filesLength && startOffset > splitZipSignatureLength))) {
|
|
5065
|
+
throwAmbiguousArchive("prepended data");
|
|
5066
|
+
}
|
|
4979
5067
|
if (extractPrependedData) {
|
|
4980
|
-
zipReader.prependedData = startOffset >
|
|
5068
|
+
zipReader.prependedData = startOffset > splitZipSignatureLength ?
|
|
5069
|
+
await readUint8Array(reader, splitZipSignatureLength, startOffset - splitZipSignatureLength) :
|
|
5070
|
+
EMPTY_UINT8_ARRAY;
|
|
4981
5071
|
}
|
|
4982
5072
|
zipReader.comment = commentLength ? await readUint8Array(reader, commentOffset + END_OF_CENTRAL_DIR_LENGTH, commentLength) : EMPTY_UINT8_ARRAY;
|
|
4983
5073
|
if (extractAppendedData) {
|
|
@@ -5044,16 +5134,16 @@
|
|
|
5044
5134
|
|
|
5045
5135
|
class ZipEntry {
|
|
5046
5136
|
|
|
5047
|
-
constructor(reader,
|
|
5137
|
+
constructor(reader, options) {
|
|
5048
5138
|
Object.assign(this, {
|
|
5049
5139
|
reader,
|
|
5050
|
-
config,
|
|
5051
5140
|
options
|
|
5052
5141
|
});
|
|
5053
5142
|
}
|
|
5054
5143
|
|
|
5055
5144
|
async getData(writer, fileEntry, readRanges, options = {}) {
|
|
5056
5145
|
const zipEntry = this;
|
|
5146
|
+
const config = getConfiguration();
|
|
5057
5147
|
const {
|
|
5058
5148
|
reader,
|
|
5059
5149
|
index,
|
|
@@ -5062,7 +5152,6 @@
|
|
|
5062
5152
|
extraFieldAES,
|
|
5063
5153
|
extraFieldZip64,
|
|
5064
5154
|
compressionMethod,
|
|
5065
|
-
config,
|
|
5066
5155
|
bitFlag,
|
|
5067
5156
|
rawBitFlag,
|
|
5068
5157
|
crc32,
|
|
@@ -5080,6 +5169,7 @@
|
|
|
5080
5169
|
let password = getOptionValue$1(zipEntry, options, OPTION_PASSWORD);
|
|
5081
5170
|
let rawPassword = getOptionValue$1(zipEntry, options, OPTION_RAW_PASSWORD);
|
|
5082
5171
|
const passThrough = getOptionValue$1(zipEntry, options, OPTION_PASS_THROUGH);
|
|
5172
|
+
checkPasswordOption(password, rawPassword);
|
|
5083
5173
|
password = password && password.length && password;
|
|
5084
5174
|
rawPassword = rawPassword && rawPassword.length && rawPassword;
|
|
5085
5175
|
if (extraFieldAES) {
|
|
@@ -5087,7 +5177,7 @@
|
|
|
5087
5177
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
|
|
5088
5178
|
}
|
|
5089
5179
|
}
|
|
5090
|
-
if (dataArray.length < HEADER_SIZE || getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
|
|
5180
|
+
if (dataArray.length < HEADER_SIZE || getUint32$1(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
|
|
5091
5181
|
throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
|
|
5092
5182
|
}
|
|
5093
5183
|
readCommonHeader(localDirectory, dataView, 4);
|
|
@@ -5149,9 +5239,12 @@
|
|
|
5149
5239
|
}
|
|
5150
5240
|
}
|
|
5151
5241
|
const dataOffset = localHeaderOffset + HEADER_SIZE + filenameLength + extraFieldLength;
|
|
5242
|
+
if (dataOffset + compressedSize > reader.size) {
|
|
5243
|
+
throw new Error(ERR_ENTRY_DATA_OUT_OF_BOUNDS);
|
|
5244
|
+
}
|
|
5152
5245
|
const size = compressedSize;
|
|
5153
5246
|
const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
|
|
5154
|
-
const signal = getOptionValue$1(zipEntry, options, OPTION_SIGNAL);
|
|
5247
|
+
const signal = checkSignalOption(getOptionValue$1(zipEntry, options, OPTION_SIGNAL));
|
|
5155
5248
|
const checkPasswordOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_PASSWORD_ONLY);
|
|
5156
5249
|
let checkOverlappingEntry = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY);
|
|
5157
5250
|
const checkOverlappingEntryOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY_ONLY);
|
|
@@ -5159,6 +5252,8 @@
|
|
|
5159
5252
|
checkOverlappingEntry = true;
|
|
5160
5253
|
}
|
|
5161
5254
|
const { onstart, onprogress, onend } = options;
|
|
5255
|
+
const compressed = compressionMethod != COMPRESSION_METHOD_STORE && !passThrough;
|
|
5256
|
+
const outputSize = passThrough ? compressedSize : uncompressedSize;
|
|
5162
5257
|
const deflate64 = compressionMethod == COMPRESSION_METHOD_DEFLATE_64;
|
|
5163
5258
|
let useCompressionStream = getOptionValue$1(zipEntry, options, OPTION_USE_COMPRESSION_STREAM);
|
|
5164
5259
|
if (deflate64) {
|
|
@@ -5179,9 +5274,9 @@
|
|
|
5179
5274
|
checkCrc32,
|
|
5180
5275
|
checkAuthenticationCode: getOptionValue$1(zipEntry, options, OPTION_CHECK_AUTHENTICATION_CODE),
|
|
5181
5276
|
passwordVerification: zipCrypto && (dataDescriptor ? ((rawLastModDate >>> 8) & MAX_8_BITS) : ((crc32 >>> 24) & MAX_8_BITS)),
|
|
5182
|
-
outputSize
|
|
5277
|
+
outputSize,
|
|
5183
5278
|
crc32,
|
|
5184
|
-
compressed
|
|
5279
|
+
compressed,
|
|
5185
5280
|
encrypted,
|
|
5186
5281
|
useWebWorkers: getOptionValue$1(zipEntry, options, OPTION_USE_WEB_WORKERS),
|
|
5187
5282
|
useCompressionStream,
|
|
@@ -5218,11 +5313,11 @@
|
|
|
5218
5313
|
writer = new WritableStream();
|
|
5219
5314
|
}
|
|
5220
5315
|
writer = new GenericWriter(writer);
|
|
5221
|
-
await initStream(writer,
|
|
5316
|
+
await initStream(writer, getDecodableOutputSize(outputSize, compressedSize, compressed));
|
|
5222
5317
|
({ writable } = writer);
|
|
5223
|
-
const { outputSize } = await runWorker({ readable, writable }, workerOptions);
|
|
5224
|
-
writer.size +=
|
|
5225
|
-
if (
|
|
5318
|
+
const { outputSize: writtenSize } = await runWorker({ readable, writable }, workerOptions);
|
|
5319
|
+
writer.size += writtenSize;
|
|
5320
|
+
if (writtenSize != outputSize) {
|
|
5226
5321
|
throw new Error(ERR_INVALID_UNCOMPRESSED_SIZE);
|
|
5227
5322
|
}
|
|
5228
5323
|
}
|
|
@@ -5256,26 +5351,47 @@
|
|
|
5256
5351
|
function detectEncryptedCentralDirectory(directoryView) {
|
|
5257
5352
|
const maxOffset = Math.min(directoryView.byteLength, 1024) - 3;
|
|
5258
5353
|
for (let offset = 0; offset < maxOffset; offset++) {
|
|
5259
|
-
if (getUint32(directoryView, offset) == ARCHIVE_EXTRA_DATA_SIGNATURE) {
|
|
5354
|
+
if (getUint32$1(directoryView, offset) == ARCHIVE_EXTRA_DATA_SIGNATURE) {
|
|
5260
5355
|
return true;
|
|
5261
5356
|
}
|
|
5262
5357
|
}
|
|
5263
5358
|
return false;
|
|
5264
5359
|
}
|
|
5265
5360
|
|
|
5361
|
+
function readDigitalSignature(signatureRecordArray) {
|
|
5362
|
+
if (signatureRecordArray.length >= 6) {
|
|
5363
|
+
const signatureRecordView = getDataView(signatureRecordArray);
|
|
5364
|
+
if (getUint32$1(signatureRecordView, 0) == DIGITAL_SIGNATURE_RECORD_SIGNATURE) {
|
|
5365
|
+
const signatureDataLength = getUint16$1(signatureRecordView, 4);
|
|
5366
|
+
if (6 + signatureDataLength <= signatureRecordArray.length) {
|
|
5367
|
+
return signatureRecordArray.subarray(6, 6 + signatureDataLength);
|
|
5368
|
+
}
|
|
5369
|
+
}
|
|
5370
|
+
}
|
|
5371
|
+
}
|
|
5372
|
+
|
|
5373
|
+
function getEncryptedDirectoryDataLength(directoryEncryptionInfo, declaredDirectoryDataLength, directoryDataLength) {
|
|
5374
|
+
const encryptedDirectoryDataLength = directoryEncryptionInfo && directoryEncryptionInfo.compressedSize ?
|
|
5375
|
+
directoryEncryptionInfo.compressedSize :
|
|
5376
|
+
declaredDirectoryDataLength;
|
|
5377
|
+
return encryptedDirectoryDataLength > 0 && encryptedDirectoryDataLength <= directoryDataLength ?
|
|
5378
|
+
encryptedDirectoryDataLength :
|
|
5379
|
+
directoryDataLength;
|
|
5380
|
+
}
|
|
5381
|
+
|
|
5266
5382
|
function getDirectoryEncryptionInfo(rawExtensibleData) {
|
|
5267
5383
|
const directoryEncryptionInfo = { rawExtensibleData };
|
|
5268
5384
|
if (rawExtensibleData.length >= 28) {
|
|
5269
5385
|
const extensibleDataView = getDataView(rawExtensibleData);
|
|
5270
|
-
const hashDataLength = getUint16(extensibleDataView, 26);
|
|
5386
|
+
const hashDataLength = getUint16$1(extensibleDataView, 26);
|
|
5271
5387
|
Object.assign(directoryEncryptionInfo, {
|
|
5272
|
-
compressionMethod: getUint16(extensibleDataView, 0),
|
|
5388
|
+
compressionMethod: getUint16$1(extensibleDataView, 0),
|
|
5273
5389
|
compressedSize: Number(getBigUint64(extensibleDataView, 2)),
|
|
5274
5390
|
uncompressedSize: Number(getBigUint64(extensibleDataView, 10)),
|
|
5275
|
-
encryptionAlgorithm: getUint16(extensibleDataView, 18),
|
|
5276
|
-
bitLength: getUint16(extensibleDataView, 20),
|
|
5277
|
-
flags: getUint16(extensibleDataView, 22),
|
|
5278
|
-
hashAlgorithm: getUint16(extensibleDataView, 24),
|
|
5391
|
+
encryptionAlgorithm: getUint16$1(extensibleDataView, 18),
|
|
5392
|
+
bitLength: getUint16$1(extensibleDataView, 20),
|
|
5393
|
+
flags: getUint16$1(extensibleDataView, 22),
|
|
5394
|
+
hashAlgorithm: getUint16$1(extensibleDataView, 24),
|
|
5279
5395
|
hashData: rawExtensibleData.subarray(28, 28 + hashDataLength)
|
|
5280
5396
|
});
|
|
5281
5397
|
}
|
|
@@ -5283,12 +5399,12 @@
|
|
|
5283
5399
|
}
|
|
5284
5400
|
|
|
5285
5401
|
function readCommonHeader(directory, dataView, offset) {
|
|
5286
|
-
const rawBitFlag = directory.rawBitFlag = getUint16(dataView, offset + 2);
|
|
5402
|
+
const rawBitFlag = directory.rawBitFlag = getUint16$1(dataView, offset + 2);
|
|
5287
5403
|
const encrypted = (rawBitFlag & BITFLAG_ENCRYPTED) == BITFLAG_ENCRYPTED;
|
|
5288
|
-
const rawLastModDate = getUint32(dataView, offset + 6);
|
|
5404
|
+
const rawLastModDate = getUint32$1(dataView, offset + 6);
|
|
5289
5405
|
Object.assign(directory, {
|
|
5290
5406
|
encrypted,
|
|
5291
|
-
version: getUint16(dataView, offset),
|
|
5407
|
+
version: getUint16$1(dataView, offset),
|
|
5292
5408
|
bitFlag: {
|
|
5293
5409
|
level: (rawBitFlag & BITFLAG_LEVEL) >> 1,
|
|
5294
5410
|
dataDescriptor: (rawBitFlag & BITFLAG_DATA_DESCRIPTOR) == BITFLAG_DATA_DESCRIPTOR,
|
|
@@ -5296,8 +5412,8 @@
|
|
|
5296
5412
|
},
|
|
5297
5413
|
rawLastModDate,
|
|
5298
5414
|
lastModDate: getDate(rawLastModDate),
|
|
5299
|
-
filenameLength: getUint16(dataView, offset + 22),
|
|
5300
|
-
extraFieldLength: getUint16(dataView, offset + 24)
|
|
5415
|
+
filenameLength: getUint16$1(dataView, offset + 22),
|
|
5416
|
+
extraFieldLength: getUint16$1(dataView, offset + 24)
|
|
5301
5417
|
});
|
|
5302
5418
|
}
|
|
5303
5419
|
|
|
@@ -5308,8 +5424,8 @@
|
|
|
5308
5424
|
let offsetExtraField = 0;
|
|
5309
5425
|
try {
|
|
5310
5426
|
while (offsetExtraField < rawExtraField.length) {
|
|
5311
|
-
const type = getUint16(rawExtraFieldView, offsetExtraField);
|
|
5312
|
-
const size = getUint16(rawExtraFieldView, offsetExtraField + 2);
|
|
5427
|
+
const type = getUint16$1(rawExtraFieldView, offsetExtraField);
|
|
5428
|
+
const size = getUint16$1(rawExtraFieldView, offsetExtraField + 2);
|
|
5313
5429
|
extraField.set(type, {
|
|
5314
5430
|
type,
|
|
5315
5431
|
data: rawExtraField.slice(offsetExtraField + 4, offsetExtraField + 4 + size)
|
|
@@ -5319,12 +5435,12 @@
|
|
|
5319
5435
|
} catch {
|
|
5320
5436
|
// ignored
|
|
5321
5437
|
}
|
|
5322
|
-
const compressionMethod = getUint16(dataView, offset + 4);
|
|
5438
|
+
const compressionMethod = getUint16$1(dataView, offset + 4);
|
|
5323
5439
|
Object.assign(directory, {
|
|
5324
|
-
signature: getUint32(dataView, offset + HEADER_OFFSET_SIGNATURE),
|
|
5325
|
-
crc32: getUint32(dataView, offset + HEADER_OFFSET_SIGNATURE),
|
|
5326
|
-
compressedSize: getUint32(dataView, offset + HEADER_OFFSET_COMPRESSED_SIZE),
|
|
5327
|
-
uncompressedSize: getUint32(dataView, offset + HEADER_OFFSET_UNCOMPRESSED_SIZE)
|
|
5440
|
+
signature: getUint32$1(dataView, offset + HEADER_OFFSET_SIGNATURE),
|
|
5441
|
+
crc32: getUint32$1(dataView, offset + HEADER_OFFSET_SIGNATURE),
|
|
5442
|
+
compressedSize: getUint32$1(dataView, offset + HEADER_OFFSET_COMPRESSED_SIZE),
|
|
5443
|
+
uncompressedSize: getUint32$1(dataView, offset + HEADER_OFFSET_UNCOMPRESSED_SIZE)
|
|
5328
5444
|
});
|
|
5329
5445
|
const extraFieldZip64 = extraField.get(EXTRAFIELD_TYPE_ZIP64);
|
|
5330
5446
|
if (extraFieldZip64) {
|
|
@@ -5413,11 +5529,11 @@
|
|
|
5413
5529
|
computedCrc32.append(fileEntry[rawPropertyName]);
|
|
5414
5530
|
const computedCrc32View = getDataView(new Uint8Array(4));
|
|
5415
5531
|
computedCrc32View.setUint32(0, computedCrc32.get(), true);
|
|
5416
|
-
const nameCrc32 = getUint32(extraFieldView, 1);
|
|
5532
|
+
const nameCrc32 = getUint32$1(extraFieldView, 1);
|
|
5417
5533
|
Object.assign(extraFieldUnicode, {
|
|
5418
5534
|
version: getUint8(extraFieldView, 0),
|
|
5419
5535
|
[propertyName]: decodeText(extraFieldUnicode.data.subarray(5)),
|
|
5420
|
-
valid: !fileEntry.bitFlag.languageEncodingFlag && nameCrc32 == getUint32(computedCrc32View, 0)
|
|
5536
|
+
valid: !fileEntry.bitFlag.languageEncodingFlag && nameCrc32 == getUint32$1(computedCrc32View, 0)
|
|
5421
5537
|
});
|
|
5422
5538
|
if (extraFieldUnicode.valid) {
|
|
5423
5539
|
directory[propertyName] = extraFieldUnicode[propertyName];
|
|
@@ -5433,7 +5549,7 @@
|
|
|
5433
5549
|
vendorId: getUint8(extraFieldView, 2),
|
|
5434
5550
|
strength,
|
|
5435
5551
|
originalCompressionMethod: compressionMethod,
|
|
5436
|
-
compressionMethod: getUint16(extraFieldView, 5)
|
|
5552
|
+
compressionMethod: getUint16$1(extraFieldView, 5)
|
|
5437
5553
|
});
|
|
5438
5554
|
directory.compressionMethod = extraFieldAES.compressionMethod;
|
|
5439
5555
|
if (extraFieldAES.vendorVersion != VENDOR_VERSION_AE_1$1) {
|
|
@@ -5447,8 +5563,8 @@
|
|
|
5447
5563
|
let tag1Data;
|
|
5448
5564
|
try {
|
|
5449
5565
|
while (offsetExtraField < extraFieldNTFS.data.length && !tag1Data) {
|
|
5450
|
-
const tagValue = getUint16(extraFieldView, offsetExtraField);
|
|
5451
|
-
const attributeSize = getUint16(extraFieldView, offsetExtraField + 2);
|
|
5566
|
+
const tagValue = getUint16$1(extraFieldView, offsetExtraField);
|
|
5567
|
+
const attributeSize = getUint16$1(extraFieldView, offsetExtraField + 2);
|
|
5452
5568
|
if (tagValue == EXTRAFIELD_TYPE_NTFS_TAG1) {
|
|
5453
5569
|
tag1Data = extraFieldNTFS.data.slice(offsetExtraField + 4, offsetExtraField + 4 + attributeSize);
|
|
5454
5570
|
}
|
|
@@ -5481,12 +5597,12 @@
|
|
|
5481
5597
|
return;
|
|
5482
5598
|
}
|
|
5483
5599
|
const extraFieldView = getDataView(extraField.data);
|
|
5484
|
-
const lastAccessDate = new Date((getUint32(extraFieldView, 0) | 0) * 1000);
|
|
5485
|
-
const lastModDate = new Date((getUint32(extraFieldView, 4) | 0) * 1000);
|
|
5600
|
+
const lastAccessDate = new Date((getUint32$1(extraFieldView, 0) | 0) * 1000);
|
|
5601
|
+
const lastModDate = new Date((getUint32$1(extraFieldView, 4) | 0) * 1000);
|
|
5486
5602
|
const extraFieldData = { lastAccessDate, lastModDate };
|
|
5487
5603
|
if (extraField.data.length >= 12) {
|
|
5488
|
-
extraFieldData.uid = getUint16(extraFieldView, 8);
|
|
5489
|
-
extraFieldData.gid = getUint16(extraFieldView, 10);
|
|
5604
|
+
extraFieldData.uid = getUint16$1(extraFieldView, 8);
|
|
5605
|
+
extraFieldData.gid = getUint16$1(extraFieldView, 10);
|
|
5490
5606
|
}
|
|
5491
5607
|
Object.assign(extraField, extraFieldData);
|
|
5492
5608
|
Object.assign(directory, extraFieldData);
|
|
@@ -5506,8 +5622,8 @@
|
|
|
5506
5622
|
gid = unpackUnixId(extraField.data.subarray(offset, offset + gidSize));
|
|
5507
5623
|
Object.assign(extraField, { version, uid, gid });
|
|
5508
5624
|
} else if (extraField.data.length >= 4) {
|
|
5509
|
-
uid = getUint16(view, 0);
|
|
5510
|
-
gid = getUint16(view, 2);
|
|
5625
|
+
uid = getUint16$1(view, 0);
|
|
5626
|
+
gid = getUint16$1(view, 2);
|
|
5511
5627
|
Object.assign(extraField, { uid, gid });
|
|
5512
5628
|
}
|
|
5513
5629
|
if (uid !== UNDEFINED_VALUE) {
|
|
@@ -5557,7 +5673,7 @@
|
|
|
5557
5673
|
let offset = 1;
|
|
5558
5674
|
timeProperties.forEach((propertyName, indexProperty) => {
|
|
5559
5675
|
if (extraFieldExtendedTimestamp.data.length >= offset + 4) {
|
|
5560
|
-
const time = getUint32(extraFieldView, offset);
|
|
5676
|
+
const time = getUint32$1(extraFieldView, offset);
|
|
5561
5677
|
directory[propertyName] = extraFieldExtendedTimestamp[propertyName] = new Date((time | 0) * 1000);
|
|
5562
5678
|
const rawPropertyName = timeRawProperties[indexProperty];
|
|
5563
5679
|
extraFieldExtendedTimestamp[rawPropertyName] = time;
|
|
@@ -5591,7 +5707,7 @@
|
|
|
5591
5707
|
const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
|
|
5592
5708
|
const dataDescriptorView = getDataView(dataDescriptorArray);
|
|
5593
5709
|
let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
|
|
5594
|
-
getUint32(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
|
|
5710
|
+
getUint32$1(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
|
|
5595
5711
|
if (signature) {
|
|
5596
5712
|
const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
|
|
5597
5713
|
const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
|
|
@@ -5625,15 +5741,15 @@
|
|
|
5625
5741
|
}
|
|
5626
5742
|
|
|
5627
5743
|
function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
|
|
5628
|
-
const crc32 = getUint32(dataDescriptorView, offset);
|
|
5744
|
+
const crc32 = getUint32$1(dataDescriptorView, offset);
|
|
5629
5745
|
let compressedSize;
|
|
5630
5746
|
let uncompressedSize;
|
|
5631
5747
|
if (extraFieldZip64) {
|
|
5632
5748
|
compressedSize = getBigUint64(dataDescriptorView, offset + 4);
|
|
5633
5749
|
uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
|
|
5634
5750
|
} else {
|
|
5635
|
-
compressedSize = getUint32(dataDescriptorView, offset + 4);
|
|
5636
|
-
uncompressedSize = getUint32(dataDescriptorView, offset + 8);
|
|
5751
|
+
compressedSize = getUint32$1(dataDescriptorView, offset + 4);
|
|
5752
|
+
uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
|
|
5637
5753
|
}
|
|
5638
5754
|
return { crc32, compressedSize, uncompressedSize };
|
|
5639
5755
|
}
|
|
@@ -5642,10 +5758,28 @@
|
|
|
5642
5758
|
return reader.getDiskOffset ? reader.getDiskOffset(diskNumber) : 0;
|
|
5643
5759
|
}
|
|
5644
5760
|
|
|
5761
|
+
async function startsWithSplitZipSignature$1(reader) {
|
|
5762
|
+
return await getFirstSignature(reader) == SPLIT_ZIP_FILE_SIGNATURE;
|
|
5763
|
+
}
|
|
5764
|
+
|
|
5765
|
+
async function startsWithSplitZipMarker(reader) {
|
|
5766
|
+
const signature = await getFirstSignature(reader);
|
|
5767
|
+
return signature == SPLIT_ZIP_FILE_SIGNATURE || signature == TEMPORARY_SPLIT_ZIP_FILE_SIGNATURE;
|
|
5768
|
+
}
|
|
5769
|
+
|
|
5770
|
+
async function getFirstSignature(reader) {
|
|
5771
|
+
const signatureArray = await readUint8Array(reader, 0, SPLIT_ZIP_FILE_SIGNATURE_LENGTH);
|
|
5772
|
+
return getUint32$1(getDataView(signatureArray));
|
|
5773
|
+
}
|
|
5774
|
+
|
|
5645
5775
|
function isStrictnessValue(value) {
|
|
5646
5776
|
return value === STRICTNESS_STRICT || value === STRICTNESS_BALANCED || value === STRICTNESS_TOLERANT;
|
|
5647
5777
|
}
|
|
5648
5778
|
|
|
5779
|
+
function getDecodableOutputSize(outputSize, compressedSize, compressed) {
|
|
5780
|
+
return Math.min(outputSize, compressed ? compressedSize * MAX_DEFLATE_EXPANSION_RATIO : compressedSize);
|
|
5781
|
+
}
|
|
5782
|
+
|
|
5649
5783
|
function getStrictness(options, inheritedOptions) {
|
|
5650
5784
|
return resolveStrictness(options, resolveStrictness(inheritedOptions, STRICTNESS_BALANCED));
|
|
5651
5785
|
}
|
|
@@ -5708,7 +5842,7 @@
|
|
|
5708
5842
|
|
|
5709
5843
|
function getMaxAppendedDataSize(maxAppendedDataSize, strictness) {
|
|
5710
5844
|
if (maxAppendedDataSize !== UNDEFINED_VALUE) {
|
|
5711
|
-
const size = toNumber
|
|
5845
|
+
const size = toNumber(maxAppendedDataSize);
|
|
5712
5846
|
if (typeof size != NUMBER_TYPE || Number.isNaN(size) || size < 0) {
|
|
5713
5847
|
throw new Error(ERR_INVALID_MAX_APPENDED_DATA_SIZE);
|
|
5714
5848
|
}
|
|
@@ -5731,7 +5865,7 @@
|
|
|
5731
5865
|
let plausibleEndOfDirectoryInfo;
|
|
5732
5866
|
let endOfDirectoryReachingEndCount = 0;
|
|
5733
5867
|
for await (const [anchoredView, anchoredOffset, anchoredArray, indexByte, offset] of scanEndOfCentralDirectory(reader, anchoredLength)) {
|
|
5734
|
-
const commentLength = getUint16(anchoredView, indexByte + 20);
|
|
5868
|
+
const commentLength = getUint16$1(anchoredView, indexByte + 20);
|
|
5735
5869
|
if (offset + END_OF_CENTRAL_DIR_LENGTH + commentLength == size) {
|
|
5736
5870
|
const reachability = await getCentralDirectoryReachability(reader, anchoredView, anchoredOffset, indexByte, offset, size, remoteProbeBudget);
|
|
5737
5871
|
if (reachability == CENTRAL_DIRECTORY_REACHABLE) {
|
|
@@ -5782,7 +5916,7 @@
|
|
|
5782
5916
|
const scanArray = await readUint8Array(reader, scanOffset, scanLength);
|
|
5783
5917
|
const scanView = getDataView(scanArray);
|
|
5784
5918
|
for (let indexByte = scanArray.length - END_OF_CENTRAL_DIR_LENGTH; indexByte >= 0; indexByte--) {
|
|
5785
|
-
if (getUint32(scanView, indexByte) == END_OF_CENTRAL_DIR_SIGNATURE) {
|
|
5919
|
+
if (getUint32$1(scanView, indexByte) == END_OF_CENTRAL_DIR_SIGNATURE) {
|
|
5786
5920
|
yield [scanView, scanOffset, scanArray, indexByte, scanOffset + indexByte];
|
|
5787
5921
|
}
|
|
5788
5922
|
}
|
|
@@ -5793,9 +5927,9 @@
|
|
|
5793
5927
|
}
|
|
5794
5928
|
|
|
5795
5929
|
async function getCentralDirectoryReachability(reader, view, anchoredOffset, indexByte, offset, size, remoteProbeBudget) {
|
|
5796
|
-
const filesLength = getUint16(view, indexByte + 10);
|
|
5797
|
-
const directoryDataLength = getUint32(view, indexByte + 12);
|
|
5798
|
-
const directoryDataOffset = getUint32(view, indexByte + 16);
|
|
5930
|
+
const filesLength = getUint16$1(view, indexByte + 10);
|
|
5931
|
+
const directoryDataLength = getUint32$1(view, indexByte + 12);
|
|
5932
|
+
const directoryDataOffset = getUint32$1(view, indexByte + 16);
|
|
5799
5933
|
if (filesLength == MAX_16_BITS || directoryDataLength == MAX_32_BITS || directoryDataOffset == MAX_32_BITS) {
|
|
5800
5934
|
const locatorSignature = await readSignature(reader, view, anchoredOffset, offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, size, remoteProbeBudget);
|
|
5801
5935
|
return locatorSignature == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE ? CENTRAL_DIRECTORY_REACHABLE : CENTRAL_DIRECTORY_UNREACHABLE;
|
|
@@ -5803,7 +5937,7 @@
|
|
|
5803
5937
|
if (!filesLength && !directoryDataLength) {
|
|
5804
5938
|
return CENTRAL_DIRECTORY_PLAUSIBLE;
|
|
5805
5939
|
}
|
|
5806
|
-
const directoryDiskNumber = getUint16(view, indexByte + 6);
|
|
5940
|
+
const directoryDiskNumber = getUint16$1(view, indexByte + 6);
|
|
5807
5941
|
for (const centralDirectoryOffset of [offset - directoryDataLength, getDiskOffset$1(reader, directoryDiskNumber) + directoryDataOffset]) {
|
|
5808
5942
|
if (await readSignature(reader, view, anchoredOffset, centralDirectoryOffset, size, remoteProbeBudget) == CENTRAL_FILE_HEADER_SIGNATURE) {
|
|
5809
5943
|
return CENTRAL_DIRECTORY_REACHABLE;
|
|
@@ -5817,19 +5951,21 @@
|
|
|
5817
5951
|
return UNDEFINED_VALUE;
|
|
5818
5952
|
}
|
|
5819
5953
|
if (signatureOffset >= anchoredOffset) {
|
|
5820
|
-
return getUint32(view, signatureOffset - anchoredOffset);
|
|
5954
|
+
return getUint32$1(view, signatureOffset - anchoredOffset);
|
|
5821
5955
|
}
|
|
5822
5956
|
if (remoteProbeBudget.count > 0) {
|
|
5823
5957
|
remoteProbeBudget.count--;
|
|
5824
5958
|
const signatureArray = await readUint8Array(reader, signatureOffset, 4);
|
|
5825
|
-
return getUint32(getDataView(signatureArray), 0);
|
|
5959
|
+
return getUint32$1(getDataView(signatureArray), 0);
|
|
5826
5960
|
}
|
|
5827
5961
|
return UNDEFINED_VALUE;
|
|
5828
5962
|
}
|
|
5829
5963
|
|
|
5830
5964
|
function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename) {
|
|
5831
5965
|
const { rawFilename } = zipEntry;
|
|
5832
|
-
|
|
5966
|
+
const maskedLocalDirectory = zipEntry.decryptedDirectory &&
|
|
5967
|
+
(localDirectory.rawBitFlag & BITFLAG_MASKED_LOCAL_HEADERS) == BITFLAG_MASKED_LOCAL_HEADERS;
|
|
5968
|
+
if (checkLocalFilename && !maskedLocalDirectory &&
|
|
5833
5969
|
(rawLocalFilename.length != rawFilename.length ||
|
|
5834
5970
|
rawLocalFilename.some((byteValue, indexByte) => byteValue != rawFilename[indexByte]))) {
|
|
5835
5971
|
throwAmbiguousArchive("mismatched local file header (filename)");
|
|
@@ -5840,7 +5976,7 @@
|
|
|
5840
5976
|
if (localDirectory.compressionMethod != zipEntry.compressionMethod) {
|
|
5841
5977
|
throwAmbiguousArchive("mismatched local file header (compression method)");
|
|
5842
5978
|
}
|
|
5843
|
-
if (!localDirectory.bitFlag.dataDescriptor &&
|
|
5979
|
+
if (!localDirectory.bitFlag.dataDescriptor && !maskedLocalDirectory &&
|
|
5844
5980
|
(localDirectory.crc32 || localDirectory.compressedSize || localDirectory.uncompressedSize) &&
|
|
5845
5981
|
(localDirectory.crc32 != zipEntry.crc32 ||
|
|
5846
5982
|
localDirectory.compressedSize != zipEntry.compressedSize ||
|
|
@@ -5859,10 +5995,11 @@
|
|
|
5859
5995
|
return options[name] === UNDEFINED_VALUE ? zipReader.options[name] : options[name];
|
|
5860
5996
|
}
|
|
5861
5997
|
|
|
5862
|
-
function
|
|
5863
|
-
return
|
|
5998
|
+
function getFunctionOptionValue$1(zipReader, options, name) {
|
|
5999
|
+
return checkFunctionOption(getOptionValue$1(zipReader, options, name));
|
|
5864
6000
|
}
|
|
5865
6001
|
|
|
6002
|
+
|
|
5866
6003
|
function getDate(timeRaw) {
|
|
5867
6004
|
const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & MAX_16_BITS;
|
|
5868
6005
|
return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
|
|
@@ -5876,11 +6013,11 @@
|
|
|
5876
6013
|
return view.getUint8(offset);
|
|
5877
6014
|
}
|
|
5878
6015
|
|
|
5879
|
-
function getUint16(view, offset) {
|
|
6016
|
+
function getUint16$1(view, offset) {
|
|
5880
6017
|
return view.getUint16(offset, true);
|
|
5881
6018
|
}
|
|
5882
6019
|
|
|
5883
|
-
function getUint32(view, offset) {
|
|
6020
|
+
function getUint32$1(view, offset) {
|
|
5884
6021
|
return view.getUint32(offset, true);
|
|
5885
6022
|
}
|
|
5886
6023
|
|
|
@@ -5895,6 +6032,7 @@
|
|
|
5895
6032
|
ERR_CENTRAL_DIRECTORY_NOT_FOUND: ERR_CENTRAL_DIRECTORY_NOT_FOUND,
|
|
5896
6033
|
ERR_ENCRYPTED: ERR_ENCRYPTED,
|
|
5897
6034
|
ERR_ENCRYPTED_CENTRAL_DIRECTORY: ERR_ENCRYPTED_CENTRAL_DIRECTORY,
|
|
6035
|
+
ERR_ENTRY_DATA_OUT_OF_BOUNDS: ERR_ENTRY_DATA_OUT_OF_BOUNDS,
|
|
5898
6036
|
ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND,
|
|
5899
6037
|
ERR_EOCDR_NOT_FOUND: ERR_EOCDR_NOT_FOUND,
|
|
5900
6038
|
ERR_EXTRAFIELD_ZIP64_NOT_FOUND: ERR_EXTRAFIELD_ZIP64_NOT_FOUND,
|
|
@@ -5951,12 +6089,16 @@
|
|
|
5951
6089
|
const ERR_INVALID_COMMENT = "Zip file comment exceeds 64KB";
|
|
5952
6090
|
const ERR_INVALID_COMMENT_TYPE = "Invalid zip file comment (must be a Uint8Array)";
|
|
5953
6091
|
const ERR_INVALID_ENTRY_COMMENT = "File entry comment exceeds 64KB";
|
|
6092
|
+
const ERR_INVALID_ENTRY_COMMENT_TYPE = "Invalid file entry comment (must be a string)";
|
|
6093
|
+
const ERR_INVALID_DATE = "Invalid date (must be a valid Date instance)";
|
|
5954
6094
|
const ERR_INVALID_ENTRY_NAME = "File entry name exceeds 64KB";
|
|
5955
6095
|
const ERR_INVALID_VERSION = "Version exceeds 65535";
|
|
5956
6096
|
const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
|
|
5957
6097
|
const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
|
|
5958
6098
|
const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
|
|
5959
|
-
const
|
|
6099
|
+
const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
|
|
6100
|
+
const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
|
|
6101
|
+
const ERR_INVALID_EXTRAFIELD_DATA_TYPE = "Invalid extra field data (must be a Uint8Array)";
|
|
5960
6102
|
const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
|
|
5961
6103
|
const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
|
|
5962
6104
|
const MIN_UNIX_TIME = -2147483648;
|
|
@@ -5965,6 +6107,7 @@
|
|
|
5965
6107
|
const MAX_NTFS_TIME = BigInt("0x7fffffffffffffff");
|
|
5966
6108
|
const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (set the 'zip64' option to 'true')";
|
|
5967
6109
|
const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
|
|
6110
|
+
const ERR_UNDEFINED_COMPRESSION_METHOD = "Undefined compression method";
|
|
5968
6111
|
const ERR_UNDETERMINED_SIZE = "Undetermined size";
|
|
5969
6112
|
const ERR_UNDEFINED_READER = "Undefined reader";
|
|
5970
6113
|
const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
|
|
@@ -5976,7 +6119,6 @@
|
|
|
5976
6119
|
const ERR_INVALID_MSDOS_ATTRIBUTES = "Invalid msdosAttributesRaw (must be integer 0..255)";
|
|
5977
6120
|
const ERR_INVALID_MSDOS_DATA = "Invalid msdosAttributes (must be an object with boolean flags)";
|
|
5978
6121
|
const ERR_INVALID_LEVEL = "Invalid level (must be integer 0..9)";
|
|
5979
|
-
const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
|
|
5980
6122
|
const ERR_INVALID_SIGNATURE_DATA = "Signature data exceeds 64KB";
|
|
5981
6123
|
|
|
5982
6124
|
const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
|
|
@@ -6001,8 +6143,7 @@
|
|
|
6001
6143
|
writer,
|
|
6002
6144
|
addSplitZipSignature,
|
|
6003
6145
|
options,
|
|
6004
|
-
|
|
6005
|
-
files: new Map(),
|
|
6146
|
+
fileEntries: new Map(),
|
|
6006
6147
|
filenames: new Set(),
|
|
6007
6148
|
offset: options[OPTION_OFFSET] === UNDEFINED_VALUE ? writer.size || writer.writable.size || 0 : options[OPTION_OFFSET],
|
|
6008
6149
|
initialOffset: options[OPTION_OFFSET] === UNDEFINED_VALUE ? 0 : options[OPTION_OFFSET] - (writer.size || writer.writable.size || 0),
|
|
@@ -6023,14 +6164,23 @@
|
|
|
6023
6164
|
await initStream(reader);
|
|
6024
6165
|
}
|
|
6025
6166
|
const { ZipReader } = await Promise.resolve().then(function () { return zipReader; });
|
|
6026
|
-
const zipReader$1 = new ZipReader(reader
|
|
6167
|
+
const zipReader$1 = new ZipReader(reader);
|
|
6027
6168
|
const entries = await zipReader$1.getEntries();
|
|
6028
6169
|
await zipReader$1.close();
|
|
6029
6170
|
await initStream(this.writer);
|
|
6030
|
-
|
|
6031
|
-
|
|
6171
|
+
const { directoryOffset } = zipReader$1;
|
|
6172
|
+
let splitZipSignatureLength = 0;
|
|
6173
|
+
if (this.addSplitZipSignature) {
|
|
6174
|
+
delete this.addSplitZipSignature;
|
|
6175
|
+
if (!await startsWithSplitZipSignature(reader)) {
|
|
6176
|
+
await writeData(this.writer, getSplitZipSignatureArray());
|
|
6177
|
+
splitZipSignatureLength = SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
|
|
6178
|
+
this.offset += splitZipSignatureLength;
|
|
6179
|
+
}
|
|
6180
|
+
}
|
|
6181
|
+
const entryPositions = await copyZipData(this, reader, entries, directoryOffset, splitZipSignatureLength);
|
|
6032
6182
|
this.filenames = new Set(entries.map(entry => entry.filename));
|
|
6033
|
-
this.
|
|
6183
|
+
this.fileEntries = new Map(entries.map(entry => {
|
|
6034
6184
|
const {
|
|
6035
6185
|
version,
|
|
6036
6186
|
rawLastModDate,
|
|
@@ -6085,11 +6235,12 @@
|
|
|
6085
6235
|
if (crc32 !== UNDEFINED_VALUE) {
|
|
6086
6236
|
setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
|
|
6087
6237
|
}
|
|
6238
|
+
const { offset, diskNumberStart } = entryPositions.get(entry);
|
|
6088
6239
|
Object.assign(entry, {
|
|
6089
6240
|
zip64UncompressedSize,
|
|
6090
6241
|
zip64CompressedSize,
|
|
6091
|
-
|
|
6092
|
-
diskNumberStart
|
|
6242
|
+
offset,
|
|
6243
|
+
diskNumberStart,
|
|
6093
6244
|
zip64DiskNumberStart: false,
|
|
6094
6245
|
rawExtraFieldZip64,
|
|
6095
6246
|
rawExtraFieldAES,
|
|
@@ -6109,11 +6260,8 @@
|
|
|
6109
6260
|
async add(name = "", reader, options = {}) {
|
|
6110
6261
|
const zipWriter = this;
|
|
6111
6262
|
options = Object.assign({}, options);
|
|
6112
|
-
const {
|
|
6113
|
-
|
|
6114
|
-
config
|
|
6115
|
-
} = zipWriter;
|
|
6116
|
-
if (workers < config.maxWorkers) {
|
|
6263
|
+
const { pendingAddFileCalls } = zipWriter;
|
|
6264
|
+
if (workers < getConfiguration().maxWorkers) {
|
|
6117
6265
|
workers++;
|
|
6118
6266
|
} else {
|
|
6119
6267
|
await new Promise(resolve => pendingEntries.push(resolve));
|
|
@@ -6150,16 +6298,16 @@
|
|
|
6150
6298
|
}
|
|
6151
6299
|
|
|
6152
6300
|
remove(entry) {
|
|
6153
|
-
const { filenames,
|
|
6301
|
+
const { filenames, fileEntries } = this;
|
|
6154
6302
|
// deno-lint-ignore valid-typeof
|
|
6155
6303
|
if (typeof entry == STRING_TYPE) {
|
|
6156
|
-
entry =
|
|
6304
|
+
entry = fileEntries.get(entry);
|
|
6157
6305
|
}
|
|
6158
6306
|
if (entry && entry.filename !== UNDEFINED_VALUE) {
|
|
6159
6307
|
const { filename } = entry;
|
|
6160
|
-
if (filenames.has(filename) &&
|
|
6308
|
+
if (filenames.has(filename) && fileEntries.has(filename)) {
|
|
6161
6309
|
filenames.delete(filename);
|
|
6162
|
-
|
|
6310
|
+
fileEntries.delete(filename);
|
|
6163
6311
|
return true;
|
|
6164
6312
|
}
|
|
6165
6313
|
}
|
|
@@ -6256,12 +6404,12 @@
|
|
|
6256
6404
|
const metadataInfo = resolveMetadata(zipWriter, name, options);
|
|
6257
6405
|
const { comment } = metadataInfo;
|
|
6258
6406
|
const extraField = options[PROPERTY_NAME_EXTRA_FIELD];
|
|
6259
|
-
zipWriter.
|
|
6407
|
+
zipWriter.fileEntries.set(name, UNDEFINED_VALUE);
|
|
6260
6408
|
let fileEntry;
|
|
6261
6409
|
try {
|
|
6262
6410
|
const { resolvedOptions } = metadataInfo;
|
|
6263
6411
|
if (resolvedOptions.level != 0 && resolvedOptions.compressionMethod === UNDEFINED_VALUE &&
|
|
6264
|
-
!resolvedOptions.passThrough && !(await supportsDeflate(
|
|
6412
|
+
!resolvedOptions.passThrough && !(await supportsDeflate(getConfiguration()))) {
|
|
6265
6413
|
resolvedOptions.level = 0;
|
|
6266
6414
|
}
|
|
6267
6415
|
const sizesInfo = await resolveSizes(zipWriter, reader, metadataInfo, options);
|
|
@@ -6279,7 +6427,7 @@
|
|
|
6279
6427
|
const metadataSize = getLength(headerInfo.localHeaderArray, dataDescriptorInfo.dataDescriptorArray);
|
|
6280
6428
|
fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo, metadataSize }, options);
|
|
6281
6429
|
} catch (error) {
|
|
6282
|
-
zipWriter.
|
|
6430
|
+
zipWriter.fileEntries.delete(name);
|
|
6283
6431
|
throw error;
|
|
6284
6432
|
}
|
|
6285
6433
|
Object.assign(fileEntry, {
|
|
@@ -6323,9 +6471,9 @@
|
|
|
6323
6471
|
if (unixExtraFieldType === UNDEFINED_VALUE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
|
|
6324
6472
|
unixExtraFieldType = INFOZIP_EXTRA_FIELD_TYPE;
|
|
6325
6473
|
}
|
|
6326
|
-
let msdosAttributesRaw =
|
|
6474
|
+
let msdosAttributesRaw = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW);
|
|
6327
6475
|
let msdosAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES);
|
|
6328
|
-
const hasUnixMetadata = uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE || unixMode !== UNDEFINED_VALUE || unixExtraFieldType;
|
|
6476
|
+
const hasUnixMetadata = uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE || unixMode !== UNDEFINED_VALUE || unixExtraFieldType || executable;
|
|
6329
6477
|
const hasMsDosProvided = msdosAttributesRaw !== UNDEFINED_VALUE || msdosAttributes !== UNDEFINED_VALUE;
|
|
6330
6478
|
if (hasUnixMetadata) {
|
|
6331
6479
|
msDosCompatible = false;
|
|
@@ -6334,10 +6482,10 @@
|
|
|
6334
6482
|
msDosCompatible = true;
|
|
6335
6483
|
versionMadeBy = (versionMadeBy & MAX_8_BITS);
|
|
6336
6484
|
}
|
|
6337
|
-
if (msdosAttributesRaw !== UNDEFINED_VALUE && (msdosAttributesRaw < 0 || msdosAttributesRaw > MAX_8_BITS)) {
|
|
6485
|
+
if (msdosAttributesRaw !== UNDEFINED_VALUE && (!Number.isInteger(msdosAttributesRaw) || msdosAttributesRaw < 0 || msdosAttributesRaw > MAX_8_BITS)) {
|
|
6338
6486
|
throw new Error(ERR_INVALID_MSDOS_ATTRIBUTES);
|
|
6339
6487
|
}
|
|
6340
|
-
if (msdosAttributes && typeof msdosAttributes !== OBJECT_TYPE) {
|
|
6488
|
+
if (msdosAttributes && (typeof msdosAttributes !== OBJECT_TYPE || Array.isArray(msdosAttributes))) {
|
|
6341
6489
|
throw new Error(ERR_INVALID_MSDOS_DATA);
|
|
6342
6490
|
}
|
|
6343
6491
|
if (versionMadeBy > MAX_16_BITS) {
|
|
@@ -6425,7 +6573,7 @@
|
|
|
6425
6573
|
}
|
|
6426
6574
|
|
|
6427
6575
|
function resolveMetadata(zipWriter, name, options) {
|
|
6428
|
-
const encode =
|
|
6576
|
+
const encode = getFunctionOptionValue(zipWriter, options, OPTION_ENCODE_TEXT) || encodeText;
|
|
6429
6577
|
let rawFilename = encode(name, TEXT_TYPE_FILENAME);
|
|
6430
6578
|
if (rawFilename === UNDEFINED_VALUE) {
|
|
6431
6579
|
rawFilename = encodeText(name);
|
|
@@ -6434,6 +6582,10 @@
|
|
|
6434
6582
|
throw new Error(ERR_INVALID_ENTRY_NAME);
|
|
6435
6583
|
}
|
|
6436
6584
|
const comment = options[PROPERTY_NAME_COMMENT] || "";
|
|
6585
|
+
// deno-lint-ignore valid-typeof
|
|
6586
|
+
if (typeof comment != STRING_TYPE) {
|
|
6587
|
+
throw new Error(ERR_INVALID_ENTRY_COMMENT_TYPE);
|
|
6588
|
+
}
|
|
6437
6589
|
let rawComment = encode(comment, TEXT_TYPE_COMMENT);
|
|
6438
6590
|
if (rawComment === UNDEFINED_VALUE) {
|
|
6439
6591
|
rawComment = encodeText(comment);
|
|
@@ -6445,16 +6597,14 @@
|
|
|
6445
6597
|
if (version > MAX_16_BITS) {
|
|
6446
6598
|
throw new Error(ERR_INVALID_VERSION);
|
|
6447
6599
|
}
|
|
6448
|
-
const lastModDate =
|
|
6449
|
-
const lastAccessDate =
|
|
6450
|
-
const creationDate =
|
|
6600
|
+
const lastModDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
|
|
6601
|
+
const lastAccessDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
|
|
6602
|
+
const creationDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
|
|
6451
6603
|
const internalFileAttributes = getAliasedOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES, 0);
|
|
6452
6604
|
const passThrough = getOptionValue(zipWriter, options, OPTION_PASS_THROUGH);
|
|
6453
6605
|
const password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
|
|
6454
6606
|
const rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
|
|
6455
|
-
|
|
6456
|
-
throw new Error(ERR_INVALID_PASSWORD_TYPE);
|
|
6457
|
-
}
|
|
6607
|
+
checkPasswordOption(password, rawPassword);
|
|
6458
6608
|
const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
|
|
6459
6609
|
const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
|
|
6460
6610
|
const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
|
|
@@ -6463,9 +6613,9 @@
|
|
|
6463
6613
|
const useWebWorkers = getOptionValue(zipWriter, options, OPTION_USE_WEB_WORKERS);
|
|
6464
6614
|
const transferStreams = getOptionValue(zipWriter, options, OPTION_TRANSFER_STREAMS);
|
|
6465
6615
|
const bufferedWrite = getOptionValue(zipWriter, options, OPTION_BUFFERED_WRITE);
|
|
6466
|
-
const createTempStream =
|
|
6616
|
+
const createTempStream = getFunctionOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
|
|
6467
6617
|
const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, true);
|
|
6468
|
-
const signal = getOptionValue(zipWriter, options, OPTION_SIGNAL);
|
|
6618
|
+
const signal = checkSignalOption(getOptionValue(zipWriter, options, OPTION_SIGNAL));
|
|
6469
6619
|
const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
|
|
6470
6620
|
const compressionMethod = getOptionValue(zipWriter, options, PROPERTY_NAME_COMPRESSION_METHOD);
|
|
6471
6621
|
const registeredCodec = passThrough || compressionMethod === UNDEFINED_VALUE ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
|
|
@@ -6485,6 +6635,9 @@
|
|
|
6485
6635
|
level = 0;
|
|
6486
6636
|
}
|
|
6487
6637
|
}
|
|
6638
|
+
if (passThrough) {
|
|
6639
|
+
level = UNDEFINED_VALUE;
|
|
6640
|
+
}
|
|
6488
6641
|
let useCompressionStream = getOptionValue(zipWriter, options, OPTION_USE_COMPRESSION_STREAM);
|
|
6489
6642
|
let dataDescriptor = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR);
|
|
6490
6643
|
if (bufferedWrite && dataDescriptor === UNDEFINED_VALUE) {
|
|
@@ -6545,18 +6698,26 @@
|
|
|
6545
6698
|
if (!extraField) {
|
|
6546
6699
|
return EMPTY_UINT8_ARRAY;
|
|
6547
6700
|
}
|
|
6701
|
+
if (!(extraField instanceof Map)) {
|
|
6702
|
+
throw new Error(ERR_INVALID_EXTRAFIELD);
|
|
6703
|
+
}
|
|
6548
6704
|
let extraFieldSize = 0;
|
|
6549
6705
|
let offset = 0;
|
|
6550
|
-
extraField.forEach(data => extraFieldSize += 4 + getLength(data));
|
|
6551
|
-
const rawExtraField = new Uint8Array(extraFieldSize);
|
|
6552
|
-
const rawExtraFieldView = getDataView(rawExtraField);
|
|
6553
6706
|
extraField.forEach((data, type) => {
|
|
6554
|
-
if (type > MAX_16_BITS) {
|
|
6707
|
+
if (!Number.isInteger(type) || type < 0 || type > MAX_16_BITS) {
|
|
6555
6708
|
throw new Error(ERR_INVALID_EXTRAFIELD_TYPE);
|
|
6556
6709
|
}
|
|
6710
|
+
if (!(data instanceof Uint8Array)) {
|
|
6711
|
+
throw new Error(ERR_INVALID_EXTRAFIELD_DATA_TYPE);
|
|
6712
|
+
}
|
|
6557
6713
|
if (getLength(data) > MAX_16_BITS) {
|
|
6558
6714
|
throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
|
|
6559
6715
|
}
|
|
6716
|
+
extraFieldSize += 4 + getLength(data);
|
|
6717
|
+
});
|
|
6718
|
+
const rawExtraField = new Uint8Array(extraFieldSize);
|
|
6719
|
+
const rawExtraFieldView = getDataView(rawExtraField);
|
|
6720
|
+
extraField.forEach((data, type) => {
|
|
6560
6721
|
setUint16(rawExtraFieldView, offset, type);
|
|
6561
6722
|
setUint16(rawExtraFieldView, offset + 2, getLength(data));
|
|
6562
6723
|
arraySet(rawExtraField, data, offset + 4);
|
|
@@ -6588,6 +6749,9 @@
|
|
|
6588
6749
|
if (uncompressedSize === UNDEFINED_VALUE) {
|
|
6589
6750
|
throw new Error(ERR_UNDEFINED_UNCOMPRESSED_SIZE);
|
|
6590
6751
|
}
|
|
6752
|
+
if (compressionMethod === UNDEFINED_VALUE) {
|
|
6753
|
+
throw new Error(ERR_UNDEFINED_COMPRESSION_METHOD);
|
|
6754
|
+
}
|
|
6591
6755
|
}
|
|
6592
6756
|
const zip64Enabled = zip64 === true;
|
|
6593
6757
|
const encrypted = getOptionValue(zipWriter, options, PROPERTY_NAME_ENCRYPTED);
|
|
@@ -6644,7 +6808,7 @@
|
|
|
6644
6808
|
|
|
6645
6809
|
async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
6646
6810
|
const {
|
|
6647
|
-
|
|
6811
|
+
fileEntries,
|
|
6648
6812
|
writer
|
|
6649
6813
|
} = zipWriter;
|
|
6650
6814
|
const {
|
|
@@ -6666,12 +6830,12 @@
|
|
|
6666
6830
|
let writerSizeBeforeEntry;
|
|
6667
6831
|
let flushedBufferedSize = 0;
|
|
6668
6832
|
let fileWriter;
|
|
6669
|
-
|
|
6833
|
+
fileEntries.set(name, fileEntry);
|
|
6670
6834
|
zipWriter.lastFileEntry = fileEntry;
|
|
6671
6835
|
try {
|
|
6672
6836
|
let lockPreviousFileEntry;
|
|
6673
6837
|
if (keepOrder) {
|
|
6674
|
-
lockPreviousFileEntry = previousFileEntry && previousFileEntry.
|
|
6838
|
+
lockPreviousFileEntry = previousFileEntry && previousFileEntry.lockFileEntry;
|
|
6675
6839
|
requestLockCurrentFileEntry();
|
|
6676
6840
|
}
|
|
6677
6841
|
if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || !dataDescriptor) {
|
|
@@ -6692,11 +6856,8 @@
|
|
|
6692
6856
|
const diskOffset = getDiskOffset(writer);
|
|
6693
6857
|
if (zipWriter.addSplitZipSignature) {
|
|
6694
6858
|
delete zipWriter.addSplitZipSignature;
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
setUint32(signatureArrayView, 0, SPLIT_ZIP_FILE_SIGNATURE);
|
|
6698
|
-
await writeData(writer, signatureArray);
|
|
6699
|
-
zipWriter.offset += 4;
|
|
6859
|
+
await writeData(writer, getSplitZipSignatureArray());
|
|
6860
|
+
zipWriter.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
|
|
6700
6861
|
}
|
|
6701
6862
|
if (usdz && !bufferedWrite) {
|
|
6702
6863
|
appendExtraFieldUSDZ(entryInfo, zipWriter.offset - diskOffset);
|
|
@@ -6714,11 +6875,11 @@
|
|
|
6714
6875
|
writerSizeBeforeEntry = writer.size;
|
|
6715
6876
|
await writeData(fileWriter, localHeaderArray);
|
|
6716
6877
|
}
|
|
6717
|
-
fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo,
|
|
6878
|
+
fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, getConfiguration(), options);
|
|
6718
6879
|
if (!bufferedWrite) {
|
|
6719
6880
|
writingEntryData = false;
|
|
6720
6881
|
}
|
|
6721
|
-
|
|
6882
|
+
fileEntries.set(name, fileEntry);
|
|
6722
6883
|
fileEntry.filename = name;
|
|
6723
6884
|
if (bufferedWrite) {
|
|
6724
6885
|
await Promise.all([fileWriter.writable.getWriter().close(), lockPreviousFileEntry]);
|
|
@@ -6759,7 +6920,7 @@
|
|
|
6759
6920
|
zipWriter.offset += flushedBufferedSize;
|
|
6760
6921
|
}
|
|
6761
6922
|
}
|
|
6762
|
-
|
|
6923
|
+
fileEntries.delete(name);
|
|
6763
6924
|
throw error;
|
|
6764
6925
|
} finally {
|
|
6765
6926
|
if (bufferedWrite) {
|
|
@@ -6781,7 +6942,7 @@
|
|
|
6781
6942
|
}
|
|
6782
6943
|
|
|
6783
6944
|
function requestLockCurrentFileEntry() {
|
|
6784
|
-
fileEntry.
|
|
6945
|
+
fileEntry.lockFileEntry = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
|
|
6785
6946
|
}
|
|
6786
6947
|
|
|
6787
6948
|
async function requestLockWriter() {
|
|
@@ -6801,7 +6962,7 @@
|
|
|
6801
6962
|
}
|
|
6802
6963
|
}
|
|
6803
6964
|
|
|
6804
|
-
async function createFileEntry(reader, writer, { diskNumberStart,
|
|
6965
|
+
async function createFileEntry(reader, writer, { diskNumberStart, lockFileEntry }, entryInfo, config, options) {
|
|
6805
6966
|
const {
|
|
6806
6967
|
headerInfo,
|
|
6807
6968
|
dataDescriptorInfo,
|
|
@@ -6869,7 +7030,7 @@
|
|
|
6869
7030
|
codecURI
|
|
6870
7031
|
} = options;
|
|
6871
7032
|
const fileEntry = {
|
|
6872
|
-
|
|
7033
|
+
lockFileEntry,
|
|
6873
7034
|
versionMadeBy,
|
|
6874
7035
|
zip64,
|
|
6875
7036
|
directory: Boolean(directory),
|
|
@@ -6911,7 +7072,7 @@
|
|
|
6911
7072
|
}
|
|
6912
7073
|
const { writable } = writer;
|
|
6913
7074
|
if (reader) {
|
|
6914
|
-
const readable = toCompatibleReadable(
|
|
7075
|
+
const readable = toCompatibleReadable(createReadable(reader));
|
|
6915
7076
|
const size = reader.size;
|
|
6916
7077
|
const workerOptions = {
|
|
6917
7078
|
options: {
|
|
@@ -7023,14 +7184,14 @@
|
|
|
7023
7184
|
if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
|
|
7024
7185
|
const length = 4 + 16;
|
|
7025
7186
|
const extraFieldZip64 = createRecordWriter(length);
|
|
7026
|
-
extraFieldZip64.
|
|
7027
|
-
extraFieldZip64.
|
|
7187
|
+
extraFieldZip64.writeUint16(EXTRAFIELD_TYPE_ZIP64);
|
|
7188
|
+
extraFieldZip64.writeUint16(length - 4);
|
|
7028
7189
|
rawLocalExtraFieldZip64 = extraFieldZip64.array;
|
|
7029
7190
|
if (zip64ExtraFieldComplete) {
|
|
7030
|
-
extraFieldZip64.
|
|
7191
|
+
extraFieldZip64.writeUint64(uncompressedSize);
|
|
7031
7192
|
if (uncompressedFile) {
|
|
7032
7193
|
const encryptionOverhead = encrypted ? (zipCrypto ? 12 : 16 + encryptionStrength * 4) : 0;
|
|
7033
|
-
extraFieldZip64.
|
|
7194
|
+
extraFieldZip64.writeUint64(passThrough ? 0 : uncompressedSize + encryptionOverhead);
|
|
7034
7195
|
}
|
|
7035
7196
|
}
|
|
7036
7197
|
} else {
|
|
@@ -7039,8 +7200,8 @@
|
|
|
7039
7200
|
let rawExtraFieldAES;
|
|
7040
7201
|
if (encrypted && !zipCrypto) {
|
|
7041
7202
|
const extraFieldAES = createRecordWriter(getLength(EXTRAFIELD_DATA_AES) + 2);
|
|
7042
|
-
extraFieldAES.
|
|
7043
|
-
extraFieldAES.
|
|
7203
|
+
extraFieldAES.writeUint16(EXTRAFIELD_TYPE_AES);
|
|
7204
|
+
extraFieldAES.writeBytes(EXTRAFIELD_DATA_AES);
|
|
7044
7205
|
rawExtraFieldAES = extraFieldAES.array;
|
|
7045
7206
|
rawExtraFieldAES[8] = encryptionStrength;
|
|
7046
7207
|
} else {
|
|
@@ -7056,15 +7217,15 @@
|
|
|
7056
7217
|
const extraFieldTimestampLength = 9 + (lastAccessDate ? 4 : 0) + (creationDate ? 4 : 0);
|
|
7057
7218
|
const extraFieldTimestamp = createRecordWriter(extraFieldTimestampLength);
|
|
7058
7219
|
extraFieldExtendedTimestampFlag = 0x1 + (lastAccessDate ? 0x2 : 0) + (creationDate ? 0x4 : 0);
|
|
7059
|
-
extraFieldTimestamp.
|
|
7060
|
-
extraFieldTimestamp.
|
|
7061
|
-
extraFieldTimestamp.
|
|
7062
|
-
extraFieldTimestamp.
|
|
7220
|
+
extraFieldTimestamp.writeUint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
|
|
7221
|
+
extraFieldTimestamp.writeUint16(extraFieldTimestampLength - 4);
|
|
7222
|
+
extraFieldTimestamp.writeUint8(extraFieldExtendedTimestampFlag);
|
|
7223
|
+
extraFieldTimestamp.writeUint32(lastModTimeUnix);
|
|
7063
7224
|
if (lastAccessDate) {
|
|
7064
|
-
extraFieldTimestamp.
|
|
7225
|
+
extraFieldTimestamp.writeUint32(clampUnixTime(getTimeUnix(lastAccessDate)));
|
|
7065
7226
|
}
|
|
7066
7227
|
if (creationDate) {
|
|
7067
|
-
extraFieldTimestamp.
|
|
7228
|
+
extraFieldTimestamp.writeUint32(clampUnixTime(getTimeUnix(creationDate)));
|
|
7068
7229
|
}
|
|
7069
7230
|
rawExtraFieldExtendedTimestamp = extraFieldTimestamp.array;
|
|
7070
7231
|
} else {
|
|
@@ -7077,14 +7238,14 @@
|
|
|
7077
7238
|
try {
|
|
7078
7239
|
const lastModTimeNTFS = getTimeNTFS(lastModDate);
|
|
7079
7240
|
const extraFieldNTFS = createRecordWriter(36);
|
|
7080
|
-
extraFieldNTFS.
|
|
7081
|
-
extraFieldNTFS.
|
|
7241
|
+
extraFieldNTFS.writeUint16(EXTRAFIELD_TYPE_NTFS);
|
|
7242
|
+
extraFieldNTFS.writeUint16(32);
|
|
7082
7243
|
extraFieldNTFS.skip(4);
|
|
7083
|
-
extraFieldNTFS.
|
|
7084
|
-
extraFieldNTFS.
|
|
7085
|
-
extraFieldNTFS.
|
|
7086
|
-
extraFieldNTFS.
|
|
7087
|
-
extraFieldNTFS.
|
|
7244
|
+
extraFieldNTFS.writeUint16(EXTRAFIELD_TYPE_NTFS_TAG1);
|
|
7245
|
+
extraFieldNTFS.writeUint16(24);
|
|
7246
|
+
extraFieldNTFS.writeUint64(lastModTimeNTFS);
|
|
7247
|
+
extraFieldNTFS.writeUint64(lastAccessDate ? getTimeNTFS(lastAccessDate) : lastModTimeNTFS);
|
|
7248
|
+
extraFieldNTFS.writeUint64(creationDate ? getTimeNTFS(creationDate) : lastModTimeNTFS);
|
|
7088
7249
|
rawExtraFieldNTFS = extraFieldNTFS.array;
|
|
7089
7250
|
} catch {
|
|
7090
7251
|
rawExtraFieldNTFS = EMPTY_UINT8_ARRAY;
|
|
@@ -7103,20 +7264,20 @@
|
|
|
7103
7264
|
const gidBytes = packUnixId(gid);
|
|
7104
7265
|
const payloadLength = 3 + uidBytes.length + gidBytes.length;
|
|
7105
7266
|
const extraFieldUnix = createRecordWriter(4 + payloadLength);
|
|
7106
|
-
extraFieldUnix.
|
|
7107
|
-
extraFieldUnix.
|
|
7108
|
-
extraFieldUnix.
|
|
7109
|
-
extraFieldUnix.
|
|
7110
|
-
extraFieldUnix.
|
|
7111
|
-
extraFieldUnix.
|
|
7112
|
-
extraFieldUnix.
|
|
7267
|
+
extraFieldUnix.writeUint16(EXTRAFIELD_TYPE_INFOZIP);
|
|
7268
|
+
extraFieldUnix.writeUint16(payloadLength);
|
|
7269
|
+
extraFieldUnix.writeUint8(1);
|
|
7270
|
+
extraFieldUnix.writeUint8(uidBytes.length);
|
|
7271
|
+
extraFieldUnix.writeBytes(uidBytes);
|
|
7272
|
+
extraFieldUnix.writeUint8(gidBytes.length);
|
|
7273
|
+
extraFieldUnix.writeBytes(gidBytes);
|
|
7113
7274
|
rawExtraFieldUnix = extraFieldUnix.array;
|
|
7114
7275
|
} else if (unixExtraFieldType == UNIX_EXTRA_FIELD_TYPE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
|
|
7115
7276
|
const extraFieldUnix = createRecordWriter(8);
|
|
7116
|
-
extraFieldUnix.
|
|
7117
|
-
extraFieldUnix.
|
|
7118
|
-
extraFieldUnix.
|
|
7119
|
-
extraFieldUnix.
|
|
7277
|
+
extraFieldUnix.writeUint16(EXTRAFIELD_TYPE_UNIX);
|
|
7278
|
+
extraFieldUnix.writeUint16(4);
|
|
7279
|
+
extraFieldUnix.writeUint16((uid === UNDEFINED_VALUE ? 0 : uid) & MAX_16_BITS);
|
|
7280
|
+
extraFieldUnix.writeUint16((gid === UNDEFINED_VALUE ? 0 : gid) & MAX_16_BITS);
|
|
7120
7281
|
rawExtraFieldUnix = extraFieldUnix.array;
|
|
7121
7282
|
} else {
|
|
7122
7283
|
rawExtraFieldUnix = EMPTY_UINT8_ARRAY;
|
|
@@ -7166,18 +7327,18 @@
|
|
|
7166
7327
|
const localHeader = createRecordWriter(HEADER_SIZE + getLength(rawFilename) + extraFieldLength);
|
|
7167
7328
|
const localHeaderArray = localHeader.array;
|
|
7168
7329
|
const localHeaderView = getDataView(localHeaderArray);
|
|
7169
|
-
localHeader.
|
|
7170
|
-
localHeader.
|
|
7171
|
-
localHeader.
|
|
7330
|
+
localHeader.writeUint32(LOCAL_FILE_HEADER_SIGNATURE);
|
|
7331
|
+
localHeader.writeBytes(headerArray);
|
|
7332
|
+
localHeader.writeBytes(rawFilename);
|
|
7172
7333
|
if (writeLocalExtraFieldZip64) {
|
|
7173
|
-
localHeader.
|
|
7174
|
-
}
|
|
7175
|
-
localHeader.
|
|
7176
|
-
localHeader.
|
|
7177
|
-
localHeader.
|
|
7178
|
-
localHeader.
|
|
7179
|
-
localHeader.
|
|
7180
|
-
localHeader.
|
|
7334
|
+
localHeader.writeBytes(rawLocalExtraFieldZip64);
|
|
7335
|
+
}
|
|
7336
|
+
localHeader.writeBytes(rawExtraFieldAES);
|
|
7337
|
+
localHeader.writeBytes(rawExtraFieldExtendedTimestamp);
|
|
7338
|
+
localHeader.writeBytes(rawExtraFieldNTFS);
|
|
7339
|
+
localHeader.writeBytes(rawExtraFieldUnix);
|
|
7340
|
+
localHeader.writeBytes(rawExtraField);
|
|
7341
|
+
localHeader.writeBytes(rawLocalExtraField);
|
|
7181
7342
|
if (dataDescriptor) {
|
|
7182
7343
|
if (!zip64CompressedSize) {
|
|
7183
7344
|
setUint32(localHeaderView, HEADER_OFFSET_COMPRESSED_SIZE + LOCAL_HEADER_COMMON_OFFSET, 0);
|
|
@@ -7367,7 +7528,7 @@
|
|
|
7367
7528
|
|
|
7368
7529
|
|
|
7369
7530
|
async function closeFile(zipWriter, comment, options) {
|
|
7370
|
-
const directoryDataLength = createDirectoryRecords(zipWriter.
|
|
7531
|
+
const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
|
|
7371
7532
|
const { directoryStart, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
|
|
7372
7533
|
const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
|
|
7373
7534
|
await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryDataLength, signatureLength });
|
|
@@ -7397,19 +7558,19 @@
|
|
|
7397
7558
|
if (zip64Offset || zip64DiskNumberStart || zip64UncompressedSize || zip64CompressedSize) {
|
|
7398
7559
|
const length = 4 + (zip64UncompressedSize ? 8 : 0) + (zip64CompressedSize ? 8 : 0) + (zip64Offset ? 8 : 0) + (zip64DiskNumberStart ? 4 : 0);
|
|
7399
7560
|
const extraFieldZip64 = createRecordWriter(length);
|
|
7400
|
-
extraFieldZip64.
|
|
7401
|
-
extraFieldZip64.
|
|
7561
|
+
extraFieldZip64.writeUint16(EXTRAFIELD_TYPE_ZIP64);
|
|
7562
|
+
extraFieldZip64.writeUint16(length - 4);
|
|
7402
7563
|
if (zip64UncompressedSize) {
|
|
7403
|
-
extraFieldZip64.
|
|
7564
|
+
extraFieldZip64.writeUint64(uncompressedSize);
|
|
7404
7565
|
}
|
|
7405
7566
|
if (zip64CompressedSize) {
|
|
7406
|
-
extraFieldZip64.
|
|
7567
|
+
extraFieldZip64.writeUint64(compressedSize);
|
|
7407
7568
|
}
|
|
7408
7569
|
if (zip64Offset) {
|
|
7409
|
-
extraFieldZip64.
|
|
7570
|
+
extraFieldZip64.writeUint64(fileEntry.offset);
|
|
7410
7571
|
}
|
|
7411
7572
|
if (zip64DiskNumberStart) {
|
|
7412
|
-
extraFieldZip64.
|
|
7573
|
+
extraFieldZip64.writeUint32(fileEntry.diskNumberStart);
|
|
7413
7574
|
}
|
|
7414
7575
|
rawExtraFieldZip64 = extraFieldZip64.array;
|
|
7415
7576
|
} else {
|
|
@@ -7422,10 +7583,10 @@
|
|
|
7422
7583
|
const lastModTimeUnix = getTimeUnix(lastModDate);
|
|
7423
7584
|
if (extendedTimestamp && inUnixTimeRange(lastModTimeUnix)) {
|
|
7424
7585
|
const extraFieldTimestamp = createRecordWriter(9);
|
|
7425
|
-
extraFieldTimestamp.
|
|
7426
|
-
extraFieldTimestamp.
|
|
7427
|
-
extraFieldTimestamp.
|
|
7428
|
-
extraFieldTimestamp.
|
|
7586
|
+
extraFieldTimestamp.writeUint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
|
|
7587
|
+
extraFieldTimestamp.writeUint16(5);
|
|
7588
|
+
extraFieldTimestamp.writeUint8(extraFieldExtendedTimestampFlag);
|
|
7589
|
+
extraFieldTimestamp.writeUint32(lastModTimeUnix);
|
|
7429
7590
|
rawExtraFieldTimestamp = extraFieldTimestamp.array;
|
|
7430
7591
|
} else {
|
|
7431
7592
|
rawExtraFieldTimestamp = EMPTY_UINT8_ARRAY;
|
|
@@ -7447,14 +7608,14 @@
|
|
|
7447
7608
|
}
|
|
7448
7609
|
|
|
7449
7610
|
async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
|
|
7450
|
-
const {
|
|
7611
|
+
const { fileEntries, writer } = zipWriter;
|
|
7451
7612
|
const directoryArray = new Uint8Array(directoryDataLength);
|
|
7452
7613
|
await initStream(writer);
|
|
7453
7614
|
let offset = 0;
|
|
7454
7615
|
let directoryDiskOffset = 0;
|
|
7455
7616
|
let directoryStartDiskNumber = getDiskNumber(writer);
|
|
7456
7617
|
let directoryStartDiskOffset = getDiskOffset(writer);
|
|
7457
|
-
for (const [indexFileEntry, fileEntry] of Array.from(
|
|
7618
|
+
for (const [indexFileEntry, fileEntry] of Array.from(fileEntries.values()).entries()) {
|
|
7458
7619
|
const {
|
|
7459
7620
|
offset: fileEntryOffset,
|
|
7460
7621
|
rawFilename,
|
|
@@ -7499,28 +7660,28 @@
|
|
|
7499
7660
|
setUint16(headerView, HEADER_OFFSET_VERSION, VERSION_ZIP64);
|
|
7500
7661
|
}
|
|
7501
7662
|
const directoryRecord = createRecordWriter(directoryRecordLength);
|
|
7502
|
-
directoryRecord.
|
|
7503
|
-
directoryRecord.
|
|
7504
|
-
directoryRecord.
|
|
7505
|
-
directoryRecord.
|
|
7506
|
-
directoryRecord.
|
|
7507
|
-
directoryRecord.
|
|
7508
|
-
directoryRecord.
|
|
7509
|
-
directoryRecord.
|
|
7510
|
-
directoryRecord.
|
|
7511
|
-
directoryRecord.
|
|
7512
|
-
directoryRecord.
|
|
7513
|
-
directoryRecord.
|
|
7514
|
-
directoryRecord.
|
|
7515
|
-
directoryRecord.
|
|
7516
|
-
directoryRecord.
|
|
7517
|
-
directoryRecord.
|
|
7518
|
-
directoryRecord.
|
|
7663
|
+
directoryRecord.writeUint32(CENTRAL_FILE_HEADER_SIGNATURE);
|
|
7664
|
+
directoryRecord.writeUint16(versionMadeBy);
|
|
7665
|
+
directoryRecord.writeBytes(headerArray.subarray(0, HEADER_SIZE - 4 - 2));
|
|
7666
|
+
directoryRecord.writeUint16(extraFieldLength);
|
|
7667
|
+
directoryRecord.writeUint16(getLength(rawComment));
|
|
7668
|
+
directoryRecord.writeUint16(zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
|
|
7669
|
+
directoryRecord.writeUint16(internalFileAttributes);
|
|
7670
|
+
directoryRecord.writeUint32(externalFileAttributes);
|
|
7671
|
+
directoryRecord.writeUint32(zip64Offset ? MAX_32_BITS : fileEntryOffset);
|
|
7672
|
+
directoryRecord.writeBytes(rawFilename);
|
|
7673
|
+
directoryRecord.writeBytes(rawExtraFieldZip64);
|
|
7674
|
+
directoryRecord.writeBytes(rawExtraFieldAES);
|
|
7675
|
+
directoryRecord.writeBytes(rawExtraFieldExtendedTimestamp);
|
|
7676
|
+
directoryRecord.writeBytes(rawExtraFieldNTFS);
|
|
7677
|
+
directoryRecord.writeBytes(rawExtraFieldUnix);
|
|
7678
|
+
directoryRecord.writeBytes(rawExtraField);
|
|
7679
|
+
directoryRecord.writeBytes(rawComment);
|
|
7519
7680
|
arraySet(directoryArray, directoryRecord.array, offset);
|
|
7520
7681
|
offset += directoryRecordLength;
|
|
7521
7682
|
if (options.onprogress) {
|
|
7522
7683
|
try {
|
|
7523
|
-
await options.onprogress(indexFileEntry + 1,
|
|
7684
|
+
await options.onprogress(indexFileEntry + 1, fileEntries.size, new Entry(fileEntry));
|
|
7524
7685
|
} catch {
|
|
7525
7686
|
// ignored
|
|
7526
7687
|
}
|
|
@@ -7534,7 +7695,7 @@
|
|
|
7534
7695
|
}
|
|
7535
7696
|
|
|
7536
7697
|
async function writeDigitalSignatureRecord(zipWriter, directoryArray, options) {
|
|
7537
|
-
const signCentralDirectory =
|
|
7698
|
+
const signCentralDirectory = getFunctionOptionValue(zipWriter, options, OPTION_SIGN_CENTRAL_DIRECTORY);
|
|
7538
7699
|
if (signCentralDirectory) {
|
|
7539
7700
|
const signatureData = await signCentralDirectory(directoryArray);
|
|
7540
7701
|
const signatureDataLength = getLength(signatureData);
|
|
@@ -7542,9 +7703,9 @@
|
|
|
7542
7703
|
throw new Error(ERR_INVALID_SIGNATURE_DATA);
|
|
7543
7704
|
}
|
|
7544
7705
|
const signatureRecord = createRecordWriter(6 + signatureDataLength);
|
|
7545
|
-
signatureRecord.
|
|
7546
|
-
signatureRecord.
|
|
7547
|
-
signatureRecord.
|
|
7706
|
+
signatureRecord.writeUint32(DIGITAL_SIGNATURE_RECORD_SIGNATURE);
|
|
7707
|
+
signatureRecord.writeUint16(signatureDataLength);
|
|
7708
|
+
signatureRecord.writeBytes(signatureData);
|
|
7548
7709
|
await writeData(zipWriter.writer, signatureRecord.array);
|
|
7549
7710
|
return 6 + signatureDataLength;
|
|
7550
7711
|
}
|
|
@@ -7555,7 +7716,7 @@
|
|
|
7555
7716
|
const { writer } = zipWriter;
|
|
7556
7717
|
const { directoryStart, signatureLength } = cdInfo;
|
|
7557
7718
|
let { directoryDataLength } = cdInfo;
|
|
7558
|
-
let
|
|
7719
|
+
let fileEntriesLength = zipWriter.fileEntries.size;
|
|
7559
7720
|
let diskNumber = directoryStart.diskNumber;
|
|
7560
7721
|
let directoryOffset = getSegmentOffset(zipWriter, directoryStart);
|
|
7561
7722
|
let lastDiskNumber = getDiskNumber(writer);
|
|
@@ -7563,7 +7724,7 @@
|
|
|
7563
7724
|
lastDiskNumber++;
|
|
7564
7725
|
}
|
|
7565
7726
|
let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
7566
|
-
if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS ||
|
|
7727
|
+
if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || fileEntriesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
|
|
7567
7728
|
if (zip64 === false) {
|
|
7568
7729
|
throw new Error(ERR_UNSUPPORTED_FORMAT);
|
|
7569
7730
|
} else {
|
|
@@ -7580,37 +7741,37 @@
|
|
|
7580
7741
|
}
|
|
7581
7742
|
lastDiskNumber = getDiskNumber(writer);
|
|
7582
7743
|
if (zip64) {
|
|
7583
|
-
endOfdirectoryRecord.
|
|
7584
|
-
endOfdirectoryRecord.
|
|
7585
|
-
endOfdirectoryRecord.
|
|
7586
|
-
endOfdirectoryRecord.
|
|
7587
|
-
endOfdirectoryRecord.
|
|
7588
|
-
endOfdirectoryRecord.
|
|
7589
|
-
endOfdirectoryRecord.
|
|
7590
|
-
endOfdirectoryRecord.
|
|
7591
|
-
endOfdirectoryRecord.
|
|
7592
|
-
endOfdirectoryRecord.
|
|
7593
|
-
endOfdirectoryRecord.
|
|
7594
|
-
endOfdirectoryRecord.
|
|
7595
|
-
endOfdirectoryRecord.
|
|
7596
|
-
endOfdirectoryRecord.
|
|
7744
|
+
endOfdirectoryRecord.writeUint32(ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
|
|
7745
|
+
endOfdirectoryRecord.writeUint64(44);
|
|
7746
|
+
endOfdirectoryRecord.writeUint16(45);
|
|
7747
|
+
endOfdirectoryRecord.writeUint16(45);
|
|
7748
|
+
endOfdirectoryRecord.writeUint32(lastDiskNumber);
|
|
7749
|
+
endOfdirectoryRecord.writeUint32(diskNumber);
|
|
7750
|
+
endOfdirectoryRecord.writeUint64(fileEntriesLength);
|
|
7751
|
+
endOfdirectoryRecord.writeUint64(fileEntriesLength);
|
|
7752
|
+
endOfdirectoryRecord.writeUint64(directoryDataLength);
|
|
7753
|
+
endOfdirectoryRecord.writeUint64(directoryOffset);
|
|
7754
|
+
endOfdirectoryRecord.writeUint32(ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
|
|
7755
|
+
endOfdirectoryRecord.writeUint32(lastDiskNumber);
|
|
7756
|
+
endOfdirectoryRecord.writeUint64(BigInt(getSegmentOffset(zipWriter, writer)) + BigInt(directoryDataLength) + BigInt(signatureLength));
|
|
7757
|
+
endOfdirectoryRecord.writeUint32(lastDiskNumber + 1);
|
|
7597
7758
|
const supportZip64SplitFile = getOptionValue(zipWriter, options, OPTION_SUPPORT_ZIP64_SPLIT_FILE, true);
|
|
7598
7759
|
if (supportZip64SplitFile) {
|
|
7599
7760
|
lastDiskNumber = MAX_16_BITS;
|
|
7600
7761
|
diskNumber = MAX_16_BITS;
|
|
7601
7762
|
}
|
|
7602
|
-
|
|
7763
|
+
fileEntriesLength = MAX_16_BITS;
|
|
7603
7764
|
directoryOffset = MAX_32_BITS;
|
|
7604
7765
|
directoryDataLength = MAX_32_BITS;
|
|
7605
7766
|
}
|
|
7606
|
-
endOfdirectoryRecord.
|
|
7607
|
-
endOfdirectoryRecord.
|
|
7608
|
-
endOfdirectoryRecord.
|
|
7609
|
-
endOfdirectoryRecord.
|
|
7610
|
-
endOfdirectoryRecord.
|
|
7611
|
-
endOfdirectoryRecord.
|
|
7612
|
-
endOfdirectoryRecord.
|
|
7613
|
-
endOfdirectoryRecord.
|
|
7767
|
+
endOfdirectoryRecord.writeUint32(END_OF_CENTRAL_DIR_SIGNATURE);
|
|
7768
|
+
endOfdirectoryRecord.writeUint16(lastDiskNumber);
|
|
7769
|
+
endOfdirectoryRecord.writeUint16(diskNumber);
|
|
7770
|
+
endOfdirectoryRecord.writeUint16(fileEntriesLength);
|
|
7771
|
+
endOfdirectoryRecord.writeUint16(fileEntriesLength);
|
|
7772
|
+
endOfdirectoryRecord.writeUint32(directoryDataLength);
|
|
7773
|
+
endOfdirectoryRecord.writeUint32(directoryOffset);
|
|
7774
|
+
endOfdirectoryRecord.writeUint16(commentLength);
|
|
7614
7775
|
await writeData(writer, endOfdirectoryRecord.array);
|
|
7615
7776
|
if (commentLength) {
|
|
7616
7777
|
await writeData(writer, comment);
|
|
@@ -7623,11 +7784,11 @@
|
|
|
7623
7784
|
let offset = 0;
|
|
7624
7785
|
return {
|
|
7625
7786
|
array,
|
|
7626
|
-
|
|
7627
|
-
|
|
7628
|
-
|
|
7629
|
-
|
|
7630
|
-
|
|
7787
|
+
writeUint8: value => { setUint8(view, offset, value); offset += 1; },
|
|
7788
|
+
writeUint16: value => { setUint16(view, offset, value); offset += 2; },
|
|
7789
|
+
writeUint32: value => { setUint32(view, offset, value); offset += 4; },
|
|
7790
|
+
writeUint64: value => { setBigUint64(view, offset, BigInt(value)); offset += 8; },
|
|
7791
|
+
writeBytes: value => { arraySet(array, value, offset); offset += getLength(value); },
|
|
7631
7792
|
skip: count => offset += count
|
|
7632
7793
|
};
|
|
7633
7794
|
}
|
|
@@ -7651,6 +7812,71 @@
|
|
|
7651
7812
|
return zipWriter.offset - diskOffset - (diskNumber ? zipWriter.initialOffset : 0);
|
|
7652
7813
|
}
|
|
7653
7814
|
|
|
7815
|
+
async function startsWithSplitZipSignature(reader) {
|
|
7816
|
+
const signatureArray = await readUint8Array(reader, 0, SPLIT_ZIP_FILE_SIGNATURE_LENGTH);
|
|
7817
|
+
return getUint32(getDataView(signatureArray), 0) == SPLIT_ZIP_FILE_SIGNATURE;
|
|
7818
|
+
}
|
|
7819
|
+
|
|
7820
|
+
async function copyZipData(zipWriter, reader, entries, directoryOffset, splitZipSignatureLength) {
|
|
7821
|
+
const { writer } = zipWriter;
|
|
7822
|
+
const entryPositions = new Map();
|
|
7823
|
+
if (writer.closeDisk) {
|
|
7824
|
+
const sortedEntries = Array.from(entries).sort((firstEntry, secondEntry) =>
|
|
7825
|
+
getSourceOffset(reader, firstEntry) - getSourceOffset(reader, secondEntry));
|
|
7826
|
+
let copiedLength = 0;
|
|
7827
|
+
for (const entry of sortedEntries) {
|
|
7828
|
+
const sourceOffset = getSourceOffset(reader, entry);
|
|
7829
|
+
await copyData(zipWriter, reader, copiedLength, sourceOffset - copiedLength);
|
|
7830
|
+
if (exceedsAvailableSize(writer, await getLocalHeaderLength(reader, sourceOffset))) {
|
|
7831
|
+
await writer.closeDisk();
|
|
7832
|
+
}
|
|
7833
|
+
entryPositions.set(entry, {
|
|
7834
|
+
offset: getSegmentOffset(zipWriter, writer),
|
|
7835
|
+
diskNumberStart: getDiskNumber(writer)
|
|
7836
|
+
});
|
|
7837
|
+
copiedLength = sourceOffset;
|
|
7838
|
+
}
|
|
7839
|
+
await copyData(zipWriter, reader, copiedLength, directoryOffset - copiedLength);
|
|
7840
|
+
} else {
|
|
7841
|
+
await copyData(zipWriter, reader, 0, directoryOffset);
|
|
7842
|
+
entries.forEach(entry => entryPositions.set(entry, {
|
|
7843
|
+
offset: splitZipSignatureLength + getSourceOffset(reader, entry),
|
|
7844
|
+
diskNumberStart: 0
|
|
7845
|
+
}));
|
|
7846
|
+
}
|
|
7847
|
+
return entryPositions;
|
|
7848
|
+
}
|
|
7849
|
+
|
|
7850
|
+
async function copyData(zipWriter, reader, offset, size) {
|
|
7851
|
+
if (size > 0) {
|
|
7852
|
+
const { writer } = zipWriter;
|
|
7853
|
+
await createReadable(reader, { offset, size }).pipeTo(writer.writable, { preventClose: true, preventAbort: true });
|
|
7854
|
+
writer.size += size;
|
|
7855
|
+
zipWriter.offset += size;
|
|
7856
|
+
}
|
|
7857
|
+
}
|
|
7858
|
+
|
|
7859
|
+
async function getLocalHeaderLength(reader, offset) {
|
|
7860
|
+
const headerArray = await readUint8Array(reader, offset, HEADER_SIZE);
|
|
7861
|
+
if (getLength(headerArray) < HEADER_SIZE) {
|
|
7862
|
+
return HEADER_SIZE;
|
|
7863
|
+
}
|
|
7864
|
+
const headerView = getDataView(headerArray);
|
|
7865
|
+
return HEADER_SIZE +
|
|
7866
|
+
getUint16(headerView, HEADER_OFFSET_FILENAME_LENGTH + LOCAL_HEADER_COMMON_OFFSET) +
|
|
7867
|
+
getUint16(headerView, HEADER_OFFSET_EXTRAFIELD_LENGTH + LOCAL_HEADER_COMMON_OFFSET);
|
|
7868
|
+
}
|
|
7869
|
+
|
|
7870
|
+
function getSourceOffset(reader, { offset, diskNumberStart }) {
|
|
7871
|
+
return offset + (reader.getDiskOffset ? reader.getDiskOffset(diskNumberStart) : 0);
|
|
7872
|
+
}
|
|
7873
|
+
|
|
7874
|
+
function getSplitZipSignatureArray() {
|
|
7875
|
+
const signatureArray = new Uint8Array(SPLIT_ZIP_FILE_SIGNATURE_LENGTH);
|
|
7876
|
+
setUint32(getDataView(signatureArray), 0, SPLIT_ZIP_FILE_SIGNATURE);
|
|
7877
|
+
return signatureArray;
|
|
7878
|
+
}
|
|
7879
|
+
|
|
7654
7880
|
async function writeData(writer, array) {
|
|
7655
7881
|
const { writable } = writer;
|
|
7656
7882
|
const streamWriter = writable.getWriter();
|
|
@@ -7702,6 +7928,21 @@
|
|
|
7702
7928
|
return result === UNDEFINED_VALUE ? defaultValue : result;
|
|
7703
7929
|
}
|
|
7704
7930
|
|
|
7931
|
+
function getDateOptionValue(zipWriter, options, name, defaultValue) {
|
|
7932
|
+
const date = getOptionValue(zipWriter, options, name, defaultValue);
|
|
7933
|
+
if (date === null) {
|
|
7934
|
+
return defaultValue;
|
|
7935
|
+
}
|
|
7936
|
+
if (date !== UNDEFINED_VALUE && (typeof date.getTime != FUNCTION_TYPE || Number.isNaN(date.getTime()))) {
|
|
7937
|
+
throw new Error(ERR_INVALID_DATE);
|
|
7938
|
+
}
|
|
7939
|
+
return date;
|
|
7940
|
+
}
|
|
7941
|
+
|
|
7942
|
+
function getFunctionOptionValue(zipWriter, options, name) {
|
|
7943
|
+
return checkFunctionOption(getOptionValue(zipWriter, options, name));
|
|
7944
|
+
}
|
|
7945
|
+
|
|
7705
7946
|
function getAliasedOptionValue(zipWriter, options, name, deprecatedName, defaultValue) {
|
|
7706
7947
|
const value = getAliasedValue(options, name, deprecatedName);
|
|
7707
7948
|
const result = value === UNDEFINED_VALUE ? getAliasedValue(zipWriter.options, name, deprecatedName) : value;
|
|
@@ -7716,9 +7957,6 @@
|
|
|
7716
7957
|
return toNumber(getOptionValue(zipWriter, options, name, defaultValue));
|
|
7717
7958
|
}
|
|
7718
7959
|
|
|
7719
|
-
function toNumber(value) {
|
|
7720
|
-
return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
|
|
7721
|
-
}
|
|
7722
7960
|
|
|
7723
7961
|
function getMaximumCompressedSize(uncompressedSize) {
|
|
7724
7962
|
return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
|
|
@@ -7730,6 +7968,14 @@
|
|
|
7730
7968
|
: compressionMethod !== COMPRESSION_METHOD_STORE;
|
|
7731
7969
|
}
|
|
7732
7970
|
|
|
7971
|
+
function getUint16(view, offset) {
|
|
7972
|
+
return view.getUint16(offset, true);
|
|
7973
|
+
}
|
|
7974
|
+
|
|
7975
|
+
function getUint32(view, offset) {
|
|
7976
|
+
return view.getUint32(offset, true);
|
|
7977
|
+
}
|
|
7978
|
+
|
|
7733
7979
|
function setUint8(view, offset, value) {
|
|
7734
7980
|
view.setUint8(offset, value);
|
|
7735
7981
|
}
|
|
@@ -7773,9 +8019,9 @@
|
|
|
7773
8019
|
const headerRecord = createRecordWriter(HEADER_SIZE - 4);
|
|
7774
8020
|
const headerArray = headerRecord.array;
|
|
7775
8021
|
const headerView = getDataView(headerArray);
|
|
7776
|
-
headerRecord.
|
|
7777
|
-
headerRecord.
|
|
7778
|
-
headerRecord.
|
|
8022
|
+
headerRecord.writeUint16(version);
|
|
8023
|
+
headerRecord.writeUint16(bitFlag);
|
|
8024
|
+
headerRecord.writeUint16(compressionMethod);
|
|
7779
8025
|
if (rawLastModDate === UNDEFINED_VALUE) {
|
|
7780
8026
|
const dateArray = new Uint32Array(1);
|
|
7781
8027
|
const dateView = getDataView(dateArray);
|
|
@@ -7783,20 +8029,20 @@
|
|
|
7783
8029
|
setUint16(dateView, 2, ((((lastModDate.getFullYear() - 1980) << 4) | (lastModDate.getMonth() + 1)) << 5) | lastModDate.getDate());
|
|
7784
8030
|
rawLastModDate = dateArray[0];
|
|
7785
8031
|
}
|
|
7786
|
-
headerRecord.
|
|
8032
|
+
headerRecord.writeUint32(rawLastModDate);
|
|
7787
8033
|
headerRecord.skip(4);
|
|
7788
8034
|
if (zip64CompressedSize || compressedSize !== UNDEFINED_VALUE) {
|
|
7789
|
-
headerRecord.
|
|
8035
|
+
headerRecord.writeUint32(zip64CompressedSize ? MAX_32_BITS : compressedSize);
|
|
7790
8036
|
} else {
|
|
7791
8037
|
headerRecord.skip(4);
|
|
7792
8038
|
}
|
|
7793
8039
|
if (zip64UncompressedSize || uncompressedSize !== UNDEFINED_VALUE) {
|
|
7794
|
-
headerRecord.
|
|
8040
|
+
headerRecord.writeUint32(zip64UncompressedSize ? MAX_32_BITS : uncompressedSize);
|
|
7795
8041
|
} else {
|
|
7796
8042
|
headerRecord.skip(4);
|
|
7797
8043
|
}
|
|
7798
|
-
headerRecord.
|
|
7799
|
-
headerRecord.
|
|
8044
|
+
headerRecord.writeUint16(getLength(rawFilename));
|
|
8045
|
+
headerRecord.writeUint16(extraFieldLength);
|
|
7800
8046
|
return {
|
|
7801
8047
|
headerArray,
|
|
7802
8048
|
headerView,
|
|
@@ -8319,6 +8565,7 @@
|
|
|
8319
8565
|
exports.ERR_DUPLICATED_NAME = ERR_DUPLICATED_NAME;
|
|
8320
8566
|
exports.ERR_ENCRYPTED = ERR_ENCRYPTED;
|
|
8321
8567
|
exports.ERR_ENCRYPTED_CENTRAL_DIRECTORY = ERR_ENCRYPTED_CENTRAL_DIRECTORY;
|
|
8568
|
+
exports.ERR_ENTRY_DATA_OUT_OF_BOUNDS = ERR_ENTRY_DATA_OUT_OF_BOUNDS;
|
|
8322
8569
|
exports.ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND;
|
|
8323
8570
|
exports.ERR_EOCDR_NOT_FOUND = ERR_EOCDR_NOT_FOUND;
|
|
8324
8571
|
exports.ERR_EXTRAFIELD_ZIP64_NOT_FOUND = ERR_EXTRAFIELD_ZIP64_NOT_FOUND;
|
|
@@ -8331,19 +8578,26 @@
|
|
|
8331
8578
|
exports.ERR_INVALID_COMMENT_TYPE = ERR_INVALID_COMMENT_TYPE;
|
|
8332
8579
|
exports.ERR_INVALID_COMPRESSED_DATA = ERR_INVALID_COMPRESSED_DATA;
|
|
8333
8580
|
exports.ERR_INVALID_CRC32 = ERR_INVALID_CRC32;
|
|
8581
|
+
exports.ERR_INVALID_DATE = ERR_INVALID_DATE;
|
|
8334
8582
|
exports.ERR_INVALID_ENCRYPTION_STRENGTH = ERR_INVALID_ENCRYPTION_STRENGTH;
|
|
8335
8583
|
exports.ERR_INVALID_ENTRY_COMMENT = ERR_INVALID_ENTRY_COMMENT;
|
|
8584
|
+
exports.ERR_INVALID_ENTRY_COMMENT_TYPE = ERR_INVALID_ENTRY_COMMENT_TYPE;
|
|
8336
8585
|
exports.ERR_INVALID_ENTRY_NAME = ERR_INVALID_ENTRY_NAME;
|
|
8586
|
+
exports.ERR_INVALID_EXTRAFIELD = ERR_INVALID_EXTRAFIELD;
|
|
8337
8587
|
exports.ERR_INVALID_EXTRAFIELD_DATA = ERR_INVALID_EXTRAFIELD_DATA;
|
|
8588
|
+
exports.ERR_INVALID_EXTRAFIELD_DATA_TYPE = ERR_INVALID_EXTRAFIELD_DATA_TYPE;
|
|
8338
8589
|
exports.ERR_INVALID_EXTRAFIELD_TYPE = ERR_INVALID_EXTRAFIELD_TYPE;
|
|
8339
8590
|
exports.ERR_INVALID_FILENAME_VALIDATION = ERR_INVALID_FILENAME_VALIDATION;
|
|
8591
|
+
exports.ERR_INVALID_FUNCTION_OPTION = ERR_INVALID_FUNCTION_OPTION;
|
|
8340
8592
|
exports.ERR_INVALID_GID = ERR_INVALID_GID;
|
|
8341
8593
|
exports.ERR_INVALID_LEVEL = ERR_INVALID_LEVEL;
|
|
8342
8594
|
exports.ERR_INVALID_MAX_APPENDED_DATA_SIZE = ERR_INVALID_MAX_APPENDED_DATA_SIZE;
|
|
8595
|
+
exports.ERR_INVALID_MAX_WORKERS = ERR_INVALID_MAX_WORKERS;
|
|
8343
8596
|
exports.ERR_INVALID_MSDOS_ATTRIBUTES = ERR_INVALID_MSDOS_ATTRIBUTES;
|
|
8344
8597
|
exports.ERR_INVALID_MSDOS_DATA = ERR_INVALID_MSDOS_DATA;
|
|
8345
8598
|
exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
|
|
8346
8599
|
exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
|
|
8600
|
+
exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
|
|
8347
8601
|
exports.ERR_INVALID_SIGNATURE = ERR_INVALID_SIGNATURE;
|
|
8348
8602
|
exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
|
|
8349
8603
|
exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;
|
|
@@ -8358,6 +8612,7 @@
|
|
|
8358
8612
|
exports.ERR_OVERLAPPING_ENTRY = ERR_OVERLAPPING_ENTRY;
|
|
8359
8613
|
exports.ERR_RESERVED_COMPRESSION_METHOD = ERR_RESERVED_COMPRESSION_METHOD;
|
|
8360
8614
|
exports.ERR_SPLIT_ZIP_FILE = ERR_SPLIT_ZIP_FILE;
|
|
8615
|
+
exports.ERR_UNDEFINED_COMPRESSION_METHOD = ERR_UNDEFINED_COMPRESSION_METHOD;
|
|
8361
8616
|
exports.ERR_UNDEFINED_READER = ERR_UNDEFINED_READER;
|
|
8362
8617
|
exports.ERR_UNDEFINED_UNCOMPRESSED_SIZE = ERR_UNDEFINED_UNCOMPRESSED_SIZE;
|
|
8363
8618
|
exports.ERR_UNDETERMINED_SIZE = ERR_UNDETERMINED_SIZE;
|