@zip.js/zip.js 2.8.35 → 2.8.37

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 (40) hide show
  1. package/deno.json +3 -2
  2. package/dist/zip-core.js +246 -55
  3. package/dist/zip-core.min.js +1 -1
  4. package/dist/zip-fs-core.js +198 -55
  5. package/dist/zip-fs-core.min.js +1 -1
  6. package/dist/zip-fs-native.js +249 -58
  7. package/dist/zip-fs-native.min.js +1 -1
  8. package/dist/zip-fs.js +247 -56
  9. package/dist/zip-fs.min.js +1 -1
  10. package/dist/zip-legacy.js +248 -57
  11. package/dist/zip-legacy.min.js +1 -1
  12. package/dist/zip-native.js +249 -58
  13. package/dist/zip-native.min.js +1 -1
  14. package/dist/zip-web-worker-native.js +1 -1
  15. package/dist/zip-web-worker.js +1 -1
  16. package/dist/zip.js +247 -56
  17. package/dist/zip.min.js +1 -1
  18. package/index-native.cjs +249 -58
  19. package/index-native.min.js +1 -1
  20. package/index.cjs +247 -56
  21. package/index.d.cts +112 -2
  22. package/index.d.ts +112 -2
  23. package/index.min.js +1 -1
  24. package/lib/core/codec-pool.js +19 -3
  25. package/lib/core/codec-registry.js +116 -0
  26. package/lib/core/constants.js +1 -1
  27. package/lib/core/io.js +47 -26
  28. package/lib/core/options.js +2 -0
  29. package/lib/core/streams/codec-stream.js +1 -1
  30. package/lib/core/streams/zip-entry-stream.js +22 -5
  31. package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
  32. package/lib/core/web-worker-base.js +5 -1
  33. package/lib/core/web-worker-inline-native.js +1 -1
  34. package/lib/core/web-worker-inline-wasm.js +1 -1
  35. package/lib/core/zip-reader.js +6 -2
  36. package/lib/core/zip-writer.js +53 -18
  37. package/lib/zip-core-base.js +7 -0
  38. package/lib/zip-core-writer.js +1 -0
  39. package/package.json +1 -1
  40. package/worker-message-property-names.js +1 -1
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zip-js/zip-js",
3
- "version": "2.8.35",
3
+ "version": "2.8.37",
4
4
  "exports": {
5
5
  ".": "./index.js"
6
6
  },
@@ -23,6 +23,7 @@
23
23
  ".eslintrc.json",
24
24
  "benchmarks",
25
25
  "docs",
26
- ".github"
26
+ ".github",
27
+ "tests/corpus"
27
28
  ]
28
29
  }
package/dist/zip-core.js CHANGED
@@ -104,7 +104,7 @@
104
104
  const HEADER_OFFSET_UNCOMPRESSED_SIZE = 18;
105
105
  const LOCAL_HEADER_COMMON_OFFSET = 4;
106
106
 
107
- const MAX_DATE = new Date(2107, 11, 31);
107
+ const MAX_DATE = new Date(2107, 11, 31, 23, 59, 58);
108
108
  const MIN_DATE = new Date(1980, 0, 1);
109
109
 
110
110
  const UNDEFINED_VALUE = undefined;
@@ -220,6 +220,103 @@
220
220
  Object.assign(config, DEFAULT_CONFIGURATION);
221
221
  }
222
222
 
223
+ /*
224
+ Copyright (c) 2025 Gildas Lormeau. All rights reserved.
225
+
226
+ Redistribution and use in source and binary forms, with or without
227
+ modification, are permitted provided that the following conditions are met:
228
+
229
+ 1. Redistributions of source code must retain the above copyright notice,
230
+ this list of conditions and the following disclaimer.
231
+
232
+ 2. Redistributions in binary form must reproduce the above copyright
233
+ notice, this list of conditions and the following disclaimer in
234
+ the documentation and/or other materials provided with the distribution.
235
+
236
+ 3. The names of the authors may not be used to endorse or promote products
237
+ derived from this software without specific prior written permission.
238
+
239
+ THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
240
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
241
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
242
+ INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
243
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
244
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
245
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
246
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
247
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
248
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
249
+ */
250
+
251
+
252
+ const ERR_INVALID_CODEC_DEFINITION = "Invalid codec definition";
253
+ const ERR_RESERVED_COMPRESSION_METHOD = "Reserved compression method";
254
+ const ERR_INVALID_CODEC_MODULE = "Invalid codec module";
255
+
256
+ const STRING_TYPE = "string";
257
+ const RESERVED_COMPRESSION_METHODS = [
258
+ COMPRESSION_METHOD_STORE,
259
+ COMPRESSION_METHOD_DEFLATE,
260
+ COMPRESSION_METHOD_DEFLATE_64,
261
+ COMPRESSION_METHOD_AES
262
+ ];
263
+
264
+ const registeredCodecs = new Map();
265
+ const codecStreams = new Map();
266
+
267
+ function registerCodec(codec = {}) {
268
+ const { compressionMethod, format, codecURI, CompressionStream, DecompressionStream, versionNeeded } = codec;
269
+ if (!Number.isInteger(compressionMethod) || compressionMethod < 0 || compressionMethod > MAX_16_BITS ||
270
+ typeof format != STRING_TYPE || !format.length) {
271
+ throw new Error(ERR_INVALID_CODEC_DEFINITION);
272
+ }
273
+ if (RESERVED_COMPRESSION_METHODS.includes(compressionMethod)) {
274
+ throw new Error(ERR_RESERVED_COMPRESSION_METHOD);
275
+ }
276
+ const hasStreams = typeof CompressionStream == FUNCTION_TYPE || typeof DecompressionStream == FUNCTION_TYPE;
277
+ if (!hasStreams && (typeof codecURI != STRING_TYPE || !codecURI.length)) {
278
+ throw new Error(ERR_INVALID_CODEC_DEFINITION);
279
+ }
280
+ registeredCodecs.set(compressionMethod, { compressionMethod, format, codecURI, versionNeeded });
281
+ if (hasStreams) {
282
+ setCodecStreams(format, { CompressionStream, DecompressionStream });
283
+ }
284
+ }
285
+
286
+ function unregisterCodec(compressionMethod) {
287
+ const codec = registeredCodecs.get(compressionMethod);
288
+ if (codec) {
289
+ registeredCodecs.delete(compressionMethod);
290
+ let formatUsed;
291
+ registeredCodecs.forEach(otherCodec => formatUsed = formatUsed || otherCodec.format == codec.format);
292
+ if (!formatUsed) {
293
+ codecStreams.delete(codec.format);
294
+ }
295
+ }
296
+ }
297
+
298
+ function getRegisteredCodec(compressionMethod) {
299
+ return registeredCodecs.get(compressionMethod);
300
+ }
301
+
302
+ function getCodecStreams(format) {
303
+ return codecStreams.get(format);
304
+ }
305
+
306
+ function setCodecStreams(format, streams) {
307
+ const { CompressionStream, DecompressionStream } = streams;
308
+ if (typeof CompressionStream != FUNCTION_TYPE && typeof DecompressionStream != FUNCTION_TYPE) {
309
+ throw new Error(ERR_INVALID_CODEC_MODULE);
310
+ }
311
+ codecStreams.set(format, { CompressionStream, DecompressionStream });
312
+ }
313
+
314
+ async function ensureCodecStreams(format, codecURI) {
315
+ if (!codecStreams.has(format) && codecURI) {
316
+ setCodecStreams(format, await import(codecURI));
317
+ }
318
+ }
319
+
223
320
  /*
224
321
  Copyright (c) 2022 Gildas Lormeau. All rights reserved.
225
322
 
@@ -1756,6 +1853,7 @@
1756
1853
 
1757
1854
  const ERR_INVALID_UNCOMPRESSED_SIZE = "Invalid uncompressed size";
1758
1855
  const ERR_INVALID_COMPRESSED_DATA = "Invalid compressed data";
1856
+ const ERR_UNSUPPORTED_COMPRESSION$2 = "Compression method not supported";
1759
1857
  const FORMAT_DEFLATE_RAW = "deflate-raw";
1760
1858
  const FORMAT_DEFLATE64_RAW = "deflate64-raw";
1761
1859
  const FORMAT_GZIP = "gzip";
@@ -1766,18 +1864,21 @@
1766
1864
 
1767
1865
  constructor(options, { chunkSize, CompressionStreamZlib, CompressionStream }) {
1768
1866
  super({});
1769
- const { compressed, encrypted, useCompressionStream, zipCrypto, signed, level, deflate64 } = options;
1867
+ const { compressed, encrypted, useCompressionStream, zipCrypto, signed, level, deflate64, format } = options;
1770
1868
  const stream = this;
1771
1869
  let crc32Stream, encryptionStream, gzipCrc32Stream;
1772
1870
  let readable = super.readable;
1773
- const useGzipCrc32 = signed && compressed && !deflate64 && (!encrypted || zipCrypto) &&
1871
+ const codecStreams = format && getCodecStreams(format);
1872
+ const useGzipCrc32 = signed && compressed && !deflate64 && !codecStreams && (!encrypted || zipCrypto) &&
1774
1873
  Boolean(useCompressionStream && CompressionStream);
1775
1874
  if ((!encrypted || zipCrypto) && signed && !useGzipCrc32) {
1776
1875
  crc32Stream = new Crc32Stream();
1777
1876
  readable = pipeThrough(readable, crc32Stream);
1778
1877
  }
1779
1878
  if (compressed) {
1780
- if (useGzipCrc32) {
1879
+ if (codecStreams) {
1880
+ readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.CompressionStream, format, { level, chunkSize }));
1881
+ } else if (useGzipCrc32) {
1781
1882
  gzipCrc32Stream = new GzipToRawDeflateStream();
1782
1883
  readable = pipeThroughBackpressured(readable, new CompressionStream(FORMAT_GZIP));
1783
1884
  readable = pipeThrough(readable, gzipCrc32Stream);
@@ -1851,7 +1952,7 @@
1851
1952
 
1852
1953
  constructor(options, { chunkSize, DecompressionStreamZlib, DecompressionStream }) {
1853
1954
  super({});
1854
- const { zipCrypto, encrypted, signed, signature, compressed, useCompressionStream, deflate64 } = options;
1955
+ const { zipCrypto, encrypted, signed, signature, compressed, useCompressionStream, deflate64, format } = options;
1855
1956
  let crc32Stream, decryptionStream;
1856
1957
  let readable = super.readable;
1857
1958
  if (encrypted) {
@@ -1863,7 +1964,12 @@
1863
1964
  }
1864
1965
  }
1865
1966
  if (compressed) {
1866
- readable = pipeThroughCommpressionStream(readable, useCompressionStream, { chunkSize, deflate64 }, DecompressionStream, DecompressionStreamZlib, DecompressionStream);
1967
+ const codecStreams = format && getCodecStreams(format);
1968
+ if (codecStreams) {
1969
+ readable = pipeThroughBackpressured(readable, createCodecStream(codecStreams.DecompressionStream, format, { chunkSize }));
1970
+ } else {
1971
+ readable = pipeThroughCommpressionStream(readable, useCompressionStream, { chunkSize, deflate64 }, DecompressionStream, DecompressionStreamZlib, DecompressionStream);
1972
+ }
1867
1973
  readable = mapInflateStreamError(readable);
1868
1974
  }
1869
1975
  if ((!encrypted || zipCrypto) && signed) {
@@ -1890,6 +1996,13 @@
1890
1996
  });
1891
1997
  }
1892
1998
 
1999
+ function createCodecStream(CodecStreamClass, format, options) {
2000
+ if (!CodecStreamClass) {
2001
+ throw new Error(ERR_UNSUPPORTED_COMPRESSION$2);
2002
+ }
2003
+ return new CodecStreamClass(format, options);
2004
+ }
2005
+
1893
2006
  function pipeThroughCommpressionStream(readable, useCompressionStream, options, CompressionStreamNative, CompressionStreamZlib, CompressionStream) {
1894
2007
  const Stream = useCompressionStream && CompressionStreamNative ? CompressionStreamNative : CompressionStreamZlib || CompressionStream;
1895
2008
  const format = options.deflate64 ? FORMAT_DEFLATE64_RAW : FORMAT_DEFLATE_RAW;
@@ -2083,7 +2196,7 @@
2083
2196
  constructor(chunkSize) {
2084
2197
  const pendingChunks = [];
2085
2198
  let pendingLength = 0;
2086
- if (!(chunkSize >= 1)) {
2199
+ if (!Number.isFinite(chunkSize) || chunkSize < 1) {
2087
2200
  chunkSize = DEFAULT_CHUNK_SIZE;
2088
2201
  }
2089
2202
  super({
@@ -2634,11 +2747,18 @@
2634
2747
 
2635
2748
  async function runWorker(stream, workerOptions) {
2636
2749
  const { options, config } = workerOptions;
2637
- const { transferStreams, useWebWorkers, useCompressionStream, compressed, signed, encrypted } = options;
2750
+ const { transferStreams, useWebWorkers, useCompressionStream, compressed, signed, encrypted, format, codecURI } = options;
2638
2751
  const { workerURI, maxWorkers } = config;
2752
+ if (format) {
2753
+ if (codecURI) {
2754
+ options.codecURI = resolveCodecURI(codecURI, config.baseURI);
2755
+ }
2756
+ await ensureCodecStreams(format, options.codecURI);
2757
+ }
2639
2758
  workerOptions.transferStreams = transferStreams || (transferStreams === UNDEFINED_VALUE && config.transferStreams);
2640
2759
  const streamCopy = !compressed && !signed && !encrypted;
2641
- workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
2760
+ const workerSupported = format === UNDEFINED_VALUE || Boolean(options.codecURI);
2761
+ workerOptions.useWebWorkers = !streamCopy && workerSupported && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
2642
2762
  workerOptions.workerURI = workerOptions.useWebWorkers && workerURI ? workerURI : UNDEFINED_VALUE;
2643
2763
  options.useCompressionStream = useCompressionStream || (useCompressionStream === UNDEFINED_VALUE && config.useCompressionStream);
2644
2764
  return (await getWorker()).run();
@@ -2678,6 +2798,14 @@
2678
2798
  }
2679
2799
  }
2680
2800
 
2801
+ function resolveCodecURI(codecURI, baseURI) {
2802
+ try {
2803
+ return new URL(codecURI, baseURI).toString();
2804
+ } catch {
2805
+ return codecURI;
2806
+ }
2807
+ }
2808
+
2681
2809
  function armStarvationTimeout() {
2682
2810
  if (!starvationTimeout && pendingRequests.length && Number.isFinite(starvationDelay) && starvationDelay >= 0) {
2683
2811
  starvationTimeout = setTimeout(onWorkerStarvation, starvationDelay);
@@ -2788,6 +2916,7 @@
2788
2916
  const HTTP_METHOD_GET = "GET";
2789
2917
  const HTTP_RANGE_UNIT = "bytes";
2790
2918
  const DEFAULT_BUFFER_SIZE = 256 * 1024;
2919
+ const DEFAULT_MAXIMUM_RANGE_SIZE = 16 * 1024 * 1024;
2791
2920
 
2792
2921
  const PROPERTY_NAME_WRITABLE = "writable";
2793
2922
  const DISK_BOUNDARY = Symbol();
@@ -3100,6 +3229,7 @@
3100
3229
  forceRangeRequests,
3101
3230
  combineSizeEocd,
3102
3231
  checkResourceChanges = true,
3232
+ maximumRangeSize = DEFAULT_MAXIMUM_RANGE_SIZE,
3103
3233
  fetch
3104
3234
  } = options;
3105
3235
  options = Object.assign({}, options);
@@ -3108,6 +3238,7 @@
3108
3238
  delete options.forceRangeRequests;
3109
3239
  delete options.combineSizeEocd;
3110
3240
  delete options.checkResourceChanges;
3241
+ delete options.maximumRangeSize;
3111
3242
  delete options.useXHR;
3112
3243
  delete options.fetch;
3113
3244
  Object.assign(httpReader, {
@@ -3118,6 +3249,7 @@
3118
3249
  forceRangeRequests,
3119
3250
  combineSizeEocd,
3120
3251
  checkResourceChanges,
3252
+ maximumRangeSize,
3121
3253
  fetch
3122
3254
  });
3123
3255
  }
@@ -3203,40 +3335,31 @@
3203
3335
 
3204
3336
  function createRangeReadable(httpReader, offset, size) {
3205
3337
  let bodyReader;
3338
+ let windowOffset = offset;
3339
+ let windowRemainingLength = 0;
3206
3340
  let remainingLength = size;
3207
3341
  return new ReadableStream({
3208
- async start() {
3209
- const response = await sendFetchRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, offset, size));
3210
- if (response.status != 206) {
3211
- throw new Error(ERR_HTTP_RANGE);
3212
- }
3213
- const contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);
3214
- if (contentRangeHeader) {
3215
- const rangeStart = Number(contentRangeHeader.trim().split(/[\s-]+/)[1]);
3216
- if (!Number.isNaN(rangeStart) && rangeStart != offset) {
3217
- throw new Error(ERR_HTTP_RANGE);
3218
- }
3219
- }
3220
- checkResourceValidators(httpReader, response);
3221
- setResourceValidators(httpReader, response);
3222
- bodyReader = response.body.getReader();
3342
+ start() {
3343
+ return openWindow();
3223
3344
  },
3224
3345
  async pull(controller) {
3346
+ if (!bodyReader) {
3347
+ await openWindow();
3348
+ }
3225
3349
  const { value, done } = await bodyReader.read();
3226
3350
  if (done) {
3227
- if (remainingLength) {
3228
- throw new Error(ERR_HTTP_RANGE);
3229
- }
3230
- controller.close();
3231
- } else {
3232
- const chunk = value.length > remainingLength ? value.subarray(0, remainingLength) : value;
3233
- remainingLength -= chunk.length;
3234
- if (chunk.length) {
3235
- controller.enqueue(chunk);
3236
- }
3351
+ throw new Error(ERR_HTTP_RANGE);
3352
+ }
3353
+ const chunk = value.length > windowRemainingLength ? value.subarray(0, windowRemainingLength) : value;
3354
+ windowRemainingLength -= chunk.length;
3355
+ remainingLength -= chunk.length;
3356
+ if (chunk.length) {
3357
+ controller.enqueue(chunk);
3358
+ }
3359
+ if (!windowRemainingLength) {
3360
+ await closeWindow();
3237
3361
  if (!remainingLength) {
3238
3362
  controller.close();
3239
- await bodyReader.cancel();
3240
3363
  }
3241
3364
  }
3242
3365
  },
@@ -3244,6 +3367,32 @@
3244
3367
  return bodyReader && bodyReader.cancel(reason);
3245
3368
  }
3246
3369
  });
3370
+
3371
+ async function openWindow() {
3372
+ const windowLength = Math.min(httpReader.maximumRangeSize, remainingLength);
3373
+ const response = await sendFetchRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, windowOffset, windowLength));
3374
+ if (response.status != 206) {
3375
+ throw new Error(ERR_HTTP_RANGE);
3376
+ }
3377
+ const contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);
3378
+ if (contentRangeHeader) {
3379
+ const rangeStart = Number(contentRangeHeader.trim().split(/[\s-]+/)[1]);
3380
+ if (!Number.isNaN(rangeStart) && rangeStart != windowOffset) {
3381
+ throw new Error(ERR_HTTP_RANGE);
3382
+ }
3383
+ }
3384
+ checkResourceValidators(httpReader, response);
3385
+ setResourceValidators(httpReader, response);
3386
+ windowOffset += windowLength;
3387
+ windowRemainingLength = windowLength;
3388
+ bodyReader = response.body.getReader();
3389
+ }
3390
+
3391
+ async function closeWindow() {
3392
+ const currentBodyReader = bodyReader;
3393
+ bodyReader = UNDEFINED_VALUE;
3394
+ await currentBodyReader.cancel();
3395
+ }
3247
3396
  }
3248
3397
 
3249
3398
  function getContentRangeSize(response) {
@@ -3940,6 +4089,7 @@
3940
4089
  const OPTION_PREVENT_CLOSE = "preventClose";
3941
4090
  const OPTION_ENCRYPTION_STRENGTH = "encryptionStrength";
3942
4091
  const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
4092
+ const OPTION_NTFS_TIMESTAMP = "ntfsTimestamp";
3943
4093
  const OPTION_KEEP_ORDER = "keepOrder";
3944
4094
  const OPTION_LEVEL = "level";
3945
4095
  const OPTION_BUFFERED_WRITE = "bufferedWrite";
@@ -4411,7 +4561,8 @@
4411
4561
  throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
4412
4562
  }
4413
4563
  }
4414
- if ((compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE && compressionMethod != COMPRESSION_METHOD_DEFLATE_64) && !passThrough) {
4564
+ const registeredCodec = passThrough ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
4565
+ if ((compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE && compressionMethod != COMPRESSION_METHOD_DEFLATE_64 && !registeredCodec) && !passThrough) {
4415
4566
  throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
4416
4567
  }
4417
4568
  if (dataArray.length < HEADER_SIZE || getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
@@ -4450,7 +4601,7 @@
4450
4601
  fileEntry.zipCrypto = zipCrypto;
4451
4602
  }
4452
4603
  if (encrypted) {
4453
- if (!zipCrypto && extraFieldAES.strength === UNDEFINED_VALUE) {
4604
+ if (!zipCrypto && (extraFieldAES.strength < 1 || extraFieldAES.strength > 3)) {
4454
4605
  throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
4455
4606
  } else if (!password && !rawPassword) {
4456
4607
  throw new Error(ERR_ENCRYPTED);
@@ -4489,6 +4640,8 @@
4489
4640
  useCompressionStream,
4490
4641
  transferStreams: getOptionValue$1(zipEntry, options, OPTION_TRANSFER_STREAMS),
4491
4642
  deflate64,
4643
+ format: registeredCodec ? registeredCodec.format : UNDEFINED_VALUE,
4644
+ codecURI: registeredCodec ? registeredCodec.codecURI : UNDEFINED_VALUE,
4492
4645
  checkPasswordOnly
4493
4646
  },
4494
4647
  config,
@@ -5106,6 +5259,7 @@
5106
5259
  const ERR_INVALID_ENTRY_NAME = "File entry name exceeds 64KB";
5107
5260
  const ERR_INVALID_VERSION = "Version exceeds 65535";
5108
5261
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
5262
+ const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
5109
5263
  const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
5110
5264
  const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
5111
5265
  const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
@@ -5570,6 +5724,7 @@
5570
5724
  const encryptionStrength = getOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
5571
5725
  const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
5572
5726
  const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
5727
+ const ntfsTimestamp = getOptionValue(zipWriter, options, OPTION_NTFS_TIMESTAMP);
5573
5728
  const keepOrder = getOptionValue(zipWriter, options, OPTION_KEEP_ORDER, true);
5574
5729
  const useWebWorkers = getOptionValue(zipWriter, options, OPTION_USE_WEB_WORKERS);
5575
5730
  const transferStreams = getOptionValue(zipWriter, options, OPTION_TRANSFER_STREAMS);
@@ -5579,11 +5734,20 @@
5579
5734
  const signal = getOptionValue(zipWriter, options, OPTION_SIGNAL);
5580
5735
  const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
5581
5736
  const compressionMethod = getOptionValue(zipWriter, options, PROPERTY_NAME_COMPRESSION_METHOD);
5737
+ const registeredCodec = passThrough || compressionMethod === UNDEFINED_VALUE ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
5582
5738
  if (!passThrough && compressionMethod !== UNDEFINED_VALUE &&
5583
- compressionMethod !== COMPRESSION_METHOD_STORE && compressionMethod !== COMPRESSION_METHOD_DEFLATE) {
5739
+ compressionMethod !== COMPRESSION_METHOD_STORE && compressionMethod !== COMPRESSION_METHOD_DEFLATE && !registeredCodec) {
5584
5740
  throw new Error(ERR_UNSUPPORTED_COMPRESSION);
5585
5741
  }
5586
5742
  let level = getOptionValue(zipWriter, options, OPTION_LEVEL);
5743
+ if (zipWriter.options[OPTION_USDZ]) {
5744
+ if (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) {
5745
+ throw new Error(ERR_UNSUPPORTED_ENCRYPTION_USDZ);
5746
+ }
5747
+ if (level === UNDEFINED_VALUE && compressionMethod === UNDEFINED_VALUE) {
5748
+ level = 0;
5749
+ }
5750
+ }
5587
5751
  let useCompressionStream = getOptionValue(zipWriter, options, OPTION_USE_COMPRESSION_STREAM);
5588
5752
  let dataDescriptor = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR);
5589
5753
  if (bufferedWrite && dataDescriptor === UNDEFINED_VALUE) {
@@ -5595,7 +5759,7 @@
5595
5759
  if (level !== UNDEFINED_VALUE && level != 6) {
5596
5760
  useCompressionStream = false;
5597
5761
  }
5598
- if (!useCompressionStream && (zipWriter.config.CompressionStream === UNDEFINED_VALUE && zipWriter.config.CompressionStreamZlib === UNDEFINED_VALUE)) {
5762
+ if (!useCompressionStream && !registeredCodec && (zipWriter.config.CompressionStream === UNDEFINED_VALUE && zipWriter.config.CompressionStreamZlib === UNDEFINED_VALUE)) {
5599
5763
  level = 0;
5600
5764
  }
5601
5765
  const zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
@@ -5639,6 +5803,7 @@
5639
5803
  encryptionStrength,
5640
5804
  zipCrypto,
5641
5805
  extendedTimestamp,
5806
+ ntfsTimestamp,
5642
5807
  keepOrder,
5643
5808
  useWebWorkers,
5644
5809
  transferStreams,
@@ -5648,6 +5813,9 @@
5648
5813
  signal,
5649
5814
  useUnicodeFileNames,
5650
5815
  compressionMethod,
5816
+ format: registeredCodec ? registeredCodec.format : UNDEFINED_VALUE,
5817
+ codecURI: registeredCodec ? registeredCodec.codecURI : UNDEFINED_VALUE,
5818
+ codecVersionNeeded: registeredCodec ? registeredCodec.versionNeeded : UNDEFINED_VALUE,
5651
5819
  level,
5652
5820
  useCompressionStream,
5653
5821
  dataDescriptor,
@@ -5944,7 +6112,9 @@
5944
6112
  msdosAttributesRaw,
5945
6113
  msdosAttributes,
5946
6114
  useCompressionStream,
5947
- passThrough
6115
+ passThrough,
6116
+ format,
6117
+ codecURI
5948
6118
  } = options;
5949
6119
  const fileEntry = {
5950
6120
  lock,
@@ -6004,7 +6174,9 @@
6004
6174
  encrypted: encrypted && !passThrough,
6005
6175
  useWebWorkers,
6006
6176
  useCompressionStream,
6007
- transferStreams
6177
+ transferStreams,
6178
+ format,
6179
+ codecURI
6008
6180
  },
6009
6181
  config,
6010
6182
  streamOptions: { signal, size, onstart, onprogress, onend }
@@ -6076,6 +6248,7 @@
6076
6248
  rawExtraField,
6077
6249
  encryptionStrength,
6078
6250
  extendedTimestamp,
6251
+ ntfsTimestamp,
6079
6252
  passThrough,
6080
6253
  encrypted,
6081
6254
  zip64UncompressedSize,
@@ -6121,7 +6294,8 @@
6121
6294
  let extraFieldExtendedTimestampFlag;
6122
6295
  if (extendedTimestamp) {
6123
6296
  const lastModTimeUnix = getTimeUnix(lastModDate);
6124
- if (inUnixTimeRange(lastModTimeUnix)) {
6297
+ const lastModTimeUnixInRange = inUnixTimeRange(lastModTimeUnix);
6298
+ if (lastModTimeUnixInRange) {
6125
6299
  const extraFieldTimestampLength = 9 + (lastAccessDate ? 4 : 0) + (creationDate ? 4 : 0);
6126
6300
  const extraFieldTimestamp = createRecordWriter(extraFieldTimestampLength);
6127
6301
  extraFieldExtendedTimestampFlag = 0x1 + (lastAccessDate ? 0x2 : 0) + (creationDate ? 0x4 : 0);
@@ -6139,19 +6313,26 @@
6139
6313
  } else {
6140
6314
  rawExtraFieldExtendedTimestamp = EMPTY_UINT8_ARRAY;
6141
6315
  }
6142
- try {
6143
- const lastModTimeNTFS = getTimeNTFS(lastModDate);
6144
- const extraFieldNTFS = createRecordWriter(36);
6145
- extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS);
6146
- extraFieldNTFS.uint16(32);
6147
- extraFieldNTFS.skip(4);
6148
- extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS_TAG1);
6149
- extraFieldNTFS.uint16(24);
6150
- extraFieldNTFS.uint64(lastModTimeNTFS);
6151
- extraFieldNTFS.uint64(getTimeNTFS(lastAccessDate) || lastModTimeNTFS);
6152
- extraFieldNTFS.uint64(getTimeNTFS(creationDate) || lastModTimeNTFS);
6153
- rawExtraFieldNTFS = extraFieldNTFS.array;
6154
- } catch {
6316
+ const writeExtraFieldNTFS = ntfsTimestamp === UNDEFINED_VALUE ?
6317
+ !lastModTimeUnixInRange || Boolean(lastAccessDate || creationDate) :
6318
+ ntfsTimestamp;
6319
+ if (writeExtraFieldNTFS) {
6320
+ try {
6321
+ const lastModTimeNTFS = getTimeNTFS(lastModDate);
6322
+ const extraFieldNTFS = createRecordWriter(36);
6323
+ extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS);
6324
+ extraFieldNTFS.uint16(32);
6325
+ extraFieldNTFS.skip(4);
6326
+ extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS_TAG1);
6327
+ extraFieldNTFS.uint16(24);
6328
+ extraFieldNTFS.uint64(lastModTimeNTFS);
6329
+ extraFieldNTFS.uint64(getTimeNTFS(lastAccessDate) || lastModTimeNTFS);
6330
+ extraFieldNTFS.uint64(getTimeNTFS(creationDate) || lastModTimeNTFS);
6331
+ rawExtraFieldNTFS = extraFieldNTFS.array;
6332
+ } catch {
6333
+ rawExtraFieldNTFS = EMPTY_UINT8_ARRAY;
6334
+ }
6335
+ } else {
6155
6336
  rawExtraFieldNTFS = EMPTY_UINT8_ARRAY;
6156
6337
  }
6157
6338
  } else {
@@ -6189,6 +6370,10 @@
6189
6370
  if (compressionMethod === UNDEFINED_VALUE) {
6190
6371
  compressionMethod = compressed ? COMPRESSION_METHOD_DEFLATE : COMPRESSION_METHOD_STORE;
6191
6372
  }
6373
+ const { codecVersionNeeded } = options;
6374
+ if (compressed && codecVersionNeeded !== UNDEFINED_VALUE) {
6375
+ version = version > codecVersionNeeded ? version : codecVersionNeeded;
6376
+ }
6192
6377
  if (zip64) {
6193
6378
  version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
6194
6379
  }
@@ -7314,6 +7499,8 @@
7314
7499
  exports.ERR_EXTRAFIELD_ZIP64_NOT_FOUND = ERR_EXTRAFIELD_ZIP64_NOT_FOUND;
7315
7500
  exports.ERR_HTTP_RANGE = ERR_HTTP_RANGE;
7316
7501
  exports.ERR_HTTP_RESOURCE_CHANGED = ERR_HTTP_RESOURCE_CHANGED;
7502
+ exports.ERR_INVALID_CODEC_DEFINITION = ERR_INVALID_CODEC_DEFINITION;
7503
+ exports.ERR_INVALID_CODEC_MODULE = ERR_INVALID_CODEC_MODULE;
7317
7504
  exports.ERR_INVALID_COMMENT = ERR_INVALID_COMMENT;
7318
7505
  exports.ERR_INVALID_COMPRESSED_DATA = ERR_INVALID_COMPRESSED_DATA;
7319
7506
  exports.ERR_INVALID_ENCRYPTION_STRENGTH = ERR_INVALID_ENCRYPTION_STRENGTH;
@@ -7328,11 +7515,13 @@
7328
7515
  exports.ERR_ITERATOR_COMPLETED_TOO_SOON = ERR_ITERATOR_COMPLETED_TOO_SOON;
7329
7516
  exports.ERR_LOCAL_FILE_HEADER_NOT_FOUND = ERR_LOCAL_FILE_HEADER_NOT_FOUND;
7330
7517
  exports.ERR_OVERLAPPING_ENTRY = ERR_OVERLAPPING_ENTRY;
7518
+ exports.ERR_RESERVED_COMPRESSION_METHOD = ERR_RESERVED_COMPRESSION_METHOD;
7331
7519
  exports.ERR_SPLIT_ZIP_FILE = ERR_SPLIT_ZIP_FILE;
7332
7520
  exports.ERR_UNDEFINED_READER = ERR_UNDEFINED_READER;
7333
7521
  exports.ERR_UNDEFINED_UNCOMPRESSED_SIZE = ERR_UNDEFINED_UNCOMPRESSED_SIZE;
7334
7522
  exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION$1;
7335
7523
  exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
7524
+ exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
7336
7525
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
7337
7526
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;
7338
7527
  exports.ERR_ZIP_NOT_EMPTY = ERR_ZIP_NOT_EMPTY;
@@ -7355,7 +7544,9 @@
7355
7544
  exports.createOPFSTempStream = createOPFSTempStream;
7356
7545
  exports.createSyncAccessHandleTempStream = createSyncAccessHandleTempStream;
7357
7546
  exports.getMimeType = getMimeType;
7547
+ exports.registerCodec = registerCodec;
7358
7548
  exports.resetConfiguration = resetConfiguration;
7359
7549
  exports.terminateWorkers = terminateWorkers;
7550
+ exports.unregisterCodec = unregisterCodec;
7360
7551
 
7361
7552
  }));