@zip.js/zip.js 2.8.53 → 2.8.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +1 -1
  2. package/deno.json +2 -1
  3. package/dist/zip-core-external.js +691 -482
  4. package/dist/zip-core-external.min.js +1 -1
  5. package/dist/zip-core.js +698 -481
  6. package/dist/zip-core.min.js +1 -1
  7. package/dist/zip-fs-core-external.js +729 -511
  8. package/dist/zip-fs-core-external.min.js +1 -1
  9. package/dist/zip-fs-core.js +691 -496
  10. package/dist/zip-fs-core.min.js +1 -1
  11. package/dist/zip-fs-external.js +729 -511
  12. package/dist/zip-fs-external.min.js +1 -1
  13. package/dist/zip-fs-native.js +743 -512
  14. package/dist/zip-fs-native.min.js +1 -1
  15. package/dist/zip-fs.js +742 -511
  16. package/dist/zip-fs.min.js +1 -1
  17. package/dist/zip-legacy.js +700 -483
  18. package/dist/zip-legacy.min.js +1 -1
  19. package/dist/zip-native.js +700 -483
  20. package/dist/zip-native.min.js +1 -1
  21. package/dist/zip-web-worker-native.js +1 -1
  22. package/dist/zip-web-worker.js +1 -1
  23. package/dist/zip.js +699 -482
  24. package/dist/zip.min.js +1 -1
  25. package/eslint.config.mjs +1 -0
  26. package/index-native.cjs +743 -512
  27. package/index-native.min.js +1 -1
  28. package/index.cjs +742 -511
  29. package/index.d.cts +398 -42
  30. package/index.d.ts +398 -42
  31. package/index.min.js +1 -1
  32. package/lib/core/configuration.js +62 -21
  33. package/lib/core/constants.js +11 -1
  34. package/lib/core/io.js +33 -27
  35. package/lib/core/options.js +44 -2
  36. package/lib/core/streams/aes-crypto-stream.js +12 -12
  37. package/lib/core/util/decode-text.js +11 -2
  38. package/lib/core/web-worker-base.js +3 -2
  39. package/lib/core/web-worker-inline-native.js +1 -1
  40. package/lib/core/web-worker-inline-wasm.js +1 -1
  41. package/lib/core/zip-fs.js +38 -27
  42. package/lib/core/zip-reader.js +58 -26
  43. package/lib/core/zip-writer.js +293 -177
  44. package/lib/zip-core-base.js +6 -1
  45. package/lib/zip-core-reader.js +1 -0
  46. package/lib/zip-core-writer.js +4 -0
  47. package/package.json +8 -2
@@ -44,6 +44,7 @@
44
44
 
45
45
  const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
46
46
  const SPLIT_ZIP_FILE_SIGNATURE = 0x08074b50;
47
+ const TEMPORARY_SPLIT_ZIP_FILE_SIGNATURE = 0x30304b50;
47
48
  const DATA_DESCRIPTOR_RECORD_SIGNATURE = SPLIT_ZIP_FILE_SIGNATURE;
48
49
  const ARCHIVE_EXTRA_DATA_SIGNATURE = 0x08064b50;
49
50
  const DIGITAL_SIGNATURE_RECORD_SIGNATURE = 0x05054b50;
@@ -60,6 +61,7 @@
60
61
  const DATA_DESCRIPTOR_RECORD_LENGTH = 12;
61
62
  const DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH = 20;
62
63
  const DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH = 4;
64
+ const SPLIT_ZIP_FILE_SIGNATURE_LENGTH = 4;
63
65
 
64
66
  const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
65
67
  const EXTRAFIELD_TYPE_AES = 0x9901;
@@ -111,6 +113,8 @@
111
113
  const HEADER_OFFSET_SIGNATURE = 10;
112
114
  const HEADER_OFFSET_COMPRESSED_SIZE = 14;
113
115
  const HEADER_OFFSET_UNCOMPRESSED_SIZE = 18;
116
+ const HEADER_OFFSET_FILENAME_LENGTH = 22;
117
+ const HEADER_OFFSET_EXTRAFIELD_LENGTH = 24;
114
118
  const LOCAL_HEADER_COMMON_OFFSET = 4;
115
119
 
116
120
  const MAX_DATE = new Date(2107, 11, 31, 23, 59, 58);
@@ -123,9 +127,116 @@
123
127
  const OBJECT_TYPE = "object";
124
128
  const STRING_TYPE = "string";
125
129
  const NUMBER_TYPE = "number";
130
+ const BOOLEAN_TYPE = "boolean";
126
131
 
127
132
  const EMPTY_UINT8_ARRAY = new Uint8Array();
128
133
 
134
+ /*
135
+ Copyright (c) 2022 Gildas Lormeau. All rights reserved.
136
+
137
+ Redistribution and use in source and binary forms, with or without
138
+ modification, are permitted provided that the following conditions are met:
139
+
140
+ 1. Redistributions of source code must retain the above copyright notice,
141
+ this list of conditions and the following disclaimer.
142
+
143
+ 2. Redistributions in binary form must reproduce the above copyright
144
+ notice, this list of conditions and the following disclaimer in
145
+ the documentation and/or other materials provided with the distribution.
146
+
147
+ 3. The names of the authors may not be used to endorse or promote products
148
+ derived from this software without specific prior written permission.
149
+
150
+ THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
151
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
152
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
153
+ INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
154
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
155
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
156
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
157
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
158
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
159
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
160
+ */
161
+
162
+
163
+ const OPTION_FILENAME_ENCODING = "filenameEncoding";
164
+ const OPTION_COMMENT_ENCODING = "commentEncoding";
165
+ const OPTION_DECODE_TEXT = "decodeText";
166
+ const OPTION_EXTRACT_PREPENDED_DATA = "extractPrependedData";
167
+ const OPTION_EXTRACT_APPENDED_DATA = "extractAppendedData";
168
+ const OPTION_PASSWORD = "password";
169
+ const OPTION_RAW_PASSWORD = "rawPassword";
170
+ const OPTION_PASS_THROUGH = "passThrough";
171
+ const OPTION_SIGNAL = "signal";
172
+ const OPTION_CHECK_PASSWORD_ONLY = "checkPasswordOnly";
173
+ const OPTION_CHECK_OVERLAPPING_ENTRY_ONLY = "checkOverlappingEntryOnly";
174
+ const OPTION_CHECK_OVERLAPPING_ENTRY = "checkOverlappingEntry";
175
+ const OPTION_CHECK_AMBIGUITY = "checkAmbiguity";
176
+ const OPTION_CHECK_LOCAL_DIRECTORY = "checkLocalDirectory";
177
+ const OPTION_CHECK_SIGNATURE = "checkSignature";
178
+ const OPTION_CHECK_CRC32 = "checkCrc32";
179
+ const OPTION_CHECK_AUTHENTICATION_CODE = "checkAuthenticationCode";
180
+ const OPTION_USE_WEB_WORKERS = "useWebWorkers";
181
+ const OPTION_USE_COMPRESSION_STREAM = "useCompressionStream";
182
+ const OPTION_TRANSFER_STREAMS = "transferStreams";
183
+ const OPTION_PREVENT_CLOSE = "preventClose";
184
+ const OPTION_ENCRYPTION_STRENGTH = "encryptionStrength";
185
+ const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
186
+ const OPTION_NTFS_TIMESTAMP = "ntfsTimestamp";
187
+ const OPTION_KEEP_ORDER = "keepOrder";
188
+ const OPTION_LEVEL = "level";
189
+ const OPTION_BUFFERED_WRITE = "bufferedWrite";
190
+ const OPTION_CREATE_TEMP_STREAM = "createTempStream";
191
+ const OPTION_DATA_DESCRIPTOR_SIGNATURE = "dataDescriptorSignature";
192
+ const OPTION_USE_UNICODE_FILE_NAMES = "useUnicodeFileNames";
193
+ const OPTION_DATA_DESCRIPTOR = "dataDescriptor";
194
+ const OPTION_SUPPORT_ZIP64_SPLIT_FILE = "supportZip64SplitFile";
195
+ const OPTION_ENCODE_TEXT = "encodeText";
196
+ const OPTION_OFFSET = "offset";
197
+ const OPTION_USDZ = "usdz";
198
+ const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
199
+ const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
200
+ const OPTION_STRICTNESS = "strictness";
201
+ const OPTION_FILENAME_VALIDATION = "filenameValidation";
202
+ const OPTION_NORMALIZE_FILENAME = "normalizeFilename";
203
+ const OPTION_MAX_APPENDED_DATA_SIZE = "maxAppendedDataSize";
204
+ const OPTION_DECRYPT_CENTRAL_DIRECTORY = "decryptCentralDirectory";
205
+ const OPTION_SIGN_CENTRAL_DIRECTORY = "signCentralDirectory";
206
+ const TEXT_TYPE_FILENAME = "filename";
207
+ const TEXT_TYPE_COMMENT = "comment";
208
+ const STRICTNESS_STRICT = "strict";
209
+ const STRICTNESS_BALANCED = "balanced";
210
+ const STRICTNESS_TOLERANT = "tolerant";
211
+
212
+ const ERR_INVALID_FUNCTION_OPTION = "Invalid option (must be a function)";
213
+ const ERR_INVALID_SIGNAL = "Invalid signal (must be an AbortSignal instance)";
214
+ const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
215
+
216
+ function checkFunctionOption(value) {
217
+ if (value && typeof value != FUNCTION_TYPE) {
218
+ throw new Error(ERR_INVALID_FUNCTION_OPTION);
219
+ }
220
+ return value;
221
+ }
222
+
223
+ function checkSignalOption(signal) {
224
+ if (signal && (typeof signal.addEventListener != FUNCTION_TYPE || typeof signal.aborted != BOOLEAN_TYPE)) {
225
+ throw new Error(ERR_INVALID_SIGNAL);
226
+ }
227
+ return signal || UNDEFINED_VALUE;
228
+ }
229
+
230
+ function checkPasswordOption(password, rawPassword) {
231
+ if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
232
+ throw new Error(ERR_INVALID_PASSWORD_TYPE);
233
+ }
234
+ }
235
+
236
+ function toNumber(value) {
237
+ return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
238
+ }
239
+
129
240
  /*
130
241
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
131
242
 
@@ -155,7 +266,9 @@
155
266
  */
156
267
 
157
268
 
269
+ const DEFAULT_CHUNK_SIZE$1 = 64 * 1024;
158
270
  const MINIMUM_CHUNK_SIZE = 64;
271
+ const MINIMUM_PROPERTY_VALUE = 1;
159
272
  let maxWorkers = 2;
160
273
  try {
161
274
  if (typeof navigator != UNDEFINED_TYPE && navigator.hardwareConcurrency) {
@@ -167,7 +280,7 @@
167
280
  const DEFAULT_CONFIGURATION = {
168
281
  workerURI: "./core/web-worker-wasm.js",
169
282
  wasmURI: "./core/streams/zlib-wasm/zlib-streams.wasm",
170
- chunkSize: 64 * 1024,
283
+ chunkSize: DEFAULT_CHUNK_SIZE$1,
171
284
  maxWorkers,
172
285
  terminateWorkerTimeout: 5000,
173
286
  workerStarvationTimeout: 5000,
@@ -186,7 +299,12 @@
186
299
  }
187
300
 
188
301
  function getChunkSize(config) {
189
- return Math.max(config.chunkSize, MINIMUM_CHUNK_SIZE);
302
+ return normalizeChunkSize(config.chunkSize);
303
+ }
304
+
305
+ function normalizeChunkSize(chunkSize) {
306
+ chunkSize = toNumber(chunkSize);
307
+ return Number.isInteger(chunkSize) && chunkSize >= MINIMUM_PROPERTY_VALUE ? Math.max(chunkSize, MINIMUM_CHUNK_SIZE) : DEFAULT_CHUNK_SIZE$1;
190
308
  }
191
309
 
192
310
  /*
@@ -320,6 +438,96 @@
320
438
  });
321
439
  }
322
440
 
441
+ /*
442
+ Copyright (c) 2022 Gildas Lormeau. All rights reserved.
443
+
444
+ Redistribution and use in source and binary forms, with or without
445
+ modification, are permitted provided that the following conditions are met:
446
+
447
+ 1. Redistributions of source code must retain the above copyright notice,
448
+ this list of conditions and the following disclaimer.
449
+
450
+ 2. Redistributions in binary form must reproduce the above copyright
451
+ notice, this list of conditions and the following disclaimer in
452
+ the documentation and/or other materials provided with the distribution.
453
+
454
+ 3. The names of the authors may not be used to endorse or promote products
455
+ derived from this software without specific prior written permission.
456
+
457
+ THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
458
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
459
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
460
+ INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
461
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
462
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
463
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
464
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
465
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
466
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
467
+ */
468
+
469
+ /* global TextDecoder */
470
+
471
+ const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");
472
+ const VALID_CP437 = CP437.length == 256;
473
+
474
+ function decodeCP437(stringValue) {
475
+ if (VALID_CP437) {
476
+ let result = "";
477
+ for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
478
+ result += CP437[stringValue[indexCharacter]];
479
+ }
480
+ return result;
481
+ } else {
482
+ return new TextDecoder().decode(stringValue);
483
+ }
484
+ }
485
+
486
+ /*
487
+ Copyright (c) 2022 Gildas Lormeau. All rights reserved.
488
+
489
+ Redistribution and use in source and binary forms, with or without
490
+ modification, are permitted provided that the following conditions are met:
491
+
492
+ 1. Redistributions of source code must retain the above copyright notice,
493
+ this list of conditions and the following disclaimer.
494
+
495
+ 2. Redistributions in binary form must reproduce the above copyright
496
+ notice, this list of conditions and the following disclaimer in
497
+ the documentation and/or other materials provided with the distribution.
498
+
499
+ 3. The names of the authors may not be used to endorse or promote products
500
+ derived from this software without specific prior written permission.
501
+
502
+ THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
503
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
504
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
505
+ INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
506
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
507
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
508
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
509
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
510
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
511
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
512
+ */
513
+
514
+
515
+ function decodeText(value, encoding) {
516
+ return decode(value, encoding, true);
517
+ }
518
+
519
+ function decodeTextRemovingBOM(value, encoding) {
520
+ return decode(value, encoding, false);
521
+ }
522
+
523
+ function decode(value, encoding, ignoreBOM) {
524
+ if (encoding && encoding.trim().toLowerCase() == "cp437") {
525
+ return decodeCP437(value);
526
+ } else {
527
+ return new TextDecoder(encoding, { ignoreBOM }).decode(value);
528
+ }
529
+ }
530
+
323
531
  /*
324
532
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
325
533
 
@@ -392,6 +600,7 @@
392
600
  createReadable({ offset = 0, size, chunkSize = getChunkSize(getConfiguration()) } = {}) {
393
601
  const reader = this;
394
602
  let chunkOffset = 0;
603
+ chunkSize = normalizeChunkSize(chunkSize);
395
604
  return new ReadableStream({
396
605
  async pull(controller) {
397
606
  const dataSize = size === UNDEFINED_VALUE ? chunkSize : Math.min(chunkSize, size - chunkOffset);
@@ -399,7 +608,7 @@
399
608
  if (data.length) {
400
609
  controller.enqueue(data);
401
610
  }
402
- if ((chunkOffset + chunkSize >= size) || (size === UNDEFINED_VALUE && !data.length && dataSize)) {
611
+ if ((chunkOffset + chunkSize >= size) || (!data.length && dataSize)) {
403
612
  controller.close();
404
613
  } else {
405
614
  chunkOffset += chunkSize;
@@ -479,31 +688,31 @@
479
688
  Object.assign(this, {
480
689
  contentType,
481
690
  data: "data:" + (contentType || "") + ";base64,",
482
- pending: []
691
+ pendingCharacters: ""
483
692
  });
484
693
  }
485
694
 
486
695
  writeUint8Array(array) {
487
696
  const writer = this;
488
697
  let indexArray;
489
- let dataString = writer.pending;
490
- const delta = writer.pending.length;
491
- writer.pending = "";
698
+ let dataString = writer.pendingCharacters;
699
+ const delta = writer.pendingCharacters.length;
700
+ writer.pendingCharacters = "";
492
701
  for (indexArray = 0; indexArray < (Math.floor((delta + array.length) / 3) * 3) - delta; indexArray++) {
493
702
  dataString += String.fromCharCode(array[indexArray]);
494
703
  }
495
704
  for (; indexArray < array.length; indexArray++) {
496
- writer.pending += String.fromCharCode(array[indexArray]);
705
+ writer.pendingCharacters += String.fromCharCode(array[indexArray]);
497
706
  }
498
707
  if (dataString.length > 2) {
499
708
  writer.data += btoa(dataString);
500
709
  } else {
501
- writer.pending = dataString + writer.pending;
710
+ writer.pendingCharacters = dataString + writer.pendingCharacters;
502
711
  }
503
712
  }
504
713
 
505
714
  getData() {
506
- return this.data + btoa(this.pending);
715
+ return this.data + btoa(this.pendingCharacters);
507
716
  }
508
717
  }
509
718
 
@@ -533,7 +742,7 @@
533
742
  constructor(blob) {
534
743
  super();
535
744
  Object.assign(this, {
536
- blob,
745
+ sourceBlob: blob,
537
746
  size: blob.size
538
747
  });
539
748
  if (!blobSliceProbe) {
@@ -543,13 +752,13 @@
543
752
 
544
753
  createReadable(options) {
545
754
  const reader = this;
546
- const { blob, size } = reader;
755
+ const { sourceBlob, size } = reader;
547
756
  const { offset = 0, size: readSize = size - offset } = options || {};
548
757
  if (!offset && readSize >= size) {
549
- return toCompatibleReadable(blob.stream());
758
+ return toCompatibleReadable(sourceBlob.stream());
550
759
  }
551
760
  if (blobSliceReliable) {
552
- return toCompatibleReadable(blob.slice(offset, offset + readSize).stream());
761
+ return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
553
762
  }
554
763
  return super.createReadable(options);
555
764
  }
@@ -558,7 +767,7 @@
558
767
  const reader = this;
559
768
  const offsetEnd = offset + length;
560
769
  const readsWholeBlob = !offset && offsetEnd >= reader.size;
561
- const blob = readsWholeBlob ? reader.blob : reader.blob.slice(offset, offsetEnd);
770
+ const blob = readsWholeBlob ? reader.sourceBlob : reader.sourceBlob.slice(offset, offsetEnd);
562
771
  let arrayBuffer = await blob.arrayBuffer();
563
772
  const sliceIgnoredByBuggyImplementation = arrayBuffer.byteLength > length;
564
773
  if (sliceIgnoredByBuggyImplementation) {
@@ -580,12 +789,12 @@
580
789
  }
581
790
  });
582
791
  writer.contentType = contentType;
583
- writer.blob = streamToBlob(transformStream.readable, contentType);
584
- writer.blob.catch(() => { });
792
+ writer.blobPromise = streamToBlob(transformStream.readable, contentType);
793
+ writer.blobPromise.catch(() => { });
585
794
  }
586
795
 
587
796
  getData() {
588
- return this.blob;
797
+ return this.blobPromise;
589
798
  }
590
799
  }
591
800
 
@@ -619,7 +828,7 @@
619
828
  class TextWriter extends BlobWriter {
620
829
 
621
830
  constructor(encoding) {
622
- super(encoding);
831
+ super();
623
832
  Object.assign(this, {
624
833
  encoding,
625
834
  utf8: !encoding || encoding.toLowerCase() == "utf-8"
@@ -635,14 +844,7 @@
635
844
  if (blob.text && utf8) {
636
845
  return blob.text();
637
846
  } else {
638
- const reader = new FileReader();
639
- return new Promise((resolve, reject) => {
640
- Object.assign(reader, {
641
- onload: ({ target }) => resolve(target.result),
642
- onerror: () => reject(reader.error)
643
- });
644
- reader.readAsText(blob, encoding);
645
- });
847
+ return decodeTextRemovingBOM(new Uint8Array(await blob.arrayBuffer()), encoding);
646
848
  }
647
849
  }
648
850
  }
@@ -1303,6 +1505,16 @@
1303
1505
  return reader.readUint8Array(offset, size);
1304
1506
  }
1305
1507
 
1508
+ function createReadable(reader, options) {
1509
+ if (reader.createReadable) {
1510
+ return reader.createReadable(options);
1511
+ } else if (reader.readUint8Array) {
1512
+ return Reader.prototype.createReadable.call(reader, options);
1513
+ } else {
1514
+ return reader.readable;
1515
+ }
1516
+ }
1517
+
1306
1518
  /*
1307
1519
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
1308
1520
 
@@ -2460,13 +2672,13 @@
2460
2672
  const {
2461
2673
  ctr,
2462
2674
  hmac,
2463
- pending,
2675
+ pendingInput,
2464
2676
  ready
2465
2677
  } = this;
2466
2678
  if (hmac && ctr) {
2467
2679
  await ready;
2468
- const chunkToDecrypt = subarray(pending, 0, pending.length - AUTHENTICATION_CODE_LENGTH);
2469
- const originalAuthenticationCode = subarray(pending, pending.length - AUTHENTICATION_CODE_LENGTH);
2680
+ const chunkToDecrypt = subarray(pendingInput, 0, pendingInput.length - AUTHENTICATION_CODE_LENGTH);
2681
+ const originalAuthenticationCode = subarray(pendingInput, pendingInput.length - AUTHENTICATION_CODE_LENGTH);
2470
2682
  let decryptedChunkArray = EMPTY_UINT8_ARRAY;
2471
2683
  if (chunkToDecrypt.length) {
2472
2684
  const encryptedChunk = toBits(codecBytes, chunkToDecrypt);
@@ -2475,7 +2687,7 @@
2475
2687
  decryptedChunkArray = fromBits(codecBytes, decryptedChunk);
2476
2688
  }
2477
2689
  const authenticationCode = subarray(fromBits(codecBytes, hmac.digest()), 0, AUTHENTICATION_CODE_LENGTH);
2478
- let invalidAuthenticationCode = pending.length < AUTHENTICATION_CODE_LENGTH ? 1 : 0;
2690
+ let invalidAuthenticationCode = pendingInput.length < AUTHENTICATION_CODE_LENGTH ? 1 : 0;
2479
2691
  for (let indexByte = 0; indexByte < AUTHENTICATION_CODE_LENGTH; indexByte++) {
2480
2692
  invalidAuthenticationCode |= authenticationCode[indexByte] ^ originalAuthenticationCode[indexByte];
2481
2693
  }
@@ -2519,14 +2731,14 @@
2519
2731
  const {
2520
2732
  ctr,
2521
2733
  hmac,
2522
- pending,
2734
+ pendingInput,
2523
2735
  ready
2524
2736
  } = this;
2525
2737
  if (hmac && ctr) {
2526
2738
  await ready;
2527
2739
  let encryptedChunkArray = EMPTY_UINT8_ARRAY;
2528
- if (pending.length) {
2529
- const encryptedChunk = ctr.update(toBits(codecBytes, pending));
2740
+ if (pendingInput.length) {
2741
+ const encryptedChunk = ctr.update(toBits(codecBytes, pendingInput));
2530
2742
  hmac.update(encryptedChunk);
2531
2743
  encryptedChunkArray = fromBits(codecBytes, encryptedChunk);
2532
2744
  }
@@ -2543,7 +2755,7 @@
2543
2755
  ready: new Promise(resolve => aesCrypto.resolveReady = resolve),
2544
2756
  password: encodePassword(password, rawPassword),
2545
2757
  strength: encryptionStrength - 1,
2546
- pending: EMPTY_UINT8_ARRAY
2758
+ pendingInput: EMPTY_UINT8_ARRAY
2547
2759
  });
2548
2760
  }
2549
2761
 
@@ -2551,10 +2763,10 @@
2551
2763
  const {
2552
2764
  ctr,
2553
2765
  hmac,
2554
- pending
2766
+ pendingInput
2555
2767
  } = aesCrypto;
2556
- if (pending.length) {
2557
- input = concat(pending, input);
2768
+ if (pendingInput.length) {
2769
+ input = concat(pendingInput, input);
2558
2770
  }
2559
2771
  const inputLength = input.length - paddingEnd;
2560
2772
  output = expand(output, paddingStart + (inputLength - (inputLength % BLOCK_LENGTH)));
@@ -2570,7 +2782,7 @@
2570
2782
  }
2571
2783
  output.set(fromBits(codecBytes, outputChunk), offset + paddingStart);
2572
2784
  }
2573
- aesCrypto.pending = subarray(input, offset);
2785
+ aesCrypto.pendingInput = subarray(input, offset);
2574
2786
  return output;
2575
2787
  }
2576
2788
 
@@ -3694,88 +3906,6 @@
3694
3906
  }
3695
3907
  }
3696
3908
 
3697
- /*
3698
- Copyright (c) 2022 Gildas Lormeau. All rights reserved.
3699
-
3700
- Redistribution and use in source and binary forms, with or without
3701
- modification, are permitted provided that the following conditions are met:
3702
-
3703
- 1. Redistributions of source code must retain the above copyright notice,
3704
- this list of conditions and the following disclaimer.
3705
-
3706
- 2. Redistributions in binary form must reproduce the above copyright
3707
- notice, this list of conditions and the following disclaimer in
3708
- the documentation and/or other materials provided with the distribution.
3709
-
3710
- 3. The names of the authors may not be used to endorse or promote products
3711
- derived from this software without specific prior written permission.
3712
-
3713
- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
3714
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
3715
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
3716
- INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
3717
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3718
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
3719
- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3720
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3721
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
3722
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3723
- */
3724
-
3725
- /* global TextDecoder */
3726
-
3727
- const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");
3728
- const VALID_CP437 = CP437.length == 256;
3729
-
3730
- function decodeCP437(stringValue) {
3731
- if (VALID_CP437) {
3732
- let result = "";
3733
- for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
3734
- result += CP437[stringValue[indexCharacter]];
3735
- }
3736
- return result;
3737
- } else {
3738
- return new TextDecoder().decode(stringValue);
3739
- }
3740
- }
3741
-
3742
- /*
3743
- Copyright (c) 2022 Gildas Lormeau. All rights reserved.
3744
-
3745
- Redistribution and use in source and binary forms, with or without
3746
- modification, are permitted provided that the following conditions are met:
3747
-
3748
- 1. Redistributions of source code must retain the above copyright notice,
3749
- this list of conditions and the following disclaimer.
3750
-
3751
- 2. Redistributions in binary form must reproduce the above copyright
3752
- notice, this list of conditions and the following disclaimer in
3753
- the documentation and/or other materials provided with the distribution.
3754
-
3755
- 3. The names of the authors may not be used to endorse or promote products
3756
- derived from this software without specific prior written permission.
3757
-
3758
- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
3759
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
3760
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
3761
- INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
3762
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3763
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
3764
- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3765
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3766
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
3767
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3768
- */
3769
-
3770
-
3771
- function decodeText(value, encoding) {
3772
- if (encoding && encoding.trim().toLowerCase() == "cp437") {
3773
- return decodeCP437(value);
3774
- } else {
3775
- return new TextDecoder(encoding, { ignoreBOM: true }).decode(value);
3776
- }
3777
- }
3778
-
3779
3909
  /*
3780
3910
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
3781
3911
 
@@ -3932,83 +4062,6 @@
3932
4062
 
3933
4063
  }
3934
4064
 
3935
- /*
3936
- Copyright (c) 2022 Gildas Lormeau. All rights reserved.
3937
-
3938
- Redistribution and use in source and binary forms, with or without
3939
- modification, are permitted provided that the following conditions are met:
3940
-
3941
- 1. Redistributions of source code must retain the above copyright notice,
3942
- this list of conditions and the following disclaimer.
3943
-
3944
- 2. Redistributions in binary form must reproduce the above copyright
3945
- notice, this list of conditions and the following disclaimer in
3946
- the documentation and/or other materials provided with the distribution.
3947
-
3948
- 3. The names of the authors may not be used to endorse or promote products
3949
- derived from this software without specific prior written permission.
3950
-
3951
- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
3952
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
3953
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
3954
- INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
3955
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3956
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
3957
- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3958
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3959
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
3960
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3961
- */
3962
-
3963
- const OPTION_FILENAME_ENCODING = "filenameEncoding";
3964
- const OPTION_COMMENT_ENCODING = "commentEncoding";
3965
- const OPTION_DECODE_TEXT = "decodeText";
3966
- const OPTION_EXTRACT_PREPENDED_DATA = "extractPrependedData";
3967
- const OPTION_EXTRACT_APPENDED_DATA = "extractAppendedData";
3968
- const OPTION_PASSWORD = "password";
3969
- const OPTION_RAW_PASSWORD = "rawPassword";
3970
- const OPTION_PASS_THROUGH = "passThrough";
3971
- const OPTION_SIGNAL = "signal";
3972
- const OPTION_CHECK_PASSWORD_ONLY = "checkPasswordOnly";
3973
- const OPTION_CHECK_OVERLAPPING_ENTRY_ONLY = "checkOverlappingEntryOnly";
3974
- const OPTION_CHECK_OVERLAPPING_ENTRY = "checkOverlappingEntry";
3975
- const OPTION_CHECK_AMBIGUITY = "checkAmbiguity";
3976
- const OPTION_CHECK_LOCAL_DIRECTORY = "checkLocalDirectory";
3977
- const OPTION_CHECK_SIGNATURE = "checkSignature";
3978
- const OPTION_CHECK_CRC32 = "checkCrc32";
3979
- const OPTION_CHECK_AUTHENTICATION_CODE = "checkAuthenticationCode";
3980
- const OPTION_USE_WEB_WORKERS = "useWebWorkers";
3981
- const OPTION_USE_COMPRESSION_STREAM = "useCompressionStream";
3982
- const OPTION_TRANSFER_STREAMS = "transferStreams";
3983
- const OPTION_PREVENT_CLOSE = "preventClose";
3984
- const OPTION_ENCRYPTION_STRENGTH = "encryptionStrength";
3985
- const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
3986
- const OPTION_NTFS_TIMESTAMP = "ntfsTimestamp";
3987
- const OPTION_KEEP_ORDER = "keepOrder";
3988
- const OPTION_LEVEL = "level";
3989
- const OPTION_BUFFERED_WRITE = "bufferedWrite";
3990
- const OPTION_CREATE_TEMP_STREAM = "createTempStream";
3991
- const OPTION_DATA_DESCRIPTOR_SIGNATURE = "dataDescriptorSignature";
3992
- const OPTION_USE_UNICODE_FILE_NAMES = "useUnicodeFileNames";
3993
- const OPTION_DATA_DESCRIPTOR = "dataDescriptor";
3994
- const OPTION_SUPPORT_ZIP64_SPLIT_FILE = "supportZip64SplitFile";
3995
- const OPTION_ENCODE_TEXT = "encodeText";
3996
- const OPTION_OFFSET = "offset";
3997
- const OPTION_USDZ = "usdz";
3998
- const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
3999
- const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
4000
- const OPTION_STRICTNESS = "strictness";
4001
- const OPTION_FILENAME_VALIDATION = "filenameValidation";
4002
- const OPTION_NORMALIZE_FILENAME = "normalizeFilename";
4003
- const OPTION_MAX_APPENDED_DATA_SIZE = "maxAppendedDataSize";
4004
- const OPTION_DECRYPT_CENTRAL_DIRECTORY = "decryptCentralDirectory";
4005
- const OPTION_SIGN_CENTRAL_DIRECTORY = "signCentralDirectory";
4006
- const TEXT_TYPE_FILENAME = "filename";
4007
- const TEXT_TYPE_COMMENT = "comment";
4008
- const STRICTNESS_STRICT = "strict";
4009
- const STRICTNESS_BALANCED = "balanced";
4010
- const STRICTNESS_TOLERANT = "tolerant";
4011
-
4012
4065
  /*
4013
4066
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
4014
4067
 
@@ -4049,6 +4102,7 @@
4049
4102
  const ERR_UNSUPPORTED_COMPRESSION$1 = "Compression method not supported";
4050
4103
  const ERR_SPLIT_ZIP_FILE = "Split zip file";
4051
4104
  const ERR_OVERLAPPING_ENTRY = "Overlapping entry found";
4105
+ const ERR_ENTRY_DATA_OUT_OF_BOUNDS = "Entry data out of bounds";
4052
4106
  const ERR_AMBIGUOUS_ARCHIVE = "Ambiguous archive";
4053
4107
  const ERR_ENCRYPTED_CENTRAL_DIRECTORY = "Encrypted central directory is not supported";
4054
4108
  const ERR_UNSAFE_FILENAME = "Unsafe filename";
@@ -4069,7 +4123,7 @@
4069
4123
  ];
4070
4124
  const ZIP64_EXTRACTION = {
4071
4125
  [MAX_16_BITS]: {
4072
- getValue: getUint32,
4126
+ getValue: getUint32$1,
4073
4127
  bytes: 4
4074
4128
  },
4075
4129
  [MAX_32_BITS]: {
@@ -4078,6 +4132,7 @@
4078
4132
  }
4079
4133
  };
4080
4134
  const MAX_END_OF_CENTRAL_DIR_PROBES = 64;
4135
+ const MAX_DEFLATE_EXPANSION_RATIO = 1032;
4081
4136
  const CENTRAL_DIRECTORY_UNREACHABLE = 0;
4082
4137
  const CENTRAL_DIRECTORY_PLAUSIBLE = 1;
4083
4138
  const CENTRAL_DIRECTORY_REACHABLE = 2;
@@ -4088,7 +4143,6 @@
4088
4143
  Object.assign(this, {
4089
4144
  reader: new GenericReader(reader),
4090
4145
  options,
4091
- config: getConfiguration(),
4092
4146
  readRanges: new Map()
4093
4147
  });
4094
4148
  }
@@ -4096,7 +4150,6 @@
4096
4150
  async* getEntriesGenerator(options = {}) {
4097
4151
  const zipReader = this;
4098
4152
  let { reader } = zipReader;
4099
- const { config } = zipReader;
4100
4153
  await initStream(reader);
4101
4154
  if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
4102
4155
  reader = new BlobReader(await streamToBlob(reader.readable));
@@ -4113,9 +4166,7 @@
4113
4166
  const normalizeFilename = getOptionValue$1(zipReader, options, OPTION_NORMALIZE_FILENAME);
4114
4167
  const { endOfDirectoryInfo, endOfDirectoryReachingEndCount } = await findEndOfCentralDirectory(reader, rejectAmbiguousEndOfDirectory, maxAppendedDataSize);
4115
4168
  if (!endOfDirectoryInfo) {
4116
- const signatureArray = await readUint8Array(reader, 0, 4);
4117
- const signatureView = getDataView(signatureArray);
4118
- if (getUint32(signatureView) == SPLIT_ZIP_FILE_SIGNATURE) {
4169
+ if (await startsWithSplitZipSignature$1(reader)) {
4119
4170
  throw new Error(ERR_SPLIT_ZIP_FILE);
4120
4171
  } else {
4121
4172
  throw new Error(ERR_EOCDR_NOT_FOUND);
@@ -4125,18 +4176,18 @@
4125
4176
  throwAmbiguousArchive("multiple end of central directory records");
4126
4177
  }
4127
4178
  const endOfDirectoryView = getDataView(endOfDirectoryInfo);
4128
- let directoryDataLength = getUint32(endOfDirectoryView, 12);
4129
- let directoryDataOffset = getUint32(endOfDirectoryView, 16);
4179
+ let directoryDataLength = getUint32$1(endOfDirectoryView, 12);
4180
+ let directoryDataOffset = getUint32$1(endOfDirectoryView, 16);
4130
4181
  const commentOffset = endOfDirectoryInfo.offset;
4131
- const commentLength = getUint16(endOfDirectoryView, 20);
4182
+ const commentLength = getUint16$1(endOfDirectoryView, 20);
4132
4183
  const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
4133
4184
  if (reader.size - appendedDataOffset > maxAppendedDataSize) {
4134
4185
  throwAmbiguousArchive("appended data");
4135
4186
  }
4136
- let lastDiskNumber = getUint16(endOfDirectoryView, 4);
4187
+ let lastDiskNumber = getUint16$1(endOfDirectoryView, 4);
4137
4188
  const expectedLastDiskNumber = reader.lastDiskNumber || 0;
4138
- let diskNumber = getUint16(endOfDirectoryView, 6);
4139
- let filesLength = getUint16(endOfDirectoryView, 10);
4189
+ let diskNumber = getUint16$1(endOfDirectoryView, 6);
4190
+ let filesLength = getUint16$1(endOfDirectoryView, 10);
4140
4191
  let prependedDataLength = 0;
4141
4192
  let startOffset;
4142
4193
  let zip64EndOfDirectory;
@@ -4152,12 +4203,12 @@
4152
4203
  EMPTY_UINT8_ARRAY;
4153
4204
  const endOfDirectoryLocatorView = getDataView(endOfDirectoryLocatorArray);
4154
4205
  if (endOfDirectoryLocatorArray.length == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH &&
4155
- getUint32(endOfDirectoryLocatorView, 0) == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
4156
- directoryDataOffset = getDiskOffset$1(reader, getUint32(endOfDirectoryLocatorView, 4)) + getBigUint64(endOfDirectoryLocatorView, 8);
4206
+ getUint32$1(endOfDirectoryLocatorView, 0) == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
4207
+ directoryDataOffset = getDiskOffset$1(reader, getUint32$1(endOfDirectoryLocatorView, 4)) + getBigUint64(endOfDirectoryLocatorView, 8);
4157
4208
  let endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4158
4209
  let endOfDirectoryView = getDataView(endOfDirectoryArray);
4159
4210
  const expectedDirectoryDataOffset = endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH - ZIP64_END_OF_CENTRAL_DIR_LENGTH;
4160
- if ((endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) &&
4211
+ if ((endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32$1(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) &&
4161
4212
  directoryDataOffset != expectedDirectoryDataOffset && expectedDirectoryDataOffset >= 0) {
4162
4213
  const originalDirectoryDataOffset = directoryDataOffset;
4163
4214
  directoryDataOffset = expectedDirectoryDataOffset;
@@ -4167,7 +4218,7 @@
4167
4218
  endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4168
4219
  endOfDirectoryView = getDataView(endOfDirectoryArray);
4169
4220
  }
4170
- if (endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
4221
+ if (endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32$1(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
4171
4222
  throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
4172
4223
  }
4173
4224
  zip64EndOfDirectory = true;
@@ -4182,13 +4233,13 @@
4182
4233
  }
4183
4234
  }
4184
4235
  if (lastDiskNumber == MAX_16_BITS) {
4185
- lastDiskNumber = getUint32(endOfDirectoryView, 16);
4186
- } else if (checkAmbiguity && lastDiskNumber != getUint32(endOfDirectoryView, 16)) {
4236
+ lastDiskNumber = getUint32$1(endOfDirectoryView, 16);
4237
+ } else if (checkAmbiguity && lastDiskNumber != getUint32$1(endOfDirectoryView, 16)) {
4187
4238
  throwAmbiguousArchive("mismatched zip64 end of central directory record");
4188
4239
  }
4189
4240
  if (diskNumber == MAX_16_BITS) {
4190
- diskNumber = getUint32(endOfDirectoryView, 20);
4191
- } else if (checkAmbiguity && diskNumber != getUint32(endOfDirectoryView, 20)) {
4241
+ diskNumber = getUint32$1(endOfDirectoryView, 20);
4242
+ } else if (checkAmbiguity && diskNumber != getUint32$1(endOfDirectoryView, 20)) {
4192
4243
  throwAmbiguousArchive("mismatched zip64 end of central directory record");
4193
4244
  }
4194
4245
  if (filesLength == MAX_16_BITS) {
@@ -4226,11 +4277,11 @@
4226
4277
  }
4227
4278
  const expectedDirectoryDataOffset = centralDirectoryEndOffset - directoryDataLength;
4228
4279
  if (directoryDataOffset != expectedDirectoryDataOffset && diskNumber == lastDiskNumber) {
4229
- const storedPointsAtDirectory = getUint32(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE;
4280
+ const storedPointsAtDirectory = getUint32$1(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE;
4230
4281
  let reconcile = !storedPointsAtDirectory;
4231
4282
  if (!reconcile && expectedDirectoryDataOffset >= 0 && expectedDirectoryDataOffset + 4 <= reader.size) {
4232
4283
  const expectedSignatureArray = await readUint8Array(reader, expectedDirectoryDataOffset, 4);
4233
- reconcile = getUint32(getDataView(expectedSignatureArray), 0) == CENTRAL_FILE_HEADER_SIGNATURE;
4284
+ reconcile = getUint32$1(getDataView(expectedSignatureArray), 0) == CENTRAL_FILE_HEADER_SIGNATURE;
4234
4285
  }
4235
4286
  if (reconcile) {
4236
4287
  const originalDirectoryDataOffset = directoryDataOffset;
@@ -4254,10 +4305,10 @@
4254
4305
  }
4255
4306
  zipReader.directoryOffset = directoryDataOffset;
4256
4307
  zipReader.directoryLength = declaredDirectoryDataLength;
4257
- const decryptCentralDirectory = getOptionValue$1(zipReader, options, OPTION_DECRYPT_CENTRAL_DIRECTORY);
4308
+ const decryptCentralDirectory = getFunctionOptionValue$1(zipReader, options, OPTION_DECRYPT_CENTRAL_DIRECTORY);
4258
4309
  let decryptedDirectory;
4259
4310
  if (decryptCentralDirectory && filesLength && directoryArray.length >= 4 &&
4260
- getUint32(directoryView, 0) != CENTRAL_FILE_HEADER_SIGNATURE &&
4311
+ getUint32$1(directoryView, 0) != CENTRAL_FILE_HEADER_SIGNATURE &&
4261
4312
  (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
4262
4313
  directoryArray = await decryptCentralDirectory(directoryArray, directoryEncryptionInfo);
4263
4314
  directoryView = getDataView(directoryArray);
@@ -4270,8 +4321,8 @@
4270
4321
  const filenames = checkAmbiguity ? new Set() : UNDEFINED_VALUE;
4271
4322
  let duplicateFilename;
4272
4323
  for (let indexFile = 0; indexFile < filesLength; indexFile++) {
4273
- const fileEntry = new ZipEntry$1(reader, config, zipReader.options);
4274
- if (offset + CENTRAL_FILE_HEADER_LENGTH > directoryArray.length || getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
4324
+ const fileEntry = new ZipEntry$1(reader, zipReader.options);
4325
+ if (offset + CENTRAL_FILE_HEADER_LENGTH > directoryArray.length || getUint32$1(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
4275
4326
  if (indexFile == 0 && !decryptedDirectory && (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
4276
4327
  throw new Error(ERR_ENCRYPTED_CENTRAL_DIRECTORY);
4277
4328
  }
@@ -4282,16 +4333,16 @@
4282
4333
  const filenameOffset = offset + CENTRAL_FILE_HEADER_LENGTH;
4283
4334
  const extraFieldOffset = filenameOffset + fileEntry.filenameLength;
4284
4335
  const commentOffset = extraFieldOffset + fileEntry.extraFieldLength;
4285
- const versionMadeBy = getUint16(directoryView, offset + 4);
4336
+ const versionMadeBy = getUint16$1(directoryView, offset + 4);
4286
4337
  const msDosCompatible = versionMadeBy >> 8 == 0;
4287
4338
  const unixCompatible = versionMadeBy >> 8 == 3;
4288
4339
  const rawFilename = directoryArray.subarray(filenameOffset, extraFieldOffset);
4289
- const commentLength = getUint16(directoryView, offset + 32);
4340
+ const commentLength = getUint16$1(directoryView, offset + 32);
4290
4341
  const endOffset = commentOffset + commentLength;
4291
4342
  const rawComment = directoryArray.subarray(commentOffset, endOffset);
4292
4343
  const filenameUTF8 = languageEncodingFlag;
4293
4344
  const commentUTF8 = languageEncodingFlag;
4294
- const externalFileAttributes = getUint32(directoryView, offset + 38);
4345
+ const externalFileAttributes = getUint32$1(directoryView, offset + 38);
4295
4346
  const msdosAttributesRaw = externalFileAttributes & MAX_8_BITS;
4296
4347
  const msdosAttributes = {
4297
4348
  readOnly: Boolean(msdosAttributesRaw & FILE_ATTR_MSDOS_READONLY_MASK),
@@ -4300,8 +4351,8 @@
4300
4351
  directory: Boolean(msdosAttributesRaw & FILE_ATTR_MSDOS_DIR_MASK),
4301
4352
  archive: Boolean(msdosAttributesRaw & FILE_ATTR_MSDOS_ARCHIVE_MASK)
4302
4353
  };
4303
- const offsetFileEntry = getUint32(directoryView, offset + 42);
4304
- const decode = getOptionValue$1(zipReader, options, OPTION_DECODE_TEXT) || decodeText;
4354
+ const offsetFileEntry = getUint32$1(directoryView, offset + 42);
4355
+ const decode = getFunctionOptionValue$1(zipReader, options, OPTION_DECODE_TEXT) || decodeText;
4305
4356
  const rawFilenameEncoding = filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437;
4306
4357
  const rawCommentEncoding = commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437;
4307
4358
  let filename = decode(rawFilename, rawFilenameEncoding, TEXT_TYPE_FILENAME);
@@ -4332,8 +4383,8 @@
4332
4383
  uncompressedSize: 0,
4333
4384
  commentLength,
4334
4385
  offset: offsetFileEntry,
4335
- diskNumberStart: getUint16(directoryView, offset + 34),
4336
- internalFileAttributes: getUint16(directoryView, offset + 36),
4386
+ diskNumberStart: getUint16$1(directoryView, offset + 34),
4387
+ internalFileAttributes: getUint16$1(directoryView, offset + 36),
4337
4388
  externalFileAttributes,
4338
4389
  msdosAttributesRaw,
4339
4390
  msdosAttributes,
@@ -4401,8 +4452,8 @@
4401
4452
  yield entry;
4402
4453
  }
4403
4454
  let offsetAfterSignature = offset;
4404
- if (offset + 6 <= directoryArray.length && getUint32(directoryView, offset) == DIGITAL_SIGNATURE_RECORD_SIGNATURE) {
4405
- const signatureDataLength = getUint16(directoryView, offset + 4);
4455
+ if (offset + 6 <= directoryArray.length && getUint32$1(directoryView, offset) == DIGITAL_SIGNATURE_RECORD_SIGNATURE) {
4456
+ const signatureDataLength = getUint16$1(directoryView, offset + 4);
4406
4457
  if (offset + 6 + signatureDataLength <= directoryArray.length) {
4407
4458
  zipReader.digitalSignature = directoryArray.subarray(offset + 6, offset + 6 + signatureDataLength);
4408
4459
  offsetAfterSignature = offset + 6 + signatureDataLength;
@@ -4414,13 +4465,17 @@
4414
4465
  if (duplicateFilename) {
4415
4466
  throwAmbiguousArchive("duplicate filename");
4416
4467
  }
4417
- if (checkAmbiguity && (prependedDataLength || (filesLength && startOffset > 0))) {
4418
- throwAmbiguousArchive("prepended data");
4419
- }
4420
4468
  const extractPrependedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_PREPENDED_DATA);
4421
4469
  const extractAppendedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_APPENDED_DATA);
4470
+ const splitZipSignatureLength = (checkAmbiguity || extractPrependedData) && filesLength &&
4471
+ startOffset == SPLIT_ZIP_FILE_SIGNATURE_LENGTH && await startsWithSplitZipMarker(reader) ? SPLIT_ZIP_FILE_SIGNATURE_LENGTH : 0;
4472
+ if (checkAmbiguity && (prependedDataLength || (filesLength && startOffset > splitZipSignatureLength))) {
4473
+ throwAmbiguousArchive("prepended data");
4474
+ }
4422
4475
  if (extractPrependedData) {
4423
- zipReader.prependedData = startOffset > 0 ? await readUint8Array(reader, 0, startOffset) : EMPTY_UINT8_ARRAY;
4476
+ zipReader.prependedData = startOffset > splitZipSignatureLength ?
4477
+ await readUint8Array(reader, splitZipSignatureLength, startOffset - splitZipSignatureLength) :
4478
+ EMPTY_UINT8_ARRAY;
4424
4479
  }
4425
4480
  zipReader.comment = commentLength ? await readUint8Array(reader, commentOffset + END_OF_CENTRAL_DIR_LENGTH, commentLength) : EMPTY_UINT8_ARRAY;
4426
4481
  if (extractAppendedData) {
@@ -4447,16 +4502,16 @@
4447
4502
 
4448
4503
  let ZipEntry$1 = class ZipEntry {
4449
4504
 
4450
- constructor(reader, config, options) {
4505
+ constructor(reader, options) {
4451
4506
  Object.assign(this, {
4452
4507
  reader,
4453
- config,
4454
4508
  options
4455
4509
  });
4456
4510
  }
4457
4511
 
4458
4512
  async getData(writer, fileEntry, readRanges, options = {}) {
4459
4513
  const zipEntry = this;
4514
+ const config = getConfiguration();
4460
4515
  const {
4461
4516
  reader,
4462
4517
  index,
@@ -4465,7 +4520,6 @@
4465
4520
  extraFieldAES,
4466
4521
  extraFieldZip64,
4467
4522
  compressionMethod,
4468
- config,
4469
4523
  bitFlag,
4470
4524
  rawBitFlag,
4471
4525
  crc32,
@@ -4483,6 +4537,7 @@
4483
4537
  let password = getOptionValue$1(zipEntry, options, OPTION_PASSWORD);
4484
4538
  let rawPassword = getOptionValue$1(zipEntry, options, OPTION_RAW_PASSWORD);
4485
4539
  const passThrough = getOptionValue$1(zipEntry, options, OPTION_PASS_THROUGH);
4540
+ checkPasswordOption(password, rawPassword);
4486
4541
  password = password && password.length && password;
4487
4542
  rawPassword = rawPassword && rawPassword.length && rawPassword;
4488
4543
  if (extraFieldAES) {
@@ -4490,7 +4545,7 @@
4490
4545
  throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
4491
4546
  }
4492
4547
  }
4493
- if (dataArray.length < HEADER_SIZE || getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
4548
+ if (dataArray.length < HEADER_SIZE || getUint32$1(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
4494
4549
  throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
4495
4550
  }
4496
4551
  readCommonHeader(localDirectory, dataView, 4);
@@ -4552,9 +4607,12 @@
4552
4607
  }
4553
4608
  }
4554
4609
  const dataOffset = localHeaderOffset + HEADER_SIZE + filenameLength + extraFieldLength;
4610
+ if (dataOffset + compressedSize > reader.size) {
4611
+ throw new Error(ERR_ENTRY_DATA_OUT_OF_BOUNDS);
4612
+ }
4555
4613
  const size = compressedSize;
4556
4614
  const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
4557
- const signal = getOptionValue$1(zipEntry, options, OPTION_SIGNAL);
4615
+ const signal = checkSignalOption(getOptionValue$1(zipEntry, options, OPTION_SIGNAL));
4558
4616
  const checkPasswordOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_PASSWORD_ONLY);
4559
4617
  let checkOverlappingEntry = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY);
4560
4618
  const checkOverlappingEntryOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY_ONLY);
@@ -4562,6 +4620,8 @@
4562
4620
  checkOverlappingEntry = true;
4563
4621
  }
4564
4622
  const { onstart, onprogress, onend } = options;
4623
+ const compressed = compressionMethod != COMPRESSION_METHOD_STORE && !passThrough;
4624
+ const outputSize = passThrough ? compressedSize : uncompressedSize;
4565
4625
  const deflate64 = compressionMethod == COMPRESSION_METHOD_DEFLATE_64;
4566
4626
  let useCompressionStream = getOptionValue$1(zipEntry, options, OPTION_USE_COMPRESSION_STREAM);
4567
4627
  if (deflate64) {
@@ -4582,9 +4642,9 @@
4582
4642
  checkCrc32,
4583
4643
  checkAuthenticationCode: getOptionValue$1(zipEntry, options, OPTION_CHECK_AUTHENTICATION_CODE),
4584
4644
  passwordVerification: zipCrypto && (dataDescriptor ? ((rawLastModDate >>> 8) & MAX_8_BITS) : ((crc32 >>> 24) & MAX_8_BITS)),
4585
- outputSize: passThrough ? compressedSize : uncompressedSize,
4645
+ outputSize,
4586
4646
  crc32,
4587
- compressed: compressionMethod != 0 && !passThrough,
4647
+ compressed,
4588
4648
  encrypted,
4589
4649
  useWebWorkers: getOptionValue$1(zipEntry, options, OPTION_USE_WEB_WORKERS),
4590
4650
  useCompressionStream,
@@ -4621,11 +4681,11 @@
4621
4681
  writer = new WritableStream();
4622
4682
  }
4623
4683
  writer = new GenericWriter(writer);
4624
- await initStream(writer, passThrough ? compressedSize : uncompressedSize);
4684
+ await initStream(writer, getDecodableOutputSize(outputSize, compressedSize, compressed));
4625
4685
  ({ writable } = writer);
4626
- const { outputSize } = await runWorker({ readable, writable }, workerOptions);
4627
- writer.size += outputSize;
4628
- if (outputSize != (passThrough ? compressedSize : uncompressedSize)) {
4686
+ const { outputSize: writtenSize } = await runWorker({ readable, writable }, workerOptions);
4687
+ writer.size += writtenSize;
4688
+ if (writtenSize != outputSize) {
4629
4689
  throw new Error(ERR_INVALID_UNCOMPRESSED_SIZE);
4630
4690
  }
4631
4691
  }
@@ -4659,7 +4719,7 @@
4659
4719
  function detectEncryptedCentralDirectory(directoryView) {
4660
4720
  const maxOffset = Math.min(directoryView.byteLength, 1024) - 3;
4661
4721
  for (let offset = 0; offset < maxOffset; offset++) {
4662
- if (getUint32(directoryView, offset) == ARCHIVE_EXTRA_DATA_SIGNATURE) {
4722
+ if (getUint32$1(directoryView, offset) == ARCHIVE_EXTRA_DATA_SIGNATURE) {
4663
4723
  return true;
4664
4724
  }
4665
4725
  }
@@ -4670,15 +4730,15 @@
4670
4730
  const directoryEncryptionInfo = { rawExtensibleData };
4671
4731
  if (rawExtensibleData.length >= 28) {
4672
4732
  const extensibleDataView = getDataView(rawExtensibleData);
4673
- const hashDataLength = getUint16(extensibleDataView, 26);
4733
+ const hashDataLength = getUint16$1(extensibleDataView, 26);
4674
4734
  Object.assign(directoryEncryptionInfo, {
4675
- compressionMethod: getUint16(extensibleDataView, 0),
4735
+ compressionMethod: getUint16$1(extensibleDataView, 0),
4676
4736
  compressedSize: Number(getBigUint64(extensibleDataView, 2)),
4677
4737
  uncompressedSize: Number(getBigUint64(extensibleDataView, 10)),
4678
- encryptionAlgorithm: getUint16(extensibleDataView, 18),
4679
- bitLength: getUint16(extensibleDataView, 20),
4680
- flags: getUint16(extensibleDataView, 22),
4681
- hashAlgorithm: getUint16(extensibleDataView, 24),
4738
+ encryptionAlgorithm: getUint16$1(extensibleDataView, 18),
4739
+ bitLength: getUint16$1(extensibleDataView, 20),
4740
+ flags: getUint16$1(extensibleDataView, 22),
4741
+ hashAlgorithm: getUint16$1(extensibleDataView, 24),
4682
4742
  hashData: rawExtensibleData.subarray(28, 28 + hashDataLength)
4683
4743
  });
4684
4744
  }
@@ -4686,12 +4746,12 @@
4686
4746
  }
4687
4747
 
4688
4748
  function readCommonHeader(directory, dataView, offset) {
4689
- const rawBitFlag = directory.rawBitFlag = getUint16(dataView, offset + 2);
4749
+ const rawBitFlag = directory.rawBitFlag = getUint16$1(dataView, offset + 2);
4690
4750
  const encrypted = (rawBitFlag & BITFLAG_ENCRYPTED) == BITFLAG_ENCRYPTED;
4691
- const rawLastModDate = getUint32(dataView, offset + 6);
4751
+ const rawLastModDate = getUint32$1(dataView, offset + 6);
4692
4752
  Object.assign(directory, {
4693
4753
  encrypted,
4694
- version: getUint16(dataView, offset),
4754
+ version: getUint16$1(dataView, offset),
4695
4755
  bitFlag: {
4696
4756
  level: (rawBitFlag & BITFLAG_LEVEL) >> 1,
4697
4757
  dataDescriptor: (rawBitFlag & BITFLAG_DATA_DESCRIPTOR) == BITFLAG_DATA_DESCRIPTOR,
@@ -4699,8 +4759,8 @@
4699
4759
  },
4700
4760
  rawLastModDate,
4701
4761
  lastModDate: getDate(rawLastModDate),
4702
- filenameLength: getUint16(dataView, offset + 22),
4703
- extraFieldLength: getUint16(dataView, offset + 24)
4762
+ filenameLength: getUint16$1(dataView, offset + 22),
4763
+ extraFieldLength: getUint16$1(dataView, offset + 24)
4704
4764
  });
4705
4765
  }
4706
4766
 
@@ -4711,8 +4771,8 @@
4711
4771
  let offsetExtraField = 0;
4712
4772
  try {
4713
4773
  while (offsetExtraField < rawExtraField.length) {
4714
- const type = getUint16(rawExtraFieldView, offsetExtraField);
4715
- const size = getUint16(rawExtraFieldView, offsetExtraField + 2);
4774
+ const type = getUint16$1(rawExtraFieldView, offsetExtraField);
4775
+ const size = getUint16$1(rawExtraFieldView, offsetExtraField + 2);
4716
4776
  extraField.set(type, {
4717
4777
  type,
4718
4778
  data: rawExtraField.slice(offsetExtraField + 4, offsetExtraField + 4 + size)
@@ -4722,12 +4782,12 @@
4722
4782
  } catch {
4723
4783
  // ignored
4724
4784
  }
4725
- const compressionMethod = getUint16(dataView, offset + 4);
4785
+ const compressionMethod = getUint16$1(dataView, offset + 4);
4726
4786
  Object.assign(directory, {
4727
- signature: getUint32(dataView, offset + HEADER_OFFSET_SIGNATURE),
4728
- crc32: getUint32(dataView, offset + HEADER_OFFSET_SIGNATURE),
4729
- compressedSize: getUint32(dataView, offset + HEADER_OFFSET_COMPRESSED_SIZE),
4730
- uncompressedSize: getUint32(dataView, offset + HEADER_OFFSET_UNCOMPRESSED_SIZE)
4787
+ signature: getUint32$1(dataView, offset + HEADER_OFFSET_SIGNATURE),
4788
+ crc32: getUint32$1(dataView, offset + HEADER_OFFSET_SIGNATURE),
4789
+ compressedSize: getUint32$1(dataView, offset + HEADER_OFFSET_COMPRESSED_SIZE),
4790
+ uncompressedSize: getUint32$1(dataView, offset + HEADER_OFFSET_UNCOMPRESSED_SIZE)
4731
4791
  });
4732
4792
  const extraFieldZip64 = extraField.get(EXTRAFIELD_TYPE_ZIP64);
4733
4793
  if (extraFieldZip64) {
@@ -4816,11 +4876,11 @@
4816
4876
  computedCrc32.append(fileEntry[rawPropertyName]);
4817
4877
  const computedCrc32View = getDataView(new Uint8Array(4));
4818
4878
  computedCrc32View.setUint32(0, computedCrc32.get(), true);
4819
- const nameCrc32 = getUint32(extraFieldView, 1);
4879
+ const nameCrc32 = getUint32$1(extraFieldView, 1);
4820
4880
  Object.assign(extraFieldUnicode, {
4821
4881
  version: getUint8(extraFieldView, 0),
4822
4882
  [propertyName]: decodeText(extraFieldUnicode.data.subarray(5)),
4823
- valid: !fileEntry.bitFlag.languageEncodingFlag && nameCrc32 == getUint32(computedCrc32View, 0)
4883
+ valid: !fileEntry.bitFlag.languageEncodingFlag && nameCrc32 == getUint32$1(computedCrc32View, 0)
4824
4884
  });
4825
4885
  if (extraFieldUnicode.valid) {
4826
4886
  directory[propertyName] = extraFieldUnicode[propertyName];
@@ -4836,7 +4896,7 @@
4836
4896
  vendorId: getUint8(extraFieldView, 2),
4837
4897
  strength,
4838
4898
  originalCompressionMethod: compressionMethod,
4839
- compressionMethod: getUint16(extraFieldView, 5)
4899
+ compressionMethod: getUint16$1(extraFieldView, 5)
4840
4900
  });
4841
4901
  directory.compressionMethod = extraFieldAES.compressionMethod;
4842
4902
  if (extraFieldAES.vendorVersion != VENDOR_VERSION_AE_1$1) {
@@ -4850,8 +4910,8 @@
4850
4910
  let tag1Data;
4851
4911
  try {
4852
4912
  while (offsetExtraField < extraFieldNTFS.data.length && !tag1Data) {
4853
- const tagValue = getUint16(extraFieldView, offsetExtraField);
4854
- const attributeSize = getUint16(extraFieldView, offsetExtraField + 2);
4913
+ const tagValue = getUint16$1(extraFieldView, offsetExtraField);
4914
+ const attributeSize = getUint16$1(extraFieldView, offsetExtraField + 2);
4855
4915
  if (tagValue == EXTRAFIELD_TYPE_NTFS_TAG1) {
4856
4916
  tag1Data = extraFieldNTFS.data.slice(offsetExtraField + 4, offsetExtraField + 4 + attributeSize);
4857
4917
  }
@@ -4884,12 +4944,12 @@
4884
4944
  return;
4885
4945
  }
4886
4946
  const extraFieldView = getDataView(extraField.data);
4887
- const lastAccessDate = new Date((getUint32(extraFieldView, 0) | 0) * 1000);
4888
- const lastModDate = new Date((getUint32(extraFieldView, 4) | 0) * 1000);
4947
+ const lastAccessDate = new Date((getUint32$1(extraFieldView, 0) | 0) * 1000);
4948
+ const lastModDate = new Date((getUint32$1(extraFieldView, 4) | 0) * 1000);
4889
4949
  const extraFieldData = { lastAccessDate, lastModDate };
4890
4950
  if (extraField.data.length >= 12) {
4891
- extraFieldData.uid = getUint16(extraFieldView, 8);
4892
- extraFieldData.gid = getUint16(extraFieldView, 10);
4951
+ extraFieldData.uid = getUint16$1(extraFieldView, 8);
4952
+ extraFieldData.gid = getUint16$1(extraFieldView, 10);
4893
4953
  }
4894
4954
  Object.assign(extraField, extraFieldData);
4895
4955
  Object.assign(directory, extraFieldData);
@@ -4909,8 +4969,8 @@
4909
4969
  gid = unpackUnixId(extraField.data.subarray(offset, offset + gidSize));
4910
4970
  Object.assign(extraField, { version, uid, gid });
4911
4971
  } else if (extraField.data.length >= 4) {
4912
- uid = getUint16(view, 0);
4913
- gid = getUint16(view, 2);
4972
+ uid = getUint16$1(view, 0);
4973
+ gid = getUint16$1(view, 2);
4914
4974
  Object.assign(extraField, { uid, gid });
4915
4975
  }
4916
4976
  if (uid !== UNDEFINED_VALUE) {
@@ -4960,7 +5020,7 @@
4960
5020
  let offset = 1;
4961
5021
  timeProperties.forEach((propertyName, indexProperty) => {
4962
5022
  if (extraFieldExtendedTimestamp.data.length >= offset + 4) {
4963
- const time = getUint32(extraFieldView, offset);
5023
+ const time = getUint32$1(extraFieldView, offset);
4964
5024
  directory[propertyName] = extraFieldExtendedTimestamp[propertyName] = new Date((time | 0) * 1000);
4965
5025
  const rawPropertyName = timeRawProperties[indexProperty];
4966
5026
  extraFieldExtendedTimestamp[rawPropertyName] = time;
@@ -4994,7 +5054,7 @@
4994
5054
  const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
4995
5055
  const dataDescriptorView = getDataView(dataDescriptorArray);
4996
5056
  let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
4997
- getUint32(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
5057
+ getUint32$1(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
4998
5058
  if (signature) {
4999
5059
  const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
5000
5060
  const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
@@ -5028,15 +5088,15 @@
5028
5088
  }
5029
5089
 
5030
5090
  function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
5031
- const crc32 = getUint32(dataDescriptorView, offset);
5091
+ const crc32 = getUint32$1(dataDescriptorView, offset);
5032
5092
  let compressedSize;
5033
5093
  let uncompressedSize;
5034
5094
  if (extraFieldZip64) {
5035
5095
  compressedSize = getBigUint64(dataDescriptorView, offset + 4);
5036
5096
  uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
5037
5097
  } else {
5038
- compressedSize = getUint32(dataDescriptorView, offset + 4);
5039
- uncompressedSize = getUint32(dataDescriptorView, offset + 8);
5098
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
5099
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
5040
5100
  }
5041
5101
  return { crc32, compressedSize, uncompressedSize };
5042
5102
  }
@@ -5045,10 +5105,28 @@
5045
5105
  return reader.getDiskOffset ? reader.getDiskOffset(diskNumber) : 0;
5046
5106
  }
5047
5107
 
5108
+ async function startsWithSplitZipSignature$1(reader) {
5109
+ return await getFirstSignature(reader) == SPLIT_ZIP_FILE_SIGNATURE;
5110
+ }
5111
+
5112
+ async function startsWithSplitZipMarker(reader) {
5113
+ const signature = await getFirstSignature(reader);
5114
+ return signature == SPLIT_ZIP_FILE_SIGNATURE || signature == TEMPORARY_SPLIT_ZIP_FILE_SIGNATURE;
5115
+ }
5116
+
5117
+ async function getFirstSignature(reader) {
5118
+ const signatureArray = await readUint8Array(reader, 0, SPLIT_ZIP_FILE_SIGNATURE_LENGTH);
5119
+ return getUint32$1(getDataView(signatureArray));
5120
+ }
5121
+
5048
5122
  function isStrictnessValue(value) {
5049
5123
  return value === STRICTNESS_STRICT || value === STRICTNESS_BALANCED || value === STRICTNESS_TOLERANT;
5050
5124
  }
5051
5125
 
5126
+ function getDecodableOutputSize(outputSize, compressedSize, compressed) {
5127
+ return Math.min(outputSize, compressed ? compressedSize * MAX_DEFLATE_EXPANSION_RATIO : compressedSize);
5128
+ }
5129
+
5052
5130
  function getStrictness(options, inheritedOptions) {
5053
5131
  return resolveStrictness(options, resolveStrictness(inheritedOptions, STRICTNESS_BALANCED));
5054
5132
  }
@@ -5111,7 +5189,7 @@
5111
5189
 
5112
5190
  function getMaxAppendedDataSize(maxAppendedDataSize, strictness) {
5113
5191
  if (maxAppendedDataSize !== UNDEFINED_VALUE) {
5114
- const size = toNumber$1(maxAppendedDataSize);
5192
+ const size = toNumber(maxAppendedDataSize);
5115
5193
  if (typeof size != NUMBER_TYPE || Number.isNaN(size) || size < 0) {
5116
5194
  throw new Error(ERR_INVALID_MAX_APPENDED_DATA_SIZE);
5117
5195
  }
@@ -5134,7 +5212,7 @@
5134
5212
  let plausibleEndOfDirectoryInfo;
5135
5213
  let endOfDirectoryReachingEndCount = 0;
5136
5214
  for await (const [anchoredView, anchoredOffset, anchoredArray, indexByte, offset] of scanEndOfCentralDirectory(reader, anchoredLength)) {
5137
- const commentLength = getUint16(anchoredView, indexByte + 20);
5215
+ const commentLength = getUint16$1(anchoredView, indexByte + 20);
5138
5216
  if (offset + END_OF_CENTRAL_DIR_LENGTH + commentLength == size) {
5139
5217
  const reachability = await getCentralDirectoryReachability(reader, anchoredView, anchoredOffset, indexByte, offset, size, remoteProbeBudget);
5140
5218
  if (reachability == CENTRAL_DIRECTORY_REACHABLE) {
@@ -5185,7 +5263,7 @@
5185
5263
  const scanArray = await readUint8Array(reader, scanOffset, scanLength);
5186
5264
  const scanView = getDataView(scanArray);
5187
5265
  for (let indexByte = scanArray.length - END_OF_CENTRAL_DIR_LENGTH; indexByte >= 0; indexByte--) {
5188
- if (getUint32(scanView, indexByte) == END_OF_CENTRAL_DIR_SIGNATURE) {
5266
+ if (getUint32$1(scanView, indexByte) == END_OF_CENTRAL_DIR_SIGNATURE) {
5189
5267
  yield [scanView, scanOffset, scanArray, indexByte, scanOffset + indexByte];
5190
5268
  }
5191
5269
  }
@@ -5196,9 +5274,9 @@
5196
5274
  }
5197
5275
 
5198
5276
  async function getCentralDirectoryReachability(reader, view, anchoredOffset, indexByte, offset, size, remoteProbeBudget) {
5199
- const filesLength = getUint16(view, indexByte + 10);
5200
- const directoryDataLength = getUint32(view, indexByte + 12);
5201
- const directoryDataOffset = getUint32(view, indexByte + 16);
5277
+ const filesLength = getUint16$1(view, indexByte + 10);
5278
+ const directoryDataLength = getUint32$1(view, indexByte + 12);
5279
+ const directoryDataOffset = getUint32$1(view, indexByte + 16);
5202
5280
  if (filesLength == MAX_16_BITS || directoryDataLength == MAX_32_BITS || directoryDataOffset == MAX_32_BITS) {
5203
5281
  const locatorSignature = await readSignature(reader, view, anchoredOffset, offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, size, remoteProbeBudget);
5204
5282
  return locatorSignature == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE ? CENTRAL_DIRECTORY_REACHABLE : CENTRAL_DIRECTORY_UNREACHABLE;
@@ -5206,7 +5284,7 @@
5206
5284
  if (!filesLength && !directoryDataLength) {
5207
5285
  return CENTRAL_DIRECTORY_PLAUSIBLE;
5208
5286
  }
5209
- const directoryDiskNumber = getUint16(view, indexByte + 6);
5287
+ const directoryDiskNumber = getUint16$1(view, indexByte + 6);
5210
5288
  for (const centralDirectoryOffset of [offset - directoryDataLength, getDiskOffset$1(reader, directoryDiskNumber) + directoryDataOffset]) {
5211
5289
  if (await readSignature(reader, view, anchoredOffset, centralDirectoryOffset, size, remoteProbeBudget) == CENTRAL_FILE_HEADER_SIGNATURE) {
5212
5290
  return CENTRAL_DIRECTORY_REACHABLE;
@@ -5220,12 +5298,12 @@
5220
5298
  return UNDEFINED_VALUE;
5221
5299
  }
5222
5300
  if (signatureOffset >= anchoredOffset) {
5223
- return getUint32(view, signatureOffset - anchoredOffset);
5301
+ return getUint32$1(view, signatureOffset - anchoredOffset);
5224
5302
  }
5225
5303
  if (remoteProbeBudget.count > 0) {
5226
5304
  remoteProbeBudget.count--;
5227
5305
  const signatureArray = await readUint8Array(reader, signatureOffset, 4);
5228
- return getUint32(getDataView(signatureArray), 0);
5306
+ return getUint32$1(getDataView(signatureArray), 0);
5229
5307
  }
5230
5308
  return UNDEFINED_VALUE;
5231
5309
  }
@@ -5262,10 +5340,11 @@
5262
5340
  return options[name] === UNDEFINED_VALUE ? zipReader.options[name] : options[name];
5263
5341
  }
5264
5342
 
5265
- function toNumber$1(value) {
5266
- return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
5343
+ function getFunctionOptionValue$1(zipReader, options, name) {
5344
+ return checkFunctionOption(getOptionValue$1(zipReader, options, name));
5267
5345
  }
5268
5346
 
5347
+
5269
5348
  function getDate(timeRaw) {
5270
5349
  const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & MAX_16_BITS;
5271
5350
  return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
@@ -5279,11 +5358,11 @@
5279
5358
  return view.getUint8(offset);
5280
5359
  }
5281
5360
 
5282
- function getUint16(view, offset) {
5361
+ function getUint16$1(view, offset) {
5283
5362
  return view.getUint16(offset, true);
5284
5363
  }
5285
5364
 
5286
- function getUint32(view, offset) {
5365
+ function getUint32$1(view, offset) {
5287
5366
  return view.getUint32(offset, true);
5288
5367
  }
5289
5368
 
@@ -5298,6 +5377,7 @@
5298
5377
  ERR_CENTRAL_DIRECTORY_NOT_FOUND: ERR_CENTRAL_DIRECTORY_NOT_FOUND,
5299
5378
  ERR_ENCRYPTED: ERR_ENCRYPTED,
5300
5379
  ERR_ENCRYPTED_CENTRAL_DIRECTORY: ERR_ENCRYPTED_CENTRAL_DIRECTORY,
5380
+ ERR_ENTRY_DATA_OUT_OF_BOUNDS: ERR_ENTRY_DATA_OUT_OF_BOUNDS,
5301
5381
  ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND,
5302
5382
  ERR_EOCDR_NOT_FOUND: ERR_EOCDR_NOT_FOUND,
5303
5383
  ERR_EXTRAFIELD_ZIP64_NOT_FOUND: ERR_EXTRAFIELD_ZIP64_NOT_FOUND,
@@ -5352,12 +5432,16 @@
5352
5432
  const ERR_INVALID_COMMENT = "Zip file comment exceeds 64KB";
5353
5433
  const ERR_INVALID_COMMENT_TYPE = "Invalid zip file comment (must be a Uint8Array)";
5354
5434
  const ERR_INVALID_ENTRY_COMMENT = "File entry comment exceeds 64KB";
5435
+ const ERR_INVALID_ENTRY_COMMENT_TYPE = "Invalid file entry comment (must be a string)";
5436
+ const ERR_INVALID_DATE = "Invalid date (must be a valid Date instance)";
5355
5437
  const ERR_INVALID_ENTRY_NAME = "File entry name exceeds 64KB";
5356
5438
  const ERR_INVALID_VERSION = "Version exceeds 65535";
5357
5439
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
5358
5440
  const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
5359
5441
  const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
5360
- const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
5442
+ const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
5443
+ const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
5444
+ const ERR_INVALID_EXTRAFIELD_DATA_TYPE = "Invalid extra field data (must be a Uint8Array)";
5361
5445
  const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
5362
5446
  const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
5363
5447
  const MIN_UNIX_TIME = -2147483648;
@@ -5377,7 +5461,6 @@
5377
5461
  const ERR_INVALID_MSDOS_ATTRIBUTES = "Invalid msdosAttributesRaw (must be integer 0..255)";
5378
5462
  const ERR_INVALID_MSDOS_DATA = "Invalid msdosAttributes (must be an object with boolean flags)";
5379
5463
  const ERR_INVALID_LEVEL = "Invalid level (must be integer 0..9)";
5380
- const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
5381
5464
  const ERR_INVALID_SIGNATURE_DATA = "Signature data exceeds 64KB";
5382
5465
 
5383
5466
  const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
@@ -5402,8 +5485,7 @@
5402
5485
  writer,
5403
5486
  addSplitZipSignature,
5404
5487
  options,
5405
- config: getConfiguration(),
5406
- files: new Map(),
5488
+ fileEntries: new Map(),
5407
5489
  filenames: new Set(),
5408
5490
  offset: options[OPTION_OFFSET] === UNDEFINED_VALUE ? writer.size || writer.writable.size || 0 : options[OPTION_OFFSET],
5409
5491
  initialOffset: options[OPTION_OFFSET] === UNDEFINED_VALUE ? 0 : options[OPTION_OFFSET] - (writer.size || writer.writable.size || 0),
@@ -5424,14 +5506,23 @@
5424
5506
  await initStream(reader);
5425
5507
  }
5426
5508
  const { ZipReader } = await Promise.resolve().then(function () { return zipReader; });
5427
- const zipReader$1 = new ZipReader(reader.readable);
5509
+ const zipReader$1 = new ZipReader(reader);
5428
5510
  const entries = await zipReader$1.getEntries();
5429
5511
  await zipReader$1.close();
5430
5512
  await initStream(this.writer);
5431
- await reader.readable.pipeTo(this.writer.writable, { preventClose: true, preventAbort: true });
5432
- this.writer.size = this.offset = reader.size;
5513
+ const { directoryOffset } = zipReader$1;
5514
+ let splitZipSignatureLength = 0;
5515
+ if (this.addSplitZipSignature) {
5516
+ delete this.addSplitZipSignature;
5517
+ if (!await startsWithSplitZipSignature(reader)) {
5518
+ await writeData(this.writer, getSplitZipSignatureArray());
5519
+ splitZipSignatureLength = SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
5520
+ this.offset += splitZipSignatureLength;
5521
+ }
5522
+ }
5523
+ const entryPositions = await copyZipData(this, reader, entries, directoryOffset, splitZipSignatureLength);
5433
5524
  this.filenames = new Set(entries.map(entry => entry.filename));
5434
- this.files = new Map(entries.map(entry => {
5525
+ this.fileEntries = new Map(entries.map(entry => {
5435
5526
  const {
5436
5527
  version,
5437
5528
  rawLastModDate,
@@ -5486,11 +5577,12 @@
5486
5577
  if (crc32 !== UNDEFINED_VALUE) {
5487
5578
  setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
5488
5579
  }
5580
+ const { offset, diskNumberStart } = entryPositions.get(entry);
5489
5581
  Object.assign(entry, {
5490
5582
  zip64UncompressedSize,
5491
5583
  zip64CompressedSize,
5492
- zip64Offset: zip64 && entry.offset >= MAX_32_BITS,
5493
- diskNumberStart: 0,
5584
+ offset,
5585
+ diskNumberStart,
5494
5586
  zip64DiskNumberStart: false,
5495
5587
  rawExtraFieldZip64,
5496
5588
  rawExtraFieldAES,
@@ -5510,11 +5602,8 @@
5510
5602
  async add(name = "", reader, options = {}) {
5511
5603
  const zipWriter = this;
5512
5604
  options = Object.assign({}, options);
5513
- const {
5514
- pendingAddFileCalls,
5515
- config
5516
- } = zipWriter;
5517
- if (workers < config.maxWorkers) {
5605
+ const { pendingAddFileCalls } = zipWriter;
5606
+ if (workers < getConfiguration().maxWorkers) {
5518
5607
  workers++;
5519
5608
  } else {
5520
5609
  await new Promise(resolve => pendingEntries.push(resolve));
@@ -5551,16 +5640,16 @@
5551
5640
  }
5552
5641
 
5553
5642
  remove(entry) {
5554
- const { filenames, files } = this;
5643
+ const { filenames, fileEntries } = this;
5555
5644
  // deno-lint-ignore valid-typeof
5556
5645
  if (typeof entry == STRING_TYPE) {
5557
- entry = files.get(entry);
5646
+ entry = fileEntries.get(entry);
5558
5647
  }
5559
5648
  if (entry && entry.filename !== UNDEFINED_VALUE) {
5560
5649
  const { filename } = entry;
5561
- if (filenames.has(filename) && files.has(filename)) {
5650
+ if (filenames.has(filename) && fileEntries.has(filename)) {
5562
5651
  filenames.delete(filename);
5563
- files.delete(filename);
5652
+ fileEntries.delete(filename);
5564
5653
  return true;
5565
5654
  }
5566
5655
  }
@@ -5595,12 +5684,12 @@
5595
5684
  const metadataInfo = resolveMetadata(zipWriter, name, options);
5596
5685
  const { comment } = metadataInfo;
5597
5686
  const extraField = options[PROPERTY_NAME_EXTRA_FIELD];
5598
- zipWriter.files.set(name, UNDEFINED_VALUE);
5687
+ zipWriter.fileEntries.set(name, UNDEFINED_VALUE);
5599
5688
  let fileEntry;
5600
5689
  try {
5601
5690
  const { resolvedOptions } = metadataInfo;
5602
5691
  if (resolvedOptions.level != 0 && resolvedOptions.compressionMethod === UNDEFINED_VALUE &&
5603
- !resolvedOptions.passThrough && !(await supportsDeflate(zipWriter.config))) {
5692
+ !resolvedOptions.passThrough && !(await supportsDeflate(getConfiguration()))) {
5604
5693
  resolvedOptions.level = 0;
5605
5694
  }
5606
5695
  const sizesInfo = await resolveSizes(zipWriter, reader, metadataInfo, options);
@@ -5618,7 +5707,7 @@
5618
5707
  const metadataSize = getLength(headerInfo.localHeaderArray, dataDescriptorInfo.dataDescriptorArray);
5619
5708
  fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo, metadataSize }, options);
5620
5709
  } catch (error) {
5621
- zipWriter.files.delete(name);
5710
+ zipWriter.fileEntries.delete(name);
5622
5711
  throw error;
5623
5712
  }
5624
5713
  Object.assign(fileEntry, {
@@ -5662,9 +5751,9 @@
5662
5751
  if (unixExtraFieldType === UNDEFINED_VALUE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
5663
5752
  unixExtraFieldType = INFOZIP_EXTRA_FIELD_TYPE$1;
5664
5753
  }
5665
- let msdosAttributesRaw = getOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW);
5754
+ let msdosAttributesRaw = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW);
5666
5755
  let msdosAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES);
5667
- const hasUnixMetadata = uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE || unixMode !== UNDEFINED_VALUE || unixExtraFieldType;
5756
+ const hasUnixMetadata = uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE || unixMode !== UNDEFINED_VALUE || unixExtraFieldType || executable;
5668
5757
  const hasMsDosProvided = msdosAttributesRaw !== UNDEFINED_VALUE || msdosAttributes !== UNDEFINED_VALUE;
5669
5758
  if (hasUnixMetadata) {
5670
5759
  msDosCompatible = false;
@@ -5673,10 +5762,10 @@
5673
5762
  msDosCompatible = true;
5674
5763
  versionMadeBy = (versionMadeBy & MAX_8_BITS);
5675
5764
  }
5676
- if (msdosAttributesRaw !== UNDEFINED_VALUE && (msdosAttributesRaw < 0 || msdosAttributesRaw > MAX_8_BITS)) {
5765
+ if (msdosAttributesRaw !== UNDEFINED_VALUE && (!Number.isInteger(msdosAttributesRaw) || msdosAttributesRaw < 0 || msdosAttributesRaw > MAX_8_BITS)) {
5677
5766
  throw new Error(ERR_INVALID_MSDOS_ATTRIBUTES);
5678
5767
  }
5679
- if (msdosAttributes && typeof msdosAttributes !== OBJECT_TYPE) {
5768
+ if (msdosAttributes && (typeof msdosAttributes !== OBJECT_TYPE || Array.isArray(msdosAttributes))) {
5680
5769
  throw new Error(ERR_INVALID_MSDOS_DATA);
5681
5770
  }
5682
5771
  if (versionMadeBy > MAX_16_BITS) {
@@ -5764,7 +5853,7 @@
5764
5853
  }
5765
5854
 
5766
5855
  function resolveMetadata(zipWriter, name, options) {
5767
- const encode = getOptionValue(zipWriter, options, OPTION_ENCODE_TEXT, encodeText);
5856
+ const encode = getFunctionOptionValue(zipWriter, options, OPTION_ENCODE_TEXT) || encodeText;
5768
5857
  let rawFilename = encode(name, TEXT_TYPE_FILENAME);
5769
5858
  if (rawFilename === UNDEFINED_VALUE) {
5770
5859
  rawFilename = encodeText(name);
@@ -5773,6 +5862,10 @@
5773
5862
  throw new Error(ERR_INVALID_ENTRY_NAME);
5774
5863
  }
5775
5864
  const comment = options[PROPERTY_NAME_COMMENT] || "";
5865
+ // deno-lint-ignore valid-typeof
5866
+ if (typeof comment != STRING_TYPE) {
5867
+ throw new Error(ERR_INVALID_ENTRY_COMMENT_TYPE);
5868
+ }
5776
5869
  let rawComment = encode(comment, TEXT_TYPE_COMMENT);
5777
5870
  if (rawComment === UNDEFINED_VALUE) {
5778
5871
  rawComment = encodeText(comment);
@@ -5784,16 +5877,14 @@
5784
5877
  if (version > MAX_16_BITS) {
5785
5878
  throw new Error(ERR_INVALID_VERSION);
5786
5879
  }
5787
- const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
5788
- const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
5789
- const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
5880
+ const lastModDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
5881
+ const lastAccessDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
5882
+ const creationDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
5790
5883
  const internalFileAttributes = getAliasedOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES, 0);
5791
5884
  const passThrough = getOptionValue(zipWriter, options, OPTION_PASS_THROUGH);
5792
5885
  const password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
5793
5886
  const rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
5794
- if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
5795
- throw new Error(ERR_INVALID_PASSWORD_TYPE);
5796
- }
5887
+ checkPasswordOption(password, rawPassword);
5797
5888
  const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
5798
5889
  const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
5799
5890
  const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
@@ -5802,9 +5893,9 @@
5802
5893
  const useWebWorkers = getOptionValue(zipWriter, options, OPTION_USE_WEB_WORKERS);
5803
5894
  const transferStreams = getOptionValue(zipWriter, options, OPTION_TRANSFER_STREAMS);
5804
5895
  const bufferedWrite = getOptionValue(zipWriter, options, OPTION_BUFFERED_WRITE);
5805
- const createTempStream = getOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
5896
+ const createTempStream = getFunctionOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
5806
5897
  const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, true);
5807
- const signal = getOptionValue(zipWriter, options, OPTION_SIGNAL);
5898
+ const signal = checkSignalOption(getOptionValue(zipWriter, options, OPTION_SIGNAL));
5808
5899
  const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
5809
5900
  const compressionMethod = getOptionValue(zipWriter, options, PROPERTY_NAME_COMPRESSION_METHOD);
5810
5901
  const registeredCodec = passThrough || compressionMethod === UNDEFINED_VALUE ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
@@ -5884,18 +5975,26 @@
5884
5975
  if (!extraField) {
5885
5976
  return EMPTY_UINT8_ARRAY;
5886
5977
  }
5978
+ if (!(extraField instanceof Map)) {
5979
+ throw new Error(ERR_INVALID_EXTRAFIELD);
5980
+ }
5887
5981
  let extraFieldSize = 0;
5888
5982
  let offset = 0;
5889
- extraField.forEach(data => extraFieldSize += 4 + getLength(data));
5890
- const rawExtraField = new Uint8Array(extraFieldSize);
5891
- const rawExtraFieldView = getDataView(rawExtraField);
5892
5983
  extraField.forEach((data, type) => {
5893
- if (type > MAX_16_BITS) {
5984
+ if (!Number.isInteger(type) || type < 0 || type > MAX_16_BITS) {
5894
5985
  throw new Error(ERR_INVALID_EXTRAFIELD_TYPE);
5895
5986
  }
5987
+ if (!(data instanceof Uint8Array)) {
5988
+ throw new Error(ERR_INVALID_EXTRAFIELD_DATA_TYPE);
5989
+ }
5896
5990
  if (getLength(data) > MAX_16_BITS) {
5897
5991
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
5898
5992
  }
5993
+ extraFieldSize += 4 + getLength(data);
5994
+ });
5995
+ const rawExtraField = new Uint8Array(extraFieldSize);
5996
+ const rawExtraFieldView = getDataView(rawExtraField);
5997
+ extraField.forEach((data, type) => {
5899
5998
  setUint16(rawExtraFieldView, offset, type);
5900
5999
  setUint16(rawExtraFieldView, offset + 2, getLength(data));
5901
6000
  arraySet(rawExtraField, data, offset + 4);
@@ -5982,8 +6081,8 @@
5982
6081
  }
5983
6082
 
5984
6083
  async function getEntriesSize(writerOptions, entries, writeOrderGuaranteed, comment) {
5985
- const zipWriter = { options: writerOptions, config: getConfiguration() };
5986
- if (writerOptions[OPTION_SIGN_CENTRAL_DIRECTORY]) {
6084
+ const zipWriter = { options: writerOptions };
6085
+ if (checkFunctionOption(writerOptions[OPTION_SIGN_CENTRAL_DIRECTORY])) {
5987
6086
  throw new Error(ERR_UNDETERMINED_SIZE);
5988
6087
  }
5989
6088
  if (comment !== UNDEFINED_VALUE && !(comment instanceof Uint8Array)) {
@@ -6009,7 +6108,7 @@
6009
6108
  ({ name } = attributesInfo);
6010
6109
  const { resolvedOptions: metadata } = resolveMetadata(zipWriter, name, options);
6011
6110
  if (metadata.level != 0 && metadata.compressionMethod === UNDEFINED_VALUE &&
6012
- !metadata.passThrough && !(await supportsDeflate(zipWriter.config))) {
6111
+ !metadata.passThrough && !(await supportsDeflate(getConfiguration()))) {
6013
6112
  metadata.level = 0;
6014
6113
  }
6015
6114
  const hasContent = !getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY);
@@ -6058,7 +6157,7 @@
6058
6157
 
6059
6158
  async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6060
6159
  const {
6061
- files,
6160
+ fileEntries,
6062
6161
  writer
6063
6162
  } = zipWriter;
6064
6163
  const {
@@ -6080,12 +6179,12 @@
6080
6179
  let writerSizeBeforeEntry;
6081
6180
  let flushedBufferedSize = 0;
6082
6181
  let fileWriter;
6083
- files.set(name, fileEntry);
6182
+ fileEntries.set(name, fileEntry);
6084
6183
  zipWriter.lastFileEntry = fileEntry;
6085
6184
  try {
6086
6185
  let lockPreviousFileEntry;
6087
6186
  if (keepOrder) {
6088
- lockPreviousFileEntry = previousFileEntry && previousFileEntry.lock;
6187
+ lockPreviousFileEntry = previousFileEntry && previousFileEntry.lockFileEntry;
6089
6188
  requestLockCurrentFileEntry();
6090
6189
  }
6091
6190
  if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || !dataDescriptor) {
@@ -6106,11 +6205,8 @@
6106
6205
  const diskOffset = getDiskOffset(writer);
6107
6206
  if (zipWriter.addSplitZipSignature) {
6108
6207
  delete zipWriter.addSplitZipSignature;
6109
- const signatureArray = new Uint8Array(4);
6110
- const signatureArrayView = getDataView(signatureArray);
6111
- setUint32(signatureArrayView, 0, SPLIT_ZIP_FILE_SIGNATURE);
6112
- await writeData(writer, signatureArray);
6113
- zipWriter.offset += 4;
6208
+ await writeData(writer, getSplitZipSignatureArray());
6209
+ zipWriter.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
6114
6210
  }
6115
6211
  if (usdz && !bufferedWrite) {
6116
6212
  appendExtraFieldUSDZ(entryInfo, zipWriter.offset - diskOffset);
@@ -6128,11 +6224,11 @@
6128
6224
  writerSizeBeforeEntry = writer.size;
6129
6225
  await writeData(fileWriter, localHeaderArray);
6130
6226
  }
6131
- fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, zipWriter.config, options);
6227
+ fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, getConfiguration(), options);
6132
6228
  if (!bufferedWrite) {
6133
6229
  writingEntryData = false;
6134
6230
  }
6135
- files.set(name, fileEntry);
6231
+ fileEntries.set(name, fileEntry);
6136
6232
  fileEntry.filename = name;
6137
6233
  if (bufferedWrite) {
6138
6234
  await Promise.all([fileWriter.writable.getWriter().close(), lockPreviousFileEntry]);
@@ -6173,7 +6269,7 @@
6173
6269
  zipWriter.offset += flushedBufferedSize;
6174
6270
  }
6175
6271
  }
6176
- files.delete(name);
6272
+ fileEntries.delete(name);
6177
6273
  throw error;
6178
6274
  } finally {
6179
6275
  if (bufferedWrite) {
@@ -6195,7 +6291,7 @@
6195
6291
  }
6196
6292
 
6197
6293
  function requestLockCurrentFileEntry() {
6198
- fileEntry.lock = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
6294
+ fileEntry.lockFileEntry = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
6199
6295
  }
6200
6296
 
6201
6297
  async function requestLockWriter() {
@@ -6215,7 +6311,7 @@
6215
6311
  }
6216
6312
  }
6217
6313
 
6218
- async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryInfo, config, options) {
6314
+ async function createFileEntry(reader, writer, { diskNumberStart, lockFileEntry }, entryInfo, config, options) {
6219
6315
  const {
6220
6316
  headerInfo,
6221
6317
  dataDescriptorInfo,
@@ -6283,7 +6379,7 @@
6283
6379
  codecURI
6284
6380
  } = options;
6285
6381
  const fileEntry = {
6286
- lock,
6382
+ lockFileEntry,
6287
6383
  versionMadeBy,
6288
6384
  zip64,
6289
6385
  directory: Boolean(directory),
@@ -6325,7 +6421,7 @@
6325
6421
  }
6326
6422
  const { writable } = writer;
6327
6423
  if (reader) {
6328
- const readable = toCompatibleReadable(reader.createReadable ? reader.createReadable() : reader.readable);
6424
+ const readable = toCompatibleReadable(createReadable(reader));
6329
6425
  const size = reader.size;
6330
6426
  const workerOptions = {
6331
6427
  options: {
@@ -6437,14 +6533,14 @@
6437
6533
  if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
6438
6534
  const length = 4 + 16;
6439
6535
  const extraFieldZip64 = createRecordWriter(length);
6440
- extraFieldZip64.uint16(EXTRAFIELD_TYPE_ZIP64);
6441
- extraFieldZip64.uint16(length - 4);
6536
+ extraFieldZip64.writeUint16(EXTRAFIELD_TYPE_ZIP64);
6537
+ extraFieldZip64.writeUint16(length - 4);
6442
6538
  rawLocalExtraFieldZip64 = extraFieldZip64.array;
6443
6539
  if (zip64ExtraFieldComplete) {
6444
- extraFieldZip64.uint64(uncompressedSize);
6540
+ extraFieldZip64.writeUint64(uncompressedSize);
6445
6541
  if (uncompressedFile) {
6446
6542
  const encryptionOverhead = encrypted ? (zipCrypto ? 12 : 16 + encryptionStrength * 4) : 0;
6447
- extraFieldZip64.uint64(passThrough ? 0 : uncompressedSize + encryptionOverhead);
6543
+ extraFieldZip64.writeUint64(passThrough ? 0 : uncompressedSize + encryptionOverhead);
6448
6544
  }
6449
6545
  }
6450
6546
  } else {
@@ -6453,8 +6549,8 @@
6453
6549
  let rawExtraFieldAES;
6454
6550
  if (encrypted && !zipCrypto) {
6455
6551
  const extraFieldAES = createRecordWriter(getLength(EXTRAFIELD_DATA_AES) + 2);
6456
- extraFieldAES.uint16(EXTRAFIELD_TYPE_AES);
6457
- extraFieldAES.bytes(EXTRAFIELD_DATA_AES);
6552
+ extraFieldAES.writeUint16(EXTRAFIELD_TYPE_AES);
6553
+ extraFieldAES.writeBytes(EXTRAFIELD_DATA_AES);
6458
6554
  rawExtraFieldAES = extraFieldAES.array;
6459
6555
  rawExtraFieldAES[8] = encryptionStrength;
6460
6556
  } else {
@@ -6470,15 +6566,15 @@
6470
6566
  const extraFieldTimestampLength = 9 + (lastAccessDate ? 4 : 0) + (creationDate ? 4 : 0);
6471
6567
  const extraFieldTimestamp = createRecordWriter(extraFieldTimestampLength);
6472
6568
  extraFieldExtendedTimestampFlag = 0x1 + (lastAccessDate ? 0x2 : 0) + (creationDate ? 0x4 : 0);
6473
- extraFieldTimestamp.uint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
6474
- extraFieldTimestamp.uint16(extraFieldTimestampLength - 4);
6475
- extraFieldTimestamp.uint8(extraFieldExtendedTimestampFlag);
6476
- extraFieldTimestamp.uint32(lastModTimeUnix);
6569
+ extraFieldTimestamp.writeUint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
6570
+ extraFieldTimestamp.writeUint16(extraFieldTimestampLength - 4);
6571
+ extraFieldTimestamp.writeUint8(extraFieldExtendedTimestampFlag);
6572
+ extraFieldTimestamp.writeUint32(lastModTimeUnix);
6477
6573
  if (lastAccessDate) {
6478
- extraFieldTimestamp.uint32(clampUnixTime(getTimeUnix(lastAccessDate)));
6574
+ extraFieldTimestamp.writeUint32(clampUnixTime(getTimeUnix(lastAccessDate)));
6479
6575
  }
6480
6576
  if (creationDate) {
6481
- extraFieldTimestamp.uint32(clampUnixTime(getTimeUnix(creationDate)));
6577
+ extraFieldTimestamp.writeUint32(clampUnixTime(getTimeUnix(creationDate)));
6482
6578
  }
6483
6579
  rawExtraFieldExtendedTimestamp = extraFieldTimestamp.array;
6484
6580
  } else {
@@ -6491,14 +6587,14 @@
6491
6587
  try {
6492
6588
  const lastModTimeNTFS = getTimeNTFS(lastModDate);
6493
6589
  const extraFieldNTFS = createRecordWriter(36);
6494
- extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS);
6495
- extraFieldNTFS.uint16(32);
6590
+ extraFieldNTFS.writeUint16(EXTRAFIELD_TYPE_NTFS);
6591
+ extraFieldNTFS.writeUint16(32);
6496
6592
  extraFieldNTFS.skip(4);
6497
- extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS_TAG1);
6498
- extraFieldNTFS.uint16(24);
6499
- extraFieldNTFS.uint64(lastModTimeNTFS);
6500
- extraFieldNTFS.uint64(lastAccessDate ? getTimeNTFS(lastAccessDate) : lastModTimeNTFS);
6501
- extraFieldNTFS.uint64(creationDate ? getTimeNTFS(creationDate) : lastModTimeNTFS);
6593
+ extraFieldNTFS.writeUint16(EXTRAFIELD_TYPE_NTFS_TAG1);
6594
+ extraFieldNTFS.writeUint16(24);
6595
+ extraFieldNTFS.writeUint64(lastModTimeNTFS);
6596
+ extraFieldNTFS.writeUint64(lastAccessDate ? getTimeNTFS(lastAccessDate) : lastModTimeNTFS);
6597
+ extraFieldNTFS.writeUint64(creationDate ? getTimeNTFS(creationDate) : lastModTimeNTFS);
6502
6598
  rawExtraFieldNTFS = extraFieldNTFS.array;
6503
6599
  } catch {
6504
6600
  rawExtraFieldNTFS = EMPTY_UINT8_ARRAY;
@@ -6517,20 +6613,20 @@
6517
6613
  const gidBytes = packUnixId(gid);
6518
6614
  const payloadLength = 3 + uidBytes.length + gidBytes.length;
6519
6615
  const extraFieldUnix = createRecordWriter(4 + payloadLength);
6520
- extraFieldUnix.uint16(EXTRAFIELD_TYPE_INFOZIP);
6521
- extraFieldUnix.uint16(payloadLength);
6522
- extraFieldUnix.uint8(1);
6523
- extraFieldUnix.uint8(uidBytes.length);
6524
- extraFieldUnix.bytes(uidBytes);
6525
- extraFieldUnix.uint8(gidBytes.length);
6526
- extraFieldUnix.bytes(gidBytes);
6616
+ extraFieldUnix.writeUint16(EXTRAFIELD_TYPE_INFOZIP);
6617
+ extraFieldUnix.writeUint16(payloadLength);
6618
+ extraFieldUnix.writeUint8(1);
6619
+ extraFieldUnix.writeUint8(uidBytes.length);
6620
+ extraFieldUnix.writeBytes(uidBytes);
6621
+ extraFieldUnix.writeUint8(gidBytes.length);
6622
+ extraFieldUnix.writeBytes(gidBytes);
6527
6623
  rawExtraFieldUnix = extraFieldUnix.array;
6528
6624
  } else if (unixExtraFieldType == UNIX_EXTRA_FIELD_TYPE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
6529
6625
  const extraFieldUnix = createRecordWriter(8);
6530
- extraFieldUnix.uint16(EXTRAFIELD_TYPE_UNIX);
6531
- extraFieldUnix.uint16(4);
6532
- extraFieldUnix.uint16((uid === UNDEFINED_VALUE ? 0 : uid) & MAX_16_BITS);
6533
- extraFieldUnix.uint16((gid === UNDEFINED_VALUE ? 0 : gid) & MAX_16_BITS);
6626
+ extraFieldUnix.writeUint16(EXTRAFIELD_TYPE_UNIX);
6627
+ extraFieldUnix.writeUint16(4);
6628
+ extraFieldUnix.writeUint16((uid === UNDEFINED_VALUE ? 0 : uid) & MAX_16_BITS);
6629
+ extraFieldUnix.writeUint16((gid === UNDEFINED_VALUE ? 0 : gid) & MAX_16_BITS);
6534
6630
  rawExtraFieldUnix = extraFieldUnix.array;
6535
6631
  } else {
6536
6632
  rawExtraFieldUnix = EMPTY_UINT8_ARRAY;
@@ -6580,18 +6676,18 @@
6580
6676
  const localHeader = createRecordWriter(HEADER_SIZE + getLength(rawFilename) + extraFieldLength);
6581
6677
  const localHeaderArray = localHeader.array;
6582
6678
  const localHeaderView = getDataView(localHeaderArray);
6583
- localHeader.uint32(LOCAL_FILE_HEADER_SIGNATURE);
6584
- localHeader.bytes(headerArray);
6585
- localHeader.bytes(rawFilename);
6679
+ localHeader.writeUint32(LOCAL_FILE_HEADER_SIGNATURE);
6680
+ localHeader.writeBytes(headerArray);
6681
+ localHeader.writeBytes(rawFilename);
6586
6682
  if (writeLocalExtraFieldZip64) {
6587
- localHeader.bytes(rawLocalExtraFieldZip64);
6588
- }
6589
- localHeader.bytes(rawExtraFieldAES);
6590
- localHeader.bytes(rawExtraFieldExtendedTimestamp);
6591
- localHeader.bytes(rawExtraFieldNTFS);
6592
- localHeader.bytes(rawExtraFieldUnix);
6593
- localHeader.bytes(rawExtraField);
6594
- localHeader.bytes(rawLocalExtraField);
6683
+ localHeader.writeBytes(rawLocalExtraFieldZip64);
6684
+ }
6685
+ localHeader.writeBytes(rawExtraFieldAES);
6686
+ localHeader.writeBytes(rawExtraFieldExtendedTimestamp);
6687
+ localHeader.writeBytes(rawExtraFieldNTFS);
6688
+ localHeader.writeBytes(rawExtraFieldUnix);
6689
+ localHeader.writeBytes(rawExtraField);
6690
+ localHeader.writeBytes(rawLocalExtraField);
6595
6691
  if (dataDescriptor) {
6596
6692
  if (!zip64CompressedSize) {
6597
6693
  setUint32(localHeaderView, HEADER_OFFSET_COMPRESSED_SIZE + LOCAL_HEADER_COMMON_OFFSET, 0);
@@ -6781,7 +6877,7 @@
6781
6877
 
6782
6878
 
6783
6879
  async function closeFile(zipWriter, comment, options) {
6784
- const directoryDataLength = createDirectoryRecords(zipWriter.files);
6880
+ const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
6785
6881
  const { directoryStart, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
6786
6882
  const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
6787
6883
  await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryDataLength, signatureLength });
@@ -6811,19 +6907,19 @@
6811
6907
  if (zip64Offset || zip64DiskNumberStart || zip64UncompressedSize || zip64CompressedSize) {
6812
6908
  const length = 4 + (zip64UncompressedSize ? 8 : 0) + (zip64CompressedSize ? 8 : 0) + (zip64Offset ? 8 : 0) + (zip64DiskNumberStart ? 4 : 0);
6813
6909
  const extraFieldZip64 = createRecordWriter(length);
6814
- extraFieldZip64.uint16(EXTRAFIELD_TYPE_ZIP64);
6815
- extraFieldZip64.uint16(length - 4);
6910
+ extraFieldZip64.writeUint16(EXTRAFIELD_TYPE_ZIP64);
6911
+ extraFieldZip64.writeUint16(length - 4);
6816
6912
  if (zip64UncompressedSize) {
6817
- extraFieldZip64.uint64(uncompressedSize);
6913
+ extraFieldZip64.writeUint64(uncompressedSize);
6818
6914
  }
6819
6915
  if (zip64CompressedSize) {
6820
- extraFieldZip64.uint64(compressedSize);
6916
+ extraFieldZip64.writeUint64(compressedSize);
6821
6917
  }
6822
6918
  if (zip64Offset) {
6823
- extraFieldZip64.uint64(fileEntry.offset);
6919
+ extraFieldZip64.writeUint64(fileEntry.offset);
6824
6920
  }
6825
6921
  if (zip64DiskNumberStart) {
6826
- extraFieldZip64.uint32(fileEntry.diskNumberStart);
6922
+ extraFieldZip64.writeUint32(fileEntry.diskNumberStart);
6827
6923
  }
6828
6924
  rawExtraFieldZip64 = extraFieldZip64.array;
6829
6925
  } else {
@@ -6836,10 +6932,10 @@
6836
6932
  const lastModTimeUnix = getTimeUnix(lastModDate);
6837
6933
  if (extendedTimestamp && inUnixTimeRange(lastModTimeUnix)) {
6838
6934
  const extraFieldTimestamp = createRecordWriter(9);
6839
- extraFieldTimestamp.uint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
6840
- extraFieldTimestamp.uint16(5);
6841
- extraFieldTimestamp.uint8(extraFieldExtendedTimestampFlag);
6842
- extraFieldTimestamp.uint32(lastModTimeUnix);
6935
+ extraFieldTimestamp.writeUint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
6936
+ extraFieldTimestamp.writeUint16(5);
6937
+ extraFieldTimestamp.writeUint8(extraFieldExtendedTimestampFlag);
6938
+ extraFieldTimestamp.writeUint32(lastModTimeUnix);
6843
6939
  rawExtraFieldTimestamp = extraFieldTimestamp.array;
6844
6940
  } else {
6845
6941
  rawExtraFieldTimestamp = EMPTY_UINT8_ARRAY;
@@ -6861,14 +6957,14 @@
6861
6957
  }
6862
6958
 
6863
6959
  async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
6864
- const { files, writer } = zipWriter;
6960
+ const { fileEntries, writer } = zipWriter;
6865
6961
  const directoryArray = new Uint8Array(directoryDataLength);
6866
6962
  await initStream(writer);
6867
6963
  let offset = 0;
6868
6964
  let directoryDiskOffset = 0;
6869
6965
  let directoryStartDiskNumber = getDiskNumber(writer);
6870
6966
  let directoryStartDiskOffset = getDiskOffset(writer);
6871
- for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
6967
+ for (const [indexFileEntry, fileEntry] of Array.from(fileEntries.values()).entries()) {
6872
6968
  const {
6873
6969
  offset: fileEntryOffset,
6874
6970
  rawFilename,
@@ -6913,28 +7009,28 @@
6913
7009
  setUint16(headerView, HEADER_OFFSET_VERSION, VERSION_ZIP64);
6914
7010
  }
6915
7011
  const directoryRecord = createRecordWriter(directoryRecordLength);
6916
- directoryRecord.uint32(CENTRAL_FILE_HEADER_SIGNATURE);
6917
- directoryRecord.uint16(versionMadeBy);
6918
- directoryRecord.bytes(headerArray.subarray(0, HEADER_SIZE - 4 - 2));
6919
- directoryRecord.uint16(extraFieldLength);
6920
- directoryRecord.uint16(getLength(rawComment));
6921
- directoryRecord.uint16(zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
6922
- directoryRecord.uint16(internalFileAttributes);
6923
- directoryRecord.uint32(externalFileAttributes);
6924
- directoryRecord.uint32(zip64Offset ? MAX_32_BITS : fileEntryOffset);
6925
- directoryRecord.bytes(rawFilename);
6926
- directoryRecord.bytes(rawExtraFieldZip64);
6927
- directoryRecord.bytes(rawExtraFieldAES);
6928
- directoryRecord.bytes(rawExtraFieldExtendedTimestamp);
6929
- directoryRecord.bytes(rawExtraFieldNTFS);
6930
- directoryRecord.bytes(rawExtraFieldUnix);
6931
- directoryRecord.bytes(rawExtraField);
6932
- directoryRecord.bytes(rawComment);
7012
+ directoryRecord.writeUint32(CENTRAL_FILE_HEADER_SIGNATURE);
7013
+ directoryRecord.writeUint16(versionMadeBy);
7014
+ directoryRecord.writeBytes(headerArray.subarray(0, HEADER_SIZE - 4 - 2));
7015
+ directoryRecord.writeUint16(extraFieldLength);
7016
+ directoryRecord.writeUint16(getLength(rawComment));
7017
+ directoryRecord.writeUint16(zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
7018
+ directoryRecord.writeUint16(internalFileAttributes);
7019
+ directoryRecord.writeUint32(externalFileAttributes);
7020
+ directoryRecord.writeUint32(zip64Offset ? MAX_32_BITS : fileEntryOffset);
7021
+ directoryRecord.writeBytes(rawFilename);
7022
+ directoryRecord.writeBytes(rawExtraFieldZip64);
7023
+ directoryRecord.writeBytes(rawExtraFieldAES);
7024
+ directoryRecord.writeBytes(rawExtraFieldExtendedTimestamp);
7025
+ directoryRecord.writeBytes(rawExtraFieldNTFS);
7026
+ directoryRecord.writeBytes(rawExtraFieldUnix);
7027
+ directoryRecord.writeBytes(rawExtraField);
7028
+ directoryRecord.writeBytes(rawComment);
6933
7029
  arraySet(directoryArray, directoryRecord.array, offset);
6934
7030
  offset += directoryRecordLength;
6935
7031
  if (options.onprogress) {
6936
7032
  try {
6937
- await options.onprogress(indexFileEntry + 1, files.size, new Entry(fileEntry));
7033
+ await options.onprogress(indexFileEntry + 1, fileEntries.size, new Entry(fileEntry));
6938
7034
  } catch {
6939
7035
  // ignored
6940
7036
  }
@@ -6948,7 +7044,7 @@
6948
7044
  }
6949
7045
 
6950
7046
  async function writeDigitalSignatureRecord(zipWriter, directoryArray, options) {
6951
- const signCentralDirectory = getOptionValue(zipWriter, options, OPTION_SIGN_CENTRAL_DIRECTORY);
7047
+ const signCentralDirectory = getFunctionOptionValue(zipWriter, options, OPTION_SIGN_CENTRAL_DIRECTORY);
6952
7048
  if (signCentralDirectory) {
6953
7049
  const signatureData = await signCentralDirectory(directoryArray);
6954
7050
  const signatureDataLength = getLength(signatureData);
@@ -6956,9 +7052,9 @@
6956
7052
  throw new Error(ERR_INVALID_SIGNATURE_DATA);
6957
7053
  }
6958
7054
  const signatureRecord = createRecordWriter(6 + signatureDataLength);
6959
- signatureRecord.uint32(DIGITAL_SIGNATURE_RECORD_SIGNATURE);
6960
- signatureRecord.uint16(signatureDataLength);
6961
- signatureRecord.bytes(signatureData);
7055
+ signatureRecord.writeUint32(DIGITAL_SIGNATURE_RECORD_SIGNATURE);
7056
+ signatureRecord.writeUint16(signatureDataLength);
7057
+ signatureRecord.writeBytes(signatureData);
6962
7058
  await writeData(zipWriter.writer, signatureRecord.array);
6963
7059
  return 6 + signatureDataLength;
6964
7060
  }
@@ -6969,7 +7065,7 @@
6969
7065
  const { writer } = zipWriter;
6970
7066
  const { directoryStart, signatureLength } = cdInfo;
6971
7067
  let { directoryDataLength } = cdInfo;
6972
- let filesLength = zipWriter.files.size;
7068
+ let fileEntriesLength = zipWriter.fileEntries.size;
6973
7069
  let diskNumber = directoryStart.diskNumber;
6974
7070
  let directoryOffset = getSegmentOffset(zipWriter, directoryStart);
6975
7071
  let lastDiskNumber = getDiskNumber(writer);
@@ -6977,7 +7073,7 @@
6977
7073
  lastDiskNumber++;
6978
7074
  }
6979
7075
  let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
6980
- if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
7076
+ if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || fileEntriesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
6981
7077
  if (zip64 === false) {
6982
7078
  throw new Error(ERR_UNSUPPORTED_FORMAT);
6983
7079
  } else {
@@ -6994,37 +7090,37 @@
6994
7090
  }
6995
7091
  lastDiskNumber = getDiskNumber(writer);
6996
7092
  if (zip64) {
6997
- endOfdirectoryRecord.uint32(ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
6998
- endOfdirectoryRecord.uint64(44);
6999
- endOfdirectoryRecord.uint16(45);
7000
- endOfdirectoryRecord.uint16(45);
7001
- endOfdirectoryRecord.uint32(lastDiskNumber);
7002
- endOfdirectoryRecord.uint32(diskNumber);
7003
- endOfdirectoryRecord.uint64(filesLength);
7004
- endOfdirectoryRecord.uint64(filesLength);
7005
- endOfdirectoryRecord.uint64(directoryDataLength);
7006
- endOfdirectoryRecord.uint64(directoryOffset);
7007
- endOfdirectoryRecord.uint32(ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
7008
- endOfdirectoryRecord.uint32(lastDiskNumber);
7009
- endOfdirectoryRecord.uint64(BigInt(getSegmentOffset(zipWriter, writer)) + BigInt(directoryDataLength) + BigInt(signatureLength));
7010
- endOfdirectoryRecord.uint32(lastDiskNumber + 1);
7093
+ endOfdirectoryRecord.writeUint32(ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
7094
+ endOfdirectoryRecord.writeUint64(44);
7095
+ endOfdirectoryRecord.writeUint16(45);
7096
+ endOfdirectoryRecord.writeUint16(45);
7097
+ endOfdirectoryRecord.writeUint32(lastDiskNumber);
7098
+ endOfdirectoryRecord.writeUint32(diskNumber);
7099
+ endOfdirectoryRecord.writeUint64(fileEntriesLength);
7100
+ endOfdirectoryRecord.writeUint64(fileEntriesLength);
7101
+ endOfdirectoryRecord.writeUint64(directoryDataLength);
7102
+ endOfdirectoryRecord.writeUint64(directoryOffset);
7103
+ endOfdirectoryRecord.writeUint32(ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
7104
+ endOfdirectoryRecord.writeUint32(lastDiskNumber);
7105
+ endOfdirectoryRecord.writeUint64(BigInt(getSegmentOffset(zipWriter, writer)) + BigInt(directoryDataLength) + BigInt(signatureLength));
7106
+ endOfdirectoryRecord.writeUint32(lastDiskNumber + 1);
7011
7107
  const supportZip64SplitFile = getOptionValue(zipWriter, options, OPTION_SUPPORT_ZIP64_SPLIT_FILE, true);
7012
7108
  if (supportZip64SplitFile) {
7013
7109
  lastDiskNumber = MAX_16_BITS;
7014
7110
  diskNumber = MAX_16_BITS;
7015
7111
  }
7016
- filesLength = MAX_16_BITS;
7112
+ fileEntriesLength = MAX_16_BITS;
7017
7113
  directoryOffset = MAX_32_BITS;
7018
7114
  directoryDataLength = MAX_32_BITS;
7019
7115
  }
7020
- endOfdirectoryRecord.uint32(END_OF_CENTRAL_DIR_SIGNATURE);
7021
- endOfdirectoryRecord.uint16(lastDiskNumber);
7022
- endOfdirectoryRecord.uint16(diskNumber);
7023
- endOfdirectoryRecord.uint16(filesLength);
7024
- endOfdirectoryRecord.uint16(filesLength);
7025
- endOfdirectoryRecord.uint32(directoryDataLength);
7026
- endOfdirectoryRecord.uint32(directoryOffset);
7027
- endOfdirectoryRecord.uint16(commentLength);
7116
+ endOfdirectoryRecord.writeUint32(END_OF_CENTRAL_DIR_SIGNATURE);
7117
+ endOfdirectoryRecord.writeUint16(lastDiskNumber);
7118
+ endOfdirectoryRecord.writeUint16(diskNumber);
7119
+ endOfdirectoryRecord.writeUint16(fileEntriesLength);
7120
+ endOfdirectoryRecord.writeUint16(fileEntriesLength);
7121
+ endOfdirectoryRecord.writeUint32(directoryDataLength);
7122
+ endOfdirectoryRecord.writeUint32(directoryOffset);
7123
+ endOfdirectoryRecord.writeUint16(commentLength);
7028
7124
  await writeData(writer, endOfdirectoryRecord.array);
7029
7125
  if (commentLength) {
7030
7126
  await writeData(writer, comment);
@@ -7037,11 +7133,11 @@
7037
7133
  let offset = 0;
7038
7134
  return {
7039
7135
  array,
7040
- uint8: value => { setUint8(view, offset, value); offset += 1; },
7041
- uint16: value => { setUint16(view, offset, value); offset += 2; },
7042
- uint32: value => { setUint32(view, offset, value); offset += 4; },
7043
- uint64: value => { setBigUint64(view, offset, BigInt(value)); offset += 8; },
7044
- bytes: value => { arraySet(array, value, offset); offset += getLength(value); },
7136
+ writeUint8: value => { setUint8(view, offset, value); offset += 1; },
7137
+ writeUint16: value => { setUint16(view, offset, value); offset += 2; },
7138
+ writeUint32: value => { setUint32(view, offset, value); offset += 4; },
7139
+ writeUint64: value => { setBigUint64(view, offset, BigInt(value)); offset += 8; },
7140
+ writeBytes: value => { arraySet(array, value, offset); offset += getLength(value); },
7045
7141
  skip: count => offset += count
7046
7142
  };
7047
7143
  }
@@ -7065,6 +7161,71 @@
7065
7161
  return zipWriter.offset - diskOffset - (diskNumber ? zipWriter.initialOffset : 0);
7066
7162
  }
7067
7163
 
7164
+ async function startsWithSplitZipSignature(reader) {
7165
+ const signatureArray = await readUint8Array(reader, 0, SPLIT_ZIP_FILE_SIGNATURE_LENGTH);
7166
+ return getUint32(getDataView(signatureArray), 0) == SPLIT_ZIP_FILE_SIGNATURE;
7167
+ }
7168
+
7169
+ async function copyZipData(zipWriter, reader, entries, directoryOffset, splitZipSignatureLength) {
7170
+ const { writer } = zipWriter;
7171
+ const entryPositions = new Map();
7172
+ if (writer.closeDisk) {
7173
+ const sortedEntries = Array.from(entries).sort((firstEntry, secondEntry) =>
7174
+ getSourceOffset(reader, firstEntry) - getSourceOffset(reader, secondEntry));
7175
+ let copiedLength = 0;
7176
+ for (const entry of sortedEntries) {
7177
+ const sourceOffset = getSourceOffset(reader, entry);
7178
+ await copyData(zipWriter, reader, copiedLength, sourceOffset - copiedLength);
7179
+ if (exceedsAvailableSize(writer, await getLocalHeaderLength(reader, sourceOffset))) {
7180
+ await writer.closeDisk();
7181
+ }
7182
+ entryPositions.set(entry, {
7183
+ offset: getSegmentOffset(zipWriter, writer),
7184
+ diskNumberStart: getDiskNumber(writer)
7185
+ });
7186
+ copiedLength = sourceOffset;
7187
+ }
7188
+ await copyData(zipWriter, reader, copiedLength, directoryOffset - copiedLength);
7189
+ } else {
7190
+ await copyData(zipWriter, reader, 0, directoryOffset);
7191
+ entries.forEach(entry => entryPositions.set(entry, {
7192
+ offset: splitZipSignatureLength + getSourceOffset(reader, entry),
7193
+ diskNumberStart: 0
7194
+ }));
7195
+ }
7196
+ return entryPositions;
7197
+ }
7198
+
7199
+ async function copyData(zipWriter, reader, offset, size) {
7200
+ if (size > 0) {
7201
+ const { writer } = zipWriter;
7202
+ await createReadable(reader, { offset, size }).pipeTo(writer.writable, { preventClose: true, preventAbort: true });
7203
+ writer.size += size;
7204
+ zipWriter.offset += size;
7205
+ }
7206
+ }
7207
+
7208
+ async function getLocalHeaderLength(reader, offset) {
7209
+ const headerArray = await readUint8Array(reader, offset, HEADER_SIZE);
7210
+ if (getLength(headerArray) < HEADER_SIZE) {
7211
+ return HEADER_SIZE;
7212
+ }
7213
+ const headerView = getDataView(headerArray);
7214
+ return HEADER_SIZE +
7215
+ getUint16(headerView, HEADER_OFFSET_FILENAME_LENGTH + LOCAL_HEADER_COMMON_OFFSET) +
7216
+ getUint16(headerView, HEADER_OFFSET_EXTRAFIELD_LENGTH + LOCAL_HEADER_COMMON_OFFSET);
7217
+ }
7218
+
7219
+ function getSourceOffset(reader, { offset, diskNumberStart }) {
7220
+ return offset + (reader.getDiskOffset ? reader.getDiskOffset(diskNumberStart) : 0);
7221
+ }
7222
+
7223
+ function getSplitZipSignatureArray() {
7224
+ const signatureArray = new Uint8Array(SPLIT_ZIP_FILE_SIGNATURE_LENGTH);
7225
+ setUint32(getDataView(signatureArray), 0, SPLIT_ZIP_FILE_SIGNATURE);
7226
+ return signatureArray;
7227
+ }
7228
+
7068
7229
  async function writeData(writer, array) {
7069
7230
  const { writable } = writer;
7070
7231
  const streamWriter = writable.getWriter();
@@ -7116,6 +7277,21 @@
7116
7277
  return result === UNDEFINED_VALUE ? defaultValue : result;
7117
7278
  }
7118
7279
 
7280
+ function getDateOptionValue(zipWriter, options, name, defaultValue) {
7281
+ const date = getOptionValue(zipWriter, options, name, defaultValue);
7282
+ if (date === null) {
7283
+ return defaultValue;
7284
+ }
7285
+ if (date !== UNDEFINED_VALUE && (typeof date.getTime != FUNCTION_TYPE || Number.isNaN(date.getTime()))) {
7286
+ throw new Error(ERR_INVALID_DATE);
7287
+ }
7288
+ return date;
7289
+ }
7290
+
7291
+ function getFunctionOptionValue(zipWriter, options, name) {
7292
+ return checkFunctionOption(getOptionValue(zipWriter, options, name));
7293
+ }
7294
+
7119
7295
  function getAliasedOptionValue(zipWriter, options, name, deprecatedName, defaultValue) {
7120
7296
  const value = getAliasedValue(options, name, deprecatedName);
7121
7297
  const result = value === UNDEFINED_VALUE ? getAliasedValue(zipWriter.options, name, deprecatedName) : value;
@@ -7130,9 +7306,6 @@
7130
7306
  return toNumber(getOptionValue(zipWriter, options, name, defaultValue));
7131
7307
  }
7132
7308
 
7133
- function toNumber(value) {
7134
- return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
7135
- }
7136
7309
 
7137
7310
  function getMaximumCompressedSize(uncompressedSize) {
7138
7311
  return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
@@ -7144,6 +7317,14 @@
7144
7317
  : compressionMethod !== COMPRESSION_METHOD_STORE;
7145
7318
  }
7146
7319
 
7320
+ function getUint16(view, offset) {
7321
+ return view.getUint16(offset, true);
7322
+ }
7323
+
7324
+ function getUint32(view, offset) {
7325
+ return view.getUint32(offset, true);
7326
+ }
7327
+
7147
7328
  function setUint8(view, offset, value) {
7148
7329
  view.setUint8(offset, value);
7149
7330
  }
@@ -7187,9 +7368,9 @@
7187
7368
  const headerRecord = createRecordWriter(HEADER_SIZE - 4);
7188
7369
  const headerArray = headerRecord.array;
7189
7370
  const headerView = getDataView(headerArray);
7190
- headerRecord.uint16(version);
7191
- headerRecord.uint16(bitFlag);
7192
- headerRecord.uint16(compressionMethod);
7371
+ headerRecord.writeUint16(version);
7372
+ headerRecord.writeUint16(bitFlag);
7373
+ headerRecord.writeUint16(compressionMethod);
7193
7374
  if (rawLastModDate === UNDEFINED_VALUE) {
7194
7375
  const dateArray = new Uint32Array(1);
7195
7376
  const dateView = getDataView(dateArray);
@@ -7197,20 +7378,20 @@
7197
7378
  setUint16(dateView, 2, ((((lastModDate.getFullYear() - 1980) << 4) | (lastModDate.getMonth() + 1)) << 5) | lastModDate.getDate());
7198
7379
  rawLastModDate = dateArray[0];
7199
7380
  }
7200
- headerRecord.uint32(rawLastModDate);
7381
+ headerRecord.writeUint32(rawLastModDate);
7201
7382
  headerRecord.skip(4);
7202
7383
  if (zip64CompressedSize || compressedSize !== UNDEFINED_VALUE) {
7203
- headerRecord.uint32(zip64CompressedSize ? MAX_32_BITS : compressedSize);
7384
+ headerRecord.writeUint32(zip64CompressedSize ? MAX_32_BITS : compressedSize);
7204
7385
  } else {
7205
7386
  headerRecord.skip(4);
7206
7387
  }
7207
7388
  if (zip64UncompressedSize || uncompressedSize !== UNDEFINED_VALUE) {
7208
- headerRecord.uint32(zip64UncompressedSize ? MAX_32_BITS : uncompressedSize);
7389
+ headerRecord.writeUint32(zip64UncompressedSize ? MAX_32_BITS : uncompressedSize);
7209
7390
  } else {
7210
7391
  headerRecord.skip(4);
7211
7392
  }
7212
- headerRecord.uint16(getLength(rawFilename));
7213
- headerRecord.uint16(extraFieldLength);
7393
+ headerRecord.writeUint16(getLength(rawFilename));
7394
+ headerRecord.writeUint16(extraFieldLength);
7214
7395
  return {
7215
7396
  headerArray,
7216
7397
  headerView,
@@ -7275,6 +7456,7 @@
7275
7456
  const ERR_ENTRY_EXISTS = "Entry filename already exists";
7276
7457
  const ERR_READABLE_CONSUMED = "Readable stream already consumed";
7277
7458
  const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.passThrough or set uncompressedSize for each entry)";
7459
+ const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
7278
7460
  const ERR_ABORT_EXPORT = "zipjs-abort-export";
7279
7461
  const ERR_ABORTED = "The operation was aborted";
7280
7462
  const ABORT_ERROR_NAME = "AbortError";
@@ -7307,13 +7489,14 @@
7307
7489
  fs,
7308
7490
  name,
7309
7491
  data: params.data,
7310
- options: params.options,
7492
+ options: params.options && Object.assign({}, params.options),
7311
7493
  id: fs.entryIdCounter++,
7312
7494
  parent,
7313
7495
  children: [],
7314
7496
  uncompressedSize: params.uncompressedSize || 0,
7315
7497
  undeterminedSize: params.undeterminedSize || params.uncompressedSize === UNDEFINED_VALUE,
7316
- passThrough: params.passThrough
7498
+ passThrough: params.passThrough,
7499
+ defaultLastModDate: params.defaultLastModDate || new Date()
7317
7500
  });
7318
7501
  if (parent || !fs.root) {
7319
7502
  fs.entries[zipEntry.id] = zipEntry;
@@ -7323,12 +7506,6 @@
7323
7506
  }
7324
7507
  }
7325
7508
 
7326
- moveTo(target) {
7327
- // deprecated
7328
- const zipEntry = this;
7329
- zipEntry.fs.move(zipEntry, target);
7330
- }
7331
-
7332
7509
  getFullname() {
7333
7510
  return this.getRelativeName();
7334
7511
  }
@@ -7360,6 +7537,11 @@
7360
7537
  this.name = name;
7361
7538
  }
7362
7539
  }
7540
+
7541
+ setOptions(options) {
7542
+ const entryOptions = Object.assign({}, this.options, options);
7543
+ this.options = Object.fromEntries(Object.entries(entryOptions).filter(([, value]) => value !== UNDEFINED_VALUE));
7544
+ }
7363
7545
  }
7364
7546
 
7365
7547
  class ZipFileEntry extends ZipEntry {
@@ -7386,7 +7568,7 @@
7386
7568
  const reader = zipEntry.reader = createReader(zipEntry.Reader, zipEntry.data, options);
7387
7569
  const dataSize = zipEntry.uncompressedSize || reader.size;
7388
7570
  await Promise.all([initStream(reader), initStream(writer, dataSize)]);
7389
- const { signal } = options;
7571
+ const signal = checkSignalOption(options.signal);
7390
7572
  const readable = createProgressReadable(zipEntry, reader, options, signal);
7391
7573
  const preventClose = !ownsWritable(writer) && Boolean(options.preventClose);
7392
7574
  zipEntry.uncompressedSize = reader.size;
@@ -7604,10 +7786,6 @@
7604
7786
  });
7605
7787
  }
7606
7788
 
7607
- addData(name, params) {
7608
- return addChild(this, name, params);
7609
- }
7610
-
7611
7789
  importBlob(blob, options) {
7612
7790
  return this.importZip(new BlobReader(blob), options);
7613
7791
  }
@@ -7721,7 +7899,7 @@
7721
7899
  if (options.bufferedWrite === UNDEFINED_VALUE) {
7722
7900
  options.bufferedWrite = true;
7723
7901
  }
7724
- const [readers] = await Promise.all([initReaders(zipEntry, options.readerOptions), initStream(writer)]);
7902
+ const [readers] = await Promise.all([initReaders(zipEntry, checkReaderOptions(options.readerOptions)), initStream(writer)]);
7725
7903
  const zipWriter = new ZipWriter(writer, options);
7726
7904
  await exportZip(zipWriter, zipEntry, getTotalSize([zipEntry], getUncompressedSize), options, readers);
7727
7905
  await zipWriter.close(options.globalComment);
@@ -7731,12 +7909,13 @@
7731
7909
  getExportedSize(options = {}) {
7732
7910
  const zipEntry = this;
7733
7911
  options = Object.assign({}, options);
7912
+ checkReaderOptions(options.readerOptions);
7734
7913
  if (options.bufferedWrite === UNDEFINED_VALUE) {
7735
7914
  options.bufferedWrite = true;
7736
7915
  }
7737
7916
  const writeOrderGuaranteed = !options.bufferedWrite ||
7738
7917
  (options.keepOrder !== false && zipEntry.children.every(child => !child.children.length));
7739
- return getEntriesSize(options, Array.from(zipEntry.getChildren({ recursive: true }), child => {
7918
+ return getEntriesSize(options, zipEntry.getChildren({ recursive: true }).filter(child => !isImplicitDirectory(child)).map(child => {
7740
7919
  const { name, entryOptions } = getChildEntryOptions(child, zipEntry, options);
7741
7920
  return { name, size: child.directory ? 0 : getDeterminedSize(child, isPassThrough(child, options)), options: entryOptions };
7742
7921
  }), writeOrderGuaranteed, options.globalComment);
@@ -7775,7 +7954,7 @@
7775
7954
  }
7776
7955
 
7777
7956
 
7778
- class FS {
7957
+ class ZipFS {
7779
7958
 
7780
7959
  constructor() {
7781
7960
  resetFS(this);
@@ -7891,10 +8070,6 @@
7891
8070
  return this.root.addFile(file, options);
7892
8071
  }
7893
8072
 
7894
- addData(name, params) {
7895
- return this.root.addData(name, params);
7896
- }
7897
-
7898
8073
  importBlob(blob, options) {
7899
8074
  resetFS(this);
7900
8075
  return this.root.importBlob(blob, options);
@@ -7962,7 +8137,7 @@
7962
8137
  }
7963
8138
  }
7964
8139
 
7965
- const fs = { FS, ZipDirectoryEntry, ZipFileEntry };
8140
+ const fs = { FS: ZipFS, ZipDirectoryEntry, ZipFileEntry };
7966
8141
 
7967
8142
  function getTotalSize(entries, getEntrySize) {
7968
8143
  let size = 0;
@@ -8106,7 +8281,7 @@
8106
8281
  }
8107
8282
 
8108
8283
  function forwardAbort(signal, abortController) {
8109
- if (!signal) {
8284
+ if (!checkSignalOption(signal)) {
8110
8285
  return () => { };
8111
8286
  }
8112
8287
  if (signal.aborted) {
@@ -8202,7 +8377,7 @@
8202
8377
  };
8203
8378
  }
8204
8379
  }
8205
- const entryOptions = Object.assign({}, zipEntryMetadata, options, passThroughOptions, childOptions, { directory: child.directory });
8380
+ const entryOptions = Object.assign({ lastModDate: child.defaultLastModDate }, zipEntryMetadata, options, childOptions, passThroughOptions, { directory: child.directory });
8206
8381
  if (!child.directory && entryOptions.passThrough && entryOptions.uncompressedSize === UNDEFINED_VALUE) {
8207
8382
  throw new Error(ERR_INVALID_PASS_THROUGH);
8208
8383
  }
@@ -8217,11 +8392,22 @@
8217
8392
  return child.undeterminedSize ? UNDEFINED_VALUE : getExtractedSize(child, passThrough);
8218
8393
  }
8219
8394
 
8395
+ function checkReaderOptions(readerOptions) {
8396
+ if (readerOptions && (typeof readerOptions != OBJECT_TYPE || Array.isArray(readerOptions))) {
8397
+ throw new Error(ERR_INVALID_READER_OPTIONS);
8398
+ }
8399
+ return readerOptions;
8400
+ }
8401
+
8220
8402
  function isPassThrough(child, options) {
8221
8403
  const { readerOptions } = options;
8222
8404
  return Boolean(!child.directory && (child.passThrough || (readerOptions && readerOptions.passThrough)));
8223
8405
  }
8224
8406
 
8407
+ function isImplicitDirectory(child) {
8408
+ return child.directory && child.data === null;
8409
+ }
8410
+
8225
8411
  function getUserExtraField(extraField) {
8226
8412
  if (extraField) {
8227
8413
  const userExtraField = new Map();
@@ -8239,7 +8425,7 @@
8239
8425
  async function exportZip(zipWriter, entry, totalSize, options, readers) {
8240
8426
  const { onstart, onprogress, onend, onentryprogress } = options;
8241
8427
  const selectedEntry = entry;
8242
- const totalEntries = getTotalSize(entry.children, () => 1);
8428
+ const totalEntries = getTotalSize(entry.children, child => isImplicitDirectory(child) ? 0 : 1);
8243
8429
  let writtenSize = 0;
8244
8430
  let writtenEntries = 0;
8245
8431
  if (onstart) {
@@ -8268,6 +8454,9 @@
8268
8454
  }
8269
8455
 
8270
8456
  async function addChild(child) {
8457
+ if (isImplicitDirectory(child)) {
8458
+ return;
8459
+ }
8271
8460
  const { name, entryOptions } = getChildEntryOptions(child, selectedEntry, options);
8272
8461
  let entryWrittenSize = 0;
8273
8462
  const entryMetadata = await zipWriter.add(name, readers.get(child), Object.assign(entryOptions, {
@@ -8301,7 +8490,7 @@
8301
8490
  if (handle.kind == "file") {
8302
8491
  const file = await handle.getFile();
8303
8492
  addedEntries.push(
8304
- parentEntry.addData(file.name, {
8493
+ addChild(parentEntry, file.name, {
8305
8494
  Reader: function () {
8306
8495
  const readable = file.stream();
8307
8496
  const size = file.size;
@@ -8335,10 +8524,11 @@
8335
8524
 
8336
8525
  async function exportFileSystemHandle(zipEntry, directoryHandle, options) {
8337
8526
  const { onstart, onprogress, onend } = options;
8527
+ const readerOptions = checkReaderOptions(options.readerOptions);
8338
8528
  const abortController = new AbortController();
8339
8529
  const { signal } = abortController;
8340
8530
  const releaseSignal = forwardAbort(options.signal, abortController);
8341
- const getDataOptions = Object.assign({}, options, options.readerOptions, {
8531
+ const getDataOptions = Object.assign({}, options, readerOptions, {
8342
8532
  signal,
8343
8533
  onstart: UNDEFINED_VALUE,
8344
8534
  onprogress: UNDEFINED_VALUE,
@@ -8535,7 +8725,12 @@
8535
8725
  exports.ERR_ABORTED = ERR_ABORTED;
8536
8726
  exports.ERR_ENTRY_EXISTS = ERR_ENTRY_EXISTS;
8537
8727
  exports.ERR_INVALID_PASS_THROUGH = ERR_INVALID_PASS_THROUGH;
8728
+ exports.ERR_INVALID_READER_OPTIONS = ERR_INVALID_READER_OPTIONS;
8538
8729
  exports.ERR_READABLE_CONSUMED = ERR_READABLE_CONSUMED;
8730
+ exports.ZipDirectoryEntry = ZipDirectoryEntry;
8731
+ exports.ZipEntry = ZipEntry;
8732
+ exports.ZipFS = ZipFS;
8733
+ exports.ZipFileEntry = ZipFileEntry;
8539
8734
  exports.fs = fs;
8540
8735
 
8541
8736
  }));