@zip.js/zip.js 2.8.53 → 2.8.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +1 -1
  2. package/deno.json +2 -1
  3. package/dist/zip-core-external.js +691 -482
  4. package/dist/zip-core-external.min.js +1 -1
  5. package/dist/zip-core.js +698 -481
  6. package/dist/zip-core.min.js +1 -1
  7. package/dist/zip-fs-core-external.js +729 -511
  8. package/dist/zip-fs-core-external.min.js +1 -1
  9. package/dist/zip-fs-core.js +691 -496
  10. package/dist/zip-fs-core.min.js +1 -1
  11. package/dist/zip-fs-external.js +729 -511
  12. package/dist/zip-fs-external.min.js +1 -1
  13. package/dist/zip-fs-native.js +743 -512
  14. package/dist/zip-fs-native.min.js +1 -1
  15. package/dist/zip-fs.js +742 -511
  16. package/dist/zip-fs.min.js +1 -1
  17. package/dist/zip-legacy.js +700 -483
  18. package/dist/zip-legacy.min.js +1 -1
  19. package/dist/zip-native.js +700 -483
  20. package/dist/zip-native.min.js +1 -1
  21. package/dist/zip-web-worker-native.js +1 -1
  22. package/dist/zip-web-worker.js +1 -1
  23. package/dist/zip.js +699 -482
  24. package/dist/zip.min.js +1 -1
  25. package/eslint.config.mjs +1 -0
  26. package/index-native.cjs +743 -512
  27. package/index-native.min.js +1 -1
  28. package/index.cjs +742 -511
  29. package/index.d.cts +398 -42
  30. package/index.d.ts +398 -42
  31. package/index.min.js +1 -1
  32. package/lib/core/configuration.js +62 -21
  33. package/lib/core/constants.js +11 -1
  34. package/lib/core/io.js +33 -27
  35. package/lib/core/options.js +44 -2
  36. package/lib/core/streams/aes-crypto-stream.js +12 -12
  37. package/lib/core/util/decode-text.js +11 -2
  38. package/lib/core/web-worker-base.js +3 -2
  39. package/lib/core/web-worker-inline-native.js +1 -1
  40. package/lib/core/web-worker-inline-wasm.js +1 -1
  41. package/lib/core/zip-fs.js +38 -27
  42. package/lib/core/zip-reader.js +58 -26
  43. package/lib/core/zip-writer.js +293 -177
  44. package/lib/zip-core-base.js +6 -1
  45. package/lib/zip-core-reader.js +1 -0
  46. package/lib/zip-core-writer.js +4 -0
  47. package/package.json +8 -2
@@ -36,6 +36,7 @@ const COMPRESSION_METHOD_AES = 0x63;
36
36
 
37
37
  const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
38
38
  const SPLIT_ZIP_FILE_SIGNATURE = 0x08074b50;
39
+ const TEMPORARY_SPLIT_ZIP_FILE_SIGNATURE = 0x30304b50;
39
40
  const DATA_DESCRIPTOR_RECORD_SIGNATURE = SPLIT_ZIP_FILE_SIGNATURE;
40
41
  const ARCHIVE_EXTRA_DATA_SIGNATURE = 0x08064b50;
41
42
  const DIGITAL_SIGNATURE_RECORD_SIGNATURE = 0x05054b50;
@@ -52,6 +53,7 @@ const ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH = END_OF_CENTRAL_DIR_LENGTH + ZIP64_
52
53
  const DATA_DESCRIPTOR_RECORD_LENGTH = 12;
53
54
  const DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH = 20;
54
55
  const DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH = 4;
56
+ const SPLIT_ZIP_FILE_SIGNATURE_LENGTH = 4;
55
57
 
56
58
  const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
57
59
  const EXTRAFIELD_TYPE_AES = 0x9901;
@@ -103,6 +105,8 @@ const HEADER_OFFSET_VERSION = 0;
103
105
  const HEADER_OFFSET_SIGNATURE = 10;
104
106
  const HEADER_OFFSET_COMPRESSED_SIZE = 14;
105
107
  const HEADER_OFFSET_UNCOMPRESSED_SIZE = 18;
108
+ const HEADER_OFFSET_FILENAME_LENGTH = 22;
109
+ const HEADER_OFFSET_EXTRAFIELD_LENGTH = 24;
106
110
  const LOCAL_HEADER_COMMON_OFFSET = 4;
107
111
 
108
112
  const MAX_DATE = new Date(2107, 11, 31, 23, 59, 58);
@@ -115,9 +119,116 @@ const FUNCTION_TYPE = "function";
115
119
  const OBJECT_TYPE = "object";
116
120
  const STRING_TYPE = "string";
117
121
  const NUMBER_TYPE = "number";
122
+ const BOOLEAN_TYPE = "boolean";
118
123
 
119
124
  const EMPTY_UINT8_ARRAY = new Uint8Array();
120
125
 
126
+ /*
127
+ Copyright (c) 2022 Gildas Lormeau. All rights reserved.
128
+
129
+ Redistribution and use in source and binary forms, with or without
130
+ modification, are permitted provided that the following conditions are met:
131
+
132
+ 1. Redistributions of source code must retain the above copyright notice,
133
+ this list of conditions and the following disclaimer.
134
+
135
+ 2. Redistributions in binary form must reproduce the above copyright
136
+ notice, this list of conditions and the following disclaimer in
137
+ the documentation and/or other materials provided with the distribution.
138
+
139
+ 3. The names of the authors may not be used to endorse or promote products
140
+ derived from this software without specific prior written permission.
141
+
142
+ THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
143
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
144
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
145
+ INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
146
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
147
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
148
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
149
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
150
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
151
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
152
+ */
153
+
154
+
155
+ const OPTION_FILENAME_ENCODING = "filenameEncoding";
156
+ const OPTION_COMMENT_ENCODING = "commentEncoding";
157
+ const OPTION_DECODE_TEXT = "decodeText";
158
+ const OPTION_EXTRACT_PREPENDED_DATA = "extractPrependedData";
159
+ const OPTION_EXTRACT_APPENDED_DATA = "extractAppendedData";
160
+ const OPTION_PASSWORD = "password";
161
+ const OPTION_RAW_PASSWORD = "rawPassword";
162
+ const OPTION_PASS_THROUGH = "passThrough";
163
+ const OPTION_SIGNAL = "signal";
164
+ const OPTION_CHECK_PASSWORD_ONLY = "checkPasswordOnly";
165
+ const OPTION_CHECK_OVERLAPPING_ENTRY_ONLY = "checkOverlappingEntryOnly";
166
+ const OPTION_CHECK_OVERLAPPING_ENTRY = "checkOverlappingEntry";
167
+ const OPTION_CHECK_AMBIGUITY = "checkAmbiguity";
168
+ const OPTION_CHECK_LOCAL_DIRECTORY = "checkLocalDirectory";
169
+ const OPTION_CHECK_SIGNATURE = "checkSignature";
170
+ const OPTION_CHECK_CRC32 = "checkCrc32";
171
+ const OPTION_CHECK_AUTHENTICATION_CODE = "checkAuthenticationCode";
172
+ const OPTION_USE_WEB_WORKERS = "useWebWorkers";
173
+ const OPTION_USE_COMPRESSION_STREAM = "useCompressionStream";
174
+ const OPTION_TRANSFER_STREAMS = "transferStreams";
175
+ const OPTION_PREVENT_CLOSE = "preventClose";
176
+ const OPTION_ENCRYPTION_STRENGTH = "encryptionStrength";
177
+ const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
178
+ const OPTION_NTFS_TIMESTAMP = "ntfsTimestamp";
179
+ const OPTION_KEEP_ORDER = "keepOrder";
180
+ const OPTION_LEVEL = "level";
181
+ const OPTION_BUFFERED_WRITE = "bufferedWrite";
182
+ const OPTION_CREATE_TEMP_STREAM = "createTempStream";
183
+ const OPTION_DATA_DESCRIPTOR_SIGNATURE = "dataDescriptorSignature";
184
+ const OPTION_USE_UNICODE_FILE_NAMES = "useUnicodeFileNames";
185
+ const OPTION_DATA_DESCRIPTOR = "dataDescriptor";
186
+ const OPTION_SUPPORT_ZIP64_SPLIT_FILE = "supportZip64SplitFile";
187
+ const OPTION_ENCODE_TEXT = "encodeText";
188
+ const OPTION_OFFSET = "offset";
189
+ const OPTION_USDZ = "usdz";
190
+ const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
191
+ const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
192
+ const OPTION_STRICTNESS = "strictness";
193
+ const OPTION_FILENAME_VALIDATION = "filenameValidation";
194
+ const OPTION_NORMALIZE_FILENAME = "normalizeFilename";
195
+ const OPTION_MAX_APPENDED_DATA_SIZE = "maxAppendedDataSize";
196
+ const OPTION_DECRYPT_CENTRAL_DIRECTORY = "decryptCentralDirectory";
197
+ const OPTION_SIGN_CENTRAL_DIRECTORY = "signCentralDirectory";
198
+ const TEXT_TYPE_FILENAME = "filename";
199
+ const TEXT_TYPE_COMMENT = "comment";
200
+ const STRICTNESS_STRICT = "strict";
201
+ const STRICTNESS_BALANCED = "balanced";
202
+ const STRICTNESS_TOLERANT = "tolerant";
203
+
204
+ const ERR_INVALID_FUNCTION_OPTION = "Invalid option (must be a function)";
205
+ const ERR_INVALID_SIGNAL = "Invalid signal (must be an AbortSignal instance)";
206
+ const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
207
+
208
+ function checkFunctionOption(value) {
209
+ if (value && typeof value != FUNCTION_TYPE) {
210
+ throw new Error(ERR_INVALID_FUNCTION_OPTION);
211
+ }
212
+ return value;
213
+ }
214
+
215
+ function checkSignalOption(signal) {
216
+ if (signal && (typeof signal.addEventListener != FUNCTION_TYPE || typeof signal.aborted != BOOLEAN_TYPE)) {
217
+ throw new Error(ERR_INVALID_SIGNAL);
218
+ }
219
+ return signal || UNDEFINED_VALUE;
220
+ }
221
+
222
+ function checkPasswordOption(password, rawPassword) {
223
+ if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
224
+ throw new Error(ERR_INVALID_PASSWORD_TYPE);
225
+ }
226
+ }
227
+
228
+ function toNumber(value) {
229
+ return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
230
+ }
231
+
121
232
  /*
122
233
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
123
234
 
@@ -147,7 +258,10 @@ const EMPTY_UINT8_ARRAY = new Uint8Array();
147
258
  */
148
259
 
149
260
 
261
+ const DEFAULT_CHUNK_SIZE$1 = 64 * 1024;
150
262
  const MINIMUM_CHUNK_SIZE = 64;
263
+ const MINIMUM_PROPERTY_VALUE = 1;
264
+ const ERR_INVALID_MAX_WORKERS = "Invalid maxWorkers (must be an integer greater than 0)";
151
265
  let maxWorkers = 2;
152
266
  try {
153
267
  if (typeof navigator != UNDEFINED_TYPE && navigator.hardwareConcurrency) {
@@ -159,7 +273,7 @@ try {
159
273
  const DEFAULT_CONFIGURATION = {
160
274
  workerURI: "./core/web-worker-wasm.js",
161
275
  wasmURI: "./core/streams/zlib-wasm/zlib-streams.wasm",
162
- chunkSize: 64 * 1024,
276
+ chunkSize: DEFAULT_CHUNK_SIZE$1,
163
277
  maxWorkers,
164
278
  terminateWorkerTimeout: 5000,
165
279
  workerStarvationTimeout: 5000,
@@ -171,24 +285,38 @@ const DEFAULT_CONFIGURATION = {
171
285
  DecompressionStream: typeof DecompressionStream != UNDEFINED_TYPE && DecompressionStream
172
286
  };
173
287
 
174
- const CONFIGURABLE_PROPERTY_NAMES = [
288
+ const PROPERTY_NAME_MAX_WORKERS = "maxWorkers";
289
+
290
+ const STRING_PROPERTY_NAMES = [
175
291
  "baseURI",
176
292
  "wasmURI",
177
- "workerURI",
178
- "createWorker",
293
+ "workerURI"
294
+ ];
295
+ const BOOLEAN_PROPERTY_NAMES = [
296
+ "useCompressionStream",
297
+ "useWebWorkers",
298
+ "transferStreams"
299
+ ];
300
+ const NUMBER_PROPERTY_NAMES = [
179
301
  "chunkSize",
180
- "maxWorkers",
302
+ PROPERTY_NAME_MAX_WORKERS,
181
303
  "terminateWorkerTimeout",
182
304
  "workerStarvationTimeout",
183
- "workerStartupTimeout",
184
- "useCompressionStream",
185
- "useWebWorkers",
186
- "transferStreams",
305
+ "workerStartupTimeout"
306
+ ];
307
+ const FUNCTION_PROPERTY_NAMES = [
308
+ "createWorker",
187
309
  "CompressionStream",
188
310
  "DecompressionStream",
189
311
  "CompressionStreamFallback",
190
312
  "DecompressionStreamFallback"
191
313
  ];
314
+ const CONFIGURABLE_PROPERTY_NAMES = [
315
+ ...STRING_PROPERTY_NAMES,
316
+ ...BOOLEAN_PROPERTY_NAMES,
317
+ ...NUMBER_PROPERTY_NAMES,
318
+ ...FUNCTION_PROPERTY_NAMES
319
+ ];
192
320
 
193
321
  const config = { ...DEFAULT_CONFIGURATION };
194
322
 
@@ -197,20 +325,43 @@ function getConfiguration() {
197
325
  }
198
326
 
199
327
  function getChunkSize(config) {
200
- return Math.max(config.chunkSize, MINIMUM_CHUNK_SIZE);
328
+ return normalizeChunkSize(config.chunkSize);
329
+ }
330
+
331
+ function normalizeChunkSize(chunkSize) {
332
+ chunkSize = toNumber(chunkSize);
333
+ return Number.isInteger(chunkSize) && chunkSize >= MINIMUM_PROPERTY_VALUE ? Math.max(chunkSize, MINIMUM_CHUNK_SIZE) : DEFAULT_CHUNK_SIZE$1;
201
334
  }
202
335
 
203
336
  function configure(configuration) {
204
- configuration = normalizeConfiguration(configuration);
337
+ Object.assign(config, checkConfiguration(normalizeConfiguration(configuration)));
338
+ }
339
+
340
+ function checkConfiguration(configuration) {
341
+ const checkedConfiguration = {};
205
342
  for (const propertyName of CONFIGURABLE_PROPERTY_NAMES) {
206
343
  const propertyValue = configuration[propertyName];
207
344
  if (propertyValue !== UNDEFINED_VALUE) {
208
- config[propertyName] = propertyValue;
345
+ checkedConfiguration[propertyName] = checkPropertyValue(propertyName, propertyValue);
209
346
  }
210
347
  }
348
+ return checkedConfiguration;
349
+ }
350
+
351
+ function checkPropertyValue(propertyName, propertyValue) {
352
+ if (NUMBER_PROPERTY_NAMES.includes(propertyName)) {
353
+ propertyValue = toNumber(propertyValue);
354
+ if (propertyName == PROPERTY_NAME_MAX_WORKERS && (!Number.isInteger(propertyValue) || propertyValue < MINIMUM_PROPERTY_VALUE)) {
355
+ throw new Error(ERR_INVALID_MAX_WORKERS);
356
+ }
357
+ } else if (FUNCTION_PROPERTY_NAMES.includes(propertyName)) {
358
+ checkFunctionOption(propertyValue);
359
+ }
360
+ return propertyValue;
211
361
  }
212
362
 
213
363
  function normalizeConfiguration(configuration) {
364
+ configuration = configuration || {};
214
365
  const { CompressionStreamZlib, DecompressionStreamZlib } = configuration;
215
366
  if (CompressionStreamZlib === UNDEFINED_VALUE && DecompressionStreamZlib === UNDEFINED_VALUE) {
216
367
  return configuration;
@@ -226,14 +377,9 @@ function normalizeConfiguration(configuration) {
226
377
  }
227
378
 
228
379
  function setDefaultConfiguration(configuration) {
229
- configuration = normalizeConfiguration(configuration);
230
- for (const propertyName of CONFIGURABLE_PROPERTY_NAMES) {
231
- const propertyValue = configuration[propertyName];
232
- if (propertyValue !== UNDEFINED_VALUE) {
233
- DEFAULT_CONFIGURATION[propertyName] = propertyValue;
234
- }
235
- }
236
- configure(configuration);
380
+ const checkedConfiguration = checkConfiguration(normalizeConfiguration(configuration));
381
+ Object.assign(DEFAULT_CONFIGURATION, checkedConfiguration);
382
+ Object.assign(config, checkedConfiguration);
237
383
  }
238
384
 
239
385
  function resetConfiguration() {
@@ -1425,13 +1571,13 @@ class AESDecryptionStream extends TransformStream {
1425
1571
  const {
1426
1572
  ctr,
1427
1573
  hmac,
1428
- pending,
1574
+ pendingInput,
1429
1575
  ready
1430
1576
  } = this;
1431
1577
  if (hmac && ctr) {
1432
1578
  await ready;
1433
- const chunkToDecrypt = subarray(pending, 0, pending.length - AUTHENTICATION_CODE_LENGTH);
1434
- const originalAuthenticationCode = subarray(pending, pending.length - AUTHENTICATION_CODE_LENGTH);
1579
+ const chunkToDecrypt = subarray(pendingInput, 0, pendingInput.length - AUTHENTICATION_CODE_LENGTH);
1580
+ const originalAuthenticationCode = subarray(pendingInput, pendingInput.length - AUTHENTICATION_CODE_LENGTH);
1435
1581
  let decryptedChunkArray = EMPTY_UINT8_ARRAY;
1436
1582
  if (chunkToDecrypt.length) {
1437
1583
  const encryptedChunk = toBits(codecBytes, chunkToDecrypt);
@@ -1440,7 +1586,7 @@ class AESDecryptionStream extends TransformStream {
1440
1586
  decryptedChunkArray = fromBits(codecBytes, decryptedChunk);
1441
1587
  }
1442
1588
  const authenticationCode = subarray(fromBits(codecBytes, hmac.digest()), 0, AUTHENTICATION_CODE_LENGTH);
1443
- let invalidAuthenticationCode = pending.length < AUTHENTICATION_CODE_LENGTH ? 1 : 0;
1589
+ let invalidAuthenticationCode = pendingInput.length < AUTHENTICATION_CODE_LENGTH ? 1 : 0;
1444
1590
  for (let indexByte = 0; indexByte < AUTHENTICATION_CODE_LENGTH; indexByte++) {
1445
1591
  invalidAuthenticationCode |= authenticationCode[indexByte] ^ originalAuthenticationCode[indexByte];
1446
1592
  }
@@ -1484,14 +1630,14 @@ class AESEncryptionStream extends TransformStream {
1484
1630
  const {
1485
1631
  ctr,
1486
1632
  hmac,
1487
- pending,
1633
+ pendingInput,
1488
1634
  ready
1489
1635
  } = this;
1490
1636
  if (hmac && ctr) {
1491
1637
  await ready;
1492
1638
  let encryptedChunkArray = EMPTY_UINT8_ARRAY;
1493
- if (pending.length) {
1494
- const encryptedChunk = ctr.update(toBits(codecBytes, pending));
1639
+ if (pendingInput.length) {
1640
+ const encryptedChunk = ctr.update(toBits(codecBytes, pendingInput));
1495
1641
  hmac.update(encryptedChunk);
1496
1642
  encryptedChunkArray = fromBits(codecBytes, encryptedChunk);
1497
1643
  }
@@ -1508,7 +1654,7 @@ function initAesCrypto(aesCrypto, password, rawPassword, encryptionStrength) {
1508
1654
  ready: new Promise(resolve => aesCrypto.resolveReady = resolve),
1509
1655
  password: encodePassword(password, rawPassword),
1510
1656
  strength: encryptionStrength - 1,
1511
- pending: EMPTY_UINT8_ARRAY
1657
+ pendingInput: EMPTY_UINT8_ARRAY
1512
1658
  });
1513
1659
  }
1514
1660
 
@@ -1516,10 +1662,10 @@ function append(aesCrypto, input, output, paddingStart, paddingEnd, verifyAuthen
1516
1662
  const {
1517
1663
  ctr,
1518
1664
  hmac,
1519
- pending
1665
+ pendingInput
1520
1666
  } = aesCrypto;
1521
- if (pending.length) {
1522
- input = concat(pending, input);
1667
+ if (pendingInput.length) {
1668
+ input = concat(pendingInput, input);
1523
1669
  }
1524
1670
  const inputLength = input.length - paddingEnd;
1525
1671
  output = expand(output, paddingStart + (inputLength - (inputLength % BLOCK_LENGTH)));
@@ -1535,7 +1681,7 @@ function append(aesCrypto, input, output, paddingStart, paddingEnd, verifyAuthen
1535
1681
  }
1536
1682
  output.set(fromBits(codecBytes, outputChunk), offset + paddingStart);
1537
1683
  }
1538
- aesCrypto.pending = subarray(input, offset);
1684
+ aesCrypto.pendingInput = subarray(input, offset);
1539
1685
  return output;
1540
1686
  }
1541
1687
 
@@ -3312,6 +3458,96 @@ async function terminateWorkers() {
3312
3458
  resetWebWorkerSupport();
3313
3459
  }
3314
3460
 
3461
+ /*
3462
+ Copyright (c) 2022 Gildas Lormeau. All rights reserved.
3463
+
3464
+ Redistribution and use in source and binary forms, with or without
3465
+ modification, are permitted provided that the following conditions are met:
3466
+
3467
+ 1. Redistributions of source code must retain the above copyright notice,
3468
+ this list of conditions and the following disclaimer.
3469
+
3470
+ 2. Redistributions in binary form must reproduce the above copyright
3471
+ notice, this list of conditions and the following disclaimer in
3472
+ the documentation and/or other materials provided with the distribution.
3473
+
3474
+ 3. The names of the authors may not be used to endorse or promote products
3475
+ derived from this software without specific prior written permission.
3476
+
3477
+ THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
3478
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
3479
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
3480
+ INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
3481
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3482
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
3483
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3484
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3485
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
3486
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3487
+ */
3488
+
3489
+ /* global TextDecoder */
3490
+
3491
+ const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");
3492
+ const VALID_CP437 = CP437.length == 256;
3493
+
3494
+ function decodeCP437(stringValue) {
3495
+ if (VALID_CP437) {
3496
+ let result = "";
3497
+ for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
3498
+ result += CP437[stringValue[indexCharacter]];
3499
+ }
3500
+ return result;
3501
+ } else {
3502
+ return new TextDecoder().decode(stringValue);
3503
+ }
3504
+ }
3505
+
3506
+ /*
3507
+ Copyright (c) 2022 Gildas Lormeau. All rights reserved.
3508
+
3509
+ Redistribution and use in source and binary forms, with or without
3510
+ modification, are permitted provided that the following conditions are met:
3511
+
3512
+ 1. Redistributions of source code must retain the above copyright notice,
3513
+ this list of conditions and the following disclaimer.
3514
+
3515
+ 2. Redistributions in binary form must reproduce the above copyright
3516
+ notice, this list of conditions and the following disclaimer in
3517
+ the documentation and/or other materials provided with the distribution.
3518
+
3519
+ 3. The names of the authors may not be used to endorse or promote products
3520
+ derived from this software without specific prior written permission.
3521
+
3522
+ THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
3523
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
3524
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
3525
+ INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
3526
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3527
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
3528
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3529
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3530
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
3531
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3532
+ */
3533
+
3534
+
3535
+ function decodeText(value, encoding) {
3536
+ return decode(value, encoding, true);
3537
+ }
3538
+
3539
+ function decodeTextRemovingBOM(value, encoding) {
3540
+ return decode(value, encoding, false);
3541
+ }
3542
+
3543
+ function decode(value, encoding, ignoreBOM) {
3544
+ if (encoding && encoding.trim().toLowerCase() == "cp437") {
3545
+ return decodeCP437(value);
3546
+ } else {
3547
+ return new TextDecoder(encoding, { ignoreBOM }).decode(value);
3548
+ }
3549
+ }
3550
+
3315
3551
  /*
3316
3552
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
3317
3553
 
@@ -3384,6 +3620,7 @@ class Reader extends Stream {
3384
3620
  createReadable({ offset = 0, size, chunkSize = getChunkSize(getConfiguration()) } = {}) {
3385
3621
  const reader = this;
3386
3622
  let chunkOffset = 0;
3623
+ chunkSize = normalizeChunkSize(chunkSize);
3387
3624
  return new ReadableStream({
3388
3625
  async pull(controller) {
3389
3626
  const dataSize = size === UNDEFINED_VALUE ? chunkSize : Math.min(chunkSize, size - chunkOffset);
@@ -3391,7 +3628,7 @@ class Reader extends Stream {
3391
3628
  if (data.length) {
3392
3629
  controller.enqueue(data);
3393
3630
  }
3394
- if ((chunkOffset + chunkSize >= size) || (size === UNDEFINED_VALUE && !data.length && dataSize)) {
3631
+ if ((chunkOffset + chunkSize >= size) || (!data.length && dataSize)) {
3395
3632
  controller.close();
3396
3633
  } else {
3397
3634
  chunkOffset += chunkSize;
@@ -3471,31 +3708,31 @@ class Data64URIWriter extends Writer {
3471
3708
  Object.assign(this, {
3472
3709
  contentType,
3473
3710
  data: "data:" + (contentType || "") + ";base64,",
3474
- pending: []
3711
+ pendingCharacters: ""
3475
3712
  });
3476
3713
  }
3477
3714
 
3478
3715
  writeUint8Array(array) {
3479
3716
  const writer = this;
3480
3717
  let indexArray;
3481
- let dataString = writer.pending;
3482
- const delta = writer.pending.length;
3483
- writer.pending = "";
3718
+ let dataString = writer.pendingCharacters;
3719
+ const delta = writer.pendingCharacters.length;
3720
+ writer.pendingCharacters = "";
3484
3721
  for (indexArray = 0; indexArray < (Math.floor((delta + array.length) / 3) * 3) - delta; indexArray++) {
3485
3722
  dataString += String.fromCharCode(array[indexArray]);
3486
3723
  }
3487
3724
  for (; indexArray < array.length; indexArray++) {
3488
- writer.pending += String.fromCharCode(array[indexArray]);
3725
+ writer.pendingCharacters += String.fromCharCode(array[indexArray]);
3489
3726
  }
3490
3727
  if (dataString.length > 2) {
3491
3728
  writer.data += btoa(dataString);
3492
3729
  } else {
3493
- writer.pending = dataString + writer.pending;
3730
+ writer.pendingCharacters = dataString + writer.pendingCharacters;
3494
3731
  }
3495
3732
  }
3496
3733
 
3497
3734
  getData() {
3498
- return this.data + btoa(this.pending);
3735
+ return this.data + btoa(this.pendingCharacters);
3499
3736
  }
3500
3737
  }
3501
3738
 
@@ -3525,7 +3762,7 @@ class BlobReader extends Reader {
3525
3762
  constructor(blob) {
3526
3763
  super();
3527
3764
  Object.assign(this, {
3528
- blob,
3765
+ sourceBlob: blob,
3529
3766
  size: blob.size
3530
3767
  });
3531
3768
  if (!blobSliceProbe) {
@@ -3535,13 +3772,13 @@ class BlobReader extends Reader {
3535
3772
 
3536
3773
  createReadable(options) {
3537
3774
  const reader = this;
3538
- const { blob, size } = reader;
3775
+ const { sourceBlob, size } = reader;
3539
3776
  const { offset = 0, size: readSize = size - offset } = options || {};
3540
3777
  if (!offset && readSize >= size) {
3541
- return toCompatibleReadable(blob.stream());
3778
+ return toCompatibleReadable(sourceBlob.stream());
3542
3779
  }
3543
3780
  if (blobSliceReliable) {
3544
- return toCompatibleReadable(blob.slice(offset, offset + readSize).stream());
3781
+ return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
3545
3782
  }
3546
3783
  return super.createReadable(options);
3547
3784
  }
@@ -3550,7 +3787,7 @@ class BlobReader extends Reader {
3550
3787
  const reader = this;
3551
3788
  const offsetEnd = offset + length;
3552
3789
  const readsWholeBlob = !offset && offsetEnd >= reader.size;
3553
- const blob = readsWholeBlob ? reader.blob : reader.blob.slice(offset, offsetEnd);
3790
+ const blob = readsWholeBlob ? reader.sourceBlob : reader.sourceBlob.slice(offset, offsetEnd);
3554
3791
  let arrayBuffer = await blob.arrayBuffer();
3555
3792
  const sliceIgnoredByBuggyImplementation = arrayBuffer.byteLength > length;
3556
3793
  if (sliceIgnoredByBuggyImplementation) {
@@ -3572,12 +3809,12 @@ class BlobWriter extends Stream {
3572
3809
  }
3573
3810
  });
3574
3811
  writer.contentType = contentType;
3575
- writer.blob = streamToBlob(transformStream.readable, contentType);
3576
- writer.blob.catch(() => { });
3812
+ writer.blobPromise = streamToBlob(transformStream.readable, contentType);
3813
+ writer.blobPromise.catch(() => { });
3577
3814
  }
3578
3815
 
3579
3816
  getData() {
3580
- return this.blob;
3817
+ return this.blobPromise;
3581
3818
  }
3582
3819
  }
3583
3820
 
@@ -3591,7 +3828,7 @@ class TextReader extends BlobReader {
3591
3828
  class TextWriter extends BlobWriter {
3592
3829
 
3593
3830
  constructor(encoding) {
3594
- super(encoding);
3831
+ super();
3595
3832
  Object.assign(this, {
3596
3833
  encoding,
3597
3834
  utf8: !encoding || encoding.toLowerCase() == "utf-8"
@@ -3607,14 +3844,7 @@ class TextWriter extends BlobWriter {
3607
3844
  if (blob.text && utf8) {
3608
3845
  return blob.text();
3609
3846
  } else {
3610
- const reader = new FileReader();
3611
- return new Promise((resolve, reject) => {
3612
- Object.assign(reader, {
3613
- onload: ({ target }) => resolve(target.result),
3614
- onerror: () => reject(reader.error)
3615
- });
3616
- reader.readAsText(blob, encoding);
3617
- });
3847
+ return decodeTextRemovingBOM(new Uint8Array(await blob.arrayBuffer()), encoding);
3618
3848
  }
3619
3849
  }
3620
3850
  }
@@ -4282,85 +4512,13 @@ function readUint8Array(reader, offset, size) {
4282
4512
  return reader.readUint8Array(offset, size);
4283
4513
  }
4284
4514
 
4285
- /*
4286
- Copyright (c) 2022 Gildas Lormeau. All rights reserved.
4287
-
4288
- Redistribution and use in source and binary forms, with or without
4289
- modification, are permitted provided that the following conditions are met:
4290
-
4291
- 1. Redistributions of source code must retain the above copyright notice,
4292
- this list of conditions and the following disclaimer.
4293
-
4294
- 2. Redistributions in binary form must reproduce the above copyright
4295
- notice, this list of conditions and the following disclaimer in
4296
- the documentation and/or other materials provided with the distribution.
4297
-
4298
- 3. The names of the authors may not be used to endorse or promote products
4299
- derived from this software without specific prior written permission.
4300
-
4301
- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
4302
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
4303
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
4304
- INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
4305
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4306
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
4307
- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
4308
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
4309
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
4310
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4311
- */
4312
-
4313
- /* global TextDecoder */
4314
-
4315
- const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");
4316
- const VALID_CP437 = CP437.length == 256;
4317
-
4318
- function decodeCP437(stringValue) {
4319
- if (VALID_CP437) {
4320
- let result = "";
4321
- for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
4322
- result += CP437[stringValue[indexCharacter]];
4323
- }
4324
- return result;
4325
- } else {
4326
- return new TextDecoder().decode(stringValue);
4327
- }
4328
- }
4329
-
4330
- /*
4331
- Copyright (c) 2022 Gildas Lormeau. All rights reserved.
4332
-
4333
- Redistribution and use in source and binary forms, with or without
4334
- modification, are permitted provided that the following conditions are met:
4335
-
4336
- 1. Redistributions of source code must retain the above copyright notice,
4337
- this list of conditions and the following disclaimer.
4338
-
4339
- 2. Redistributions in binary form must reproduce the above copyright
4340
- notice, this list of conditions and the following disclaimer in
4341
- the documentation and/or other materials provided with the distribution.
4342
-
4343
- 3. The names of the authors may not be used to endorse or promote products
4344
- derived from this software without specific prior written permission.
4345
-
4346
- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
4347
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
4348
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
4349
- INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
4350
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4351
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
4352
- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
4353
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
4354
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
4355
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4356
- */
4357
-
4358
-
4359
- function decodeText(value, encoding) {
4360
- if (encoding && encoding.trim().toLowerCase() == "cp437") {
4361
- return decodeCP437(value);
4515
+ function createReadable(reader, options) {
4516
+ if (reader.createReadable) {
4517
+ return reader.createReadable(options);
4518
+ } else if (reader.readUint8Array) {
4519
+ return Reader.prototype.createReadable.call(reader, options);
4362
4520
  } else {
4363
- return new TextDecoder(encoding, { ignoreBOM: true }).decode(value);
4521
+ return reader.readable;
4364
4522
  }
4365
4523
  }
4366
4524
 
@@ -4520,83 +4678,6 @@ class Entry {
4520
4678
 
4521
4679
  }
4522
4680
 
4523
- /*
4524
- Copyright (c) 2022 Gildas Lormeau. All rights reserved.
4525
-
4526
- Redistribution and use in source and binary forms, with or without
4527
- modification, are permitted provided that the following conditions are met:
4528
-
4529
- 1. Redistributions of source code must retain the above copyright notice,
4530
- this list of conditions and the following disclaimer.
4531
-
4532
- 2. Redistributions in binary form must reproduce the above copyright
4533
- notice, this list of conditions and the following disclaimer in
4534
- the documentation and/or other materials provided with the distribution.
4535
-
4536
- 3. The names of the authors may not be used to endorse or promote products
4537
- derived from this software without specific prior written permission.
4538
-
4539
- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
4540
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
4541
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
4542
- INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
4543
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4544
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
4545
- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
4546
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
4547
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
4548
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4549
- */
4550
-
4551
- const OPTION_FILENAME_ENCODING = "filenameEncoding";
4552
- const OPTION_COMMENT_ENCODING = "commentEncoding";
4553
- const OPTION_DECODE_TEXT = "decodeText";
4554
- const OPTION_EXTRACT_PREPENDED_DATA = "extractPrependedData";
4555
- const OPTION_EXTRACT_APPENDED_DATA = "extractAppendedData";
4556
- const OPTION_PASSWORD = "password";
4557
- const OPTION_RAW_PASSWORD = "rawPassword";
4558
- const OPTION_PASS_THROUGH = "passThrough";
4559
- const OPTION_SIGNAL = "signal";
4560
- const OPTION_CHECK_PASSWORD_ONLY = "checkPasswordOnly";
4561
- const OPTION_CHECK_OVERLAPPING_ENTRY_ONLY = "checkOverlappingEntryOnly";
4562
- const OPTION_CHECK_OVERLAPPING_ENTRY = "checkOverlappingEntry";
4563
- const OPTION_CHECK_AMBIGUITY = "checkAmbiguity";
4564
- const OPTION_CHECK_LOCAL_DIRECTORY = "checkLocalDirectory";
4565
- const OPTION_CHECK_SIGNATURE = "checkSignature";
4566
- const OPTION_CHECK_CRC32 = "checkCrc32";
4567
- const OPTION_CHECK_AUTHENTICATION_CODE = "checkAuthenticationCode";
4568
- const OPTION_USE_WEB_WORKERS = "useWebWorkers";
4569
- const OPTION_USE_COMPRESSION_STREAM = "useCompressionStream";
4570
- const OPTION_TRANSFER_STREAMS = "transferStreams";
4571
- const OPTION_PREVENT_CLOSE = "preventClose";
4572
- const OPTION_ENCRYPTION_STRENGTH = "encryptionStrength";
4573
- const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
4574
- const OPTION_NTFS_TIMESTAMP = "ntfsTimestamp";
4575
- const OPTION_KEEP_ORDER = "keepOrder";
4576
- const OPTION_LEVEL = "level";
4577
- const OPTION_BUFFERED_WRITE = "bufferedWrite";
4578
- const OPTION_CREATE_TEMP_STREAM = "createTempStream";
4579
- const OPTION_DATA_DESCRIPTOR_SIGNATURE = "dataDescriptorSignature";
4580
- const OPTION_USE_UNICODE_FILE_NAMES = "useUnicodeFileNames";
4581
- const OPTION_DATA_DESCRIPTOR = "dataDescriptor";
4582
- const OPTION_SUPPORT_ZIP64_SPLIT_FILE = "supportZip64SplitFile";
4583
- const OPTION_ENCODE_TEXT = "encodeText";
4584
- const OPTION_OFFSET = "offset";
4585
- const OPTION_USDZ = "usdz";
4586
- const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
4587
- const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
4588
- const OPTION_STRICTNESS = "strictness";
4589
- const OPTION_FILENAME_VALIDATION = "filenameValidation";
4590
- const OPTION_NORMALIZE_FILENAME = "normalizeFilename";
4591
- const OPTION_MAX_APPENDED_DATA_SIZE = "maxAppendedDataSize";
4592
- const OPTION_DECRYPT_CENTRAL_DIRECTORY = "decryptCentralDirectory";
4593
- const OPTION_SIGN_CENTRAL_DIRECTORY = "signCentralDirectory";
4594
- const TEXT_TYPE_FILENAME = "filename";
4595
- const TEXT_TYPE_COMMENT = "comment";
4596
- const STRICTNESS_STRICT = "strict";
4597
- const STRICTNESS_BALANCED = "balanced";
4598
- const STRICTNESS_TOLERANT = "tolerant";
4599
-
4600
4681
  /*
4601
4682
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
4602
4683
 
@@ -4637,6 +4718,7 @@ const ERR_UNSUPPORTED_ENCRYPTION = "Encryption method not supported";
4637
4718
  const ERR_UNSUPPORTED_COMPRESSION$1 = "Compression method not supported";
4638
4719
  const ERR_SPLIT_ZIP_FILE = "Split zip file";
4639
4720
  const ERR_OVERLAPPING_ENTRY = "Overlapping entry found";
4721
+ const ERR_ENTRY_DATA_OUT_OF_BOUNDS = "Entry data out of bounds";
4640
4722
  const ERR_AMBIGUOUS_ARCHIVE = "Ambiguous archive";
4641
4723
  const ERR_ENCRYPTED_CENTRAL_DIRECTORY = "Encrypted central directory is not supported";
4642
4724
  const ERR_UNSAFE_FILENAME = "Unsafe filename";
@@ -4657,7 +4739,7 @@ const ZIP64_PROPERTIES = [
4657
4739
  ];
4658
4740
  const ZIP64_EXTRACTION = {
4659
4741
  [MAX_16_BITS]: {
4660
- getValue: getUint32,
4742
+ getValue: getUint32$1,
4661
4743
  bytes: 4
4662
4744
  },
4663
4745
  [MAX_32_BITS]: {
@@ -4666,6 +4748,7 @@ const ZIP64_EXTRACTION = {
4666
4748
  }
4667
4749
  };
4668
4750
  const MAX_END_OF_CENTRAL_DIR_PROBES = 64;
4751
+ const MAX_DEFLATE_EXPANSION_RATIO = 1032;
4669
4752
  const CENTRAL_DIRECTORY_UNREACHABLE = 0;
4670
4753
  const CENTRAL_DIRECTORY_PLAUSIBLE = 1;
4671
4754
  const CENTRAL_DIRECTORY_REACHABLE = 2;
@@ -4676,7 +4759,6 @@ class ZipReader {
4676
4759
  Object.assign(this, {
4677
4760
  reader: new GenericReader(reader),
4678
4761
  options,
4679
- config: getConfiguration(),
4680
4762
  readRanges: new Map()
4681
4763
  });
4682
4764
  }
@@ -4684,7 +4766,6 @@ class ZipReader {
4684
4766
  async* getEntriesGenerator(options = {}) {
4685
4767
  const zipReader = this;
4686
4768
  let { reader } = zipReader;
4687
- const { config } = zipReader;
4688
4769
  await initStream(reader);
4689
4770
  if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
4690
4771
  reader = new BlobReader(await streamToBlob(reader.readable));
@@ -4701,9 +4782,7 @@ class ZipReader {
4701
4782
  const normalizeFilename = getOptionValue$1(zipReader, options, OPTION_NORMALIZE_FILENAME);
4702
4783
  const { endOfDirectoryInfo, endOfDirectoryReachingEndCount } = await findEndOfCentralDirectory(reader, rejectAmbiguousEndOfDirectory, maxAppendedDataSize);
4703
4784
  if (!endOfDirectoryInfo) {
4704
- const signatureArray = await readUint8Array(reader, 0, 4);
4705
- const signatureView = getDataView(signatureArray);
4706
- if (getUint32(signatureView) == SPLIT_ZIP_FILE_SIGNATURE) {
4785
+ if (await startsWithSplitZipSignature$1(reader)) {
4707
4786
  throw new Error(ERR_SPLIT_ZIP_FILE);
4708
4787
  } else {
4709
4788
  throw new Error(ERR_EOCDR_NOT_FOUND);
@@ -4713,18 +4792,18 @@ class ZipReader {
4713
4792
  throwAmbiguousArchive("multiple end of central directory records");
4714
4793
  }
4715
4794
  const endOfDirectoryView = getDataView(endOfDirectoryInfo);
4716
- let directoryDataLength = getUint32(endOfDirectoryView, 12);
4717
- let directoryDataOffset = getUint32(endOfDirectoryView, 16);
4795
+ let directoryDataLength = getUint32$1(endOfDirectoryView, 12);
4796
+ let directoryDataOffset = getUint32$1(endOfDirectoryView, 16);
4718
4797
  const commentOffset = endOfDirectoryInfo.offset;
4719
- const commentLength = getUint16(endOfDirectoryView, 20);
4798
+ const commentLength = getUint16$1(endOfDirectoryView, 20);
4720
4799
  const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
4721
4800
  if (reader.size - appendedDataOffset > maxAppendedDataSize) {
4722
4801
  throwAmbiguousArchive("appended data");
4723
4802
  }
4724
- let lastDiskNumber = getUint16(endOfDirectoryView, 4);
4803
+ let lastDiskNumber = getUint16$1(endOfDirectoryView, 4);
4725
4804
  const expectedLastDiskNumber = reader.lastDiskNumber || 0;
4726
- let diskNumber = getUint16(endOfDirectoryView, 6);
4727
- let filesLength = getUint16(endOfDirectoryView, 10);
4805
+ let diskNumber = getUint16$1(endOfDirectoryView, 6);
4806
+ let filesLength = getUint16$1(endOfDirectoryView, 10);
4728
4807
  let prependedDataLength = 0;
4729
4808
  let startOffset;
4730
4809
  let zip64EndOfDirectory;
@@ -4740,12 +4819,12 @@ class ZipReader {
4740
4819
  EMPTY_UINT8_ARRAY;
4741
4820
  const endOfDirectoryLocatorView = getDataView(endOfDirectoryLocatorArray);
4742
4821
  if (endOfDirectoryLocatorArray.length == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH &&
4743
- getUint32(endOfDirectoryLocatorView, 0) == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
4744
- directoryDataOffset = getDiskOffset$1(reader, getUint32(endOfDirectoryLocatorView, 4)) + getBigUint64(endOfDirectoryLocatorView, 8);
4822
+ getUint32$1(endOfDirectoryLocatorView, 0) == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
4823
+ directoryDataOffset = getDiskOffset$1(reader, getUint32$1(endOfDirectoryLocatorView, 4)) + getBigUint64(endOfDirectoryLocatorView, 8);
4745
4824
  let endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4746
4825
  let endOfDirectoryView = getDataView(endOfDirectoryArray);
4747
4826
  const expectedDirectoryDataOffset = endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH - ZIP64_END_OF_CENTRAL_DIR_LENGTH;
4748
- if ((endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) &&
4827
+ if ((endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32$1(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) &&
4749
4828
  directoryDataOffset != expectedDirectoryDataOffset && expectedDirectoryDataOffset >= 0) {
4750
4829
  const originalDirectoryDataOffset = directoryDataOffset;
4751
4830
  directoryDataOffset = expectedDirectoryDataOffset;
@@ -4755,7 +4834,7 @@ class ZipReader {
4755
4834
  endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4756
4835
  endOfDirectoryView = getDataView(endOfDirectoryArray);
4757
4836
  }
4758
- if (endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
4837
+ if (endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32$1(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
4759
4838
  throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
4760
4839
  }
4761
4840
  zip64EndOfDirectory = true;
@@ -4770,13 +4849,13 @@ class ZipReader {
4770
4849
  }
4771
4850
  }
4772
4851
  if (lastDiskNumber == MAX_16_BITS) {
4773
- lastDiskNumber = getUint32(endOfDirectoryView, 16);
4774
- } else if (checkAmbiguity && lastDiskNumber != getUint32(endOfDirectoryView, 16)) {
4852
+ lastDiskNumber = getUint32$1(endOfDirectoryView, 16);
4853
+ } else if (checkAmbiguity && lastDiskNumber != getUint32$1(endOfDirectoryView, 16)) {
4775
4854
  throwAmbiguousArchive("mismatched zip64 end of central directory record");
4776
4855
  }
4777
4856
  if (diskNumber == MAX_16_BITS) {
4778
- diskNumber = getUint32(endOfDirectoryView, 20);
4779
- } else if (checkAmbiguity && diskNumber != getUint32(endOfDirectoryView, 20)) {
4857
+ diskNumber = getUint32$1(endOfDirectoryView, 20);
4858
+ } else if (checkAmbiguity && diskNumber != getUint32$1(endOfDirectoryView, 20)) {
4780
4859
  throwAmbiguousArchive("mismatched zip64 end of central directory record");
4781
4860
  }
4782
4861
  if (filesLength == MAX_16_BITS) {
@@ -4814,11 +4893,11 @@ class ZipReader {
4814
4893
  }
4815
4894
  const expectedDirectoryDataOffset = centralDirectoryEndOffset - directoryDataLength;
4816
4895
  if (directoryDataOffset != expectedDirectoryDataOffset && diskNumber == lastDiskNumber) {
4817
- const storedPointsAtDirectory = getUint32(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE;
4896
+ const storedPointsAtDirectory = getUint32$1(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE;
4818
4897
  let reconcile = !storedPointsAtDirectory;
4819
4898
  if (!reconcile && expectedDirectoryDataOffset >= 0 && expectedDirectoryDataOffset + 4 <= reader.size) {
4820
4899
  const expectedSignatureArray = await readUint8Array(reader, expectedDirectoryDataOffset, 4);
4821
- reconcile = getUint32(getDataView(expectedSignatureArray), 0) == CENTRAL_FILE_HEADER_SIGNATURE;
4900
+ reconcile = getUint32$1(getDataView(expectedSignatureArray), 0) == CENTRAL_FILE_HEADER_SIGNATURE;
4822
4901
  }
4823
4902
  if (reconcile) {
4824
4903
  const originalDirectoryDataOffset = directoryDataOffset;
@@ -4842,10 +4921,10 @@ class ZipReader {
4842
4921
  }
4843
4922
  zipReader.directoryOffset = directoryDataOffset;
4844
4923
  zipReader.directoryLength = declaredDirectoryDataLength;
4845
- const decryptCentralDirectory = getOptionValue$1(zipReader, options, OPTION_DECRYPT_CENTRAL_DIRECTORY);
4924
+ const decryptCentralDirectory = getFunctionOptionValue$1(zipReader, options, OPTION_DECRYPT_CENTRAL_DIRECTORY);
4846
4925
  let decryptedDirectory;
4847
4926
  if (decryptCentralDirectory && filesLength && directoryArray.length >= 4 &&
4848
- getUint32(directoryView, 0) != CENTRAL_FILE_HEADER_SIGNATURE &&
4927
+ getUint32$1(directoryView, 0) != CENTRAL_FILE_HEADER_SIGNATURE &&
4849
4928
  (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
4850
4929
  directoryArray = await decryptCentralDirectory(directoryArray, directoryEncryptionInfo);
4851
4930
  directoryView = getDataView(directoryArray);
@@ -4858,8 +4937,8 @@ class ZipReader {
4858
4937
  const filenames = checkAmbiguity ? new Set() : UNDEFINED_VALUE;
4859
4938
  let duplicateFilename;
4860
4939
  for (let indexFile = 0; indexFile < filesLength; indexFile++) {
4861
- const fileEntry = new ZipEntry(reader, config, zipReader.options);
4862
- if (offset + CENTRAL_FILE_HEADER_LENGTH > directoryArray.length || getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
4940
+ const fileEntry = new ZipEntry(reader, zipReader.options);
4941
+ if (offset + CENTRAL_FILE_HEADER_LENGTH > directoryArray.length || getUint32$1(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
4863
4942
  if (indexFile == 0 && !decryptedDirectory && (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
4864
4943
  throw new Error(ERR_ENCRYPTED_CENTRAL_DIRECTORY);
4865
4944
  }
@@ -4870,16 +4949,16 @@ class ZipReader {
4870
4949
  const filenameOffset = offset + CENTRAL_FILE_HEADER_LENGTH;
4871
4950
  const extraFieldOffset = filenameOffset + fileEntry.filenameLength;
4872
4951
  const commentOffset = extraFieldOffset + fileEntry.extraFieldLength;
4873
- const versionMadeBy = getUint16(directoryView, offset + 4);
4952
+ const versionMadeBy = getUint16$1(directoryView, offset + 4);
4874
4953
  const msDosCompatible = versionMadeBy >> 8 == 0;
4875
4954
  const unixCompatible = versionMadeBy >> 8 == 3;
4876
4955
  const rawFilename = directoryArray.subarray(filenameOffset, extraFieldOffset);
4877
- const commentLength = getUint16(directoryView, offset + 32);
4956
+ const commentLength = getUint16$1(directoryView, offset + 32);
4878
4957
  const endOffset = commentOffset + commentLength;
4879
4958
  const rawComment = directoryArray.subarray(commentOffset, endOffset);
4880
4959
  const filenameUTF8 = languageEncodingFlag;
4881
4960
  const commentUTF8 = languageEncodingFlag;
4882
- const externalFileAttributes = getUint32(directoryView, offset + 38);
4961
+ const externalFileAttributes = getUint32$1(directoryView, offset + 38);
4883
4962
  const msdosAttributesRaw = externalFileAttributes & MAX_8_BITS;
4884
4963
  const msdosAttributes = {
4885
4964
  readOnly: Boolean(msdosAttributesRaw & FILE_ATTR_MSDOS_READONLY_MASK),
@@ -4888,8 +4967,8 @@ class ZipReader {
4888
4967
  directory: Boolean(msdosAttributesRaw & FILE_ATTR_MSDOS_DIR_MASK),
4889
4968
  archive: Boolean(msdosAttributesRaw & FILE_ATTR_MSDOS_ARCHIVE_MASK)
4890
4969
  };
4891
- const offsetFileEntry = getUint32(directoryView, offset + 42);
4892
- const decode = getOptionValue$1(zipReader, options, OPTION_DECODE_TEXT) || decodeText;
4970
+ const offsetFileEntry = getUint32$1(directoryView, offset + 42);
4971
+ const decode = getFunctionOptionValue$1(zipReader, options, OPTION_DECODE_TEXT) || decodeText;
4893
4972
  const rawFilenameEncoding = filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437;
4894
4973
  const rawCommentEncoding = commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437;
4895
4974
  let filename = decode(rawFilename, rawFilenameEncoding, TEXT_TYPE_FILENAME);
@@ -4920,8 +4999,8 @@ class ZipReader {
4920
4999
  uncompressedSize: 0,
4921
5000
  commentLength,
4922
5001
  offset: offsetFileEntry,
4923
- diskNumberStart: getUint16(directoryView, offset + 34),
4924
- internalFileAttributes: getUint16(directoryView, offset + 36),
5002
+ diskNumberStart: getUint16$1(directoryView, offset + 34),
5003
+ internalFileAttributes: getUint16$1(directoryView, offset + 36),
4925
5004
  externalFileAttributes,
4926
5005
  msdosAttributesRaw,
4927
5006
  msdosAttributes,
@@ -4989,8 +5068,8 @@ class ZipReader {
4989
5068
  yield entry;
4990
5069
  }
4991
5070
  let offsetAfterSignature = offset;
4992
- if (offset + 6 <= directoryArray.length && getUint32(directoryView, offset) == DIGITAL_SIGNATURE_RECORD_SIGNATURE) {
4993
- const signatureDataLength = getUint16(directoryView, offset + 4);
5071
+ if (offset + 6 <= directoryArray.length && getUint32$1(directoryView, offset) == DIGITAL_SIGNATURE_RECORD_SIGNATURE) {
5072
+ const signatureDataLength = getUint16$1(directoryView, offset + 4);
4994
5073
  if (offset + 6 + signatureDataLength <= directoryArray.length) {
4995
5074
  zipReader.digitalSignature = directoryArray.subarray(offset + 6, offset + 6 + signatureDataLength);
4996
5075
  offsetAfterSignature = offset + 6 + signatureDataLength;
@@ -5002,13 +5081,17 @@ class ZipReader {
5002
5081
  if (duplicateFilename) {
5003
5082
  throwAmbiguousArchive("duplicate filename");
5004
5083
  }
5005
- if (checkAmbiguity && (prependedDataLength || (filesLength && startOffset > 0))) {
5006
- throwAmbiguousArchive("prepended data");
5007
- }
5008
5084
  const extractPrependedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_PREPENDED_DATA);
5009
5085
  const extractAppendedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_APPENDED_DATA);
5086
+ const splitZipSignatureLength = (checkAmbiguity || extractPrependedData) && filesLength &&
5087
+ startOffset == SPLIT_ZIP_FILE_SIGNATURE_LENGTH && await startsWithSplitZipMarker(reader) ? SPLIT_ZIP_FILE_SIGNATURE_LENGTH : 0;
5088
+ if (checkAmbiguity && (prependedDataLength || (filesLength && startOffset > splitZipSignatureLength))) {
5089
+ throwAmbiguousArchive("prepended data");
5090
+ }
5010
5091
  if (extractPrependedData) {
5011
- zipReader.prependedData = startOffset > 0 ? await readUint8Array(reader, 0, startOffset) : EMPTY_UINT8_ARRAY;
5092
+ zipReader.prependedData = startOffset > splitZipSignatureLength ?
5093
+ await readUint8Array(reader, splitZipSignatureLength, startOffset - splitZipSignatureLength) :
5094
+ EMPTY_UINT8_ARRAY;
5012
5095
  }
5013
5096
  zipReader.comment = commentLength ? await readUint8Array(reader, commentOffset + END_OF_CENTRAL_DIR_LENGTH, commentLength) : EMPTY_UINT8_ARRAY;
5014
5097
  if (extractAppendedData) {
@@ -5075,16 +5158,16 @@ class ZipReaderStream {
5075
5158
 
5076
5159
  class ZipEntry {
5077
5160
 
5078
- constructor(reader, config, options) {
5161
+ constructor(reader, options) {
5079
5162
  Object.assign(this, {
5080
5163
  reader,
5081
- config,
5082
5164
  options
5083
5165
  });
5084
5166
  }
5085
5167
 
5086
5168
  async getData(writer, fileEntry, readRanges, options = {}) {
5087
5169
  const zipEntry = this;
5170
+ const config = getConfiguration();
5088
5171
  const {
5089
5172
  reader,
5090
5173
  index,
@@ -5093,7 +5176,6 @@ class ZipEntry {
5093
5176
  extraFieldAES,
5094
5177
  extraFieldZip64,
5095
5178
  compressionMethod,
5096
- config,
5097
5179
  bitFlag,
5098
5180
  rawBitFlag,
5099
5181
  crc32,
@@ -5111,6 +5193,7 @@ class ZipEntry {
5111
5193
  let password = getOptionValue$1(zipEntry, options, OPTION_PASSWORD);
5112
5194
  let rawPassword = getOptionValue$1(zipEntry, options, OPTION_RAW_PASSWORD);
5113
5195
  const passThrough = getOptionValue$1(zipEntry, options, OPTION_PASS_THROUGH);
5196
+ checkPasswordOption(password, rawPassword);
5114
5197
  password = password && password.length && password;
5115
5198
  rawPassword = rawPassword && rawPassword.length && rawPassword;
5116
5199
  if (extraFieldAES) {
@@ -5118,7 +5201,7 @@ class ZipEntry {
5118
5201
  throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
5119
5202
  }
5120
5203
  }
5121
- if (dataArray.length < HEADER_SIZE || getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
5204
+ if (dataArray.length < HEADER_SIZE || getUint32$1(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
5122
5205
  throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
5123
5206
  }
5124
5207
  readCommonHeader(localDirectory, dataView, 4);
@@ -5180,9 +5263,12 @@ class ZipEntry {
5180
5263
  }
5181
5264
  }
5182
5265
  const dataOffset = localHeaderOffset + HEADER_SIZE + filenameLength + extraFieldLength;
5266
+ if (dataOffset + compressedSize > reader.size) {
5267
+ throw new Error(ERR_ENTRY_DATA_OUT_OF_BOUNDS);
5268
+ }
5183
5269
  const size = compressedSize;
5184
5270
  const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
5185
- const signal = getOptionValue$1(zipEntry, options, OPTION_SIGNAL);
5271
+ const signal = checkSignalOption(getOptionValue$1(zipEntry, options, OPTION_SIGNAL));
5186
5272
  const checkPasswordOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_PASSWORD_ONLY);
5187
5273
  let checkOverlappingEntry = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY);
5188
5274
  const checkOverlappingEntryOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY_ONLY);
@@ -5190,6 +5276,8 @@ class ZipEntry {
5190
5276
  checkOverlappingEntry = true;
5191
5277
  }
5192
5278
  const { onstart, onprogress, onend } = options;
5279
+ const compressed = compressionMethod != COMPRESSION_METHOD_STORE && !passThrough;
5280
+ const outputSize = passThrough ? compressedSize : uncompressedSize;
5193
5281
  const deflate64 = compressionMethod == COMPRESSION_METHOD_DEFLATE_64;
5194
5282
  let useCompressionStream = getOptionValue$1(zipEntry, options, OPTION_USE_COMPRESSION_STREAM);
5195
5283
  if (deflate64) {
@@ -5210,9 +5298,9 @@ class ZipEntry {
5210
5298
  checkCrc32,
5211
5299
  checkAuthenticationCode: getOptionValue$1(zipEntry, options, OPTION_CHECK_AUTHENTICATION_CODE),
5212
5300
  passwordVerification: zipCrypto && (dataDescriptor ? ((rawLastModDate >>> 8) & MAX_8_BITS) : ((crc32 >>> 24) & MAX_8_BITS)),
5213
- outputSize: passThrough ? compressedSize : uncompressedSize,
5301
+ outputSize,
5214
5302
  crc32,
5215
- compressed: compressionMethod != 0 && !passThrough,
5303
+ compressed,
5216
5304
  encrypted,
5217
5305
  useWebWorkers: getOptionValue$1(zipEntry, options, OPTION_USE_WEB_WORKERS),
5218
5306
  useCompressionStream,
@@ -5249,11 +5337,11 @@ class ZipEntry {
5249
5337
  writer = new WritableStream();
5250
5338
  }
5251
5339
  writer = new GenericWriter(writer);
5252
- await initStream(writer, passThrough ? compressedSize : uncompressedSize);
5340
+ await initStream(writer, getDecodableOutputSize(outputSize, compressedSize, compressed));
5253
5341
  ({ writable } = writer);
5254
- const { outputSize } = await runWorker({ readable, writable }, workerOptions);
5255
- writer.size += outputSize;
5256
- if (outputSize != (passThrough ? compressedSize : uncompressedSize)) {
5342
+ const { outputSize: writtenSize } = await runWorker({ readable, writable }, workerOptions);
5343
+ writer.size += writtenSize;
5344
+ if (writtenSize != outputSize) {
5257
5345
  throw new Error(ERR_INVALID_UNCOMPRESSED_SIZE);
5258
5346
  }
5259
5347
  }
@@ -5287,7 +5375,7 @@ class ZipEntry {
5287
5375
  function detectEncryptedCentralDirectory(directoryView) {
5288
5376
  const maxOffset = Math.min(directoryView.byteLength, 1024) - 3;
5289
5377
  for (let offset = 0; offset < maxOffset; offset++) {
5290
- if (getUint32(directoryView, offset) == ARCHIVE_EXTRA_DATA_SIGNATURE) {
5378
+ if (getUint32$1(directoryView, offset) == ARCHIVE_EXTRA_DATA_SIGNATURE) {
5291
5379
  return true;
5292
5380
  }
5293
5381
  }
@@ -5298,15 +5386,15 @@ function getDirectoryEncryptionInfo(rawExtensibleData) {
5298
5386
  const directoryEncryptionInfo = { rawExtensibleData };
5299
5387
  if (rawExtensibleData.length >= 28) {
5300
5388
  const extensibleDataView = getDataView(rawExtensibleData);
5301
- const hashDataLength = getUint16(extensibleDataView, 26);
5389
+ const hashDataLength = getUint16$1(extensibleDataView, 26);
5302
5390
  Object.assign(directoryEncryptionInfo, {
5303
- compressionMethod: getUint16(extensibleDataView, 0),
5391
+ compressionMethod: getUint16$1(extensibleDataView, 0),
5304
5392
  compressedSize: Number(getBigUint64(extensibleDataView, 2)),
5305
5393
  uncompressedSize: Number(getBigUint64(extensibleDataView, 10)),
5306
- encryptionAlgorithm: getUint16(extensibleDataView, 18),
5307
- bitLength: getUint16(extensibleDataView, 20),
5308
- flags: getUint16(extensibleDataView, 22),
5309
- hashAlgorithm: getUint16(extensibleDataView, 24),
5394
+ encryptionAlgorithm: getUint16$1(extensibleDataView, 18),
5395
+ bitLength: getUint16$1(extensibleDataView, 20),
5396
+ flags: getUint16$1(extensibleDataView, 22),
5397
+ hashAlgorithm: getUint16$1(extensibleDataView, 24),
5310
5398
  hashData: rawExtensibleData.subarray(28, 28 + hashDataLength)
5311
5399
  });
5312
5400
  }
@@ -5314,12 +5402,12 @@ function getDirectoryEncryptionInfo(rawExtensibleData) {
5314
5402
  }
5315
5403
 
5316
5404
  function readCommonHeader(directory, dataView, offset) {
5317
- const rawBitFlag = directory.rawBitFlag = getUint16(dataView, offset + 2);
5405
+ const rawBitFlag = directory.rawBitFlag = getUint16$1(dataView, offset + 2);
5318
5406
  const encrypted = (rawBitFlag & BITFLAG_ENCRYPTED) == BITFLAG_ENCRYPTED;
5319
- const rawLastModDate = getUint32(dataView, offset + 6);
5407
+ const rawLastModDate = getUint32$1(dataView, offset + 6);
5320
5408
  Object.assign(directory, {
5321
5409
  encrypted,
5322
- version: getUint16(dataView, offset),
5410
+ version: getUint16$1(dataView, offset),
5323
5411
  bitFlag: {
5324
5412
  level: (rawBitFlag & BITFLAG_LEVEL) >> 1,
5325
5413
  dataDescriptor: (rawBitFlag & BITFLAG_DATA_DESCRIPTOR) == BITFLAG_DATA_DESCRIPTOR,
@@ -5327,8 +5415,8 @@ function readCommonHeader(directory, dataView, offset) {
5327
5415
  },
5328
5416
  rawLastModDate,
5329
5417
  lastModDate: getDate(rawLastModDate),
5330
- filenameLength: getUint16(dataView, offset + 22),
5331
- extraFieldLength: getUint16(dataView, offset + 24)
5418
+ filenameLength: getUint16$1(dataView, offset + 22),
5419
+ extraFieldLength: getUint16$1(dataView, offset + 24)
5332
5420
  });
5333
5421
  }
5334
5422
 
@@ -5339,8 +5427,8 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
5339
5427
  let offsetExtraField = 0;
5340
5428
  try {
5341
5429
  while (offsetExtraField < rawExtraField.length) {
5342
- const type = getUint16(rawExtraFieldView, offsetExtraField);
5343
- const size = getUint16(rawExtraFieldView, offsetExtraField + 2);
5430
+ const type = getUint16$1(rawExtraFieldView, offsetExtraField);
5431
+ const size = getUint16$1(rawExtraFieldView, offsetExtraField + 2);
5344
5432
  extraField.set(type, {
5345
5433
  type,
5346
5434
  data: rawExtraField.slice(offsetExtraField + 4, offsetExtraField + 4 + size)
@@ -5350,12 +5438,12 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
5350
5438
  } catch {
5351
5439
  // ignored
5352
5440
  }
5353
- const compressionMethod = getUint16(dataView, offset + 4);
5441
+ const compressionMethod = getUint16$1(dataView, offset + 4);
5354
5442
  Object.assign(directory, {
5355
- signature: getUint32(dataView, offset + HEADER_OFFSET_SIGNATURE),
5356
- crc32: getUint32(dataView, offset + HEADER_OFFSET_SIGNATURE),
5357
- compressedSize: getUint32(dataView, offset + HEADER_OFFSET_COMPRESSED_SIZE),
5358
- uncompressedSize: getUint32(dataView, offset + HEADER_OFFSET_UNCOMPRESSED_SIZE)
5443
+ signature: getUint32$1(dataView, offset + HEADER_OFFSET_SIGNATURE),
5444
+ crc32: getUint32$1(dataView, offset + HEADER_OFFSET_SIGNATURE),
5445
+ compressedSize: getUint32$1(dataView, offset + HEADER_OFFSET_COMPRESSED_SIZE),
5446
+ uncompressedSize: getUint32$1(dataView, offset + HEADER_OFFSET_UNCOMPRESSED_SIZE)
5359
5447
  });
5360
5448
  const extraFieldZip64 = extraField.get(EXTRAFIELD_TYPE_ZIP64);
5361
5449
  if (extraFieldZip64) {
@@ -5444,11 +5532,11 @@ function readExtraFieldUnicode(extraFieldUnicode, propertyName, rawPropertyName,
5444
5532
  computedCrc32.append(fileEntry[rawPropertyName]);
5445
5533
  const computedCrc32View = getDataView(new Uint8Array(4));
5446
5534
  computedCrc32View.setUint32(0, computedCrc32.get(), true);
5447
- const nameCrc32 = getUint32(extraFieldView, 1);
5535
+ const nameCrc32 = getUint32$1(extraFieldView, 1);
5448
5536
  Object.assign(extraFieldUnicode, {
5449
5537
  version: getUint8(extraFieldView, 0),
5450
5538
  [propertyName]: decodeText(extraFieldUnicode.data.subarray(5)),
5451
- valid: !fileEntry.bitFlag.languageEncodingFlag && nameCrc32 == getUint32(computedCrc32View, 0)
5539
+ valid: !fileEntry.bitFlag.languageEncodingFlag && nameCrc32 == getUint32$1(computedCrc32View, 0)
5452
5540
  });
5453
5541
  if (extraFieldUnicode.valid) {
5454
5542
  directory[propertyName] = extraFieldUnicode[propertyName];
@@ -5464,7 +5552,7 @@ function readExtraFieldAES(extraFieldAES, directory, compressionMethod) {
5464
5552
  vendorId: getUint8(extraFieldView, 2),
5465
5553
  strength,
5466
5554
  originalCompressionMethod: compressionMethod,
5467
- compressionMethod: getUint16(extraFieldView, 5)
5555
+ compressionMethod: getUint16$1(extraFieldView, 5)
5468
5556
  });
5469
5557
  directory.compressionMethod = extraFieldAES.compressionMethod;
5470
5558
  if (extraFieldAES.vendorVersion != VENDOR_VERSION_AE_1$1) {
@@ -5478,8 +5566,8 @@ function readExtraFieldNTFS(extraFieldNTFS, directory) {
5478
5566
  let tag1Data;
5479
5567
  try {
5480
5568
  while (offsetExtraField < extraFieldNTFS.data.length && !tag1Data) {
5481
- const tagValue = getUint16(extraFieldView, offsetExtraField);
5482
- const attributeSize = getUint16(extraFieldView, offsetExtraField + 2);
5569
+ const tagValue = getUint16$1(extraFieldView, offsetExtraField);
5570
+ const attributeSize = getUint16$1(extraFieldView, offsetExtraField + 2);
5483
5571
  if (tagValue == EXTRAFIELD_TYPE_NTFS_TAG1) {
5484
5572
  tag1Data = extraFieldNTFS.data.slice(offsetExtraField + 4, offsetExtraField + 4 + attributeSize);
5485
5573
  }
@@ -5512,12 +5600,12 @@ function readExtraFieldUnixDates(extraField, directory) {
5512
5600
  return;
5513
5601
  }
5514
5602
  const extraFieldView = getDataView(extraField.data);
5515
- const lastAccessDate = new Date((getUint32(extraFieldView, 0) | 0) * 1000);
5516
- const lastModDate = new Date((getUint32(extraFieldView, 4) | 0) * 1000);
5603
+ const lastAccessDate = new Date((getUint32$1(extraFieldView, 0) | 0) * 1000);
5604
+ const lastModDate = new Date((getUint32$1(extraFieldView, 4) | 0) * 1000);
5517
5605
  const extraFieldData = { lastAccessDate, lastModDate };
5518
5606
  if (extraField.data.length >= 12) {
5519
- extraFieldData.uid = getUint16(extraFieldView, 8);
5520
- extraFieldData.gid = getUint16(extraFieldView, 10);
5607
+ extraFieldData.uid = getUint16$1(extraFieldView, 8);
5608
+ extraFieldData.gid = getUint16$1(extraFieldView, 10);
5521
5609
  }
5522
5610
  Object.assign(extraField, extraFieldData);
5523
5611
  Object.assign(directory, extraFieldData);
@@ -5537,8 +5625,8 @@ function readExtraFieldUnix(extraField, directory, isInfoZip) {
5537
5625
  gid = unpackUnixId(extraField.data.subarray(offset, offset + gidSize));
5538
5626
  Object.assign(extraField, { version, uid, gid });
5539
5627
  } else if (extraField.data.length >= 4) {
5540
- uid = getUint16(view, 0);
5541
- gid = getUint16(view, 2);
5628
+ uid = getUint16$1(view, 0);
5629
+ gid = getUint16$1(view, 2);
5542
5630
  Object.assign(extraField, { uid, gid });
5543
5631
  }
5544
5632
  if (uid !== UNDEFINED_VALUE) {
@@ -5588,7 +5676,7 @@ function readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory,
5588
5676
  let offset = 1;
5589
5677
  timeProperties.forEach((propertyName, indexProperty) => {
5590
5678
  if (extraFieldExtendedTimestamp.data.length >= offset + 4) {
5591
- const time = getUint32(extraFieldView, offset);
5679
+ const time = getUint32$1(extraFieldView, offset);
5592
5680
  directory[propertyName] = extraFieldExtendedTimestamp[propertyName] = new Date((time | 0) * 1000);
5593
5681
  const rawPropertyName = timeRawProperties[indexProperty];
5594
5682
  extraFieldExtendedTimestamp[rawPropertyName] = time;
@@ -5622,7 +5710,7 @@ async function detectOverlappingEntry({
5622
5710
  const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
5623
5711
  const dataDescriptorView = getDataView(dataDescriptorArray);
5624
5712
  let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
5625
- getUint32(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
5713
+ getUint32$1(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
5626
5714
  if (signature) {
5627
5715
  const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
5628
5716
  const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
@@ -5656,15 +5744,15 @@ async function detectOverlappingEntry({
5656
5744
  }
5657
5745
 
5658
5746
  function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
5659
- const crc32 = getUint32(dataDescriptorView, offset);
5747
+ const crc32 = getUint32$1(dataDescriptorView, offset);
5660
5748
  let compressedSize;
5661
5749
  let uncompressedSize;
5662
5750
  if (extraFieldZip64) {
5663
5751
  compressedSize = getBigUint64(dataDescriptorView, offset + 4);
5664
5752
  uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
5665
5753
  } else {
5666
- compressedSize = getUint32(dataDescriptorView, offset + 4);
5667
- uncompressedSize = getUint32(dataDescriptorView, offset + 8);
5754
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
5755
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
5668
5756
  }
5669
5757
  return { crc32, compressedSize, uncompressedSize };
5670
5758
  }
@@ -5673,10 +5761,28 @@ function getDiskOffset$1(reader, diskNumber) {
5673
5761
  return reader.getDiskOffset ? reader.getDiskOffset(diskNumber) : 0;
5674
5762
  }
5675
5763
 
5764
+ async function startsWithSplitZipSignature$1(reader) {
5765
+ return await getFirstSignature(reader) == SPLIT_ZIP_FILE_SIGNATURE;
5766
+ }
5767
+
5768
+ async function startsWithSplitZipMarker(reader) {
5769
+ const signature = await getFirstSignature(reader);
5770
+ return signature == SPLIT_ZIP_FILE_SIGNATURE || signature == TEMPORARY_SPLIT_ZIP_FILE_SIGNATURE;
5771
+ }
5772
+
5773
+ async function getFirstSignature(reader) {
5774
+ const signatureArray = await readUint8Array(reader, 0, SPLIT_ZIP_FILE_SIGNATURE_LENGTH);
5775
+ return getUint32$1(getDataView(signatureArray));
5776
+ }
5777
+
5676
5778
  function isStrictnessValue(value) {
5677
5779
  return value === STRICTNESS_STRICT || value === STRICTNESS_BALANCED || value === STRICTNESS_TOLERANT;
5678
5780
  }
5679
5781
 
5782
+ function getDecodableOutputSize(outputSize, compressedSize, compressed) {
5783
+ return Math.min(outputSize, compressed ? compressedSize * MAX_DEFLATE_EXPANSION_RATIO : compressedSize);
5784
+ }
5785
+
5680
5786
  function getStrictness(options, inheritedOptions) {
5681
5787
  return resolveStrictness(options, resolveStrictness(inheritedOptions, STRICTNESS_BALANCED));
5682
5788
  }
@@ -5739,7 +5845,7 @@ function isUnsafeFilename(filename, filenameValidation) {
5739
5845
 
5740
5846
  function getMaxAppendedDataSize(maxAppendedDataSize, strictness) {
5741
5847
  if (maxAppendedDataSize !== UNDEFINED_VALUE) {
5742
- const size = toNumber$1(maxAppendedDataSize);
5848
+ const size = toNumber(maxAppendedDataSize);
5743
5849
  if (typeof size != NUMBER_TYPE || Number.isNaN(size) || size < 0) {
5744
5850
  throw new Error(ERR_INVALID_MAX_APPENDED_DATA_SIZE);
5745
5851
  }
@@ -5762,7 +5868,7 @@ async function findEndOfCentralDirectory(reader, rejectAmbiguous, maxAppendedDat
5762
5868
  let plausibleEndOfDirectoryInfo;
5763
5869
  let endOfDirectoryReachingEndCount = 0;
5764
5870
  for await (const [anchoredView, anchoredOffset, anchoredArray, indexByte, offset] of scanEndOfCentralDirectory(reader, anchoredLength)) {
5765
- const commentLength = getUint16(anchoredView, indexByte + 20);
5871
+ const commentLength = getUint16$1(anchoredView, indexByte + 20);
5766
5872
  if (offset + END_OF_CENTRAL_DIR_LENGTH + commentLength == size) {
5767
5873
  const reachability = await getCentralDirectoryReachability(reader, anchoredView, anchoredOffset, indexByte, offset, size, remoteProbeBudget);
5768
5874
  if (reachability == CENTRAL_DIRECTORY_REACHABLE) {
@@ -5813,7 +5919,7 @@ async function* scanEndOfCentralDirectory(reader, scanLength) {
5813
5919
  const scanArray = await readUint8Array(reader, scanOffset, scanLength);
5814
5920
  const scanView = getDataView(scanArray);
5815
5921
  for (let indexByte = scanArray.length - END_OF_CENTRAL_DIR_LENGTH; indexByte >= 0; indexByte--) {
5816
- if (getUint32(scanView, indexByte) == END_OF_CENTRAL_DIR_SIGNATURE) {
5922
+ if (getUint32$1(scanView, indexByte) == END_OF_CENTRAL_DIR_SIGNATURE) {
5817
5923
  yield [scanView, scanOffset, scanArray, indexByte, scanOffset + indexByte];
5818
5924
  }
5819
5925
  }
@@ -5824,9 +5930,9 @@ function getEndOfCentralDirectoryInfo(scanArray, indexByte, offset) {
5824
5930
  }
5825
5931
 
5826
5932
  async function getCentralDirectoryReachability(reader, view, anchoredOffset, indexByte, offset, size, remoteProbeBudget) {
5827
- const filesLength = getUint16(view, indexByte + 10);
5828
- const directoryDataLength = getUint32(view, indexByte + 12);
5829
- const directoryDataOffset = getUint32(view, indexByte + 16);
5933
+ const filesLength = getUint16$1(view, indexByte + 10);
5934
+ const directoryDataLength = getUint32$1(view, indexByte + 12);
5935
+ const directoryDataOffset = getUint32$1(view, indexByte + 16);
5830
5936
  if (filesLength == MAX_16_BITS || directoryDataLength == MAX_32_BITS || directoryDataOffset == MAX_32_BITS) {
5831
5937
  const locatorSignature = await readSignature(reader, view, anchoredOffset, offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, size, remoteProbeBudget);
5832
5938
  return locatorSignature == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE ? CENTRAL_DIRECTORY_REACHABLE : CENTRAL_DIRECTORY_UNREACHABLE;
@@ -5834,7 +5940,7 @@ async function getCentralDirectoryReachability(reader, view, anchoredOffset, ind
5834
5940
  if (!filesLength && !directoryDataLength) {
5835
5941
  return CENTRAL_DIRECTORY_PLAUSIBLE;
5836
5942
  }
5837
- const directoryDiskNumber = getUint16(view, indexByte + 6);
5943
+ const directoryDiskNumber = getUint16$1(view, indexByte + 6);
5838
5944
  for (const centralDirectoryOffset of [offset - directoryDataLength, getDiskOffset$1(reader, directoryDiskNumber) + directoryDataOffset]) {
5839
5945
  if (await readSignature(reader, view, anchoredOffset, centralDirectoryOffset, size, remoteProbeBudget) == CENTRAL_FILE_HEADER_SIGNATURE) {
5840
5946
  return CENTRAL_DIRECTORY_REACHABLE;
@@ -5848,12 +5954,12 @@ async function readSignature(reader, view, anchoredOffset, signatureOffset, size
5848
5954
  return UNDEFINED_VALUE;
5849
5955
  }
5850
5956
  if (signatureOffset >= anchoredOffset) {
5851
- return getUint32(view, signatureOffset - anchoredOffset);
5957
+ return getUint32$1(view, signatureOffset - anchoredOffset);
5852
5958
  }
5853
5959
  if (remoteProbeBudget.count > 0) {
5854
5960
  remoteProbeBudget.count--;
5855
5961
  const signatureArray = await readUint8Array(reader, signatureOffset, 4);
5856
- return getUint32(getDataView(signatureArray), 0);
5962
+ return getUint32$1(getDataView(signatureArray), 0);
5857
5963
  }
5858
5964
  return UNDEFINED_VALUE;
5859
5965
  }
@@ -5890,10 +5996,11 @@ function getOptionValue$1(zipReader, options, name) {
5890
5996
  return options[name] === UNDEFINED_VALUE ? zipReader.options[name] : options[name];
5891
5997
  }
5892
5998
 
5893
- function toNumber$1(value) {
5894
- return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
5999
+ function getFunctionOptionValue$1(zipReader, options, name) {
6000
+ return checkFunctionOption(getOptionValue$1(zipReader, options, name));
5895
6001
  }
5896
6002
 
6003
+
5897
6004
  function getDate(timeRaw) {
5898
6005
  const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & MAX_16_BITS;
5899
6006
  return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
@@ -5907,11 +6014,11 @@ function getUint8(view, offset) {
5907
6014
  return view.getUint8(offset);
5908
6015
  }
5909
6016
 
5910
- function getUint16(view, offset) {
6017
+ function getUint16$1(view, offset) {
5911
6018
  return view.getUint16(offset, true);
5912
6019
  }
5913
6020
 
5914
- function getUint32(view, offset) {
6021
+ function getUint32$1(view, offset) {
5915
6022
  return view.getUint32(offset, true);
5916
6023
  }
5917
6024
 
@@ -5926,6 +6033,7 @@ var zipReader = /*#__PURE__*/Object.freeze({
5926
6033
  ERR_CENTRAL_DIRECTORY_NOT_FOUND: ERR_CENTRAL_DIRECTORY_NOT_FOUND,
5927
6034
  ERR_ENCRYPTED: ERR_ENCRYPTED,
5928
6035
  ERR_ENCRYPTED_CENTRAL_DIRECTORY: ERR_ENCRYPTED_CENTRAL_DIRECTORY,
6036
+ ERR_ENTRY_DATA_OUT_OF_BOUNDS: ERR_ENTRY_DATA_OUT_OF_BOUNDS,
5929
6037
  ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND,
5930
6038
  ERR_EOCDR_NOT_FOUND: ERR_EOCDR_NOT_FOUND,
5931
6039
  ERR_EXTRAFIELD_ZIP64_NOT_FOUND: ERR_EXTRAFIELD_ZIP64_NOT_FOUND,
@@ -5982,12 +6090,16 @@ const ERR_DUPLICATED_NAME = "File already exists";
5982
6090
  const ERR_INVALID_COMMENT = "Zip file comment exceeds 64KB";
5983
6091
  const ERR_INVALID_COMMENT_TYPE = "Invalid zip file comment (must be a Uint8Array)";
5984
6092
  const ERR_INVALID_ENTRY_COMMENT = "File entry comment exceeds 64KB";
6093
+ const ERR_INVALID_ENTRY_COMMENT_TYPE = "Invalid file entry comment (must be a string)";
6094
+ const ERR_INVALID_DATE = "Invalid date (must be a valid Date instance)";
5985
6095
  const ERR_INVALID_ENTRY_NAME = "File entry name exceeds 64KB";
5986
6096
  const ERR_INVALID_VERSION = "Version exceeds 65535";
5987
6097
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
5988
6098
  const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
5989
6099
  const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
5990
- const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
6100
+ const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
6101
+ const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
6102
+ const ERR_INVALID_EXTRAFIELD_DATA_TYPE = "Invalid extra field data (must be a Uint8Array)";
5991
6103
  const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
5992
6104
  const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
5993
6105
  const MIN_UNIX_TIME = -2147483648;
@@ -6007,7 +6119,6 @@ const ERR_INVALID_UNIX_ID_SIZE = "uid/gid must be 0..65535 for unixExtraFieldTyp
6007
6119
  const ERR_INVALID_MSDOS_ATTRIBUTES = "Invalid msdosAttributesRaw (must be integer 0..255)";
6008
6120
  const ERR_INVALID_MSDOS_DATA = "Invalid msdosAttributes (must be an object with boolean flags)";
6009
6121
  const ERR_INVALID_LEVEL = "Invalid level (must be integer 0..9)";
6010
- const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
6011
6122
  const ERR_INVALID_SIGNATURE_DATA = "Signature data exceeds 64KB";
6012
6123
 
6013
6124
  const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
@@ -6032,8 +6143,7 @@ class ZipWriter {
6032
6143
  writer,
6033
6144
  addSplitZipSignature,
6034
6145
  options,
6035
- config: getConfiguration(),
6036
- files: new Map(),
6146
+ fileEntries: new Map(),
6037
6147
  filenames: new Set(),
6038
6148
  offset: options[OPTION_OFFSET] === UNDEFINED_VALUE ? writer.size || writer.writable.size || 0 : options[OPTION_OFFSET],
6039
6149
  initialOffset: options[OPTION_OFFSET] === UNDEFINED_VALUE ? 0 : options[OPTION_OFFSET] - (writer.size || writer.writable.size || 0),
@@ -6054,14 +6164,23 @@ class ZipWriter {
6054
6164
  await initStream(reader);
6055
6165
  }
6056
6166
  const { ZipReader } = await Promise.resolve().then(function () { return zipReader; });
6057
- const zipReader$1 = new ZipReader(reader.readable);
6167
+ const zipReader$1 = new ZipReader(reader);
6058
6168
  const entries = await zipReader$1.getEntries();
6059
6169
  await zipReader$1.close();
6060
6170
  await initStream(this.writer);
6061
- await reader.readable.pipeTo(this.writer.writable, { preventClose: true, preventAbort: true });
6062
- this.writer.size = this.offset = reader.size;
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);
6063
6182
  this.filenames = new Set(entries.map(entry => entry.filename));
6064
- this.files = new Map(entries.map(entry => {
6183
+ this.fileEntries = new Map(entries.map(entry => {
6065
6184
  const {
6066
6185
  version,
6067
6186
  rawLastModDate,
@@ -6116,11 +6235,12 @@ class ZipWriter {
6116
6235
  if (crc32 !== UNDEFINED_VALUE) {
6117
6236
  setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
6118
6237
  }
6238
+ const { offset, diskNumberStart } = entryPositions.get(entry);
6119
6239
  Object.assign(entry, {
6120
6240
  zip64UncompressedSize,
6121
6241
  zip64CompressedSize,
6122
- zip64Offset: zip64 && entry.offset >= MAX_32_BITS,
6123
- diskNumberStart: 0,
6242
+ offset,
6243
+ diskNumberStart,
6124
6244
  zip64DiskNumberStart: false,
6125
6245
  rawExtraFieldZip64,
6126
6246
  rawExtraFieldAES,
@@ -6140,11 +6260,8 @@ class ZipWriter {
6140
6260
  async add(name = "", reader, options = {}) {
6141
6261
  const zipWriter = this;
6142
6262
  options = Object.assign({}, options);
6143
- const {
6144
- pendingAddFileCalls,
6145
- config
6146
- } = zipWriter;
6147
- if (workers < config.maxWorkers) {
6263
+ const { pendingAddFileCalls } = zipWriter;
6264
+ if (workers < getConfiguration().maxWorkers) {
6148
6265
  workers++;
6149
6266
  } else {
6150
6267
  await new Promise(resolve => pendingEntries.push(resolve));
@@ -6181,16 +6298,16 @@ class ZipWriter {
6181
6298
  }
6182
6299
 
6183
6300
  remove(entry) {
6184
- const { filenames, files } = this;
6301
+ const { filenames, fileEntries } = this;
6185
6302
  // deno-lint-ignore valid-typeof
6186
6303
  if (typeof entry == STRING_TYPE) {
6187
- entry = files.get(entry);
6304
+ entry = fileEntries.get(entry);
6188
6305
  }
6189
6306
  if (entry && entry.filename !== UNDEFINED_VALUE) {
6190
6307
  const { filename } = entry;
6191
- if (filenames.has(filename) && files.has(filename)) {
6308
+ if (filenames.has(filename) && fileEntries.has(filename)) {
6192
6309
  filenames.delete(filename);
6193
- files.delete(filename);
6310
+ fileEntries.delete(filename);
6194
6311
  return true;
6195
6312
  }
6196
6313
  }
@@ -6287,12 +6404,12 @@ async function addFile(zipWriter, name, reader, options) {
6287
6404
  const metadataInfo = resolveMetadata(zipWriter, name, options);
6288
6405
  const { comment } = metadataInfo;
6289
6406
  const extraField = options[PROPERTY_NAME_EXTRA_FIELD];
6290
- zipWriter.files.set(name, UNDEFINED_VALUE);
6407
+ zipWriter.fileEntries.set(name, UNDEFINED_VALUE);
6291
6408
  let fileEntry;
6292
6409
  try {
6293
6410
  const { resolvedOptions } = metadataInfo;
6294
6411
  if (resolvedOptions.level != 0 && resolvedOptions.compressionMethod === UNDEFINED_VALUE &&
6295
- !resolvedOptions.passThrough && !(await supportsDeflate(zipWriter.config))) {
6412
+ !resolvedOptions.passThrough && !(await supportsDeflate(getConfiguration()))) {
6296
6413
  resolvedOptions.level = 0;
6297
6414
  }
6298
6415
  const sizesInfo = await resolveSizes(zipWriter, reader, metadataInfo, options);
@@ -6310,7 +6427,7 @@ async function addFile(zipWriter, name, reader, options) {
6310
6427
  const metadataSize = getLength(headerInfo.localHeaderArray, dataDescriptorInfo.dataDescriptorArray);
6311
6428
  fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo, metadataSize }, options);
6312
6429
  } catch (error) {
6313
- zipWriter.files.delete(name);
6430
+ zipWriter.fileEntries.delete(name);
6314
6431
  throw error;
6315
6432
  }
6316
6433
  Object.assign(fileEntry, {
@@ -6354,9 +6471,9 @@ function resolveAttributes(zipWriter, name, options) {
6354
6471
  if (unixExtraFieldType === UNDEFINED_VALUE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
6355
6472
  unixExtraFieldType = INFOZIP_EXTRA_FIELD_TYPE;
6356
6473
  }
6357
- let msdosAttributesRaw = getOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW);
6474
+ let msdosAttributesRaw = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW);
6358
6475
  let msdosAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES);
6359
- 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;
6360
6477
  const hasMsDosProvided = msdosAttributesRaw !== UNDEFINED_VALUE || msdosAttributes !== UNDEFINED_VALUE;
6361
6478
  if (hasUnixMetadata) {
6362
6479
  msDosCompatible = false;
@@ -6365,10 +6482,10 @@ function resolveAttributes(zipWriter, name, options) {
6365
6482
  msDosCompatible = true;
6366
6483
  versionMadeBy = (versionMadeBy & MAX_8_BITS);
6367
6484
  }
6368
- if (msdosAttributesRaw !== UNDEFINED_VALUE && (msdosAttributesRaw < 0 || msdosAttributesRaw > MAX_8_BITS)) {
6485
+ if (msdosAttributesRaw !== UNDEFINED_VALUE && (!Number.isInteger(msdosAttributesRaw) || msdosAttributesRaw < 0 || msdosAttributesRaw > MAX_8_BITS)) {
6369
6486
  throw new Error(ERR_INVALID_MSDOS_ATTRIBUTES);
6370
6487
  }
6371
- if (msdosAttributes && typeof msdosAttributes !== OBJECT_TYPE) {
6488
+ if (msdosAttributes && (typeof msdosAttributes !== OBJECT_TYPE || Array.isArray(msdosAttributes))) {
6372
6489
  throw new Error(ERR_INVALID_MSDOS_DATA);
6373
6490
  }
6374
6491
  if (versionMadeBy > MAX_16_BITS) {
@@ -6456,7 +6573,7 @@ function resolveAttributes(zipWriter, name, options) {
6456
6573
  }
6457
6574
 
6458
6575
  function resolveMetadata(zipWriter, name, options) {
6459
- const encode = getOptionValue(zipWriter, options, OPTION_ENCODE_TEXT, encodeText);
6576
+ const encode = getFunctionOptionValue(zipWriter, options, OPTION_ENCODE_TEXT) || encodeText;
6460
6577
  let rawFilename = encode(name, TEXT_TYPE_FILENAME);
6461
6578
  if (rawFilename === UNDEFINED_VALUE) {
6462
6579
  rawFilename = encodeText(name);
@@ -6465,6 +6582,10 @@ function resolveMetadata(zipWriter, name, options) {
6465
6582
  throw new Error(ERR_INVALID_ENTRY_NAME);
6466
6583
  }
6467
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
+ }
6468
6589
  let rawComment = encode(comment, TEXT_TYPE_COMMENT);
6469
6590
  if (rawComment === UNDEFINED_VALUE) {
6470
6591
  rawComment = encodeText(comment);
@@ -6476,16 +6597,14 @@ function resolveMetadata(zipWriter, name, options) {
6476
6597
  if (version > MAX_16_BITS) {
6477
6598
  throw new Error(ERR_INVALID_VERSION);
6478
6599
  }
6479
- const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
6480
- const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
6481
- const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
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);
6482
6603
  const internalFileAttributes = getAliasedOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES, 0);
6483
6604
  const passThrough = getOptionValue(zipWriter, options, OPTION_PASS_THROUGH);
6484
6605
  const password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
6485
6606
  const rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
6486
- if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
6487
- throw new Error(ERR_INVALID_PASSWORD_TYPE);
6488
- }
6607
+ checkPasswordOption(password, rawPassword);
6489
6608
  const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
6490
6609
  const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
6491
6610
  const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
@@ -6494,9 +6613,9 @@ function resolveMetadata(zipWriter, name, options) {
6494
6613
  const useWebWorkers = getOptionValue(zipWriter, options, OPTION_USE_WEB_WORKERS);
6495
6614
  const transferStreams = getOptionValue(zipWriter, options, OPTION_TRANSFER_STREAMS);
6496
6615
  const bufferedWrite = getOptionValue(zipWriter, options, OPTION_BUFFERED_WRITE);
6497
- const createTempStream = getOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
6616
+ const createTempStream = getFunctionOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
6498
6617
  const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, true);
6499
- const signal = getOptionValue(zipWriter, options, OPTION_SIGNAL);
6618
+ const signal = checkSignalOption(getOptionValue(zipWriter, options, OPTION_SIGNAL));
6500
6619
  const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
6501
6620
  const compressionMethod = getOptionValue(zipWriter, options, PROPERTY_NAME_COMPRESSION_METHOD);
6502
6621
  const registeredCodec = passThrough || compressionMethod === UNDEFINED_VALUE ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
@@ -6576,18 +6695,26 @@ function serializeExtraField(extraField) {
6576
6695
  if (!extraField) {
6577
6696
  return EMPTY_UINT8_ARRAY;
6578
6697
  }
6698
+ if (!(extraField instanceof Map)) {
6699
+ throw new Error(ERR_INVALID_EXTRAFIELD);
6700
+ }
6579
6701
  let extraFieldSize = 0;
6580
6702
  let offset = 0;
6581
- extraField.forEach(data => extraFieldSize += 4 + getLength(data));
6582
- const rawExtraField = new Uint8Array(extraFieldSize);
6583
- const rawExtraFieldView = getDataView(rawExtraField);
6584
6703
  extraField.forEach((data, type) => {
6585
- if (type > MAX_16_BITS) {
6704
+ if (!Number.isInteger(type) || type < 0 || type > MAX_16_BITS) {
6586
6705
  throw new Error(ERR_INVALID_EXTRAFIELD_TYPE);
6587
6706
  }
6707
+ if (!(data instanceof Uint8Array)) {
6708
+ throw new Error(ERR_INVALID_EXTRAFIELD_DATA_TYPE);
6709
+ }
6588
6710
  if (getLength(data) > MAX_16_BITS) {
6589
6711
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
6590
6712
  }
6713
+ extraFieldSize += 4 + getLength(data);
6714
+ });
6715
+ const rawExtraField = new Uint8Array(extraFieldSize);
6716
+ const rawExtraFieldView = getDataView(rawExtraField);
6717
+ extraField.forEach((data, type) => {
6591
6718
  setUint16(rawExtraFieldView, offset, type);
6592
6719
  setUint16(rawExtraFieldView, offset + 2, getLength(data));
6593
6720
  arraySet(rawExtraField, data, offset + 4);
@@ -6675,7 +6802,7 @@ function resolveEntrySizes(zipWriter, hasContent, contentSize, metadata, options
6675
6802
 
6676
6803
  async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6677
6804
  const {
6678
- files,
6805
+ fileEntries,
6679
6806
  writer
6680
6807
  } = zipWriter;
6681
6808
  const {
@@ -6697,12 +6824,12 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6697
6824
  let writerSizeBeforeEntry;
6698
6825
  let flushedBufferedSize = 0;
6699
6826
  let fileWriter;
6700
- files.set(name, fileEntry);
6827
+ fileEntries.set(name, fileEntry);
6701
6828
  zipWriter.lastFileEntry = fileEntry;
6702
6829
  try {
6703
6830
  let lockPreviousFileEntry;
6704
6831
  if (keepOrder) {
6705
- lockPreviousFileEntry = previousFileEntry && previousFileEntry.lock;
6832
+ lockPreviousFileEntry = previousFileEntry && previousFileEntry.lockFileEntry;
6706
6833
  requestLockCurrentFileEntry();
6707
6834
  }
6708
6835
  if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || !dataDescriptor) {
@@ -6723,11 +6850,8 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6723
6850
  const diskOffset = getDiskOffset(writer);
6724
6851
  if (zipWriter.addSplitZipSignature) {
6725
6852
  delete zipWriter.addSplitZipSignature;
6726
- const signatureArray = new Uint8Array(4);
6727
- const signatureArrayView = getDataView(signatureArray);
6728
- setUint32(signatureArrayView, 0, SPLIT_ZIP_FILE_SIGNATURE);
6729
- await writeData(writer, signatureArray);
6730
- zipWriter.offset += 4;
6853
+ await writeData(writer, getSplitZipSignatureArray());
6854
+ zipWriter.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
6731
6855
  }
6732
6856
  if (usdz && !bufferedWrite) {
6733
6857
  appendExtraFieldUSDZ(entryInfo, zipWriter.offset - diskOffset);
@@ -6745,11 +6869,11 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6745
6869
  writerSizeBeforeEntry = writer.size;
6746
6870
  await writeData(fileWriter, localHeaderArray);
6747
6871
  }
6748
- fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, zipWriter.config, options);
6872
+ fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, getConfiguration(), options);
6749
6873
  if (!bufferedWrite) {
6750
6874
  writingEntryData = false;
6751
6875
  }
6752
- files.set(name, fileEntry);
6876
+ fileEntries.set(name, fileEntry);
6753
6877
  fileEntry.filename = name;
6754
6878
  if (bufferedWrite) {
6755
6879
  await Promise.all([fileWriter.writable.getWriter().close(), lockPreviousFileEntry]);
@@ -6790,7 +6914,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6790
6914
  zipWriter.offset += flushedBufferedSize;
6791
6915
  }
6792
6916
  }
6793
- files.delete(name);
6917
+ fileEntries.delete(name);
6794
6918
  throw error;
6795
6919
  } finally {
6796
6920
  if (bufferedWrite) {
@@ -6812,7 +6936,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6812
6936
  }
6813
6937
 
6814
6938
  function requestLockCurrentFileEntry() {
6815
- fileEntry.lock = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
6939
+ fileEntry.lockFileEntry = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
6816
6940
  }
6817
6941
 
6818
6942
  async function requestLockWriter() {
@@ -6832,7 +6956,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6832
6956
  }
6833
6957
  }
6834
6958
 
6835
- async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryInfo, config, options) {
6959
+ async function createFileEntry(reader, writer, { diskNumberStart, lockFileEntry }, entryInfo, config, options) {
6836
6960
  const {
6837
6961
  headerInfo,
6838
6962
  dataDescriptorInfo,
@@ -6900,7 +7024,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6900
7024
  codecURI
6901
7025
  } = options;
6902
7026
  const fileEntry = {
6903
- lock,
7027
+ lockFileEntry,
6904
7028
  versionMadeBy,
6905
7029
  zip64,
6906
7030
  directory: Boolean(directory),
@@ -6942,7 +7066,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6942
7066
  }
6943
7067
  const { writable } = writer;
6944
7068
  if (reader) {
6945
- const readable = toCompatibleReadable(reader.createReadable ? reader.createReadable() : reader.readable);
7069
+ const readable = toCompatibleReadable(createReadable(reader));
6946
7070
  const size = reader.size;
6947
7071
  const workerOptions = {
6948
7072
  options: {
@@ -7054,14 +7178,14 @@ function getHeaderInfo(options) {
7054
7178
  if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
7055
7179
  const length = 4 + 16;
7056
7180
  const extraFieldZip64 = createRecordWriter(length);
7057
- extraFieldZip64.uint16(EXTRAFIELD_TYPE_ZIP64);
7058
- extraFieldZip64.uint16(length - 4);
7181
+ extraFieldZip64.writeUint16(EXTRAFIELD_TYPE_ZIP64);
7182
+ extraFieldZip64.writeUint16(length - 4);
7059
7183
  rawLocalExtraFieldZip64 = extraFieldZip64.array;
7060
7184
  if (zip64ExtraFieldComplete) {
7061
- extraFieldZip64.uint64(uncompressedSize);
7185
+ extraFieldZip64.writeUint64(uncompressedSize);
7062
7186
  if (uncompressedFile) {
7063
7187
  const encryptionOverhead = encrypted ? (zipCrypto ? 12 : 16 + encryptionStrength * 4) : 0;
7064
- extraFieldZip64.uint64(passThrough ? 0 : uncompressedSize + encryptionOverhead);
7188
+ extraFieldZip64.writeUint64(passThrough ? 0 : uncompressedSize + encryptionOverhead);
7065
7189
  }
7066
7190
  }
7067
7191
  } else {
@@ -7070,8 +7194,8 @@ function getHeaderInfo(options) {
7070
7194
  let rawExtraFieldAES;
7071
7195
  if (encrypted && !zipCrypto) {
7072
7196
  const extraFieldAES = createRecordWriter(getLength(EXTRAFIELD_DATA_AES) + 2);
7073
- extraFieldAES.uint16(EXTRAFIELD_TYPE_AES);
7074
- extraFieldAES.bytes(EXTRAFIELD_DATA_AES);
7197
+ extraFieldAES.writeUint16(EXTRAFIELD_TYPE_AES);
7198
+ extraFieldAES.writeBytes(EXTRAFIELD_DATA_AES);
7075
7199
  rawExtraFieldAES = extraFieldAES.array;
7076
7200
  rawExtraFieldAES[8] = encryptionStrength;
7077
7201
  } else {
@@ -7087,15 +7211,15 @@ function getHeaderInfo(options) {
7087
7211
  const extraFieldTimestampLength = 9 + (lastAccessDate ? 4 : 0) + (creationDate ? 4 : 0);
7088
7212
  const extraFieldTimestamp = createRecordWriter(extraFieldTimestampLength);
7089
7213
  extraFieldExtendedTimestampFlag = 0x1 + (lastAccessDate ? 0x2 : 0) + (creationDate ? 0x4 : 0);
7090
- extraFieldTimestamp.uint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
7091
- extraFieldTimestamp.uint16(extraFieldTimestampLength - 4);
7092
- extraFieldTimestamp.uint8(extraFieldExtendedTimestampFlag);
7093
- extraFieldTimestamp.uint32(lastModTimeUnix);
7214
+ extraFieldTimestamp.writeUint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
7215
+ extraFieldTimestamp.writeUint16(extraFieldTimestampLength - 4);
7216
+ extraFieldTimestamp.writeUint8(extraFieldExtendedTimestampFlag);
7217
+ extraFieldTimestamp.writeUint32(lastModTimeUnix);
7094
7218
  if (lastAccessDate) {
7095
- extraFieldTimestamp.uint32(clampUnixTime(getTimeUnix(lastAccessDate)));
7219
+ extraFieldTimestamp.writeUint32(clampUnixTime(getTimeUnix(lastAccessDate)));
7096
7220
  }
7097
7221
  if (creationDate) {
7098
- extraFieldTimestamp.uint32(clampUnixTime(getTimeUnix(creationDate)));
7222
+ extraFieldTimestamp.writeUint32(clampUnixTime(getTimeUnix(creationDate)));
7099
7223
  }
7100
7224
  rawExtraFieldExtendedTimestamp = extraFieldTimestamp.array;
7101
7225
  } else {
@@ -7108,14 +7232,14 @@ function getHeaderInfo(options) {
7108
7232
  try {
7109
7233
  const lastModTimeNTFS = getTimeNTFS(lastModDate);
7110
7234
  const extraFieldNTFS = createRecordWriter(36);
7111
- extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS);
7112
- extraFieldNTFS.uint16(32);
7235
+ extraFieldNTFS.writeUint16(EXTRAFIELD_TYPE_NTFS);
7236
+ extraFieldNTFS.writeUint16(32);
7113
7237
  extraFieldNTFS.skip(4);
7114
- extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS_TAG1);
7115
- extraFieldNTFS.uint16(24);
7116
- extraFieldNTFS.uint64(lastModTimeNTFS);
7117
- extraFieldNTFS.uint64(lastAccessDate ? getTimeNTFS(lastAccessDate) : lastModTimeNTFS);
7118
- extraFieldNTFS.uint64(creationDate ? getTimeNTFS(creationDate) : lastModTimeNTFS);
7238
+ extraFieldNTFS.writeUint16(EXTRAFIELD_TYPE_NTFS_TAG1);
7239
+ extraFieldNTFS.writeUint16(24);
7240
+ extraFieldNTFS.writeUint64(lastModTimeNTFS);
7241
+ extraFieldNTFS.writeUint64(lastAccessDate ? getTimeNTFS(lastAccessDate) : lastModTimeNTFS);
7242
+ extraFieldNTFS.writeUint64(creationDate ? getTimeNTFS(creationDate) : lastModTimeNTFS);
7119
7243
  rawExtraFieldNTFS = extraFieldNTFS.array;
7120
7244
  } catch {
7121
7245
  rawExtraFieldNTFS = EMPTY_UINT8_ARRAY;
@@ -7134,20 +7258,20 @@ function getHeaderInfo(options) {
7134
7258
  const gidBytes = packUnixId(gid);
7135
7259
  const payloadLength = 3 + uidBytes.length + gidBytes.length;
7136
7260
  const extraFieldUnix = createRecordWriter(4 + payloadLength);
7137
- extraFieldUnix.uint16(EXTRAFIELD_TYPE_INFOZIP);
7138
- extraFieldUnix.uint16(payloadLength);
7139
- extraFieldUnix.uint8(1);
7140
- extraFieldUnix.uint8(uidBytes.length);
7141
- extraFieldUnix.bytes(uidBytes);
7142
- extraFieldUnix.uint8(gidBytes.length);
7143
- extraFieldUnix.bytes(gidBytes);
7261
+ extraFieldUnix.writeUint16(EXTRAFIELD_TYPE_INFOZIP);
7262
+ extraFieldUnix.writeUint16(payloadLength);
7263
+ extraFieldUnix.writeUint8(1);
7264
+ extraFieldUnix.writeUint8(uidBytes.length);
7265
+ extraFieldUnix.writeBytes(uidBytes);
7266
+ extraFieldUnix.writeUint8(gidBytes.length);
7267
+ extraFieldUnix.writeBytes(gidBytes);
7144
7268
  rawExtraFieldUnix = extraFieldUnix.array;
7145
7269
  } else if (unixExtraFieldType == UNIX_EXTRA_FIELD_TYPE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
7146
7270
  const extraFieldUnix = createRecordWriter(8);
7147
- extraFieldUnix.uint16(EXTRAFIELD_TYPE_UNIX);
7148
- extraFieldUnix.uint16(4);
7149
- extraFieldUnix.uint16((uid === UNDEFINED_VALUE ? 0 : uid) & MAX_16_BITS);
7150
- extraFieldUnix.uint16((gid === UNDEFINED_VALUE ? 0 : gid) & MAX_16_BITS);
7271
+ extraFieldUnix.writeUint16(EXTRAFIELD_TYPE_UNIX);
7272
+ extraFieldUnix.writeUint16(4);
7273
+ extraFieldUnix.writeUint16((uid === UNDEFINED_VALUE ? 0 : uid) & MAX_16_BITS);
7274
+ extraFieldUnix.writeUint16((gid === UNDEFINED_VALUE ? 0 : gid) & MAX_16_BITS);
7151
7275
  rawExtraFieldUnix = extraFieldUnix.array;
7152
7276
  } else {
7153
7277
  rawExtraFieldUnix = EMPTY_UINT8_ARRAY;
@@ -7197,18 +7321,18 @@ function getHeaderInfo(options) {
7197
7321
  const localHeader = createRecordWriter(HEADER_SIZE + getLength(rawFilename) + extraFieldLength);
7198
7322
  const localHeaderArray = localHeader.array;
7199
7323
  const localHeaderView = getDataView(localHeaderArray);
7200
- localHeader.uint32(LOCAL_FILE_HEADER_SIGNATURE);
7201
- localHeader.bytes(headerArray);
7202
- localHeader.bytes(rawFilename);
7324
+ localHeader.writeUint32(LOCAL_FILE_HEADER_SIGNATURE);
7325
+ localHeader.writeBytes(headerArray);
7326
+ localHeader.writeBytes(rawFilename);
7203
7327
  if (writeLocalExtraFieldZip64) {
7204
- localHeader.bytes(rawLocalExtraFieldZip64);
7205
- }
7206
- localHeader.bytes(rawExtraFieldAES);
7207
- localHeader.bytes(rawExtraFieldExtendedTimestamp);
7208
- localHeader.bytes(rawExtraFieldNTFS);
7209
- localHeader.bytes(rawExtraFieldUnix);
7210
- localHeader.bytes(rawExtraField);
7211
- localHeader.bytes(rawLocalExtraField);
7328
+ localHeader.writeBytes(rawLocalExtraFieldZip64);
7329
+ }
7330
+ localHeader.writeBytes(rawExtraFieldAES);
7331
+ localHeader.writeBytes(rawExtraFieldExtendedTimestamp);
7332
+ localHeader.writeBytes(rawExtraFieldNTFS);
7333
+ localHeader.writeBytes(rawExtraFieldUnix);
7334
+ localHeader.writeBytes(rawExtraField);
7335
+ localHeader.writeBytes(rawLocalExtraField);
7212
7336
  if (dataDescriptor) {
7213
7337
  if (!zip64CompressedSize) {
7214
7338
  setUint32(localHeaderView, HEADER_OFFSET_COMPRESSED_SIZE + LOCAL_HEADER_COMMON_OFFSET, 0);
@@ -7398,7 +7522,7 @@ function updateLocalHeader({
7398
7522
 
7399
7523
 
7400
7524
  async function closeFile(zipWriter, comment, options) {
7401
- const directoryDataLength = createDirectoryRecords(zipWriter.files);
7525
+ const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
7402
7526
  const { directoryStart, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7403
7527
  const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
7404
7528
  await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryDataLength, signatureLength });
@@ -7428,19 +7552,19 @@ function createDirectoryRecords(files) {
7428
7552
  if (zip64Offset || zip64DiskNumberStart || zip64UncompressedSize || zip64CompressedSize) {
7429
7553
  const length = 4 + (zip64UncompressedSize ? 8 : 0) + (zip64CompressedSize ? 8 : 0) + (zip64Offset ? 8 : 0) + (zip64DiskNumberStart ? 4 : 0);
7430
7554
  const extraFieldZip64 = createRecordWriter(length);
7431
- extraFieldZip64.uint16(EXTRAFIELD_TYPE_ZIP64);
7432
- extraFieldZip64.uint16(length - 4);
7555
+ extraFieldZip64.writeUint16(EXTRAFIELD_TYPE_ZIP64);
7556
+ extraFieldZip64.writeUint16(length - 4);
7433
7557
  if (zip64UncompressedSize) {
7434
- extraFieldZip64.uint64(uncompressedSize);
7558
+ extraFieldZip64.writeUint64(uncompressedSize);
7435
7559
  }
7436
7560
  if (zip64CompressedSize) {
7437
- extraFieldZip64.uint64(compressedSize);
7561
+ extraFieldZip64.writeUint64(compressedSize);
7438
7562
  }
7439
7563
  if (zip64Offset) {
7440
- extraFieldZip64.uint64(fileEntry.offset);
7564
+ extraFieldZip64.writeUint64(fileEntry.offset);
7441
7565
  }
7442
7566
  if (zip64DiskNumberStart) {
7443
- extraFieldZip64.uint32(fileEntry.diskNumberStart);
7567
+ extraFieldZip64.writeUint32(fileEntry.diskNumberStart);
7444
7568
  }
7445
7569
  rawExtraFieldZip64 = extraFieldZip64.array;
7446
7570
  } else {
@@ -7453,10 +7577,10 @@ function createDirectoryRecords(files) {
7453
7577
  const lastModTimeUnix = getTimeUnix(lastModDate);
7454
7578
  if (extendedTimestamp && inUnixTimeRange(lastModTimeUnix)) {
7455
7579
  const extraFieldTimestamp = createRecordWriter(9);
7456
- extraFieldTimestamp.uint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
7457
- extraFieldTimestamp.uint16(5);
7458
- extraFieldTimestamp.uint8(extraFieldExtendedTimestampFlag);
7459
- extraFieldTimestamp.uint32(lastModTimeUnix);
7580
+ extraFieldTimestamp.writeUint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
7581
+ extraFieldTimestamp.writeUint16(5);
7582
+ extraFieldTimestamp.writeUint8(extraFieldExtendedTimestampFlag);
7583
+ extraFieldTimestamp.writeUint32(lastModTimeUnix);
7460
7584
  rawExtraFieldTimestamp = extraFieldTimestamp.array;
7461
7585
  } else {
7462
7586
  rawExtraFieldTimestamp = EMPTY_UINT8_ARRAY;
@@ -7478,14 +7602,14 @@ function createDirectoryRecords(files) {
7478
7602
  }
7479
7603
 
7480
7604
  async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
7481
- const { files, writer } = zipWriter;
7605
+ const { fileEntries, writer } = zipWriter;
7482
7606
  const directoryArray = new Uint8Array(directoryDataLength);
7483
7607
  await initStream(writer);
7484
7608
  let offset = 0;
7485
7609
  let directoryDiskOffset = 0;
7486
7610
  let directoryStartDiskNumber = getDiskNumber(writer);
7487
7611
  let directoryStartDiskOffset = getDiskOffset(writer);
7488
- for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
7612
+ for (const [indexFileEntry, fileEntry] of Array.from(fileEntries.values()).entries()) {
7489
7613
  const {
7490
7614
  offset: fileEntryOffset,
7491
7615
  rawFilename,
@@ -7530,28 +7654,28 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
7530
7654
  setUint16(headerView, HEADER_OFFSET_VERSION, VERSION_ZIP64);
7531
7655
  }
7532
7656
  const directoryRecord = createRecordWriter(directoryRecordLength);
7533
- directoryRecord.uint32(CENTRAL_FILE_HEADER_SIGNATURE);
7534
- directoryRecord.uint16(versionMadeBy);
7535
- directoryRecord.bytes(headerArray.subarray(0, HEADER_SIZE - 4 - 2));
7536
- directoryRecord.uint16(extraFieldLength);
7537
- directoryRecord.uint16(getLength(rawComment));
7538
- directoryRecord.uint16(zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
7539
- directoryRecord.uint16(internalFileAttributes);
7540
- directoryRecord.uint32(externalFileAttributes);
7541
- directoryRecord.uint32(zip64Offset ? MAX_32_BITS : fileEntryOffset);
7542
- directoryRecord.bytes(rawFilename);
7543
- directoryRecord.bytes(rawExtraFieldZip64);
7544
- directoryRecord.bytes(rawExtraFieldAES);
7545
- directoryRecord.bytes(rawExtraFieldExtendedTimestamp);
7546
- directoryRecord.bytes(rawExtraFieldNTFS);
7547
- directoryRecord.bytes(rawExtraFieldUnix);
7548
- directoryRecord.bytes(rawExtraField);
7549
- directoryRecord.bytes(rawComment);
7657
+ directoryRecord.writeUint32(CENTRAL_FILE_HEADER_SIGNATURE);
7658
+ directoryRecord.writeUint16(versionMadeBy);
7659
+ directoryRecord.writeBytes(headerArray.subarray(0, HEADER_SIZE - 4 - 2));
7660
+ directoryRecord.writeUint16(extraFieldLength);
7661
+ directoryRecord.writeUint16(getLength(rawComment));
7662
+ directoryRecord.writeUint16(zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
7663
+ directoryRecord.writeUint16(internalFileAttributes);
7664
+ directoryRecord.writeUint32(externalFileAttributes);
7665
+ directoryRecord.writeUint32(zip64Offset ? MAX_32_BITS : fileEntryOffset);
7666
+ directoryRecord.writeBytes(rawFilename);
7667
+ directoryRecord.writeBytes(rawExtraFieldZip64);
7668
+ directoryRecord.writeBytes(rawExtraFieldAES);
7669
+ directoryRecord.writeBytes(rawExtraFieldExtendedTimestamp);
7670
+ directoryRecord.writeBytes(rawExtraFieldNTFS);
7671
+ directoryRecord.writeBytes(rawExtraFieldUnix);
7672
+ directoryRecord.writeBytes(rawExtraField);
7673
+ directoryRecord.writeBytes(rawComment);
7550
7674
  arraySet(directoryArray, directoryRecord.array, offset);
7551
7675
  offset += directoryRecordLength;
7552
7676
  if (options.onprogress) {
7553
7677
  try {
7554
- await options.onprogress(indexFileEntry + 1, files.size, new Entry(fileEntry));
7678
+ await options.onprogress(indexFileEntry + 1, fileEntries.size, new Entry(fileEntry));
7555
7679
  } catch {
7556
7680
  // ignored
7557
7681
  }
@@ -7565,7 +7689,7 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
7565
7689
  }
7566
7690
 
7567
7691
  async function writeDigitalSignatureRecord(zipWriter, directoryArray, options) {
7568
- const signCentralDirectory = getOptionValue(zipWriter, options, OPTION_SIGN_CENTRAL_DIRECTORY);
7692
+ const signCentralDirectory = getFunctionOptionValue(zipWriter, options, OPTION_SIGN_CENTRAL_DIRECTORY);
7569
7693
  if (signCentralDirectory) {
7570
7694
  const signatureData = await signCentralDirectory(directoryArray);
7571
7695
  const signatureDataLength = getLength(signatureData);
@@ -7573,9 +7697,9 @@ async function writeDigitalSignatureRecord(zipWriter, directoryArray, options) {
7573
7697
  throw new Error(ERR_INVALID_SIGNATURE_DATA);
7574
7698
  }
7575
7699
  const signatureRecord = createRecordWriter(6 + signatureDataLength);
7576
- signatureRecord.uint32(DIGITAL_SIGNATURE_RECORD_SIGNATURE);
7577
- signatureRecord.uint16(signatureDataLength);
7578
- signatureRecord.bytes(signatureData);
7700
+ signatureRecord.writeUint32(DIGITAL_SIGNATURE_RECORD_SIGNATURE);
7701
+ signatureRecord.writeUint16(signatureDataLength);
7702
+ signatureRecord.writeBytes(signatureData);
7579
7703
  await writeData(zipWriter.writer, signatureRecord.array);
7580
7704
  return 6 + signatureDataLength;
7581
7705
  }
@@ -7586,7 +7710,7 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7586
7710
  const { writer } = zipWriter;
7587
7711
  const { directoryStart, signatureLength } = cdInfo;
7588
7712
  let { directoryDataLength } = cdInfo;
7589
- let filesLength = zipWriter.files.size;
7713
+ let fileEntriesLength = zipWriter.fileEntries.size;
7590
7714
  let diskNumber = directoryStart.diskNumber;
7591
7715
  let directoryOffset = getSegmentOffset(zipWriter, directoryStart);
7592
7716
  let lastDiskNumber = getDiskNumber(writer);
@@ -7594,7 +7718,7 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7594
7718
  lastDiskNumber++;
7595
7719
  }
7596
7720
  let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
7597
- if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
7721
+ if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || fileEntriesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
7598
7722
  if (zip64 === false) {
7599
7723
  throw new Error(ERR_UNSUPPORTED_FORMAT);
7600
7724
  } else {
@@ -7611,37 +7735,37 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7611
7735
  }
7612
7736
  lastDiskNumber = getDiskNumber(writer);
7613
7737
  if (zip64) {
7614
- endOfdirectoryRecord.uint32(ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
7615
- endOfdirectoryRecord.uint64(44);
7616
- endOfdirectoryRecord.uint16(45);
7617
- endOfdirectoryRecord.uint16(45);
7618
- endOfdirectoryRecord.uint32(lastDiskNumber);
7619
- endOfdirectoryRecord.uint32(diskNumber);
7620
- endOfdirectoryRecord.uint64(filesLength);
7621
- endOfdirectoryRecord.uint64(filesLength);
7622
- endOfdirectoryRecord.uint64(directoryDataLength);
7623
- endOfdirectoryRecord.uint64(directoryOffset);
7624
- endOfdirectoryRecord.uint32(ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
7625
- endOfdirectoryRecord.uint32(lastDiskNumber);
7626
- endOfdirectoryRecord.uint64(BigInt(getSegmentOffset(zipWriter, writer)) + BigInt(directoryDataLength) + BigInt(signatureLength));
7627
- endOfdirectoryRecord.uint32(lastDiskNumber + 1);
7738
+ endOfdirectoryRecord.writeUint32(ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
7739
+ endOfdirectoryRecord.writeUint64(44);
7740
+ endOfdirectoryRecord.writeUint16(45);
7741
+ endOfdirectoryRecord.writeUint16(45);
7742
+ endOfdirectoryRecord.writeUint32(lastDiskNumber);
7743
+ endOfdirectoryRecord.writeUint32(diskNumber);
7744
+ endOfdirectoryRecord.writeUint64(fileEntriesLength);
7745
+ endOfdirectoryRecord.writeUint64(fileEntriesLength);
7746
+ endOfdirectoryRecord.writeUint64(directoryDataLength);
7747
+ endOfdirectoryRecord.writeUint64(directoryOffset);
7748
+ endOfdirectoryRecord.writeUint32(ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
7749
+ endOfdirectoryRecord.writeUint32(lastDiskNumber);
7750
+ endOfdirectoryRecord.writeUint64(BigInt(getSegmentOffset(zipWriter, writer)) + BigInt(directoryDataLength) + BigInt(signatureLength));
7751
+ endOfdirectoryRecord.writeUint32(lastDiskNumber + 1);
7628
7752
  const supportZip64SplitFile = getOptionValue(zipWriter, options, OPTION_SUPPORT_ZIP64_SPLIT_FILE, true);
7629
7753
  if (supportZip64SplitFile) {
7630
7754
  lastDiskNumber = MAX_16_BITS;
7631
7755
  diskNumber = MAX_16_BITS;
7632
7756
  }
7633
- filesLength = MAX_16_BITS;
7757
+ fileEntriesLength = MAX_16_BITS;
7634
7758
  directoryOffset = MAX_32_BITS;
7635
7759
  directoryDataLength = MAX_32_BITS;
7636
7760
  }
7637
- endOfdirectoryRecord.uint32(END_OF_CENTRAL_DIR_SIGNATURE);
7638
- endOfdirectoryRecord.uint16(lastDiskNumber);
7639
- endOfdirectoryRecord.uint16(diskNumber);
7640
- endOfdirectoryRecord.uint16(filesLength);
7641
- endOfdirectoryRecord.uint16(filesLength);
7642
- endOfdirectoryRecord.uint32(directoryDataLength);
7643
- endOfdirectoryRecord.uint32(directoryOffset);
7644
- endOfdirectoryRecord.uint16(commentLength);
7761
+ endOfdirectoryRecord.writeUint32(END_OF_CENTRAL_DIR_SIGNATURE);
7762
+ endOfdirectoryRecord.writeUint16(lastDiskNumber);
7763
+ endOfdirectoryRecord.writeUint16(diskNumber);
7764
+ endOfdirectoryRecord.writeUint16(fileEntriesLength);
7765
+ endOfdirectoryRecord.writeUint16(fileEntriesLength);
7766
+ endOfdirectoryRecord.writeUint32(directoryDataLength);
7767
+ endOfdirectoryRecord.writeUint32(directoryOffset);
7768
+ endOfdirectoryRecord.writeUint16(commentLength);
7645
7769
  await writeData(writer, endOfdirectoryRecord.array);
7646
7770
  if (commentLength) {
7647
7771
  await writeData(writer, comment);
@@ -7654,11 +7778,11 @@ function createRecordWriter(length) {
7654
7778
  let offset = 0;
7655
7779
  return {
7656
7780
  array,
7657
- uint8: value => { setUint8(view, offset, value); offset += 1; },
7658
- uint16: value => { setUint16(view, offset, value); offset += 2; },
7659
- uint32: value => { setUint32(view, offset, value); offset += 4; },
7660
- uint64: value => { setBigUint64(view, offset, BigInt(value)); offset += 8; },
7661
- bytes: value => { arraySet(array, value, offset); offset += getLength(value); },
7781
+ writeUint8: value => { setUint8(view, offset, value); offset += 1; },
7782
+ writeUint16: value => { setUint16(view, offset, value); offset += 2; },
7783
+ writeUint32: value => { setUint32(view, offset, value); offset += 4; },
7784
+ writeUint64: value => { setBigUint64(view, offset, BigInt(value)); offset += 8; },
7785
+ writeBytes: value => { arraySet(array, value, offset); offset += getLength(value); },
7662
7786
  skip: count => offset += count
7663
7787
  };
7664
7788
  }
@@ -7682,6 +7806,71 @@ function getSegmentOffset(zipWriter, { diskNumber = 0, diskOffset = 0 }) {
7682
7806
  return zipWriter.offset - diskOffset - (diskNumber ? zipWriter.initialOffset : 0);
7683
7807
  }
7684
7808
 
7809
+ async function startsWithSplitZipSignature(reader) {
7810
+ const signatureArray = await readUint8Array(reader, 0, SPLIT_ZIP_FILE_SIGNATURE_LENGTH);
7811
+ return getUint32(getDataView(signatureArray), 0) == SPLIT_ZIP_FILE_SIGNATURE;
7812
+ }
7813
+
7814
+ async function copyZipData(zipWriter, reader, entries, directoryOffset, splitZipSignatureLength) {
7815
+ const { writer } = zipWriter;
7816
+ const entryPositions = new Map();
7817
+ if (writer.closeDisk) {
7818
+ const sortedEntries = Array.from(entries).sort((firstEntry, secondEntry) =>
7819
+ getSourceOffset(reader, firstEntry) - getSourceOffset(reader, secondEntry));
7820
+ let copiedLength = 0;
7821
+ for (const entry of sortedEntries) {
7822
+ const sourceOffset = getSourceOffset(reader, entry);
7823
+ await copyData(zipWriter, reader, copiedLength, sourceOffset - copiedLength);
7824
+ if (exceedsAvailableSize(writer, await getLocalHeaderLength(reader, sourceOffset))) {
7825
+ await writer.closeDisk();
7826
+ }
7827
+ entryPositions.set(entry, {
7828
+ offset: getSegmentOffset(zipWriter, writer),
7829
+ diskNumberStart: getDiskNumber(writer)
7830
+ });
7831
+ copiedLength = sourceOffset;
7832
+ }
7833
+ await copyData(zipWriter, reader, copiedLength, directoryOffset - copiedLength);
7834
+ } else {
7835
+ await copyData(zipWriter, reader, 0, directoryOffset);
7836
+ entries.forEach(entry => entryPositions.set(entry, {
7837
+ offset: splitZipSignatureLength + getSourceOffset(reader, entry),
7838
+ diskNumberStart: 0
7839
+ }));
7840
+ }
7841
+ return entryPositions;
7842
+ }
7843
+
7844
+ async function copyData(zipWriter, reader, offset, size) {
7845
+ if (size > 0) {
7846
+ const { writer } = zipWriter;
7847
+ await createReadable(reader, { offset, size }).pipeTo(writer.writable, { preventClose: true, preventAbort: true });
7848
+ writer.size += size;
7849
+ zipWriter.offset += size;
7850
+ }
7851
+ }
7852
+
7853
+ async function getLocalHeaderLength(reader, offset) {
7854
+ const headerArray = await readUint8Array(reader, offset, HEADER_SIZE);
7855
+ if (getLength(headerArray) < HEADER_SIZE) {
7856
+ return HEADER_SIZE;
7857
+ }
7858
+ const headerView = getDataView(headerArray);
7859
+ return HEADER_SIZE +
7860
+ getUint16(headerView, HEADER_OFFSET_FILENAME_LENGTH + LOCAL_HEADER_COMMON_OFFSET) +
7861
+ getUint16(headerView, HEADER_OFFSET_EXTRAFIELD_LENGTH + LOCAL_HEADER_COMMON_OFFSET);
7862
+ }
7863
+
7864
+ function getSourceOffset(reader, { offset, diskNumberStart }) {
7865
+ return offset + (reader.getDiskOffset ? reader.getDiskOffset(diskNumberStart) : 0);
7866
+ }
7867
+
7868
+ function getSplitZipSignatureArray() {
7869
+ const signatureArray = new Uint8Array(SPLIT_ZIP_FILE_SIGNATURE_LENGTH);
7870
+ setUint32(getDataView(signatureArray), 0, SPLIT_ZIP_FILE_SIGNATURE);
7871
+ return signatureArray;
7872
+ }
7873
+
7685
7874
  async function writeData(writer, array) {
7686
7875
  const { writable } = writer;
7687
7876
  const streamWriter = writable.getWriter();
@@ -7733,6 +7922,21 @@ function getOptionValue(zipWriter, options, name, defaultValue) {
7733
7922
  return result === UNDEFINED_VALUE ? defaultValue : result;
7734
7923
  }
7735
7924
 
7925
+ function getDateOptionValue(zipWriter, options, name, defaultValue) {
7926
+ const date = getOptionValue(zipWriter, options, name, defaultValue);
7927
+ if (date === null) {
7928
+ return defaultValue;
7929
+ }
7930
+ if (date !== UNDEFINED_VALUE && (typeof date.getTime != FUNCTION_TYPE || Number.isNaN(date.getTime()))) {
7931
+ throw new Error(ERR_INVALID_DATE);
7932
+ }
7933
+ return date;
7934
+ }
7935
+
7936
+ function getFunctionOptionValue(zipWriter, options, name) {
7937
+ return checkFunctionOption(getOptionValue(zipWriter, options, name));
7938
+ }
7939
+
7736
7940
  function getAliasedOptionValue(zipWriter, options, name, deprecatedName, defaultValue) {
7737
7941
  const value = getAliasedValue(options, name, deprecatedName);
7738
7942
  const result = value === UNDEFINED_VALUE ? getAliasedValue(zipWriter.options, name, deprecatedName) : value;
@@ -7747,9 +7951,6 @@ function getNumberOptionValue(zipWriter, options, name, defaultValue) {
7747
7951
  return toNumber(getOptionValue(zipWriter, options, name, defaultValue));
7748
7952
  }
7749
7953
 
7750
- function toNumber(value) {
7751
- return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
7752
- }
7753
7954
 
7754
7955
  function getMaximumCompressedSize(uncompressedSize) {
7755
7956
  return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
@@ -7761,6 +7962,14 @@ function isCompressed(compressionMethod, level) {
7761
7962
  : compressionMethod !== COMPRESSION_METHOD_STORE;
7762
7963
  }
7763
7964
 
7965
+ function getUint16(view, offset) {
7966
+ return view.getUint16(offset, true);
7967
+ }
7968
+
7969
+ function getUint32(view, offset) {
7970
+ return view.getUint32(offset, true);
7971
+ }
7972
+
7764
7973
  function setUint8(view, offset, value) {
7765
7974
  view.setUint8(offset, value);
7766
7975
  }
@@ -7804,9 +8013,9 @@ function getHeaderArrayData({
7804
8013
  const headerRecord = createRecordWriter(HEADER_SIZE - 4);
7805
8014
  const headerArray = headerRecord.array;
7806
8015
  const headerView = getDataView(headerArray);
7807
- headerRecord.uint16(version);
7808
- headerRecord.uint16(bitFlag);
7809
- headerRecord.uint16(compressionMethod);
8016
+ headerRecord.writeUint16(version);
8017
+ headerRecord.writeUint16(bitFlag);
8018
+ headerRecord.writeUint16(compressionMethod);
7810
8019
  if (rawLastModDate === UNDEFINED_VALUE) {
7811
8020
  const dateArray = new Uint32Array(1);
7812
8021
  const dateView = getDataView(dateArray);
@@ -7814,20 +8023,20 @@ function getHeaderArrayData({
7814
8023
  setUint16(dateView, 2, ((((lastModDate.getFullYear() - 1980) << 4) | (lastModDate.getMonth() + 1)) << 5) | lastModDate.getDate());
7815
8024
  rawLastModDate = dateArray[0];
7816
8025
  }
7817
- headerRecord.uint32(rawLastModDate);
8026
+ headerRecord.writeUint32(rawLastModDate);
7818
8027
  headerRecord.skip(4);
7819
8028
  if (zip64CompressedSize || compressedSize !== UNDEFINED_VALUE) {
7820
- headerRecord.uint32(zip64CompressedSize ? MAX_32_BITS : compressedSize);
8029
+ headerRecord.writeUint32(zip64CompressedSize ? MAX_32_BITS : compressedSize);
7821
8030
  } else {
7822
8031
  headerRecord.skip(4);
7823
8032
  }
7824
8033
  if (zip64UncompressedSize || uncompressedSize !== UNDEFINED_VALUE) {
7825
- headerRecord.uint32(zip64UncompressedSize ? MAX_32_BITS : uncompressedSize);
8034
+ headerRecord.writeUint32(zip64UncompressedSize ? MAX_32_BITS : uncompressedSize);
7826
8035
  } else {
7827
8036
  headerRecord.skip(4);
7828
8037
  }
7829
- headerRecord.uint16(getLength(rawFilename));
7830
- headerRecord.uint16(extraFieldLength);
8038
+ headerRecord.writeUint16(getLength(rawFilename));
8039
+ headerRecord.writeUint16(extraFieldLength);
7831
8040
  return {
7832
8041
  headerArray,
7833
8042
  headerView,
@@ -8715,4 +8924,4 @@ function terminateWorkersAndModule() {
8715
8924
 
8716
8925
  configureExternalAssets();
8717
8926
 
8718
- export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_AMBIGUOUS_ARCHIVE, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_DUPLICATED_NAME, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_INVALID_AUTHENTICATION_CODE, ERR_INVALID_CODEC_DEFINITION, ERR_INVALID_CODEC_MODULE, ERR_INVALID_COMMENT, ERR_INVALID_COMMENT_TYPE, ERR_INVALID_COMPRESSED_DATA, ERR_INVALID_CRC32, ERR_INVALID_ENCRYPTION_STRENGTH, ERR_INVALID_ENTRY_COMMENT, ERR_INVALID_ENTRY_NAME, ERR_INVALID_EXTRAFIELD_DATA, ERR_INVALID_EXTRAFIELD_TYPE, ERR_INVALID_FILENAME_VALIDATION, ERR_INVALID_GID, ERR_INVALID_LEVEL, ERR_INVALID_MAX_APPENDED_DATA_SIZE, ERR_INVALID_MSDOS_ATTRIBUTES, ERR_INVALID_MSDOS_DATA, ERR_INVALID_PASSWORD, ERR_INVALID_PASSWORD_TYPE, ERR_INVALID_SIGNATURE, ERR_INVALID_SIGNATURE_DATA, ERR_INVALID_STRICTNESS, ERR_INVALID_UID, ERR_INVALID_UNCOMPRESSED_SIZE, ERR_INVALID_UNIX_EXTRA_FIELD_TYPE, ERR_INVALID_UNIX_ID_SIZE, ERR_INVALID_UNIX_MODE, ERR_INVALID_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_RESERVED_COMPRESSION_METHOD, ERR_SPLIT_ZIP_FILE, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNDETERMINED_SIZE, ERR_UNSAFE_FILENAME, ERR_UNSUPPORTED_COMPRESSION$1 as ERR_UNSUPPORTED_COMPRESSION, ERR_UNSUPPORTED_CONTEXT, ERR_UNSUPPORTED_CRYPTO_API, ERR_UNSUPPORTED_ENCRYPTION, ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH, ERR_UNSUPPORTED_ENCRYPTION_USDZ, ERR_UNSUPPORTED_FORMAT, ERR_WORKER_STARTUP_TIMEOUT, ERR_WRITER_NOT_INITIALIZED, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, Writer, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, getMimeType, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };
8927
+ export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_AMBIGUOUS_ARCHIVE, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_DUPLICATED_NAME, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_ENTRY_DATA_OUT_OF_BOUNDS, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_INVALID_AUTHENTICATION_CODE, ERR_INVALID_CODEC_DEFINITION, ERR_INVALID_CODEC_MODULE, ERR_INVALID_COMMENT, ERR_INVALID_COMMENT_TYPE, ERR_INVALID_COMPRESSED_DATA, ERR_INVALID_CRC32, ERR_INVALID_DATE, ERR_INVALID_ENCRYPTION_STRENGTH, ERR_INVALID_ENTRY_COMMENT, ERR_INVALID_ENTRY_COMMENT_TYPE, ERR_INVALID_ENTRY_NAME, ERR_INVALID_EXTRAFIELD, ERR_INVALID_EXTRAFIELD_DATA, ERR_INVALID_EXTRAFIELD_DATA_TYPE, ERR_INVALID_EXTRAFIELD_TYPE, ERR_INVALID_FILENAME_VALIDATION, ERR_INVALID_FUNCTION_OPTION, ERR_INVALID_GID, ERR_INVALID_LEVEL, ERR_INVALID_MAX_APPENDED_DATA_SIZE, ERR_INVALID_MAX_WORKERS, ERR_INVALID_MSDOS_ATTRIBUTES, ERR_INVALID_MSDOS_DATA, ERR_INVALID_PASSWORD, ERR_INVALID_PASSWORD_TYPE, ERR_INVALID_SIGNAL, ERR_INVALID_SIGNATURE, ERR_INVALID_SIGNATURE_DATA, ERR_INVALID_STRICTNESS, ERR_INVALID_UID, ERR_INVALID_UNCOMPRESSED_SIZE, ERR_INVALID_UNIX_EXTRA_FIELD_TYPE, ERR_INVALID_UNIX_ID_SIZE, ERR_INVALID_UNIX_MODE, ERR_INVALID_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_RESERVED_COMPRESSION_METHOD, ERR_SPLIT_ZIP_FILE, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNDETERMINED_SIZE, ERR_UNSAFE_FILENAME, ERR_UNSUPPORTED_COMPRESSION$1 as ERR_UNSUPPORTED_COMPRESSION, ERR_UNSUPPORTED_CONTEXT, ERR_UNSUPPORTED_CRYPTO_API, ERR_UNSUPPORTED_ENCRYPTION, ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH, ERR_UNSUPPORTED_ENCRYPTION_USDZ, ERR_UNSUPPORTED_FORMAT, ERR_WORKER_STARTUP_TIMEOUT, ERR_WRITER_NOT_INITIALIZED, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, Writer, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, getMimeType, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };