@zip.js/zip.js 2.8.52 → 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 (49) hide show
  1. package/README.md +1 -1
  2. package/deno.json +2 -1
  3. package/dist/zip-core-external.js +839 -528
  4. package/dist/zip-core-external.min.js +1 -1
  5. package/dist/zip-core.js +847 -527
  6. package/dist/zip-core.min.js +1 -1
  7. package/dist/zip-fs-core-external.js +880 -557
  8. package/dist/zip-fs-core-external.min.js +1 -1
  9. package/dist/zip-fs-core.js +829 -538
  10. package/dist/zip-fs-core.min.js +1 -1
  11. package/dist/zip-fs-external.js +880 -557
  12. package/dist/zip-fs-external.min.js +1 -1
  13. package/dist/zip-fs-native.js +895 -558
  14. package/dist/zip-fs-native.min.js +1 -1
  15. package/dist/zip-fs.js +894 -557
  16. package/dist/zip-fs.min.js +1 -1
  17. package/dist/zip-legacy.js +849 -529
  18. package/dist/zip-legacy.min.js +1 -1
  19. package/dist/zip-native.js +849 -529
  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 +848 -528
  24. package/dist/zip.min.js +1 -1
  25. package/eslint.config.mjs +2 -1
  26. package/index-native.cjs +895 -558
  27. package/index-native.min.js +1 -1
  28. package/index.cjs +894 -557
  29. package/index.d.cts +672 -78
  30. package/index.d.ts +672 -78
  31. package/index.min.js +1 -1
  32. package/lib/core/codec-worker-web.js +13 -4
  33. package/lib/core/configuration.js +62 -21
  34. package/lib/core/constants.js +16 -1
  35. package/lib/core/io.js +44 -29
  36. package/lib/core/options.js +46 -2
  37. package/lib/core/streams/aes-crypto-stream.js +12 -12
  38. package/lib/core/util/decode-text.js +11 -2
  39. package/lib/core/web-worker-base.js +3 -2
  40. package/lib/core/web-worker-inline-native.js +1 -1
  41. package/lib/core/web-worker-inline-wasm.js +1 -1
  42. package/lib/core/zip-entry.js +8 -0
  43. package/lib/core/zip-fs.js +38 -27
  44. package/lib/core/zip-reader.js +149 -60
  45. package/lib/core/zip-writer.js +329 -189
  46. package/lib/zip-core-base.js +6 -1
  47. package/lib/zip-core-reader.js +1 -0
  48. package/lib/zip-core-writer.js +5 -0
  49. package/package.json +11 -3
@@ -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;
@@ -93,6 +95,9 @@ const VERSION_DEFLATE = 0x14;
93
95
  const VERSION_ZIP64 = 0x2D;
94
96
  const VERSION_AES = 0x33;
95
97
 
98
+ const VERSION_MADE_BY_MSDOS = 0x0014;
99
+ const VERSION_MADE_BY_UNIX = 0x0300;
100
+
96
101
  const DIRECTORY_SIGNATURE = "/";
97
102
 
98
103
  const HEADER_SIZE = 30;
@@ -100,6 +105,8 @@ const HEADER_OFFSET_VERSION = 0;
100
105
  const HEADER_OFFSET_SIGNATURE = 10;
101
106
  const HEADER_OFFSET_COMPRESSED_SIZE = 14;
102
107
  const HEADER_OFFSET_UNCOMPRESSED_SIZE = 18;
108
+ const HEADER_OFFSET_FILENAME_LENGTH = 22;
109
+ const HEADER_OFFSET_EXTRAFIELD_LENGTH = 24;
103
110
  const LOCAL_HEADER_COMMON_OFFSET = 4;
104
111
 
105
112
  const MAX_DATE = new Date(2107, 11, 31, 23, 59, 58);
@@ -112,9 +119,116 @@ const FUNCTION_TYPE = "function";
112
119
  const OBJECT_TYPE = "object";
113
120
  const STRING_TYPE = "string";
114
121
  const NUMBER_TYPE = "number";
122
+ const BOOLEAN_TYPE = "boolean";
115
123
 
116
124
  const EMPTY_UINT8_ARRAY = new Uint8Array();
117
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
+
118
232
  /*
119
233
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
120
234
 
@@ -144,7 +258,10 @@ const EMPTY_UINT8_ARRAY = new Uint8Array();
144
258
  */
145
259
 
146
260
 
261
+ const DEFAULT_CHUNK_SIZE$1 = 64 * 1024;
147
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)";
148
265
  let maxWorkers = 2;
149
266
  try {
150
267
  if (typeof navigator != UNDEFINED_TYPE && navigator.hardwareConcurrency) {
@@ -156,7 +273,7 @@ try {
156
273
  const DEFAULT_CONFIGURATION = {
157
274
  workerURI: "./core/web-worker-wasm.js",
158
275
  wasmURI: "./core/streams/zlib-wasm/zlib-streams.wasm",
159
- chunkSize: 64 * 1024,
276
+ chunkSize: DEFAULT_CHUNK_SIZE$1,
160
277
  maxWorkers,
161
278
  terminateWorkerTimeout: 5000,
162
279
  workerStarvationTimeout: 5000,
@@ -168,24 +285,38 @@ const DEFAULT_CONFIGURATION = {
168
285
  DecompressionStream: typeof DecompressionStream != UNDEFINED_TYPE && DecompressionStream
169
286
  };
170
287
 
171
- const CONFIGURABLE_PROPERTY_NAMES = [
288
+ const PROPERTY_NAME_MAX_WORKERS = "maxWorkers";
289
+
290
+ const STRING_PROPERTY_NAMES = [
172
291
  "baseURI",
173
292
  "wasmURI",
174
- "workerURI",
175
- "createWorker",
293
+ "workerURI"
294
+ ];
295
+ const BOOLEAN_PROPERTY_NAMES = [
296
+ "useCompressionStream",
297
+ "useWebWorkers",
298
+ "transferStreams"
299
+ ];
300
+ const NUMBER_PROPERTY_NAMES = [
176
301
  "chunkSize",
177
- "maxWorkers",
302
+ PROPERTY_NAME_MAX_WORKERS,
178
303
  "terminateWorkerTimeout",
179
304
  "workerStarvationTimeout",
180
- "workerStartupTimeout",
181
- "useCompressionStream",
182
- "useWebWorkers",
183
- "transferStreams",
305
+ "workerStartupTimeout"
306
+ ];
307
+ const FUNCTION_PROPERTY_NAMES = [
308
+ "createWorker",
184
309
  "CompressionStream",
185
310
  "DecompressionStream",
186
311
  "CompressionStreamFallback",
187
312
  "DecompressionStreamFallback"
188
313
  ];
314
+ const CONFIGURABLE_PROPERTY_NAMES = [
315
+ ...STRING_PROPERTY_NAMES,
316
+ ...BOOLEAN_PROPERTY_NAMES,
317
+ ...NUMBER_PROPERTY_NAMES,
318
+ ...FUNCTION_PROPERTY_NAMES
319
+ ];
189
320
 
190
321
  const config = { ...DEFAULT_CONFIGURATION };
191
322
 
@@ -194,20 +325,43 @@ function getConfiguration() {
194
325
  }
195
326
 
196
327
  function getChunkSize(config) {
197
- 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;
198
334
  }
199
335
 
200
336
  function configure(configuration) {
201
- configuration = normalizeConfiguration(configuration);
337
+ Object.assign(config, checkConfiguration(normalizeConfiguration(configuration)));
338
+ }
339
+
340
+ function checkConfiguration(configuration) {
341
+ const checkedConfiguration = {};
202
342
  for (const propertyName of CONFIGURABLE_PROPERTY_NAMES) {
203
343
  const propertyValue = configuration[propertyName];
204
344
  if (propertyValue !== UNDEFINED_VALUE) {
205
- config[propertyName] = propertyValue;
345
+ checkedConfiguration[propertyName] = checkPropertyValue(propertyName, propertyValue);
206
346
  }
207
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;
208
361
  }
209
362
 
210
363
  function normalizeConfiguration(configuration) {
364
+ configuration = configuration || {};
211
365
  const { CompressionStreamZlib, DecompressionStreamZlib } = configuration;
212
366
  if (CompressionStreamZlib === UNDEFINED_VALUE && DecompressionStreamZlib === UNDEFINED_VALUE) {
213
367
  return configuration;
@@ -223,14 +377,9 @@ function normalizeConfiguration(configuration) {
223
377
  }
224
378
 
225
379
  function setDefaultConfiguration(configuration) {
226
- configuration = normalizeConfiguration(configuration);
227
- for (const propertyName of CONFIGURABLE_PROPERTY_NAMES) {
228
- const propertyValue = configuration[propertyName];
229
- if (propertyValue !== UNDEFINED_VALUE) {
230
- DEFAULT_CONFIGURATION[propertyName] = propertyValue;
231
- }
232
- }
233
- configure(configuration);
380
+ const checkedConfiguration = checkConfiguration(normalizeConfiguration(configuration));
381
+ Object.assign(DEFAULT_CONFIGURATION, checkedConfiguration);
382
+ Object.assign(config, checkedConfiguration);
234
383
  }
235
384
 
236
385
  function resetConfiguration() {
@@ -1422,13 +1571,13 @@ class AESDecryptionStream extends TransformStream {
1422
1571
  const {
1423
1572
  ctr,
1424
1573
  hmac,
1425
- pending,
1574
+ pendingInput,
1426
1575
  ready
1427
1576
  } = this;
1428
1577
  if (hmac && ctr) {
1429
1578
  await ready;
1430
- const chunkToDecrypt = subarray(pending, 0, pending.length - AUTHENTICATION_CODE_LENGTH);
1431
- 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);
1432
1581
  let decryptedChunkArray = EMPTY_UINT8_ARRAY;
1433
1582
  if (chunkToDecrypt.length) {
1434
1583
  const encryptedChunk = toBits(codecBytes, chunkToDecrypt);
@@ -1437,7 +1586,7 @@ class AESDecryptionStream extends TransformStream {
1437
1586
  decryptedChunkArray = fromBits(codecBytes, decryptedChunk);
1438
1587
  }
1439
1588
  const authenticationCode = subarray(fromBits(codecBytes, hmac.digest()), 0, AUTHENTICATION_CODE_LENGTH);
1440
- let invalidAuthenticationCode = pending.length < AUTHENTICATION_CODE_LENGTH ? 1 : 0;
1589
+ let invalidAuthenticationCode = pendingInput.length < AUTHENTICATION_CODE_LENGTH ? 1 : 0;
1441
1590
  for (let indexByte = 0; indexByte < AUTHENTICATION_CODE_LENGTH; indexByte++) {
1442
1591
  invalidAuthenticationCode |= authenticationCode[indexByte] ^ originalAuthenticationCode[indexByte];
1443
1592
  }
@@ -1481,14 +1630,14 @@ class AESEncryptionStream extends TransformStream {
1481
1630
  const {
1482
1631
  ctr,
1483
1632
  hmac,
1484
- pending,
1633
+ pendingInput,
1485
1634
  ready
1486
1635
  } = this;
1487
1636
  if (hmac && ctr) {
1488
1637
  await ready;
1489
1638
  let encryptedChunkArray = EMPTY_UINT8_ARRAY;
1490
- if (pending.length) {
1491
- const encryptedChunk = ctr.update(toBits(codecBytes, pending));
1639
+ if (pendingInput.length) {
1640
+ const encryptedChunk = ctr.update(toBits(codecBytes, pendingInput));
1492
1641
  hmac.update(encryptedChunk);
1493
1642
  encryptedChunkArray = fromBits(codecBytes, encryptedChunk);
1494
1643
  }
@@ -1505,7 +1654,7 @@ function initAesCrypto(aesCrypto, password, rawPassword, encryptionStrength) {
1505
1654
  ready: new Promise(resolve => aesCrypto.resolveReady = resolve),
1506
1655
  password: encodePassword(password, rawPassword),
1507
1656
  strength: encryptionStrength - 1,
1508
- pending: EMPTY_UINT8_ARRAY
1657
+ pendingInput: EMPTY_UINT8_ARRAY
1509
1658
  });
1510
1659
  }
1511
1660
 
@@ -1513,10 +1662,10 @@ function append(aesCrypto, input, output, paddingStart, paddingEnd, verifyAuthen
1513
1662
  const {
1514
1663
  ctr,
1515
1664
  hmac,
1516
- pending
1665
+ pendingInput
1517
1666
  } = aesCrypto;
1518
- if (pending.length) {
1519
- input = concat(pending, input);
1667
+ if (pendingInput.length) {
1668
+ input = concat(pendingInput, input);
1520
1669
  }
1521
1670
  const inputLength = input.length - paddingEnd;
1522
1671
  output = expand(output, paddingStart + (inputLength - (inputLength % BLOCK_LENGTH)));
@@ -1532,7 +1681,7 @@ function append(aesCrypto, input, output, paddingStart, paddingEnd, verifyAuthen
1532
1681
  }
1533
1682
  output.set(fromBits(codecBytes, outputChunk), offset + paddingStart);
1534
1683
  }
1535
- aesCrypto.pending = subarray(input, offset);
1684
+ aesCrypto.pendingInput = subarray(input, offset);
1536
1685
  return output;
1537
1686
  }
1538
1687
 
@@ -2787,6 +2936,7 @@ function createWebWorkerInterface(workerData, config) {
2787
2936
  worker,
2788
2937
  workerAlive: false,
2789
2938
  terminated: false,
2939
+ startupError: null,
2790
2940
  interface: {
2791
2941
  run: async () => {
2792
2942
  try {
@@ -2814,6 +2964,13 @@ function createWebWorkerInterface(workerData, config) {
2814
2964
  }
2815
2965
 
2816
2966
  async function runWebWorker(workerData, config) {
2967
+ if (!workerData.worker) {
2968
+ const { startupError } = workerData;
2969
+ workerData.startupError = null;
2970
+ const error = startupError || new Error(ERR_WORKER_STARTUP_TIMEOUT);
2971
+ error.workerStartupFailed = true;
2972
+ throw error;
2973
+ }
2817
2974
  let resolveResult, rejectResult;
2818
2975
  const result = new Promise((resolve, reject) => {
2819
2976
  resolveResult = resolve;
@@ -3027,11 +3184,12 @@ function onWorkerError(event, workerData) {
3027
3184
  if (!workerAlive) {
3028
3185
  workerData.worker = null;
3029
3186
  }
3187
+ let error = event.error || new Error(event.message || ERROR_EVENT_TYPE);
3188
+ if (!workerAlive) {
3189
+ error = Object.assign(new Error(error.message || ERROR_EVENT_TYPE), { workerStartupFailed: true });
3190
+ workerData.startupError = error;
3191
+ }
3030
3192
  if (rejectResult) {
3031
- let error = event.error || new Error(event.message || ERROR_EVENT_TYPE);
3032
- if (!workerAlive) {
3033
- error = Object.assign(new Error(error.message || ERROR_EVENT_TYPE), { workerStartupFailed: true });
3034
- }
3035
3193
  rejectResult(error);
3036
3194
  if (writer) {
3037
3195
  writer.releaseLock();
@@ -3300,6 +3458,96 @@ async function terminateWorkers() {
3300
3458
  resetWebWorkerSupport();
3301
3459
  }
3302
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
+
3303
3551
  /*
3304
3552
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
3305
3553
 
@@ -3372,6 +3620,7 @@ class Reader extends Stream {
3372
3620
  createReadable({ offset = 0, size, chunkSize = getChunkSize(getConfiguration()) } = {}) {
3373
3621
  const reader = this;
3374
3622
  let chunkOffset = 0;
3623
+ chunkSize = normalizeChunkSize(chunkSize);
3375
3624
  return new ReadableStream({
3376
3625
  async pull(controller) {
3377
3626
  const dataSize = size === UNDEFINED_VALUE ? chunkSize : Math.min(chunkSize, size - chunkOffset);
@@ -3379,7 +3628,7 @@ class Reader extends Stream {
3379
3628
  if (data.length) {
3380
3629
  controller.enqueue(data);
3381
3630
  }
3382
- if ((chunkOffset + chunkSize >= size) || (size === UNDEFINED_VALUE && !data.length && dataSize)) {
3631
+ if ((chunkOffset + chunkSize >= size) || (!data.length && dataSize)) {
3383
3632
  controller.close();
3384
3633
  } else {
3385
3634
  chunkOffset += chunkSize;
@@ -3459,31 +3708,31 @@ class Data64URIWriter extends Writer {
3459
3708
  Object.assign(this, {
3460
3709
  contentType,
3461
3710
  data: "data:" + (contentType || "") + ";base64,",
3462
- pending: []
3711
+ pendingCharacters: ""
3463
3712
  });
3464
3713
  }
3465
3714
 
3466
3715
  writeUint8Array(array) {
3467
3716
  const writer = this;
3468
3717
  let indexArray;
3469
- let dataString = writer.pending;
3470
- const delta = writer.pending.length;
3471
- writer.pending = "";
3718
+ let dataString = writer.pendingCharacters;
3719
+ const delta = writer.pendingCharacters.length;
3720
+ writer.pendingCharacters = "";
3472
3721
  for (indexArray = 0; indexArray < (Math.floor((delta + array.length) / 3) * 3) - delta; indexArray++) {
3473
3722
  dataString += String.fromCharCode(array[indexArray]);
3474
3723
  }
3475
3724
  for (; indexArray < array.length; indexArray++) {
3476
- writer.pending += String.fromCharCode(array[indexArray]);
3725
+ writer.pendingCharacters += String.fromCharCode(array[indexArray]);
3477
3726
  }
3478
3727
  if (dataString.length > 2) {
3479
3728
  writer.data += btoa(dataString);
3480
3729
  } else {
3481
- writer.pending = dataString + writer.pending;
3730
+ writer.pendingCharacters = dataString + writer.pendingCharacters;
3482
3731
  }
3483
3732
  }
3484
3733
 
3485
3734
  getData() {
3486
- return this.data + btoa(this.pending);
3735
+ return this.data + btoa(this.pendingCharacters);
3487
3736
  }
3488
3737
  }
3489
3738
 
@@ -3513,7 +3762,7 @@ class BlobReader extends Reader {
3513
3762
  constructor(blob) {
3514
3763
  super();
3515
3764
  Object.assign(this, {
3516
- blob,
3765
+ sourceBlob: blob,
3517
3766
  size: blob.size
3518
3767
  });
3519
3768
  if (!blobSliceProbe) {
@@ -3523,13 +3772,13 @@ class BlobReader extends Reader {
3523
3772
 
3524
3773
  createReadable(options) {
3525
3774
  const reader = this;
3526
- const { blob, size } = reader;
3775
+ const { sourceBlob, size } = reader;
3527
3776
  const { offset = 0, size: readSize = size - offset } = options || {};
3528
3777
  if (!offset && readSize >= size) {
3529
- return toCompatibleReadable(blob.stream());
3778
+ return toCompatibleReadable(sourceBlob.stream());
3530
3779
  }
3531
3780
  if (blobSliceReliable) {
3532
- return toCompatibleReadable(blob.slice(offset, offset + readSize).stream());
3781
+ return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
3533
3782
  }
3534
3783
  return super.createReadable(options);
3535
3784
  }
@@ -3538,7 +3787,7 @@ class BlobReader extends Reader {
3538
3787
  const reader = this;
3539
3788
  const offsetEnd = offset + length;
3540
3789
  const readsWholeBlob = !offset && offsetEnd >= reader.size;
3541
- const blob = readsWholeBlob ? reader.blob : reader.blob.slice(offset, offsetEnd);
3790
+ const blob = readsWholeBlob ? reader.sourceBlob : reader.sourceBlob.slice(offset, offsetEnd);
3542
3791
  let arrayBuffer = await blob.arrayBuffer();
3543
3792
  const sliceIgnoredByBuggyImplementation = arrayBuffer.byteLength > length;
3544
3793
  if (sliceIgnoredByBuggyImplementation) {
@@ -3560,12 +3809,12 @@ class BlobWriter extends Stream {
3560
3809
  }
3561
3810
  });
3562
3811
  writer.contentType = contentType;
3563
- writer.blob = streamToBlob(transformStream.readable, contentType);
3564
- writer.blob.catch(() => { });
3812
+ writer.blobPromise = streamToBlob(transformStream.readable, contentType);
3813
+ writer.blobPromise.catch(() => { });
3565
3814
  }
3566
3815
 
3567
3816
  getData() {
3568
- return this.blob;
3817
+ return this.blobPromise;
3569
3818
  }
3570
3819
  }
3571
3820
 
@@ -3579,7 +3828,7 @@ class TextReader extends BlobReader {
3579
3828
  class TextWriter extends BlobWriter {
3580
3829
 
3581
3830
  constructor(encoding) {
3582
- super(encoding);
3831
+ super();
3583
3832
  Object.assign(this, {
3584
3833
  encoding,
3585
3834
  utf8: !encoding || encoding.toLowerCase() == "utf-8"
@@ -3595,14 +3844,7 @@ class TextWriter extends BlobWriter {
3595
3844
  if (blob.text && utf8) {
3596
3845
  return blob.text();
3597
3846
  } else {
3598
- const reader = new FileReader();
3599
- return new Promise((resolve, reject) => {
3600
- Object.assign(reader, {
3601
- onload: ({ target }) => resolve(target.result),
3602
- onerror: () => reject(reader.error)
3603
- });
3604
- reader.readAsText(blob, encoding);
3605
- });
3847
+ return decodeTextRemovingBOM(new Uint8Array(await blob.arrayBuffer()), encoding);
3606
3848
  }
3607
3849
  }
3608
3850
  }
@@ -4060,9 +4302,8 @@ class SplitDataReader extends Reader {
4060
4302
 
4061
4303
  async init() {
4062
4304
  const reader = this;
4063
- const { readers } = reader;
4064
4305
  reader.lastDiskNumber = 0;
4065
- await Promise.all(readers.map(diskReader => initStream(diskReader)));
4306
+ const readers = reader.readers = await Promise.all(reader.readers.map(initDiskReader));
4066
4307
  reader.diskOffsets = readers.map(diskReader => {
4067
4308
  const diskOffset = reader.size;
4068
4309
  reader.size += diskReader.size;
@@ -4257,89 +4498,27 @@ async function initStream(stream, initSize) {
4257
4498
  }
4258
4499
  }
4259
4500
 
4260
- function readUint8Array(reader, offset, size) {
4261
- return reader.readUint8Array(offset, size);
4262
- }
4263
-
4264
- /*
4265
- Copyright (c) 2022 Gildas Lormeau. All rights reserved.
4266
-
4267
- Redistribution and use in source and binary forms, with or without
4268
- modification, are permitted provided that the following conditions are met:
4269
-
4270
- 1. Redistributions of source code must retain the above copyright notice,
4271
- this list of conditions and the following disclaimer.
4272
-
4273
- 2. Redistributions in binary form must reproduce the above copyright
4274
- notice, this list of conditions and the following disclaimer in
4275
- the documentation and/or other materials provided with the distribution.
4276
-
4277
- 3. The names of the authors may not be used to endorse or promote products
4278
- derived from this software without specific prior written permission.
4279
-
4280
- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
4281
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
4282
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
4283
- INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
4284
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4285
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
4286
- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
4287
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
4288
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
4289
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4290
- */
4291
-
4292
- /* global TextDecoder */
4293
-
4294
- const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");
4295
- const VALID_CP437 = CP437.length == 256;
4296
-
4297
- function decodeCP437(stringValue) {
4298
- if (VALID_CP437) {
4299
- let result = "";
4300
- for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
4301
- result += CP437[stringValue[indexCharacter]];
4302
- }
4303
- return result;
4304
- } else {
4305
- return new TextDecoder().decode(stringValue);
4501
+ async function initDiskReader(diskReader) {
4502
+ diskReader = new GenericReader(diskReader);
4503
+ await initStream(diskReader);
4504
+ if (diskReader.size === UNDEFINED_VALUE || !diskReader.readUint8Array) {
4505
+ diskReader = new BlobReader(await streamToBlob(diskReader.readable));
4506
+ await initStream(diskReader);
4306
4507
  }
4508
+ return diskReader;
4307
4509
  }
4308
4510
 
4309
- /*
4310
- Copyright (c) 2022 Gildas Lormeau. All rights reserved.
4311
-
4312
- Redistribution and use in source and binary forms, with or without
4313
- modification, are permitted provided that the following conditions are met:
4314
-
4315
- 1. Redistributions of source code must retain the above copyright notice,
4316
- this list of conditions and the following disclaimer.
4317
-
4318
- 2. Redistributions in binary form must reproduce the above copyright
4319
- notice, this list of conditions and the following disclaimer in
4320
- the documentation and/or other materials provided with the distribution.
4321
-
4322
- 3. The names of the authors may not be used to endorse or promote products
4323
- derived from this software without specific prior written permission.
4324
-
4325
- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
4326
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
4327
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
4328
- INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
4329
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4330
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
4331
- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
4332
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
4333
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
4334
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4335
- */
4336
-
4511
+ function readUint8Array(reader, offset, size) {
4512
+ return reader.readUint8Array(offset, size);
4513
+ }
4337
4514
 
4338
- function decodeText(value, encoding) {
4339
- if (encoding && encoding.trim().toLowerCase() == "cp437") {
4340
- 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);
4341
4520
  } else {
4342
- return new TextDecoder(encoding, { ignoreBOM: true }).decode(value);
4521
+ return reader.readable;
4343
4522
  }
4344
4523
  }
4345
4524
 
@@ -4415,6 +4594,10 @@ const PROPERTY_NAME_SETUID = "setuid";
4415
4594
  const PROPERTY_NAME_SETGID = "setgid";
4416
4595
  const PROPERTY_NAME_STICKY = "sticky";
4417
4596
  const PROPERTY_NAME_BITFLAG = "bitFlag";
4597
+ const PROPERTY_NAME_RAW_BITFLAG = "rawBitFlag";
4598
+ const PROPERTY_NAME_FILENAME_LENGTH = "filenameLength";
4599
+ const PROPERTY_NAME_EXTRA_FIELD_LENGTH = "extraFieldLength";
4600
+ const PROPERTY_NAME_UNIX_EXTERNAL_UPPER = "unixExternalUpper";
4418
4601
  const PROPERTY_NAME_FILENAME_UTF8 = "filenameUTF8";
4419
4602
  const PROPERTY_NAME_COMMENT_UTF8 = "commentUTF8";
4420
4603
  const PROPERTY_NAME_RAW_EXTRA_FIELD = "rawExtraField";
@@ -4467,10 +4650,14 @@ const PROPERTY_NAMES = [
4467
4650
  PROPERTY_NAME_UID,
4468
4651
  PROPERTY_NAME_GID,
4469
4652
  PROPERTY_NAME_UNIX_MODE,
4653
+ PROPERTY_NAME_UNIX_EXTERNAL_UPPER,
4470
4654
  PROPERTY_NAME_SETUID,
4471
4655
  PROPERTY_NAME_SETGID,
4472
4656
  PROPERTY_NAME_STICKY,
4473
4657
  PROPERTY_NAME_BITFLAG,
4658
+ PROPERTY_NAME_RAW_BITFLAG,
4659
+ PROPERTY_NAME_FILENAME_LENGTH,
4660
+ PROPERTY_NAME_EXTRA_FIELD_LENGTH,
4474
4661
  PROPERTY_NAME_FILENAME_UTF8,
4475
4662
  PROPERTY_NAME_COMMENT_UTF8,
4476
4663
  PROPERTY_NAME_RAW_EXTRA_FIELD,
@@ -4491,82 +4678,6 @@ class Entry {
4491
4678
 
4492
4679
  }
4493
4680
 
4494
- /*
4495
- Copyright (c) 2022 Gildas Lormeau. All rights reserved.
4496
-
4497
- Redistribution and use in source and binary forms, with or without
4498
- modification, are permitted provided that the following conditions are met:
4499
-
4500
- 1. Redistributions of source code must retain the above copyright notice,
4501
- this list of conditions and the following disclaimer.
4502
-
4503
- 2. Redistributions in binary form must reproduce the above copyright
4504
- notice, this list of conditions and the following disclaimer in
4505
- the documentation and/or other materials provided with the distribution.
4506
-
4507
- 3. The names of the authors may not be used to endorse or promote products
4508
- derived from this software without specific prior written permission.
4509
-
4510
- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
4511
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
4512
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
4513
- INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
4514
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4515
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
4516
- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
4517
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
4518
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
4519
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4520
- */
4521
-
4522
- const OPTION_FILENAME_ENCODING = "filenameEncoding";
4523
- const OPTION_COMMENT_ENCODING = "commentEncoding";
4524
- const OPTION_DECODE_TEXT = "decodeText";
4525
- const OPTION_EXTRACT_PREPENDED_DATA = "extractPrependedData";
4526
- const OPTION_EXTRACT_APPENDED_DATA = "extractAppendedData";
4527
- const OPTION_PASSWORD = "password";
4528
- const OPTION_RAW_PASSWORD = "rawPassword";
4529
- const OPTION_PASS_THROUGH = "passThrough";
4530
- const OPTION_SIGNAL = "signal";
4531
- const OPTION_CHECK_PASSWORD_ONLY = "checkPasswordOnly";
4532
- const OPTION_CHECK_OVERLAPPING_ENTRY_ONLY = "checkOverlappingEntryOnly";
4533
- const OPTION_CHECK_OVERLAPPING_ENTRY = "checkOverlappingEntry";
4534
- const OPTION_CHECK_AMBIGUITY = "checkAmbiguity";
4535
- const OPTION_CHECK_SIGNATURE = "checkSignature";
4536
- const OPTION_CHECK_CRC32 = "checkCrc32";
4537
- const OPTION_CHECK_AUTHENTICATION_CODE = "checkAuthenticationCode";
4538
- const OPTION_USE_WEB_WORKERS = "useWebWorkers";
4539
- const OPTION_USE_COMPRESSION_STREAM = "useCompressionStream";
4540
- const OPTION_TRANSFER_STREAMS = "transferStreams";
4541
- const OPTION_PREVENT_CLOSE = "preventClose";
4542
- const OPTION_ENCRYPTION_STRENGTH = "encryptionStrength";
4543
- const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
4544
- const OPTION_NTFS_TIMESTAMP = "ntfsTimestamp";
4545
- const OPTION_KEEP_ORDER = "keepOrder";
4546
- const OPTION_LEVEL = "level";
4547
- const OPTION_BUFFERED_WRITE = "bufferedWrite";
4548
- const OPTION_CREATE_TEMP_STREAM = "createTempStream";
4549
- const OPTION_DATA_DESCRIPTOR_SIGNATURE = "dataDescriptorSignature";
4550
- const OPTION_USE_UNICODE_FILE_NAMES = "useUnicodeFileNames";
4551
- const OPTION_DATA_DESCRIPTOR = "dataDescriptor";
4552
- const OPTION_SUPPORT_ZIP64_SPLIT_FILE = "supportZip64SplitFile";
4553
- const OPTION_ENCODE_TEXT = "encodeText";
4554
- const OPTION_OFFSET = "offset";
4555
- const OPTION_USDZ = "usdz";
4556
- const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
4557
- const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
4558
- const OPTION_STRICTNESS = "strictness";
4559
- const OPTION_FILENAME_VALIDATION = "filenameValidation";
4560
- const OPTION_NORMALIZE_FILENAME = "normalizeFilename";
4561
- const OPTION_MAX_APPENDED_DATA_SIZE = "maxAppendedDataSize";
4562
- const OPTION_DECRYPT_CENTRAL_DIRECTORY = "decryptCentralDirectory";
4563
- const OPTION_SIGN_CENTRAL_DIRECTORY = "signCentralDirectory";
4564
- const TEXT_TYPE_FILENAME = "filename";
4565
- const TEXT_TYPE_COMMENT = "comment";
4566
- const STRICTNESS_STRICT = "strict";
4567
- const STRICTNESS_BALANCED = "balanced";
4568
- const STRICTNESS_TOLERANT = "tolerant";
4569
-
4570
4681
  /*
4571
4682
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
4572
4683
 
@@ -4607,6 +4718,7 @@ const ERR_UNSUPPORTED_ENCRYPTION = "Encryption method not supported";
4607
4718
  const ERR_UNSUPPORTED_COMPRESSION$1 = "Compression method not supported";
4608
4719
  const ERR_SPLIT_ZIP_FILE = "Split zip file";
4609
4720
  const ERR_OVERLAPPING_ENTRY = "Overlapping entry found";
4721
+ const ERR_ENTRY_DATA_OUT_OF_BOUNDS = "Entry data out of bounds";
4610
4722
  const ERR_AMBIGUOUS_ARCHIVE = "Ambiguous archive";
4611
4723
  const ERR_ENCRYPTED_CENTRAL_DIRECTORY = "Encrypted central directory is not supported";
4612
4724
  const ERR_UNSAFE_FILENAME = "Unsafe filename";
@@ -4627,7 +4739,7 @@ const ZIP64_PROPERTIES = [
4627
4739
  ];
4628
4740
  const ZIP64_EXTRACTION = {
4629
4741
  [MAX_16_BITS]: {
4630
- getValue: getUint32,
4742
+ getValue: getUint32$1,
4631
4743
  bytes: 4
4632
4744
  },
4633
4745
  [MAX_32_BITS]: {
@@ -4636,6 +4748,7 @@ const ZIP64_EXTRACTION = {
4636
4748
  }
4637
4749
  };
4638
4750
  const MAX_END_OF_CENTRAL_DIR_PROBES = 64;
4751
+ const MAX_DEFLATE_EXPANSION_RATIO = 1032;
4639
4752
  const CENTRAL_DIRECTORY_UNREACHABLE = 0;
4640
4753
  const CENTRAL_DIRECTORY_PLAUSIBLE = 1;
4641
4754
  const CENTRAL_DIRECTORY_REACHABLE = 2;
@@ -4646,7 +4759,6 @@ class ZipReader {
4646
4759
  Object.assign(this, {
4647
4760
  reader: new GenericReader(reader),
4648
4761
  options,
4649
- config: getConfiguration(),
4650
4762
  readRanges: new Map()
4651
4763
  });
4652
4764
  }
@@ -4654,7 +4766,6 @@ class ZipReader {
4654
4766
  async* getEntriesGenerator(options = {}) {
4655
4767
  const zipReader = this;
4656
4768
  let { reader } = zipReader;
4657
- const { config } = zipReader;
4658
4769
  await initStream(reader);
4659
4770
  if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
4660
4771
  reader = new BlobReader(await streamToBlob(reader.readable));
@@ -4663,7 +4774,7 @@ class ZipReader {
4663
4774
  if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
4664
4775
  throw new Error(ERR_BAD_FORMAT);
4665
4776
  }
4666
- const strictness = getStrictness(getOptionValue$1(zipReader, options, OPTION_STRICTNESS), getOptionValue$1(zipReader, options, OPTION_CHECK_AMBIGUITY));
4777
+ const strictness = getStrictness(options, zipReader.options);
4667
4778
  const checkAmbiguity = strictness == STRICTNESS_STRICT;
4668
4779
  const rejectAmbiguousEndOfDirectory = strictness != STRICTNESS_TOLERANT;
4669
4780
  const maxAppendedDataSize = getMaxAppendedDataSize(getOptionValue$1(zipReader, options, OPTION_MAX_APPENDED_DATA_SIZE), strictness);
@@ -4671,9 +4782,7 @@ class ZipReader {
4671
4782
  const normalizeFilename = getOptionValue$1(zipReader, options, OPTION_NORMALIZE_FILENAME);
4672
4783
  const { endOfDirectoryInfo, endOfDirectoryReachingEndCount } = await findEndOfCentralDirectory(reader, rejectAmbiguousEndOfDirectory, maxAppendedDataSize);
4673
4784
  if (!endOfDirectoryInfo) {
4674
- const signatureArray = await readUint8Array(reader, 0, 4);
4675
- const signatureView = getDataView(signatureArray);
4676
- if (getUint32(signatureView) == SPLIT_ZIP_FILE_SIGNATURE) {
4785
+ if (await startsWithSplitZipSignature$1(reader)) {
4677
4786
  throw new Error(ERR_SPLIT_ZIP_FILE);
4678
4787
  } else {
4679
4788
  throw new Error(ERR_EOCDR_NOT_FOUND);
@@ -4683,18 +4792,18 @@ class ZipReader {
4683
4792
  throwAmbiguousArchive("multiple end of central directory records");
4684
4793
  }
4685
4794
  const endOfDirectoryView = getDataView(endOfDirectoryInfo);
4686
- let directoryDataLength = getUint32(endOfDirectoryView, 12);
4687
- let directoryDataOffset = getUint32(endOfDirectoryView, 16);
4795
+ let directoryDataLength = getUint32$1(endOfDirectoryView, 12);
4796
+ let directoryDataOffset = getUint32$1(endOfDirectoryView, 16);
4688
4797
  const commentOffset = endOfDirectoryInfo.offset;
4689
- const commentLength = getUint16(endOfDirectoryView, 20);
4798
+ const commentLength = getUint16$1(endOfDirectoryView, 20);
4690
4799
  const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
4691
4800
  if (reader.size - appendedDataOffset > maxAppendedDataSize) {
4692
4801
  throwAmbiguousArchive("appended data");
4693
4802
  }
4694
- let lastDiskNumber = getUint16(endOfDirectoryView, 4);
4803
+ let lastDiskNumber = getUint16$1(endOfDirectoryView, 4);
4695
4804
  const expectedLastDiskNumber = reader.lastDiskNumber || 0;
4696
- let diskNumber = getUint16(endOfDirectoryView, 6);
4697
- let filesLength = getUint16(endOfDirectoryView, 10);
4805
+ let diskNumber = getUint16$1(endOfDirectoryView, 6);
4806
+ let filesLength = getUint16$1(endOfDirectoryView, 10);
4698
4807
  let prependedDataLength = 0;
4699
4808
  let startOffset;
4700
4809
  let zip64EndOfDirectory;
@@ -4710,12 +4819,12 @@ class ZipReader {
4710
4819
  EMPTY_UINT8_ARRAY;
4711
4820
  const endOfDirectoryLocatorView = getDataView(endOfDirectoryLocatorArray);
4712
4821
  if (endOfDirectoryLocatorArray.length == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH &&
4713
- getUint32(endOfDirectoryLocatorView, 0) == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
4714
- 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);
4715
4824
  let endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4716
4825
  let endOfDirectoryView = getDataView(endOfDirectoryArray);
4717
4826
  const expectedDirectoryDataOffset = endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH - ZIP64_END_OF_CENTRAL_DIR_LENGTH;
4718
- 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) &&
4719
4828
  directoryDataOffset != expectedDirectoryDataOffset && expectedDirectoryDataOffset >= 0) {
4720
4829
  const originalDirectoryDataOffset = directoryDataOffset;
4721
4830
  directoryDataOffset = expectedDirectoryDataOffset;
@@ -4725,7 +4834,7 @@ class ZipReader {
4725
4834
  endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4726
4835
  endOfDirectoryView = getDataView(endOfDirectoryArray);
4727
4836
  }
4728
- 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) {
4729
4838
  throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
4730
4839
  }
4731
4840
  zip64EndOfDirectory = true;
@@ -4740,13 +4849,13 @@ class ZipReader {
4740
4849
  }
4741
4850
  }
4742
4851
  if (lastDiskNumber == MAX_16_BITS) {
4743
- lastDiskNumber = getUint32(endOfDirectoryView, 16);
4744
- } else if (checkAmbiguity && lastDiskNumber != getUint32(endOfDirectoryView, 16)) {
4852
+ lastDiskNumber = getUint32$1(endOfDirectoryView, 16);
4853
+ } else if (checkAmbiguity && lastDiskNumber != getUint32$1(endOfDirectoryView, 16)) {
4745
4854
  throwAmbiguousArchive("mismatched zip64 end of central directory record");
4746
4855
  }
4747
4856
  if (diskNumber == MAX_16_BITS) {
4748
- diskNumber = getUint32(endOfDirectoryView, 20);
4749
- } else if (checkAmbiguity && diskNumber != getUint32(endOfDirectoryView, 20)) {
4857
+ diskNumber = getUint32$1(endOfDirectoryView, 20);
4858
+ } else if (checkAmbiguity && diskNumber != getUint32$1(endOfDirectoryView, 20)) {
4750
4859
  throwAmbiguousArchive("mismatched zip64 end of central directory record");
4751
4860
  }
4752
4861
  if (filesLength == MAX_16_BITS) {
@@ -4784,11 +4893,11 @@ class ZipReader {
4784
4893
  }
4785
4894
  const expectedDirectoryDataOffset = centralDirectoryEndOffset - directoryDataLength;
4786
4895
  if (directoryDataOffset != expectedDirectoryDataOffset && diskNumber == lastDiskNumber) {
4787
- const storedPointsAtDirectory = getUint32(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE;
4896
+ const storedPointsAtDirectory = getUint32$1(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE;
4788
4897
  let reconcile = !storedPointsAtDirectory;
4789
4898
  if (!reconcile && expectedDirectoryDataOffset >= 0 && expectedDirectoryDataOffset + 4 <= reader.size) {
4790
4899
  const expectedSignatureArray = await readUint8Array(reader, expectedDirectoryDataOffset, 4);
4791
- reconcile = getUint32(getDataView(expectedSignatureArray), 0) == CENTRAL_FILE_HEADER_SIGNATURE;
4900
+ reconcile = getUint32$1(getDataView(expectedSignatureArray), 0) == CENTRAL_FILE_HEADER_SIGNATURE;
4792
4901
  }
4793
4902
  if (reconcile) {
4794
4903
  const originalDirectoryDataOffset = directoryDataOffset;
@@ -4812,10 +4921,10 @@ class ZipReader {
4812
4921
  }
4813
4922
  zipReader.directoryOffset = directoryDataOffset;
4814
4923
  zipReader.directoryLength = declaredDirectoryDataLength;
4815
- const decryptCentralDirectory = getOptionValue$1(zipReader, options, OPTION_DECRYPT_CENTRAL_DIRECTORY);
4924
+ const decryptCentralDirectory = getFunctionOptionValue$1(zipReader, options, OPTION_DECRYPT_CENTRAL_DIRECTORY);
4816
4925
  let decryptedDirectory;
4817
4926
  if (decryptCentralDirectory && filesLength && directoryArray.length >= 4 &&
4818
- getUint32(directoryView, 0) != CENTRAL_FILE_HEADER_SIGNATURE &&
4927
+ getUint32$1(directoryView, 0) != CENTRAL_FILE_HEADER_SIGNATURE &&
4819
4928
  (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
4820
4929
  directoryArray = await decryptCentralDirectory(directoryArray, directoryEncryptionInfo);
4821
4930
  directoryView = getDataView(directoryArray);
@@ -4828,8 +4937,8 @@ class ZipReader {
4828
4937
  const filenames = checkAmbiguity ? new Set() : UNDEFINED_VALUE;
4829
4938
  let duplicateFilename;
4830
4939
  for (let indexFile = 0; indexFile < filesLength; indexFile++) {
4831
- const fileEntry = new ZipEntry(reader, config, zipReader.options);
4832
- 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) {
4833
4942
  if (indexFile == 0 && !decryptedDirectory && (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
4834
4943
  throw new Error(ERR_ENCRYPTED_CENTRAL_DIRECTORY);
4835
4944
  }
@@ -4840,16 +4949,16 @@ class ZipReader {
4840
4949
  const filenameOffset = offset + CENTRAL_FILE_HEADER_LENGTH;
4841
4950
  const extraFieldOffset = filenameOffset + fileEntry.filenameLength;
4842
4951
  const commentOffset = extraFieldOffset + fileEntry.extraFieldLength;
4843
- const versionMadeBy = getUint16(directoryView, offset + 4);
4952
+ const versionMadeBy = getUint16$1(directoryView, offset + 4);
4844
4953
  const msDosCompatible = versionMadeBy >> 8 == 0;
4845
4954
  const unixCompatible = versionMadeBy >> 8 == 3;
4846
4955
  const rawFilename = directoryArray.subarray(filenameOffset, extraFieldOffset);
4847
- const commentLength = getUint16(directoryView, offset + 32);
4956
+ const commentLength = getUint16$1(directoryView, offset + 32);
4848
4957
  const endOffset = commentOffset + commentLength;
4849
4958
  const rawComment = directoryArray.subarray(commentOffset, endOffset);
4850
4959
  const filenameUTF8 = languageEncodingFlag;
4851
4960
  const commentUTF8 = languageEncodingFlag;
4852
- const externalFileAttributes = getUint32(directoryView, offset + 38);
4961
+ const externalFileAttributes = getUint32$1(directoryView, offset + 38);
4853
4962
  const msdosAttributesRaw = externalFileAttributes & MAX_8_BITS;
4854
4963
  const msdosAttributes = {
4855
4964
  readOnly: Boolean(msdosAttributesRaw & FILE_ATTR_MSDOS_READONLY_MASK),
@@ -4858,8 +4967,8 @@ class ZipReader {
4858
4967
  directory: Boolean(msdosAttributesRaw & FILE_ATTR_MSDOS_DIR_MASK),
4859
4968
  archive: Boolean(msdosAttributesRaw & FILE_ATTR_MSDOS_ARCHIVE_MASK)
4860
4969
  };
4861
- const offsetFileEntry = getUint32(directoryView, offset + 42);
4862
- 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;
4863
4972
  const rawFilenameEncoding = filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437;
4864
4973
  const rawCommentEncoding = commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437;
4865
4974
  let filename = decode(rawFilename, rawFilenameEncoding, TEXT_TYPE_FILENAME);
@@ -4885,12 +4994,13 @@ class ZipReader {
4885
4994
  index: indexFile,
4886
4995
  versionMadeBy,
4887
4996
  msDosCompatible,
4997
+ zip64: false,
4888
4998
  compressedSize: 0,
4889
4999
  uncompressedSize: 0,
4890
5000
  commentLength,
4891
5001
  offset: offsetFileEntry,
4892
- diskNumberStart: getUint16(directoryView, offset + 34),
4893
- internalFileAttributes: getUint16(directoryView, offset + 36),
5002
+ diskNumberStart: getUint16$1(directoryView, offset + 34),
5003
+ internalFileAttributes: getUint16$1(directoryView, offset + 36),
4894
5004
  externalFileAttributes,
4895
5005
  msdosAttributesRaw,
4896
5006
  msdosAttributes,
@@ -4958,8 +5068,8 @@ class ZipReader {
4958
5068
  yield entry;
4959
5069
  }
4960
5070
  let offsetAfterSignature = offset;
4961
- if (offset + 6 <= directoryArray.length && getUint32(directoryView, offset) == DIGITAL_SIGNATURE_RECORD_SIGNATURE) {
4962
- 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);
4963
5073
  if (offset + 6 + signatureDataLength <= directoryArray.length) {
4964
5074
  zipReader.digitalSignature = directoryArray.subarray(offset + 6, offset + 6 + signatureDataLength);
4965
5075
  offsetAfterSignature = offset + 6 + signatureDataLength;
@@ -4971,13 +5081,17 @@ class ZipReader {
4971
5081
  if (duplicateFilename) {
4972
5082
  throwAmbiguousArchive("duplicate filename");
4973
5083
  }
4974
- if (checkAmbiguity && (prependedDataLength || (filesLength && startOffset > 0))) {
4975
- throwAmbiguousArchive("prepended data");
4976
- }
4977
5084
  const extractPrependedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_PREPENDED_DATA);
4978
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
+ }
4979
5091
  if (extractPrependedData) {
4980
- 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;
4981
5095
  }
4982
5096
  zipReader.comment = commentLength ? await readUint8Array(reader, commentOffset + END_OF_CENTRAL_DIR_LENGTH, commentLength) : EMPTY_UINT8_ARRAY;
4983
5097
  if (extractAppendedData) {
@@ -5044,16 +5158,16 @@ class ZipReaderStream {
5044
5158
 
5045
5159
  class ZipEntry {
5046
5160
 
5047
- constructor(reader, config, options) {
5161
+ constructor(reader, options) {
5048
5162
  Object.assign(this, {
5049
5163
  reader,
5050
- config,
5051
5164
  options
5052
5165
  });
5053
5166
  }
5054
5167
 
5055
5168
  async getData(writer, fileEntry, readRanges, options = {}) {
5056
5169
  const zipEntry = this;
5170
+ const config = getConfiguration();
5057
5171
  const {
5058
5172
  reader,
5059
5173
  index,
@@ -5062,7 +5176,6 @@ class ZipEntry {
5062
5176
  extraFieldAES,
5063
5177
  extraFieldZip64,
5064
5178
  compressionMethod,
5065
- config,
5066
5179
  bitFlag,
5067
5180
  rawBitFlag,
5068
5181
  crc32,
@@ -5080,6 +5193,7 @@ class ZipEntry {
5080
5193
  let password = getOptionValue$1(zipEntry, options, OPTION_PASSWORD);
5081
5194
  let rawPassword = getOptionValue$1(zipEntry, options, OPTION_RAW_PASSWORD);
5082
5195
  const passThrough = getOptionValue$1(zipEntry, options, OPTION_PASS_THROUGH);
5196
+ checkPasswordOption(password, rawPassword);
5083
5197
  password = password && password.length && password;
5084
5198
  rawPassword = rawPassword && rawPassword.length && rawPassword;
5085
5199
  if (extraFieldAES) {
@@ -5087,7 +5201,7 @@ class ZipEntry {
5087
5201
  throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
5088
5202
  }
5089
5203
  }
5090
- 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) {
5091
5205
  throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
5092
5206
  }
5093
5207
  readCommonHeader(localDirectory, dataView, 4);
@@ -5095,9 +5209,12 @@ class ZipEntry {
5095
5209
  extraFieldLength,
5096
5210
  filenameLength
5097
5211
  } = localDirectory;
5098
- const checkAmbiguity = getStrictness(getOptionValue$1(zipEntry, options, OPTION_STRICTNESS), getOptionValue$1(zipEntry, options, OPTION_CHECK_AMBIGUITY)) == STRICTNESS_STRICT;
5212
+ const checkLocalDirectoryOption = getOptionValue$1(zipEntry, options, OPTION_CHECK_LOCAL_DIRECTORY);
5213
+ const entryStrictness = getStrictness(options, zipEntry.options);
5214
+ const checkLocalDirectory = getCheckLocalDirectory(checkLocalDirectoryOption, entryStrictness);
5215
+ const checkLocalFilename = getCheckLocalFilename(checkLocalDirectoryOption, entryStrictness);
5099
5216
  let rawLocalFilename = EMPTY_UINT8_ARRAY;
5100
- if (checkAmbiguity && (filenameLength || extraFieldLength)) {
5217
+ if (checkLocalFilename && (filenameLength || extraFieldLength)) {
5101
5218
  const trailingDataArray = await readUint8Array(reader, localHeaderOffset + HEADER_SIZE, filenameLength + extraFieldLength);
5102
5219
  rawLocalFilename = trailingDataArray.subarray(0, filenameLength);
5103
5220
  localDirectory.rawExtraField = trailingDataArray.subarray(filenameLength);
@@ -5106,17 +5223,26 @@ class ZipEntry {
5106
5223
  await readUint8Array(reader, localHeaderOffset + HEADER_SIZE + filenameLength, extraFieldLength) :
5107
5224
  EMPTY_UINT8_ARRAY;
5108
5225
  }
5226
+ if (checkLocalFilename) {
5227
+ localDirectory.rawFilename = rawLocalFilename;
5228
+ }
5109
5229
  readCommonFooter(zipEntry, localDirectory, dataView, 4, true);
5110
- if (checkAmbiguity) {
5111
- checkLocalDirectory(zipEntry, localDirectory, rawLocalFilename);
5230
+ if (checkLocalDirectory) {
5231
+ validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename);
5112
5232
  }
5113
- const { lastAccessDate, creationDate } = localDirectory;
5233
+ const { lastAccessDate, creationDate, uid, gid } = localDirectory;
5114
5234
  if (lastAccessDate) {
5115
5235
  fileEntry.lastAccessDate = lastAccessDate;
5116
5236
  }
5117
5237
  if (creationDate) {
5118
5238
  fileEntry.creationDate = creationDate;
5119
5239
  }
5240
+ if (uid !== UNDEFINED_VALUE && fileEntry.uid === UNDEFINED_VALUE) {
5241
+ fileEntry.uid = uid;
5242
+ }
5243
+ if (gid !== UNDEFINED_VALUE && fileEntry.gid === UNDEFINED_VALUE) {
5244
+ fileEntry.gid = gid;
5245
+ }
5120
5246
  const encrypted = zipEntry.encrypted && localDirectory.encrypted && !passThrough;
5121
5247
  const zipCrypto = encrypted && !extraFieldAES;
5122
5248
  if (!passThrough) {
@@ -5137,9 +5263,12 @@ class ZipEntry {
5137
5263
  }
5138
5264
  }
5139
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
+ }
5140
5269
  const size = compressedSize;
5141
5270
  const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
5142
- const signal = getOptionValue$1(zipEntry, options, OPTION_SIGNAL);
5271
+ const signal = checkSignalOption(getOptionValue$1(zipEntry, options, OPTION_SIGNAL));
5143
5272
  const checkPasswordOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_PASSWORD_ONLY);
5144
5273
  let checkOverlappingEntry = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY);
5145
5274
  const checkOverlappingEntryOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY_ONLY);
@@ -5147,6 +5276,8 @@ class ZipEntry {
5147
5276
  checkOverlappingEntry = true;
5148
5277
  }
5149
5278
  const { onstart, onprogress, onend } = options;
5279
+ const compressed = compressionMethod != COMPRESSION_METHOD_STORE && !passThrough;
5280
+ const outputSize = passThrough ? compressedSize : uncompressedSize;
5150
5281
  const deflate64 = compressionMethod == COMPRESSION_METHOD_DEFLATE_64;
5151
5282
  let useCompressionStream = getOptionValue$1(zipEntry, options, OPTION_USE_COMPRESSION_STREAM);
5152
5283
  if (deflate64) {
@@ -5167,9 +5298,9 @@ class ZipEntry {
5167
5298
  checkCrc32,
5168
5299
  checkAuthenticationCode: getOptionValue$1(zipEntry, options, OPTION_CHECK_AUTHENTICATION_CODE),
5169
5300
  passwordVerification: zipCrypto && (dataDescriptor ? ((rawLastModDate >>> 8) & MAX_8_BITS) : ((crc32 >>> 24) & MAX_8_BITS)),
5170
- outputSize: passThrough ? compressedSize : uncompressedSize,
5301
+ outputSize,
5171
5302
  crc32,
5172
- compressed: compressionMethod != 0 && !passThrough,
5303
+ compressed,
5173
5304
  encrypted,
5174
5305
  useWebWorkers: getOptionValue$1(zipEntry, options, OPTION_USE_WEB_WORKERS),
5175
5306
  useCompressionStream,
@@ -5206,11 +5337,11 @@ class ZipEntry {
5206
5337
  writer = new WritableStream();
5207
5338
  }
5208
5339
  writer = new GenericWriter(writer);
5209
- await initStream(writer, passThrough ? compressedSize : uncompressedSize);
5340
+ await initStream(writer, getDecodableOutputSize(outputSize, compressedSize, compressed));
5210
5341
  ({ writable } = writer);
5211
- const { outputSize } = await runWorker({ readable, writable }, workerOptions);
5212
- writer.size += outputSize;
5213
- if (outputSize != (passThrough ? compressedSize : uncompressedSize)) {
5342
+ const { outputSize: writtenSize } = await runWorker({ readable, writable }, workerOptions);
5343
+ writer.size += writtenSize;
5344
+ if (writtenSize != outputSize) {
5214
5345
  throw new Error(ERR_INVALID_UNCOMPRESSED_SIZE);
5215
5346
  }
5216
5347
  }
@@ -5244,7 +5375,7 @@ class ZipEntry {
5244
5375
  function detectEncryptedCentralDirectory(directoryView) {
5245
5376
  const maxOffset = Math.min(directoryView.byteLength, 1024) - 3;
5246
5377
  for (let offset = 0; offset < maxOffset; offset++) {
5247
- if (getUint32(directoryView, offset) == ARCHIVE_EXTRA_DATA_SIGNATURE) {
5378
+ if (getUint32$1(directoryView, offset) == ARCHIVE_EXTRA_DATA_SIGNATURE) {
5248
5379
  return true;
5249
5380
  }
5250
5381
  }
@@ -5255,15 +5386,15 @@ function getDirectoryEncryptionInfo(rawExtensibleData) {
5255
5386
  const directoryEncryptionInfo = { rawExtensibleData };
5256
5387
  if (rawExtensibleData.length >= 28) {
5257
5388
  const extensibleDataView = getDataView(rawExtensibleData);
5258
- const hashDataLength = getUint16(extensibleDataView, 26);
5389
+ const hashDataLength = getUint16$1(extensibleDataView, 26);
5259
5390
  Object.assign(directoryEncryptionInfo, {
5260
- compressionMethod: getUint16(extensibleDataView, 0),
5391
+ compressionMethod: getUint16$1(extensibleDataView, 0),
5261
5392
  compressedSize: Number(getBigUint64(extensibleDataView, 2)),
5262
5393
  uncompressedSize: Number(getBigUint64(extensibleDataView, 10)),
5263
- encryptionAlgorithm: getUint16(extensibleDataView, 18),
5264
- bitLength: getUint16(extensibleDataView, 20),
5265
- flags: getUint16(extensibleDataView, 22),
5266
- 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),
5267
5398
  hashData: rawExtensibleData.subarray(28, 28 + hashDataLength)
5268
5399
  });
5269
5400
  }
@@ -5271,12 +5402,12 @@ function getDirectoryEncryptionInfo(rawExtensibleData) {
5271
5402
  }
5272
5403
 
5273
5404
  function readCommonHeader(directory, dataView, offset) {
5274
- const rawBitFlag = directory.rawBitFlag = getUint16(dataView, offset + 2);
5405
+ const rawBitFlag = directory.rawBitFlag = getUint16$1(dataView, offset + 2);
5275
5406
  const encrypted = (rawBitFlag & BITFLAG_ENCRYPTED) == BITFLAG_ENCRYPTED;
5276
- const rawLastModDate = getUint32(dataView, offset + 6);
5407
+ const rawLastModDate = getUint32$1(dataView, offset + 6);
5277
5408
  Object.assign(directory, {
5278
5409
  encrypted,
5279
- version: getUint16(dataView, offset),
5410
+ version: getUint16$1(dataView, offset),
5280
5411
  bitFlag: {
5281
5412
  level: (rawBitFlag & BITFLAG_LEVEL) >> 1,
5282
5413
  dataDescriptor: (rawBitFlag & BITFLAG_DATA_DESCRIPTOR) == BITFLAG_DATA_DESCRIPTOR,
@@ -5284,8 +5415,8 @@ function readCommonHeader(directory, dataView, offset) {
5284
5415
  },
5285
5416
  rawLastModDate,
5286
5417
  lastModDate: getDate(rawLastModDate),
5287
- filenameLength: getUint16(dataView, offset + 22),
5288
- extraFieldLength: getUint16(dataView, offset + 24)
5418
+ filenameLength: getUint16$1(dataView, offset + 22),
5419
+ extraFieldLength: getUint16$1(dataView, offset + 24)
5289
5420
  });
5290
5421
  }
5291
5422
 
@@ -5296,8 +5427,8 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
5296
5427
  let offsetExtraField = 0;
5297
5428
  try {
5298
5429
  while (offsetExtraField < rawExtraField.length) {
5299
- const type = getUint16(rawExtraFieldView, offsetExtraField);
5300
- const size = getUint16(rawExtraFieldView, offsetExtraField + 2);
5430
+ const type = getUint16$1(rawExtraFieldView, offsetExtraField);
5431
+ const size = getUint16$1(rawExtraFieldView, offsetExtraField + 2);
5301
5432
  extraField.set(type, {
5302
5433
  type,
5303
5434
  data: rawExtraField.slice(offsetExtraField + 4, offsetExtraField + 4 + size)
@@ -5307,12 +5438,12 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
5307
5438
  } catch {
5308
5439
  // ignored
5309
5440
  }
5310
- const compressionMethod = getUint16(dataView, offset + 4);
5441
+ const compressionMethod = getUint16$1(dataView, offset + 4);
5311
5442
  Object.assign(directory, {
5312
- signature: getUint32(dataView, offset + HEADER_OFFSET_SIGNATURE),
5313
- crc32: getUint32(dataView, offset + HEADER_OFFSET_SIGNATURE),
5314
- compressedSize: getUint32(dataView, offset + HEADER_OFFSET_COMPRESSED_SIZE),
5315
- 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)
5316
5447
  });
5317
5448
  const extraFieldZip64 = extraField.get(EXTRAFIELD_TYPE_ZIP64);
5318
5449
  if (extraFieldZip64) {
@@ -5352,10 +5483,12 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
5352
5483
  directory.extraFieldNTFS = extraFieldNTFS;
5353
5484
  }
5354
5485
  const extraFieldUnix = extraField.get(EXTRAFIELD_TYPE_UNIX);
5486
+ let unixIdsRead;
5355
5487
  if (extraFieldUnix) {
5356
- readExtraFieldUnix(extraFieldUnix, directory, false);
5488
+ unixIdsRead = readExtraFieldUnix(extraFieldUnix, directory, false);
5357
5489
  directory.extraFieldUnix = extraFieldUnix;
5358
- } else {
5490
+ }
5491
+ if (!unixIdsRead) {
5359
5492
  const extraFieldInfoZip = extraField.get(EXTRAFIELD_TYPE_INFOZIP);
5360
5493
  if (extraFieldInfoZip) {
5361
5494
  readExtraFieldUnix(extraFieldInfoZip, directory, true);
@@ -5399,11 +5532,11 @@ function readExtraFieldUnicode(extraFieldUnicode, propertyName, rawPropertyName,
5399
5532
  computedCrc32.append(fileEntry[rawPropertyName]);
5400
5533
  const computedCrc32View = getDataView(new Uint8Array(4));
5401
5534
  computedCrc32View.setUint32(0, computedCrc32.get(), true);
5402
- const nameCrc32 = getUint32(extraFieldView, 1);
5535
+ const nameCrc32 = getUint32$1(extraFieldView, 1);
5403
5536
  Object.assign(extraFieldUnicode, {
5404
5537
  version: getUint8(extraFieldView, 0),
5405
5538
  [propertyName]: decodeText(extraFieldUnicode.data.subarray(5)),
5406
- valid: !fileEntry.bitFlag.languageEncodingFlag && nameCrc32 == getUint32(computedCrc32View, 0)
5539
+ valid: !fileEntry.bitFlag.languageEncodingFlag && nameCrc32 == getUint32$1(computedCrc32View, 0)
5407
5540
  });
5408
5541
  if (extraFieldUnicode.valid) {
5409
5542
  directory[propertyName] = extraFieldUnicode[propertyName];
@@ -5419,7 +5552,7 @@ function readExtraFieldAES(extraFieldAES, directory, compressionMethod) {
5419
5552
  vendorId: getUint8(extraFieldView, 2),
5420
5553
  strength,
5421
5554
  originalCompressionMethod: compressionMethod,
5422
- compressionMethod: getUint16(extraFieldView, 5)
5555
+ compressionMethod: getUint16$1(extraFieldView, 5)
5423
5556
  });
5424
5557
  directory.compressionMethod = extraFieldAES.compressionMethod;
5425
5558
  if (extraFieldAES.vendorVersion != VENDOR_VERSION_AE_1$1) {
@@ -5433,8 +5566,8 @@ function readExtraFieldNTFS(extraFieldNTFS, directory) {
5433
5566
  let tag1Data;
5434
5567
  try {
5435
5568
  while (offsetExtraField < extraFieldNTFS.data.length && !tag1Data) {
5436
- const tagValue = getUint16(extraFieldView, offsetExtraField);
5437
- const attributeSize = getUint16(extraFieldView, offsetExtraField + 2);
5569
+ const tagValue = getUint16$1(extraFieldView, offsetExtraField);
5570
+ const attributeSize = getUint16$1(extraFieldView, offsetExtraField + 2);
5438
5571
  if (tagValue == EXTRAFIELD_TYPE_NTFS_TAG1) {
5439
5572
  tag1Data = extraFieldNTFS.data.slice(offsetExtraField + 4, offsetExtraField + 4 + attributeSize);
5440
5573
  }
@@ -5458,7 +5591,7 @@ function readExtraFieldNTFS(extraFieldNTFS, directory) {
5458
5591
  const creationDate = getDateNTFS(rawCreationDate);
5459
5592
  const extraFieldData = { lastModDate, lastAccessDate, creationDate };
5460
5593
  Object.assign(extraFieldNTFS, extraFieldData);
5461
- Object.assign(directory, extraFieldData);
5594
+ Object.assign(directory, extraFieldData, { rawLastAccessDate, rawCreationDate });
5462
5595
  }
5463
5596
  }
5464
5597
 
@@ -5467,12 +5600,12 @@ function readExtraFieldUnixDates(extraField, directory) {
5467
5600
  return;
5468
5601
  }
5469
5602
  const extraFieldView = getDataView(extraField.data);
5470
- const lastAccessDate = new Date((getUint32(extraFieldView, 0) | 0) * 1000);
5471
- 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);
5472
5605
  const extraFieldData = { lastAccessDate, lastModDate };
5473
5606
  if (extraField.data.length >= 12) {
5474
- extraFieldData.uid = getUint16(extraFieldView, 8);
5475
- extraFieldData.gid = getUint16(extraFieldView, 10);
5607
+ extraFieldData.uid = getUint16$1(extraFieldView, 8);
5608
+ extraFieldData.gid = getUint16$1(extraFieldView, 10);
5476
5609
  }
5477
5610
  Object.assign(extraField, extraFieldData);
5478
5611
  Object.assign(directory, extraFieldData);
@@ -5492,8 +5625,8 @@ function readExtraFieldUnix(extraField, directory, isInfoZip) {
5492
5625
  gid = unpackUnixId(extraField.data.subarray(offset, offset + gidSize));
5493
5626
  Object.assign(extraField, { version, uid, gid });
5494
5627
  } else if (extraField.data.length >= 4) {
5495
- uid = getUint16(view, 0);
5496
- gid = getUint16(view, 2);
5628
+ uid = getUint16$1(view, 0);
5629
+ gid = getUint16$1(view, 2);
5497
5630
  Object.assign(extraField, { uid, gid });
5498
5631
  }
5499
5632
  if (uid !== UNDEFINED_VALUE) {
@@ -5502,6 +5635,7 @@ function readExtraFieldUnix(extraField, directory, isInfoZip) {
5502
5635
  if (gid !== UNDEFINED_VALUE) {
5503
5636
  directory.gid = gid;
5504
5637
  }
5638
+ return uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE;
5505
5639
  } catch {
5506
5640
  // ignored
5507
5641
  }
@@ -5542,7 +5676,7 @@ function readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory,
5542
5676
  let offset = 1;
5543
5677
  timeProperties.forEach((propertyName, indexProperty) => {
5544
5678
  if (extraFieldExtendedTimestamp.data.length >= offset + 4) {
5545
- const time = getUint32(extraFieldView, offset);
5679
+ const time = getUint32$1(extraFieldView, offset);
5546
5680
  directory[propertyName] = extraFieldExtendedTimestamp[propertyName] = new Date((time | 0) * 1000);
5547
5681
  const rawPropertyName = timeRawProperties[indexProperty];
5548
5682
  extraFieldExtendedTimestamp[rawPropertyName] = time;
@@ -5574,26 +5708,25 @@ async function detectOverlappingEntry({
5574
5708
  }
5575
5709
  if (dataDescriptorLength) {
5576
5710
  const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
5577
- const dataDescriptorSignature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
5578
- getUint32(getDataView(dataDescriptorArray), 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
5579
- if (dataDescriptorSignature) {
5580
- const readCrc32 = getUint32(getDataView(dataDescriptorArray), 4);
5581
- let readCompressedSize;
5582
- let readUncompressedSize;
5583
- if (extraFieldZip64) {
5584
- readCompressedSize = getBigUint64(getDataView(dataDescriptorArray), 8);
5585
- readUncompressedSize = getBigUint64(getDataView(dataDescriptorArray), 16);
5586
- } else {
5587
- readCompressedSize = getUint32(getDataView(dataDescriptorArray), 8);
5588
- readUncompressedSize = getUint32(getDataView(dataDescriptorArray), 12);
5589
- }
5590
- const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || readCrc32 == crc32;
5711
+ const dataDescriptorView = getDataView(dataDescriptorArray);
5712
+ let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
5713
+ getUint32$1(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
5714
+ if (signature) {
5715
+ const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
5716
+ const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
5591
5717
  if (matchCrc32 &&
5592
- readCompressedSize == compressedSize &&
5593
- readUncompressedSize == uncompressedSize) {
5718
+ signedDataDescriptor.compressedSize == compressedSize &&
5719
+ signedDataDescriptor.uncompressedSize == uncompressedSize) {
5594
5720
  dataDescriptorLength += DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH;
5721
+ } else {
5722
+ signature = false;
5595
5723
  }
5596
5724
  }
5725
+ if (dataDescriptorArray.length >= dataDescriptorLength) {
5726
+ const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
5727
+ localDataDescriptor.signature = signature;
5728
+ fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
5729
+ }
5597
5730
  }
5598
5731
  const range = {
5599
5732
  start: offset,
@@ -5610,22 +5743,80 @@ async function detectOverlappingEntry({
5610
5743
  readRanges.set(index, range);
5611
5744
  }
5612
5745
 
5746
+ function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
5747
+ const crc32 = getUint32$1(dataDescriptorView, offset);
5748
+ let compressedSize;
5749
+ let uncompressedSize;
5750
+ if (extraFieldZip64) {
5751
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
5752
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
5753
+ } else {
5754
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
5755
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
5756
+ }
5757
+ return { crc32, compressedSize, uncompressedSize };
5758
+ }
5759
+
5613
5760
  function getDiskOffset$1(reader, diskNumber) {
5614
5761
  return reader.getDiskOffset ? reader.getDiskOffset(diskNumber) : 0;
5615
5762
  }
5616
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
+
5617
5778
  function isStrictnessValue(value) {
5618
5779
  return value === STRICTNESS_STRICT || value === STRICTNESS_BALANCED || value === STRICTNESS_TOLERANT;
5619
5780
  }
5620
5781
 
5621
- function getStrictness(strictness, checkAmbiguity) {
5622
- if (strictness === UNDEFINED_VALUE) {
5623
- return checkAmbiguity ? STRICTNESS_STRICT : STRICTNESS_BALANCED;
5782
+ function getDecodableOutputSize(outputSize, compressedSize, compressed) {
5783
+ return Math.min(outputSize, compressed ? compressedSize * MAX_DEFLATE_EXPANSION_RATIO : compressedSize);
5784
+ }
5785
+
5786
+ function getStrictness(options, inheritedOptions) {
5787
+ return resolveStrictness(options, resolveStrictness(inheritedOptions, STRICTNESS_BALANCED));
5788
+ }
5789
+
5790
+ function resolveStrictness(options, inheritedStrictness) {
5791
+ const strictness = options[OPTION_STRICTNESS];
5792
+ if (strictness !== UNDEFINED_VALUE) {
5793
+ if (!isStrictnessValue(strictness)) {
5794
+ throw new Error(ERR_INVALID_STRICTNESS);
5795
+ }
5796
+ return strictness;
5797
+ }
5798
+ const checkAmbiguity = options[OPTION_CHECK_AMBIGUITY];
5799
+ if (checkAmbiguity === UNDEFINED_VALUE) {
5800
+ return inheritedStrictness;
5801
+ }
5802
+ if (checkAmbiguity) {
5803
+ return STRICTNESS_STRICT;
5804
+ }
5805
+ return inheritedStrictness == STRICTNESS_TOLERANT ? STRICTNESS_TOLERANT : STRICTNESS_BALANCED;
5806
+ }
5807
+
5808
+ function getCheckLocalDirectory(checkLocalDirectory, strictness) {
5809
+ if (checkLocalDirectory === UNDEFINED_VALUE) {
5810
+ return strictness != STRICTNESS_TOLERANT;
5624
5811
  }
5625
- if (!isStrictnessValue(strictness)) {
5626
- throw new Error(ERR_INVALID_STRICTNESS);
5812
+ return Boolean(checkLocalDirectory);
5813
+ }
5814
+
5815
+ function getCheckLocalFilename(checkLocalFilename, strictness) {
5816
+ if (checkLocalFilename === UNDEFINED_VALUE) {
5817
+ return strictness == STRICTNESS_STRICT;
5627
5818
  }
5628
- return strictness;
5819
+ return Boolean(checkLocalFilename);
5629
5820
  }
5630
5821
 
5631
5822
  function getFilenameValidation(filenameValidation, strictness) {
@@ -5654,7 +5845,7 @@ function isUnsafeFilename(filename, filenameValidation) {
5654
5845
 
5655
5846
  function getMaxAppendedDataSize(maxAppendedDataSize, strictness) {
5656
5847
  if (maxAppendedDataSize !== UNDEFINED_VALUE) {
5657
- const size = toNumber$1(maxAppendedDataSize);
5848
+ const size = toNumber(maxAppendedDataSize);
5658
5849
  if (typeof size != NUMBER_TYPE || Number.isNaN(size) || size < 0) {
5659
5850
  throw new Error(ERR_INVALID_MAX_APPENDED_DATA_SIZE);
5660
5851
  }
@@ -5677,7 +5868,7 @@ async function findEndOfCentralDirectory(reader, rejectAmbiguous, maxAppendedDat
5677
5868
  let plausibleEndOfDirectoryInfo;
5678
5869
  let endOfDirectoryReachingEndCount = 0;
5679
5870
  for await (const [anchoredView, anchoredOffset, anchoredArray, indexByte, offset] of scanEndOfCentralDirectory(reader, anchoredLength)) {
5680
- const commentLength = getUint16(anchoredView, indexByte + 20);
5871
+ const commentLength = getUint16$1(anchoredView, indexByte + 20);
5681
5872
  if (offset + END_OF_CENTRAL_DIR_LENGTH + commentLength == size) {
5682
5873
  const reachability = await getCentralDirectoryReachability(reader, anchoredView, anchoredOffset, indexByte, offset, size, remoteProbeBudget);
5683
5874
  if (reachability == CENTRAL_DIRECTORY_REACHABLE) {
@@ -5728,7 +5919,7 @@ async function* scanEndOfCentralDirectory(reader, scanLength) {
5728
5919
  const scanArray = await readUint8Array(reader, scanOffset, scanLength);
5729
5920
  const scanView = getDataView(scanArray);
5730
5921
  for (let indexByte = scanArray.length - END_OF_CENTRAL_DIR_LENGTH; indexByte >= 0; indexByte--) {
5731
- if (getUint32(scanView, indexByte) == END_OF_CENTRAL_DIR_SIGNATURE) {
5922
+ if (getUint32$1(scanView, indexByte) == END_OF_CENTRAL_DIR_SIGNATURE) {
5732
5923
  yield [scanView, scanOffset, scanArray, indexByte, scanOffset + indexByte];
5733
5924
  }
5734
5925
  }
@@ -5739,9 +5930,9 @@ function getEndOfCentralDirectoryInfo(scanArray, indexByte, offset) {
5739
5930
  }
5740
5931
 
5741
5932
  async function getCentralDirectoryReachability(reader, view, anchoredOffset, indexByte, offset, size, remoteProbeBudget) {
5742
- const filesLength = getUint16(view, indexByte + 10);
5743
- const directoryDataLength = getUint32(view, indexByte + 12);
5744
- 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);
5745
5936
  if (filesLength == MAX_16_BITS || directoryDataLength == MAX_32_BITS || directoryDataOffset == MAX_32_BITS) {
5746
5937
  const locatorSignature = await readSignature(reader, view, anchoredOffset, offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, size, remoteProbeBudget);
5747
5938
  return locatorSignature == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE ? CENTRAL_DIRECTORY_REACHABLE : CENTRAL_DIRECTORY_UNREACHABLE;
@@ -5749,7 +5940,7 @@ async function getCentralDirectoryReachability(reader, view, anchoredOffset, ind
5749
5940
  if (!filesLength && !directoryDataLength) {
5750
5941
  return CENTRAL_DIRECTORY_PLAUSIBLE;
5751
5942
  }
5752
- const directoryDiskNumber = getUint16(view, indexByte + 6);
5943
+ const directoryDiskNumber = getUint16$1(view, indexByte + 6);
5753
5944
  for (const centralDirectoryOffset of [offset - directoryDataLength, getDiskOffset$1(reader, directoryDiskNumber) + directoryDataOffset]) {
5754
5945
  if (await readSignature(reader, view, anchoredOffset, centralDirectoryOffset, size, remoteProbeBudget) == CENTRAL_FILE_HEADER_SIGNATURE) {
5755
5946
  return CENTRAL_DIRECTORY_REACHABLE;
@@ -5763,20 +5954,21 @@ async function readSignature(reader, view, anchoredOffset, signatureOffset, size
5763
5954
  return UNDEFINED_VALUE;
5764
5955
  }
5765
5956
  if (signatureOffset >= anchoredOffset) {
5766
- return getUint32(view, signatureOffset - anchoredOffset);
5957
+ return getUint32$1(view, signatureOffset - anchoredOffset);
5767
5958
  }
5768
5959
  if (remoteProbeBudget.count > 0) {
5769
5960
  remoteProbeBudget.count--;
5770
5961
  const signatureArray = await readUint8Array(reader, signatureOffset, 4);
5771
- return getUint32(getDataView(signatureArray), 0);
5962
+ return getUint32$1(getDataView(signatureArray), 0);
5772
5963
  }
5773
5964
  return UNDEFINED_VALUE;
5774
5965
  }
5775
5966
 
5776
- function checkLocalDirectory(zipEntry, localDirectory, rawLocalFilename) {
5967
+ function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename) {
5777
5968
  const { rawFilename } = zipEntry;
5778
- if (rawLocalFilename.length != rawFilename.length ||
5779
- rawLocalFilename.some((byteValue, indexByte) => byteValue != rawFilename[indexByte])) {
5969
+ if (checkLocalFilename &&
5970
+ (rawLocalFilename.length != rawFilename.length ||
5971
+ rawLocalFilename.some((byteValue, indexByte) => byteValue != rawFilename[indexByte]))) {
5780
5972
  throwAmbiguousArchive("mismatched local file header (filename)");
5781
5973
  }
5782
5974
  if ((localDirectory.rawBitFlag & BITFLAG_AMBIGUITY_MASK) != (zipEntry.rawBitFlag & BITFLAG_AMBIGUITY_MASK)) {
@@ -5804,10 +5996,11 @@ function getOptionValue$1(zipReader, options, name) {
5804
5996
  return options[name] === UNDEFINED_VALUE ? zipReader.options[name] : options[name];
5805
5997
  }
5806
5998
 
5807
- function toNumber$1(value) {
5808
- 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));
5809
6001
  }
5810
6002
 
6003
+
5811
6004
  function getDate(timeRaw) {
5812
6005
  const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & MAX_16_BITS;
5813
6006
  return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
@@ -5821,11 +6014,11 @@ function getUint8(view, offset) {
5821
6014
  return view.getUint8(offset);
5822
6015
  }
5823
6016
 
5824
- function getUint16(view, offset) {
6017
+ function getUint16$1(view, offset) {
5825
6018
  return view.getUint16(offset, true);
5826
6019
  }
5827
6020
 
5828
- function getUint32(view, offset) {
6021
+ function getUint32$1(view, offset) {
5829
6022
  return view.getUint32(offset, true);
5830
6023
  }
5831
6024
 
@@ -5840,6 +6033,7 @@ var zipReader = /*#__PURE__*/Object.freeze({
5840
6033
  ERR_CENTRAL_DIRECTORY_NOT_FOUND: ERR_CENTRAL_DIRECTORY_NOT_FOUND,
5841
6034
  ERR_ENCRYPTED: ERR_ENCRYPTED,
5842
6035
  ERR_ENCRYPTED_CENTRAL_DIRECTORY: ERR_ENCRYPTED_CENTRAL_DIRECTORY,
6036
+ ERR_ENTRY_DATA_OUT_OF_BOUNDS: ERR_ENTRY_DATA_OUT_OF_BOUNDS,
5843
6037
  ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND,
5844
6038
  ERR_EOCDR_NOT_FOUND: ERR_EOCDR_NOT_FOUND,
5845
6039
  ERR_EXTRAFIELD_ZIP64_NOT_FOUND: ERR_EXTRAFIELD_ZIP64_NOT_FOUND,
@@ -5894,13 +6088,18 @@ var zipReader = /*#__PURE__*/Object.freeze({
5894
6088
 
5895
6089
  const ERR_DUPLICATED_NAME = "File already exists";
5896
6090
  const ERR_INVALID_COMMENT = "Zip file comment exceeds 64KB";
6091
+ const ERR_INVALID_COMMENT_TYPE = "Invalid zip file comment (must be a Uint8Array)";
5897
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)";
5898
6095
  const ERR_INVALID_ENTRY_NAME = "File entry name exceeds 64KB";
5899
6096
  const ERR_INVALID_VERSION = "Version exceeds 65535";
5900
6097
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
5901
6098
  const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
5902
6099
  const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
5903
- 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)";
5904
6103
  const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
5905
6104
  const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
5906
6105
  const MIN_UNIX_TIME = -2147483648;
@@ -5920,7 +6119,6 @@ const ERR_INVALID_UNIX_ID_SIZE = "uid/gid must be 0..65535 for unixExtraFieldTyp
5920
6119
  const ERR_INVALID_MSDOS_ATTRIBUTES = "Invalid msdosAttributesRaw (must be integer 0..255)";
5921
6120
  const ERR_INVALID_MSDOS_DATA = "Invalid msdosAttributes (must be an object with boolean flags)";
5922
6121
  const ERR_INVALID_LEVEL = "Invalid level (must be integer 0..9)";
5923
- const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
5924
6122
  const ERR_INVALID_SIGNATURE_DATA = "Signature data exceeds 64KB";
5925
6123
 
5926
6124
  const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
@@ -5945,8 +6143,7 @@ class ZipWriter {
5945
6143
  writer,
5946
6144
  addSplitZipSignature,
5947
6145
  options,
5948
- config: getConfiguration(),
5949
- files: new Map(),
6146
+ fileEntries: new Map(),
5950
6147
  filenames: new Set(),
5951
6148
  offset: options[OPTION_OFFSET] === UNDEFINED_VALUE ? writer.size || writer.writable.size || 0 : options[OPTION_OFFSET],
5952
6149
  initialOffset: options[OPTION_OFFSET] === UNDEFINED_VALUE ? 0 : options[OPTION_OFFSET] - (writer.size || writer.writable.size || 0),
@@ -5962,15 +6159,28 @@ class ZipWriter {
5962
6159
  }
5963
6160
  reader = new GenericReader(reader);
5964
6161
  await initStream(reader);
6162
+ if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
6163
+ reader = new BlobReader(await streamToBlob(reader.readable));
6164
+ await initStream(reader);
6165
+ }
5965
6166
  const { ZipReader } = await Promise.resolve().then(function () { return zipReader; });
5966
- const zipReader$1 = new ZipReader(reader.readable);
6167
+ const zipReader$1 = new ZipReader(reader);
5967
6168
  const entries = await zipReader$1.getEntries();
5968
6169
  await zipReader$1.close();
5969
6170
  await initStream(this.writer);
5970
- await reader.readable.pipeTo(this.writer.writable, { preventClose: true, preventAbort: true });
5971
- 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);
5972
6182
  this.filenames = new Set(entries.map(entry => entry.filename));
5973
- this.files = new Map(entries.map(entry => {
6183
+ this.fileEntries = new Map(entries.map(entry => {
5974
6184
  const {
5975
6185
  version,
5976
6186
  rawLastModDate,
@@ -6025,11 +6235,12 @@ class ZipWriter {
6025
6235
  if (crc32 !== UNDEFINED_VALUE) {
6026
6236
  setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
6027
6237
  }
6238
+ const { offset, diskNumberStart } = entryPositions.get(entry);
6028
6239
  Object.assign(entry, {
6029
6240
  zip64UncompressedSize,
6030
6241
  zip64CompressedSize,
6031
- zip64Offset: zip64 && entry.offset >= MAX_32_BITS,
6032
- diskNumberStart: 0,
6242
+ offset,
6243
+ diskNumberStart,
6033
6244
  zip64DiskNumberStart: false,
6034
6245
  rawExtraFieldZip64,
6035
6246
  rawExtraFieldAES,
@@ -6049,11 +6260,8 @@ class ZipWriter {
6049
6260
  async add(name = "", reader, options = {}) {
6050
6261
  const zipWriter = this;
6051
6262
  options = Object.assign({}, options);
6052
- const {
6053
- pendingAddFileCalls,
6054
- config
6055
- } = zipWriter;
6056
- if (workers < config.maxWorkers) {
6263
+ const { pendingAddFileCalls } = zipWriter;
6264
+ if (workers < getConfiguration().maxWorkers) {
6057
6265
  workers++;
6058
6266
  } else {
6059
6267
  await new Promise(resolve => pendingEntries.push(resolve));
@@ -6090,16 +6298,16 @@ class ZipWriter {
6090
6298
  }
6091
6299
 
6092
6300
  remove(entry) {
6093
- const { filenames, files } = this;
6301
+ const { filenames, fileEntries } = this;
6094
6302
  // deno-lint-ignore valid-typeof
6095
6303
  if (typeof entry == STRING_TYPE) {
6096
- entry = files.get(entry);
6304
+ entry = fileEntries.get(entry);
6097
6305
  }
6098
6306
  if (entry && entry.filename !== UNDEFINED_VALUE) {
6099
6307
  const { filename } = entry;
6100
- if (filenames.has(filename) && files.has(filename)) {
6308
+ if (filenames.has(filename) && fileEntries.has(filename)) {
6101
6309
  filenames.delete(filename);
6102
- files.delete(filename);
6310
+ fileEntries.delete(filename);
6103
6311
  return true;
6104
6312
  }
6105
6313
  }
@@ -6110,6 +6318,9 @@ class ZipWriter {
6110
6318
  const zipWriter = this;
6111
6319
  const { pendingAddFileCalls, writer } = this;
6112
6320
  const { writable } = writer;
6321
+ if (!(comment instanceof Uint8Array)) {
6322
+ throw new Error(ERR_INVALID_COMMENT_TYPE);
6323
+ }
6113
6324
  if (getLength(comment) > MAX_16_BITS) {
6114
6325
  throw new Error(ERR_INVALID_COMMENT);
6115
6326
  }
@@ -6193,12 +6404,12 @@ async function addFile(zipWriter, name, reader, options) {
6193
6404
  const metadataInfo = resolveMetadata(zipWriter, name, options);
6194
6405
  const { comment } = metadataInfo;
6195
6406
  const extraField = options[PROPERTY_NAME_EXTRA_FIELD];
6196
- zipWriter.files.set(name, UNDEFINED_VALUE);
6407
+ zipWriter.fileEntries.set(name, UNDEFINED_VALUE);
6197
6408
  let fileEntry;
6198
6409
  try {
6199
6410
  const { resolvedOptions } = metadataInfo;
6200
6411
  if (resolvedOptions.level != 0 && resolvedOptions.compressionMethod === UNDEFINED_VALUE &&
6201
- !resolvedOptions.passThrough && !(await supportsDeflate(zipWriter.config))) {
6412
+ !resolvedOptions.passThrough && !(await supportsDeflate(getConfiguration()))) {
6202
6413
  resolvedOptions.level = 0;
6203
6414
  }
6204
6415
  const sizesInfo = await resolveSizes(zipWriter, reader, metadataInfo, options);
@@ -6206,8 +6417,6 @@ async function addFile(zipWriter, name, reader, options) {
6206
6417
  const diskOffset = getDiskOffset(zipWriter.writer);
6207
6418
  const diskNumber = getDiskNumber(zipWriter.writer);
6208
6419
  options = Object.assign({}, options, attributesInfo.resolvedOptions, metadataInfo.resolvedOptions, sizesInfo.resolvedOptions, {
6209
- internalFileAttribute: metadataInfo.resolvedOptions.internalFileAttributes,
6210
- externalFileAttribute: attributesInfo.resolvedOptions.externalFileAttributes,
6211
6420
  signature: options[PROPERTY_NAME_SIGNATURE],
6212
6421
  crc32: options.crc32 === UNDEFINED_VALUE ? options[PROPERTY_NAME_SIGNATURE] : options.crc32,
6213
6422
  offset: zipWriter.offset - diskOffset,
@@ -6218,17 +6427,23 @@ async function addFile(zipWriter, name, reader, options) {
6218
6427
  const metadataSize = getLength(headerInfo.localHeaderArray, dataDescriptorInfo.dataDescriptorArray);
6219
6428
  fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo, metadataSize }, options);
6220
6429
  } catch (error) {
6221
- zipWriter.files.delete(name);
6430
+ zipWriter.fileEntries.delete(name);
6222
6431
  throw error;
6223
6432
  }
6224
- Object.assign(fileEntry, { name, comment, extraField });
6433
+ Object.assign(fileEntry, {
6434
+ name,
6435
+ comment,
6436
+ extraField,
6437
+ [PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES]: fileEntry.internalFileAttributes,
6438
+ [PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES]: fileEntry.externalFileAttributes
6439
+ });
6225
6440
  return new Entry(fileEntry);
6226
6441
  }
6227
6442
 
6228
6443
  function resolveAttributes(zipWriter, name, options) {
6229
6444
  name = name.trim();
6230
6445
  let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
6231
- let versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, msDosCompatible ? 20 : 768);
6446
+ let versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, msDosCompatible ? VERSION_MADE_BY_MSDOS : VERSION_MADE_BY_UNIX);
6232
6447
  const executable = getOptionValue(zipWriter, options, PROPERTY_NAME_EXECUTABLE);
6233
6448
  const uid = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_UID);
6234
6449
  const gid = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_GID);
@@ -6256,21 +6471,21 @@ function resolveAttributes(zipWriter, name, options) {
6256
6471
  if (unixExtraFieldType === UNDEFINED_VALUE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
6257
6472
  unixExtraFieldType = INFOZIP_EXTRA_FIELD_TYPE;
6258
6473
  }
6259
- let msdosAttributesRaw = getOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW);
6474
+ let msdosAttributesRaw = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW);
6260
6475
  let msdosAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES);
6261
- 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;
6262
6477
  const hasMsDosProvided = msdosAttributesRaw !== UNDEFINED_VALUE || msdosAttributes !== UNDEFINED_VALUE;
6263
6478
  if (hasUnixMetadata) {
6264
6479
  msDosCompatible = false;
6265
- versionMadeBy = (versionMadeBy & MAX_16_BITS) | (3 << 8);
6480
+ versionMadeBy = (versionMadeBy & MAX_8_BITS) | VERSION_MADE_BY_UNIX;
6266
6481
  } else if (hasMsDosProvided) {
6267
6482
  msDosCompatible = true;
6268
6483
  versionMadeBy = (versionMadeBy & MAX_8_BITS);
6269
6484
  }
6270
- if (msdosAttributesRaw !== UNDEFINED_VALUE && (msdosAttributesRaw < 0 || msdosAttributesRaw > MAX_8_BITS)) {
6485
+ if (msdosAttributesRaw !== UNDEFINED_VALUE && (!Number.isInteger(msdosAttributesRaw) || msdosAttributesRaw < 0 || msdosAttributesRaw > MAX_8_BITS)) {
6271
6486
  throw new Error(ERR_INVALID_MSDOS_ATTRIBUTES);
6272
6487
  }
6273
- if (msdosAttributes && typeof msdosAttributes !== OBJECT_TYPE) {
6488
+ if (msdosAttributes && (typeof msdosAttributes !== OBJECT_TYPE || Array.isArray(msdosAttributes))) {
6274
6489
  throw new Error(ERR_INVALID_MSDOS_DATA);
6275
6490
  }
6276
6491
  if (versionMadeBy > MAX_16_BITS) {
@@ -6302,11 +6517,10 @@ function resolveAttributes(zipWriter, name, options) {
6302
6517
  externalFileAttributes = FILE_ATTR_UNIX_DEFAULT_MASK << 16;
6303
6518
  }
6304
6519
  }
6305
- let unixExternalUpper;
6306
6520
  if (!msDosCompatible) {
6307
6521
  const unixModeProvided = unixMode !== UNDEFINED_VALUE || Boolean(setuid || setgid || sticky);
6308
- unixExternalUpper = (externalFileAttributes >> 16) & MAX_16_BITS;
6309
- unixMode = unixMode === UNDEFINED_VALUE ? unixExternalUpper : (unixMode & MAX_16_BITS);
6522
+ const defaultUnixMode = (externalFileAttributes >> 16) & MAX_16_BITS;
6523
+ unixMode = unixMode === UNDEFINED_VALUE ? defaultUnixMode : (unixMode & MAX_16_BITS);
6310
6524
  if (setuid) {
6311
6525
  unixMode |= FILE_ATTR_UNIX_SETUID_MASK;
6312
6526
  } else {
@@ -6335,17 +6549,20 @@ function resolveAttributes(zipWriter, name, options) {
6335
6549
  if (hasMsDosProvided) {
6336
6550
  externalFileAttributes = (externalFileAttributes & MAX_32_BITS) | (msdosAttributesRaw & MAX_8_BITS);
6337
6551
  }
6552
+ const unixExternalUpper = (externalFileAttributes >> 16) & MAX_16_BITS;
6553
+ const symlink = unixMode !== UNDEFINED_VALUE && ((unixMode & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_SYMLINK);
6338
6554
  return {
6339
6555
  name,
6340
6556
  resolvedOptions: {
6341
6557
  versionMadeBy,
6342
- msDosCompatible,
6558
+ msDosCompatible: Boolean(msDosCompatible),
6343
6559
  externalFileAttributes,
6344
6560
  unixExternalUpper,
6345
6561
  uid,
6346
6562
  gid,
6347
6563
  unixMode,
6348
6564
  unixExtraFieldType,
6565
+ symlink,
6349
6566
  setuid,
6350
6567
  setgid,
6351
6568
  sticky,
@@ -6356,7 +6573,7 @@ function resolveAttributes(zipWriter, name, options) {
6356
6573
  }
6357
6574
 
6358
6575
  function resolveMetadata(zipWriter, name, options) {
6359
- const encode = getOptionValue(zipWriter, options, OPTION_ENCODE_TEXT, encodeText);
6576
+ const encode = getFunctionOptionValue(zipWriter, options, OPTION_ENCODE_TEXT) || encodeText;
6360
6577
  let rawFilename = encode(name, TEXT_TYPE_FILENAME);
6361
6578
  if (rawFilename === UNDEFINED_VALUE) {
6362
6579
  rawFilename = encodeText(name);
@@ -6365,6 +6582,10 @@ function resolveMetadata(zipWriter, name, options) {
6365
6582
  throw new Error(ERR_INVALID_ENTRY_NAME);
6366
6583
  }
6367
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
+ }
6368
6589
  let rawComment = encode(comment, TEXT_TYPE_COMMENT);
6369
6590
  if (rawComment === UNDEFINED_VALUE) {
6370
6591
  rawComment = encodeText(comment);
@@ -6376,16 +6597,14 @@ function resolveMetadata(zipWriter, name, options) {
6376
6597
  if (version > MAX_16_BITS) {
6377
6598
  throw new Error(ERR_INVALID_VERSION);
6378
6599
  }
6379
- const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
6380
- const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
6381
- 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);
6382
6603
  const internalFileAttributes = getAliasedOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES, 0);
6383
6604
  const passThrough = getOptionValue(zipWriter, options, OPTION_PASS_THROUGH);
6384
6605
  const password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
6385
6606
  const rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
6386
- if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
6387
- throw new Error(ERR_INVALID_PASSWORD_TYPE);
6388
- }
6607
+ checkPasswordOption(password, rawPassword);
6389
6608
  const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
6390
6609
  const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
6391
6610
  const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
@@ -6394,9 +6613,9 @@ function resolveMetadata(zipWriter, name, options) {
6394
6613
  const useWebWorkers = getOptionValue(zipWriter, options, OPTION_USE_WEB_WORKERS);
6395
6614
  const transferStreams = getOptionValue(zipWriter, options, OPTION_TRANSFER_STREAMS);
6396
6615
  const bufferedWrite = getOptionValue(zipWriter, options, OPTION_BUFFERED_WRITE);
6397
- const createTempStream = getOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
6616
+ const createTempStream = getFunctionOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
6398
6617
  const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, true);
6399
- const signal = getOptionValue(zipWriter, options, OPTION_SIGNAL);
6618
+ const signal = checkSignalOption(getOptionValue(zipWriter, options, OPTION_SIGNAL));
6400
6619
  const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
6401
6620
  const compressionMethod = getOptionValue(zipWriter, options, PROPERTY_NAME_COMPRESSION_METHOD);
6402
6621
  const registeredCodec = passThrough || compressionMethod === UNDEFINED_VALUE ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
@@ -6476,18 +6695,26 @@ function serializeExtraField(extraField) {
6476
6695
  if (!extraField) {
6477
6696
  return EMPTY_UINT8_ARRAY;
6478
6697
  }
6698
+ if (!(extraField instanceof Map)) {
6699
+ throw new Error(ERR_INVALID_EXTRAFIELD);
6700
+ }
6479
6701
  let extraFieldSize = 0;
6480
6702
  let offset = 0;
6481
- extraField.forEach(data => extraFieldSize += 4 + getLength(data));
6482
- const rawExtraField = new Uint8Array(extraFieldSize);
6483
- const rawExtraFieldView = getDataView(rawExtraField);
6484
6703
  extraField.forEach((data, type) => {
6485
- if (type > MAX_16_BITS) {
6704
+ if (!Number.isInteger(type) || type < 0 || type > MAX_16_BITS) {
6486
6705
  throw new Error(ERR_INVALID_EXTRAFIELD_TYPE);
6487
6706
  }
6707
+ if (!(data instanceof Uint8Array)) {
6708
+ throw new Error(ERR_INVALID_EXTRAFIELD_DATA_TYPE);
6709
+ }
6488
6710
  if (getLength(data) > MAX_16_BITS) {
6489
6711
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
6490
6712
  }
6713
+ extraFieldSize += 4 + getLength(data);
6714
+ });
6715
+ const rawExtraField = new Uint8Array(extraFieldSize);
6716
+ const rawExtraFieldView = getDataView(rawExtraField);
6717
+ extraField.forEach((data, type) => {
6491
6718
  setUint16(rawExtraFieldView, offset, type);
6492
6719
  setUint16(rawExtraFieldView, offset + 2, getLength(data));
6493
6720
  arraySet(rawExtraField, data, offset + 4);
@@ -6575,7 +6802,7 @@ function resolveEntrySizes(zipWriter, hasContent, contentSize, metadata, options
6575
6802
 
6576
6803
  async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6577
6804
  const {
6578
- files,
6805
+ fileEntries,
6579
6806
  writer
6580
6807
  } = zipWriter;
6581
6808
  const {
@@ -6597,12 +6824,12 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6597
6824
  let writerSizeBeforeEntry;
6598
6825
  let flushedBufferedSize = 0;
6599
6826
  let fileWriter;
6600
- files.set(name, fileEntry);
6827
+ fileEntries.set(name, fileEntry);
6601
6828
  zipWriter.lastFileEntry = fileEntry;
6602
6829
  try {
6603
6830
  let lockPreviousFileEntry;
6604
6831
  if (keepOrder) {
6605
- lockPreviousFileEntry = previousFileEntry && previousFileEntry.lock;
6832
+ lockPreviousFileEntry = previousFileEntry && previousFileEntry.lockFileEntry;
6606
6833
  requestLockCurrentFileEntry();
6607
6834
  }
6608
6835
  if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || !dataDescriptor) {
@@ -6623,11 +6850,8 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6623
6850
  const diskOffset = getDiskOffset(writer);
6624
6851
  if (zipWriter.addSplitZipSignature) {
6625
6852
  delete zipWriter.addSplitZipSignature;
6626
- const signatureArray = new Uint8Array(4);
6627
- const signatureArrayView = getDataView(signatureArray);
6628
- setUint32(signatureArrayView, 0, SPLIT_ZIP_FILE_SIGNATURE);
6629
- await writeData(writer, signatureArray);
6630
- zipWriter.offset += 4;
6853
+ await writeData(writer, getSplitZipSignatureArray());
6854
+ zipWriter.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
6631
6855
  }
6632
6856
  if (usdz && !bufferedWrite) {
6633
6857
  appendExtraFieldUSDZ(entryInfo, zipWriter.offset - diskOffset);
@@ -6645,11 +6869,11 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6645
6869
  writerSizeBeforeEntry = writer.size;
6646
6870
  await writeData(fileWriter, localHeaderArray);
6647
6871
  }
6648
- fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, zipWriter.config, options);
6872
+ fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, getConfiguration(), options);
6649
6873
  if (!bufferedWrite) {
6650
6874
  writingEntryData = false;
6651
6875
  }
6652
- files.set(name, fileEntry);
6876
+ fileEntries.set(name, fileEntry);
6653
6877
  fileEntry.filename = name;
6654
6878
  if (bufferedWrite) {
6655
6879
  await Promise.all([fileWriter.writable.getWriter().close(), lockPreviousFileEntry]);
@@ -6690,7 +6914,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6690
6914
  zipWriter.offset += flushedBufferedSize;
6691
6915
  }
6692
6916
  }
6693
- files.delete(name);
6917
+ fileEntries.delete(name);
6694
6918
  throw error;
6695
6919
  } finally {
6696
6920
  if (bufferedWrite) {
@@ -6712,7 +6936,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6712
6936
  }
6713
6937
 
6714
6938
  function requestLockCurrentFileEntry() {
6715
- fileEntry.lock = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
6939
+ fileEntry.lockFileEntry = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
6716
6940
  }
6717
6941
 
6718
6942
  async function requestLockWriter() {
@@ -6732,7 +6956,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6732
6956
  }
6733
6957
  }
6734
6958
 
6735
- async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryInfo, config, options) {
6959
+ async function createFileEntry(reader, writer, { diskNumberStart, lockFileEntry }, entryInfo, config, options) {
6736
6960
  const {
6737
6961
  headerInfo,
6738
6962
  dataDescriptorInfo,
@@ -6787,6 +7011,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6787
7011
  uid,
6788
7012
  gid,
6789
7013
  unixMode,
7014
+ symlink,
6790
7015
  setuid,
6791
7016
  setgid,
6792
7017
  sticky,
@@ -6799,7 +7024,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6799
7024
  codecURI
6800
7025
  } = options;
6801
7026
  const fileEntry = {
6802
- lock,
7027
+ lockFileEntry,
6803
7028
  versionMadeBy,
6804
7029
  zip64,
6805
7030
  directory: Boolean(directory),
@@ -6823,6 +7048,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6823
7048
  uid,
6824
7049
  gid,
6825
7050
  unixMode,
7051
+ symlink: Boolean(symlink),
6826
7052
  setuid,
6827
7053
  setgid,
6828
7054
  sticky,
@@ -6840,7 +7066,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6840
7066
  }
6841
7067
  const { writable } = writer;
6842
7068
  if (reader) {
6843
- const readable = toCompatibleReadable(reader.createReadable ? reader.createReadable() : reader.readable);
7069
+ const readable = toCompatibleReadable(createReadable(reader));
6844
7070
  const size = reader.size;
6845
7071
  const workerOptions = {
6846
7072
  options: {
@@ -6903,8 +7129,8 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6903
7129
  rawLastModDate,
6904
7130
  creationDate,
6905
7131
  lastAccessDate,
6906
- encrypted,
6907
- zipCrypto,
7132
+ encrypted: Boolean(encrypted),
7133
+ zipCrypto: Boolean(zipCrypto),
6908
7134
  size: metadataSize + compressedSize,
6909
7135
  compressionMethod,
6910
7136
  version,
@@ -6952,14 +7178,14 @@ function getHeaderInfo(options) {
6952
7178
  if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
6953
7179
  const length = 4 + 16;
6954
7180
  const extraFieldZip64 = createRecordWriter(length);
6955
- extraFieldZip64.uint16(EXTRAFIELD_TYPE_ZIP64);
6956
- extraFieldZip64.uint16(length - 4);
7181
+ extraFieldZip64.writeUint16(EXTRAFIELD_TYPE_ZIP64);
7182
+ extraFieldZip64.writeUint16(length - 4);
6957
7183
  rawLocalExtraFieldZip64 = extraFieldZip64.array;
6958
7184
  if (zip64ExtraFieldComplete) {
6959
- extraFieldZip64.uint64(uncompressedSize);
7185
+ extraFieldZip64.writeUint64(uncompressedSize);
6960
7186
  if (uncompressedFile) {
6961
7187
  const encryptionOverhead = encrypted ? (zipCrypto ? 12 : 16 + encryptionStrength * 4) : 0;
6962
- extraFieldZip64.uint64(passThrough ? 0 : uncompressedSize + encryptionOverhead);
7188
+ extraFieldZip64.writeUint64(passThrough ? 0 : uncompressedSize + encryptionOverhead);
6963
7189
  }
6964
7190
  }
6965
7191
  } else {
@@ -6968,8 +7194,8 @@ function getHeaderInfo(options) {
6968
7194
  let rawExtraFieldAES;
6969
7195
  if (encrypted && !zipCrypto) {
6970
7196
  const extraFieldAES = createRecordWriter(getLength(EXTRAFIELD_DATA_AES) + 2);
6971
- extraFieldAES.uint16(EXTRAFIELD_TYPE_AES);
6972
- extraFieldAES.bytes(EXTRAFIELD_DATA_AES);
7197
+ extraFieldAES.writeUint16(EXTRAFIELD_TYPE_AES);
7198
+ extraFieldAES.writeBytes(EXTRAFIELD_DATA_AES);
6973
7199
  rawExtraFieldAES = extraFieldAES.array;
6974
7200
  rawExtraFieldAES[8] = encryptionStrength;
6975
7201
  } else {
@@ -6985,15 +7211,15 @@ function getHeaderInfo(options) {
6985
7211
  const extraFieldTimestampLength = 9 + (lastAccessDate ? 4 : 0) + (creationDate ? 4 : 0);
6986
7212
  const extraFieldTimestamp = createRecordWriter(extraFieldTimestampLength);
6987
7213
  extraFieldExtendedTimestampFlag = 0x1 + (lastAccessDate ? 0x2 : 0) + (creationDate ? 0x4 : 0);
6988
- extraFieldTimestamp.uint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
6989
- extraFieldTimestamp.uint16(extraFieldTimestampLength - 4);
6990
- extraFieldTimestamp.uint8(extraFieldExtendedTimestampFlag);
6991
- extraFieldTimestamp.uint32(lastModTimeUnix);
7214
+ extraFieldTimestamp.writeUint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
7215
+ extraFieldTimestamp.writeUint16(extraFieldTimestampLength - 4);
7216
+ extraFieldTimestamp.writeUint8(extraFieldExtendedTimestampFlag);
7217
+ extraFieldTimestamp.writeUint32(lastModTimeUnix);
6992
7218
  if (lastAccessDate) {
6993
- extraFieldTimestamp.uint32(clampUnixTime(getTimeUnix(lastAccessDate)));
7219
+ extraFieldTimestamp.writeUint32(clampUnixTime(getTimeUnix(lastAccessDate)));
6994
7220
  }
6995
7221
  if (creationDate) {
6996
- extraFieldTimestamp.uint32(clampUnixTime(getTimeUnix(creationDate)));
7222
+ extraFieldTimestamp.writeUint32(clampUnixTime(getTimeUnix(creationDate)));
6997
7223
  }
6998
7224
  rawExtraFieldExtendedTimestamp = extraFieldTimestamp.array;
6999
7225
  } else {
@@ -7006,14 +7232,14 @@ function getHeaderInfo(options) {
7006
7232
  try {
7007
7233
  const lastModTimeNTFS = getTimeNTFS(lastModDate);
7008
7234
  const extraFieldNTFS = createRecordWriter(36);
7009
- extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS);
7010
- extraFieldNTFS.uint16(32);
7235
+ extraFieldNTFS.writeUint16(EXTRAFIELD_TYPE_NTFS);
7236
+ extraFieldNTFS.writeUint16(32);
7011
7237
  extraFieldNTFS.skip(4);
7012
- extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS_TAG1);
7013
- extraFieldNTFS.uint16(24);
7014
- extraFieldNTFS.uint64(lastModTimeNTFS);
7015
- extraFieldNTFS.uint64(lastAccessDate ? getTimeNTFS(lastAccessDate) : lastModTimeNTFS);
7016
- 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);
7017
7243
  rawExtraFieldNTFS = extraFieldNTFS.array;
7018
7244
  } catch {
7019
7245
  rawExtraFieldNTFS = EMPTY_UINT8_ARRAY;
@@ -7032,20 +7258,20 @@ function getHeaderInfo(options) {
7032
7258
  const gidBytes = packUnixId(gid);
7033
7259
  const payloadLength = 3 + uidBytes.length + gidBytes.length;
7034
7260
  const extraFieldUnix = createRecordWriter(4 + payloadLength);
7035
- extraFieldUnix.uint16(EXTRAFIELD_TYPE_INFOZIP);
7036
- extraFieldUnix.uint16(payloadLength);
7037
- extraFieldUnix.uint8(1);
7038
- extraFieldUnix.uint8(uidBytes.length);
7039
- extraFieldUnix.bytes(uidBytes);
7040
- extraFieldUnix.uint8(gidBytes.length);
7041
- 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);
7042
7268
  rawExtraFieldUnix = extraFieldUnix.array;
7043
7269
  } else if (unixExtraFieldType == UNIX_EXTRA_FIELD_TYPE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
7044
7270
  const extraFieldUnix = createRecordWriter(8);
7045
- extraFieldUnix.uint16(EXTRAFIELD_TYPE_UNIX);
7046
- extraFieldUnix.uint16(4);
7047
- extraFieldUnix.uint16((uid === UNDEFINED_VALUE ? 0 : uid) & MAX_16_BITS);
7048
- 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);
7049
7275
  rawExtraFieldUnix = extraFieldUnix.array;
7050
7276
  } else {
7051
7277
  rawExtraFieldUnix = EMPTY_UINT8_ARRAY;
@@ -7095,18 +7321,18 @@ function getHeaderInfo(options) {
7095
7321
  const localHeader = createRecordWriter(HEADER_SIZE + getLength(rawFilename) + extraFieldLength);
7096
7322
  const localHeaderArray = localHeader.array;
7097
7323
  const localHeaderView = getDataView(localHeaderArray);
7098
- localHeader.uint32(LOCAL_FILE_HEADER_SIGNATURE);
7099
- localHeader.bytes(headerArray);
7100
- localHeader.bytes(rawFilename);
7324
+ localHeader.writeUint32(LOCAL_FILE_HEADER_SIGNATURE);
7325
+ localHeader.writeBytes(headerArray);
7326
+ localHeader.writeBytes(rawFilename);
7101
7327
  if (writeLocalExtraFieldZip64) {
7102
- localHeader.bytes(rawLocalExtraFieldZip64);
7103
- }
7104
- localHeader.bytes(rawExtraFieldAES);
7105
- localHeader.bytes(rawExtraFieldExtendedTimestamp);
7106
- localHeader.bytes(rawExtraFieldNTFS);
7107
- localHeader.bytes(rawExtraFieldUnix);
7108
- localHeader.bytes(rawExtraField);
7109
- 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);
7110
7336
  if (dataDescriptor) {
7111
7337
  if (!zip64CompressedSize) {
7112
7338
  setUint32(localHeaderView, HEADER_OFFSET_COMPRESSED_SIZE + LOCAL_HEADER_COMMON_OFFSET, 0);
@@ -7296,7 +7522,7 @@ function updateLocalHeader({
7296
7522
 
7297
7523
 
7298
7524
  async function closeFile(zipWriter, comment, options) {
7299
- const directoryDataLength = createDirectoryRecords(zipWriter.files);
7525
+ const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
7300
7526
  const { directoryStart, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7301
7527
  const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
7302
7528
  await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryDataLength, signatureLength });
@@ -7326,19 +7552,19 @@ function createDirectoryRecords(files) {
7326
7552
  if (zip64Offset || zip64DiskNumberStart || zip64UncompressedSize || zip64CompressedSize) {
7327
7553
  const length = 4 + (zip64UncompressedSize ? 8 : 0) + (zip64CompressedSize ? 8 : 0) + (zip64Offset ? 8 : 0) + (zip64DiskNumberStart ? 4 : 0);
7328
7554
  const extraFieldZip64 = createRecordWriter(length);
7329
- extraFieldZip64.uint16(EXTRAFIELD_TYPE_ZIP64);
7330
- extraFieldZip64.uint16(length - 4);
7555
+ extraFieldZip64.writeUint16(EXTRAFIELD_TYPE_ZIP64);
7556
+ extraFieldZip64.writeUint16(length - 4);
7331
7557
  if (zip64UncompressedSize) {
7332
- extraFieldZip64.uint64(uncompressedSize);
7558
+ extraFieldZip64.writeUint64(uncompressedSize);
7333
7559
  }
7334
7560
  if (zip64CompressedSize) {
7335
- extraFieldZip64.uint64(compressedSize);
7561
+ extraFieldZip64.writeUint64(compressedSize);
7336
7562
  }
7337
7563
  if (zip64Offset) {
7338
- extraFieldZip64.uint64(fileEntry.offset);
7564
+ extraFieldZip64.writeUint64(fileEntry.offset);
7339
7565
  }
7340
7566
  if (zip64DiskNumberStart) {
7341
- extraFieldZip64.uint32(fileEntry.diskNumberStart);
7567
+ extraFieldZip64.writeUint32(fileEntry.diskNumberStart);
7342
7568
  }
7343
7569
  rawExtraFieldZip64 = extraFieldZip64.array;
7344
7570
  } else {
@@ -7351,10 +7577,10 @@ function createDirectoryRecords(files) {
7351
7577
  const lastModTimeUnix = getTimeUnix(lastModDate);
7352
7578
  if (extendedTimestamp && inUnixTimeRange(lastModTimeUnix)) {
7353
7579
  const extraFieldTimestamp = createRecordWriter(9);
7354
- extraFieldTimestamp.uint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
7355
- extraFieldTimestamp.uint16(5);
7356
- extraFieldTimestamp.uint8(extraFieldExtendedTimestampFlag);
7357
- extraFieldTimestamp.uint32(lastModTimeUnix);
7580
+ extraFieldTimestamp.writeUint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
7581
+ extraFieldTimestamp.writeUint16(5);
7582
+ extraFieldTimestamp.writeUint8(extraFieldExtendedTimestampFlag);
7583
+ extraFieldTimestamp.writeUint32(lastModTimeUnix);
7358
7584
  rawExtraFieldTimestamp = extraFieldTimestamp.array;
7359
7585
  } else {
7360
7586
  rawExtraFieldTimestamp = EMPTY_UINT8_ARRAY;
@@ -7376,14 +7602,14 @@ function createDirectoryRecords(files) {
7376
7602
  }
7377
7603
 
7378
7604
  async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
7379
- const { files, writer } = zipWriter;
7605
+ const { fileEntries, writer } = zipWriter;
7380
7606
  const directoryArray = new Uint8Array(directoryDataLength);
7381
7607
  await initStream(writer);
7382
7608
  let offset = 0;
7383
7609
  let directoryDiskOffset = 0;
7384
7610
  let directoryStartDiskNumber = getDiskNumber(writer);
7385
7611
  let directoryStartDiskOffset = getDiskOffset(writer);
7386
- for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
7612
+ for (const [indexFileEntry, fileEntry] of Array.from(fileEntries.values()).entries()) {
7387
7613
  const {
7388
7614
  offset: fileEntryOffset,
7389
7615
  rawFilename,
@@ -7428,28 +7654,28 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
7428
7654
  setUint16(headerView, HEADER_OFFSET_VERSION, VERSION_ZIP64);
7429
7655
  }
7430
7656
  const directoryRecord = createRecordWriter(directoryRecordLength);
7431
- directoryRecord.uint32(CENTRAL_FILE_HEADER_SIGNATURE);
7432
- directoryRecord.uint16(versionMadeBy);
7433
- directoryRecord.bytes(headerArray.subarray(0, HEADER_SIZE - 4 - 2));
7434
- directoryRecord.uint16(extraFieldLength);
7435
- directoryRecord.uint16(getLength(rawComment));
7436
- directoryRecord.uint16(zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
7437
- directoryRecord.uint16(internalFileAttributes);
7438
- directoryRecord.uint32(externalFileAttributes);
7439
- directoryRecord.uint32(zip64Offset ? MAX_32_BITS : fileEntryOffset);
7440
- directoryRecord.bytes(rawFilename);
7441
- directoryRecord.bytes(rawExtraFieldZip64);
7442
- directoryRecord.bytes(rawExtraFieldAES);
7443
- directoryRecord.bytes(rawExtraFieldExtendedTimestamp);
7444
- directoryRecord.bytes(rawExtraFieldNTFS);
7445
- directoryRecord.bytes(rawExtraFieldUnix);
7446
- directoryRecord.bytes(rawExtraField);
7447
- 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);
7448
7674
  arraySet(directoryArray, directoryRecord.array, offset);
7449
7675
  offset += directoryRecordLength;
7450
7676
  if (options.onprogress) {
7451
7677
  try {
7452
- await options.onprogress(indexFileEntry + 1, files.size, new Entry(fileEntry));
7678
+ await options.onprogress(indexFileEntry + 1, fileEntries.size, new Entry(fileEntry));
7453
7679
  } catch {
7454
7680
  // ignored
7455
7681
  }
@@ -7463,7 +7689,7 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
7463
7689
  }
7464
7690
 
7465
7691
  async function writeDigitalSignatureRecord(zipWriter, directoryArray, options) {
7466
- const signCentralDirectory = getOptionValue(zipWriter, options, OPTION_SIGN_CENTRAL_DIRECTORY);
7692
+ const signCentralDirectory = getFunctionOptionValue(zipWriter, options, OPTION_SIGN_CENTRAL_DIRECTORY);
7467
7693
  if (signCentralDirectory) {
7468
7694
  const signatureData = await signCentralDirectory(directoryArray);
7469
7695
  const signatureDataLength = getLength(signatureData);
@@ -7471,9 +7697,9 @@ async function writeDigitalSignatureRecord(zipWriter, directoryArray, options) {
7471
7697
  throw new Error(ERR_INVALID_SIGNATURE_DATA);
7472
7698
  }
7473
7699
  const signatureRecord = createRecordWriter(6 + signatureDataLength);
7474
- signatureRecord.uint32(DIGITAL_SIGNATURE_RECORD_SIGNATURE);
7475
- signatureRecord.uint16(signatureDataLength);
7476
- signatureRecord.bytes(signatureData);
7700
+ signatureRecord.writeUint32(DIGITAL_SIGNATURE_RECORD_SIGNATURE);
7701
+ signatureRecord.writeUint16(signatureDataLength);
7702
+ signatureRecord.writeBytes(signatureData);
7477
7703
  await writeData(zipWriter.writer, signatureRecord.array);
7478
7704
  return 6 + signatureDataLength;
7479
7705
  }
@@ -7484,7 +7710,7 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7484
7710
  const { writer } = zipWriter;
7485
7711
  const { directoryStart, signatureLength } = cdInfo;
7486
7712
  let { directoryDataLength } = cdInfo;
7487
- let filesLength = zipWriter.files.size;
7713
+ let fileEntriesLength = zipWriter.fileEntries.size;
7488
7714
  let diskNumber = directoryStart.diskNumber;
7489
7715
  let directoryOffset = getSegmentOffset(zipWriter, directoryStart);
7490
7716
  let lastDiskNumber = getDiskNumber(writer);
@@ -7492,7 +7718,7 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7492
7718
  lastDiskNumber++;
7493
7719
  }
7494
7720
  let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
7495
- 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) {
7496
7722
  if (zip64 === false) {
7497
7723
  throw new Error(ERR_UNSUPPORTED_FORMAT);
7498
7724
  } else {
@@ -7509,37 +7735,37 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7509
7735
  }
7510
7736
  lastDiskNumber = getDiskNumber(writer);
7511
7737
  if (zip64) {
7512
- endOfdirectoryRecord.uint32(ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
7513
- endOfdirectoryRecord.uint64(44);
7514
- endOfdirectoryRecord.uint16(45);
7515
- endOfdirectoryRecord.uint16(45);
7516
- endOfdirectoryRecord.uint32(lastDiskNumber);
7517
- endOfdirectoryRecord.uint32(diskNumber);
7518
- endOfdirectoryRecord.uint64(filesLength);
7519
- endOfdirectoryRecord.uint64(filesLength);
7520
- endOfdirectoryRecord.uint64(directoryDataLength);
7521
- endOfdirectoryRecord.uint64(directoryOffset);
7522
- endOfdirectoryRecord.uint32(ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
7523
- endOfdirectoryRecord.uint32(lastDiskNumber);
7524
- endOfdirectoryRecord.uint64(BigInt(getSegmentOffset(zipWriter, writer)) + BigInt(directoryDataLength) + BigInt(signatureLength));
7525
- 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);
7526
7752
  const supportZip64SplitFile = getOptionValue(zipWriter, options, OPTION_SUPPORT_ZIP64_SPLIT_FILE, true);
7527
7753
  if (supportZip64SplitFile) {
7528
7754
  lastDiskNumber = MAX_16_BITS;
7529
7755
  diskNumber = MAX_16_BITS;
7530
7756
  }
7531
- filesLength = MAX_16_BITS;
7757
+ fileEntriesLength = MAX_16_BITS;
7532
7758
  directoryOffset = MAX_32_BITS;
7533
7759
  directoryDataLength = MAX_32_BITS;
7534
7760
  }
7535
- endOfdirectoryRecord.uint32(END_OF_CENTRAL_DIR_SIGNATURE);
7536
- endOfdirectoryRecord.uint16(lastDiskNumber);
7537
- endOfdirectoryRecord.uint16(diskNumber);
7538
- endOfdirectoryRecord.uint16(filesLength);
7539
- endOfdirectoryRecord.uint16(filesLength);
7540
- endOfdirectoryRecord.uint32(directoryDataLength);
7541
- endOfdirectoryRecord.uint32(directoryOffset);
7542
- 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);
7543
7769
  await writeData(writer, endOfdirectoryRecord.array);
7544
7770
  if (commentLength) {
7545
7771
  await writeData(writer, comment);
@@ -7552,11 +7778,11 @@ function createRecordWriter(length) {
7552
7778
  let offset = 0;
7553
7779
  return {
7554
7780
  array,
7555
- uint8: value => { setUint8(view, offset, value); offset += 1; },
7556
- uint16: value => { setUint16(view, offset, value); offset += 2; },
7557
- uint32: value => { setUint32(view, offset, value); offset += 4; },
7558
- uint64: value => { setBigUint64(view, offset, BigInt(value)); offset += 8; },
7559
- 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); },
7560
7786
  skip: count => offset += count
7561
7787
  };
7562
7788
  }
@@ -7580,6 +7806,71 @@ function getSegmentOffset(zipWriter, { diskNumber = 0, diskOffset = 0 }) {
7580
7806
  return zipWriter.offset - diskOffset - (diskNumber ? zipWriter.initialOffset : 0);
7581
7807
  }
7582
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
+
7583
7874
  async function writeData(writer, array) {
7584
7875
  const { writable } = writer;
7585
7876
  const streamWriter = writable.getWriter();
@@ -7631,6 +7922,21 @@ function getOptionValue(zipWriter, options, name, defaultValue) {
7631
7922
  return result === UNDEFINED_VALUE ? defaultValue : result;
7632
7923
  }
7633
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
+
7634
7940
  function getAliasedOptionValue(zipWriter, options, name, deprecatedName, defaultValue) {
7635
7941
  const value = getAliasedValue(options, name, deprecatedName);
7636
7942
  const result = value === UNDEFINED_VALUE ? getAliasedValue(zipWriter.options, name, deprecatedName) : value;
@@ -7645,9 +7951,6 @@ function getNumberOptionValue(zipWriter, options, name, defaultValue) {
7645
7951
  return toNumber(getOptionValue(zipWriter, options, name, defaultValue));
7646
7952
  }
7647
7953
 
7648
- function toNumber(value) {
7649
- return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
7650
- }
7651
7954
 
7652
7955
  function getMaximumCompressedSize(uncompressedSize) {
7653
7956
  return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
@@ -7659,6 +7962,14 @@ function isCompressed(compressionMethod, level) {
7659
7962
  : compressionMethod !== COMPRESSION_METHOD_STORE;
7660
7963
  }
7661
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
+
7662
7973
  function setUint8(view, offset, value) {
7663
7974
  view.setUint8(offset, value);
7664
7975
  }
@@ -7702,9 +8013,9 @@ function getHeaderArrayData({
7702
8013
  const headerRecord = createRecordWriter(HEADER_SIZE - 4);
7703
8014
  const headerArray = headerRecord.array;
7704
8015
  const headerView = getDataView(headerArray);
7705
- headerRecord.uint16(version);
7706
- headerRecord.uint16(bitFlag);
7707
- headerRecord.uint16(compressionMethod);
8016
+ headerRecord.writeUint16(version);
8017
+ headerRecord.writeUint16(bitFlag);
8018
+ headerRecord.writeUint16(compressionMethod);
7708
8019
  if (rawLastModDate === UNDEFINED_VALUE) {
7709
8020
  const dateArray = new Uint32Array(1);
7710
8021
  const dateView = getDataView(dateArray);
@@ -7712,20 +8023,20 @@ function getHeaderArrayData({
7712
8023
  setUint16(dateView, 2, ((((lastModDate.getFullYear() - 1980) << 4) | (lastModDate.getMonth() + 1)) << 5) | lastModDate.getDate());
7713
8024
  rawLastModDate = dateArray[0];
7714
8025
  }
7715
- headerRecord.uint32(rawLastModDate);
8026
+ headerRecord.writeUint32(rawLastModDate);
7716
8027
  headerRecord.skip(4);
7717
8028
  if (zip64CompressedSize || compressedSize !== UNDEFINED_VALUE) {
7718
- headerRecord.uint32(zip64CompressedSize ? MAX_32_BITS : compressedSize);
8029
+ headerRecord.writeUint32(zip64CompressedSize ? MAX_32_BITS : compressedSize);
7719
8030
  } else {
7720
8031
  headerRecord.skip(4);
7721
8032
  }
7722
8033
  if (zip64UncompressedSize || uncompressedSize !== UNDEFINED_VALUE) {
7723
- headerRecord.uint32(zip64UncompressedSize ? MAX_32_BITS : uncompressedSize);
8034
+ headerRecord.writeUint32(zip64UncompressedSize ? MAX_32_BITS : uncompressedSize);
7724
8035
  } else {
7725
8036
  headerRecord.skip(4);
7726
8037
  }
7727
- headerRecord.uint16(getLength(rawFilename));
7728
- headerRecord.uint16(extraFieldLength);
8038
+ headerRecord.writeUint16(getLength(rawFilename));
8039
+ headerRecord.writeUint16(extraFieldLength);
7729
8040
  return {
7730
8041
  headerArray,
7731
8042
  headerView,
@@ -8613,4 +8924,4 @@ function terminateWorkersAndModule() {
8613
8924
 
8614
8925
  configureExternalAssets();
8615
8926
 
8616
- 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_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 };