@zip.js/zip.js 2.18.2 → 2.19.0

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 (44) hide show
  1. package/BENCHMARKS.md +122 -118
  2. package/deno.json +1 -1
  3. package/dist/zip-core-external.js +54 -81
  4. package/dist/zip-core-external.min.js +1 -1
  5. package/dist/zip-core.js +54 -81
  6. package/dist/zip-core.min.js +1 -1
  7. package/dist/zip-fs-core-external.js +54 -81
  8. package/dist/zip-fs-core-external.min.js +1 -1
  9. package/dist/zip-fs-core.js +54 -81
  10. package/dist/zip-fs-core.min.js +1 -1
  11. package/dist/zip-fs-external.js +54 -81
  12. package/dist/zip-fs-external.min.js +1 -1
  13. package/dist/zip-fs-native.js +56 -83
  14. package/dist/zip-fs-native.min.js +1 -1
  15. package/dist/zip-fs.js +55 -82
  16. package/dist/zip-fs.min.js +1 -1
  17. package/dist/zip-legacy.js +56 -83
  18. package/dist/zip-legacy.min.js +1 -1
  19. package/dist/zip-native.js +56 -83
  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 +55 -82
  24. package/dist/zip.min.js +1 -1
  25. package/index-native.cjs +56 -83
  26. package/index-native.min.js +1 -1
  27. package/index.cjs +55 -82
  28. package/index.d.cts +27 -18
  29. package/index.d.ts +27 -18
  30. package/index.min.js +1 -1
  31. package/lib/core/codec-pool.js +1 -2
  32. package/lib/core/codec-worker-web.js +11 -39
  33. package/lib/core/codec-worker.js +1 -2
  34. package/lib/core/configuration.js +1 -1
  35. package/lib/core/options.js +0 -2
  36. package/lib/core/streams/codec-stream.js +1 -1
  37. package/lib/core/version.js +1 -1
  38. package/lib/core/web-worker-base.js +2 -3
  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-reader.js +21 -23
  42. package/lib/core/zip-writer.js +18 -14
  43. package/package.json +1 -1
  44. package/worker-message-property-names.js +1 -1
@@ -185,7 +185,6 @@
185
185
  const OPTION_CHECK_AUTHENTICATION_CODE = "checkAuthenticationCode";
186
186
  const OPTION_USE_WEB_WORKERS = "useWebWorkers";
187
187
  const OPTION_USE_COMPRESSION_STREAM = "useCompressionStream";
188
- const OPTION_TRANSFER_STREAMS = "transferStreams";
189
188
  const OPTION_PREVENT_CLOSE = "preventClose";
190
189
  const OPTION_ENCRYPTION_STRENGTH = "encryptionStrength";
191
190
  const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
@@ -303,7 +302,7 @@
303
302
  */
304
303
 
305
304
 
306
- const DEFAULT_CHUNK_SIZE$1 = 64 * 1024;
305
+ const DEFAULT_CHUNK_SIZE$1 = 256 * 1024;
307
306
  const MINIMUM_CHUNK_SIZE = 64;
308
307
  const MINIMUM_PROPERTY_VALUE = 1;
309
308
  const ERR_INVALID_MAX_WORKERS = "Invalid maxWorkers (must be an integer greater than 0)";
@@ -2392,7 +2391,7 @@
2392
2391
  */
2393
2392
 
2394
2393
 
2395
- const DEFAULT_CHUNK_SIZE = 64 * 1024;
2394
+ const DEFAULT_CHUNK_SIZE = 256 * 1024;
2396
2395
  const MESSAGE_EVENT_TYPE = "message";
2397
2396
  const MESSAGE_START = "start";
2398
2397
  const MESSAGE_PULL = "pull";
@@ -2598,7 +2597,7 @@
2598
2597
  class CodecWorker {
2599
2598
 
2600
2599
  constructor(workerData, { readable, writable }, workerOptions, onTaskFinished) {
2601
- const { options, config, streamOptions, useWebWorkers, transferStreams, workerURI } = workerOptions;
2600
+ const { options, config, streamOptions, useWebWorkers, workerURI } = workerOptions;
2602
2601
  let { createWorker } = workerOptions;
2603
2602
  const { signal } = streamOptions;
2604
2603
  if (createWorkerFailed) {
@@ -2615,7 +2614,6 @@
2615
2614
  workerOptions,
2616
2615
  workerURI,
2617
2616
  createWorker,
2618
- transferStreams,
2619
2617
  terminate() {
2620
2618
  return new Promise(resolve => {
2621
2619
  const { worker, busy } = workerData;
@@ -2793,12 +2791,6 @@
2793
2791
  const ABORT_EVENT_TYPE = "abort";
2794
2792
 
2795
2793
  let webWorkerSource, webWorkerURI, webWorkerOptions;
2796
- let transferStreamsSupported = true;
2797
- try {
2798
- transferStreamsSupported = typeof structuredClone == FUNCTION_TYPE && structuredClone(new DOMException("", "AbortError")).code !== UNDEFINED_VALUE;
2799
- } catch {
2800
- // ignored
2801
- }
2802
2794
 
2803
2795
  setWebWorkerBackend(createWebWorkerInterface);
2804
2796
 
@@ -2885,14 +2877,11 @@
2885
2877
  });
2886
2878
  const { readable, options } = workerData;
2887
2879
  const { writable, closed, abortPipe } = watchClosedStream(workerData.writable, workerData);
2888
- let streamsTransferred;
2889
2880
  try {
2890
- streamsTransferred = sendMessage({
2881
+ sendMessage({
2891
2882
  type: MESSAGE_START,
2892
2883
  options,
2893
- config,
2894
- readable,
2895
- writable
2884
+ config
2896
2885
  }, workerData);
2897
2886
  } catch (error) {
2898
2887
  abortPipe();
@@ -2904,12 +2893,10 @@
2904
2893
  workerData.onTaskFinished();
2905
2894
  throw error;
2906
2895
  }
2907
- if (!streamsTransferred) {
2908
- Object.assign(workerData, {
2909
- reader: readable.getReader(),
2910
- writer: writable.getWriter()
2911
- });
2912
- }
2896
+ Object.assign(workerData, {
2897
+ reader: readable.getReader(),
2898
+ writer: writable.getWriter()
2899
+ });
2913
2900
  const { workerStartupTimeout } = config;
2914
2901
  if (!workerData.workerAlive && Number.isFinite(workerStartupTimeout) && workerStartupTimeout >= 0) {
2915
2902
  workerData.startupTimeout = setTimeout(() => onStartupTimeout(workerData), workerStartupTimeout);
@@ -2942,7 +2929,7 @@
2942
2929
  }
2943
2930
 
2944
2931
  async function closeWritable() {
2945
- if (!streamsTransferred && !writable.locked) {
2932
+ if (!writable.locked) {
2946
2933
  try {
2947
2934
  await writable.getWriter().close();
2948
2935
  } catch {
@@ -3133,31 +3120,14 @@
3133
3120
  }
3134
3121
  }
3135
3122
 
3136
- function sendMessage(message, { worker, writer, transferStreams, workerAlive }) {
3123
+ function sendMessage(message, { worker, writer }) {
3137
3124
  try {
3138
- const { value, readable, writable } = message;
3139
- const transferables = [];
3125
+ const { value } = message;
3140
3126
  if (value) {
3141
3127
  message.value = toExactUint8Array(value);
3142
- transferables.push(message.value.buffer);
3143
- }
3144
- if (transferStreams && transferStreamsSupported && workerAlive) {
3145
- if (readable) {
3146
- transferables.push(readable);
3147
- }
3148
- if (writable) {
3149
- transferables.push(writable);
3150
- }
3151
- } else {
3152
- message.readable = message.writable = null;
3153
- }
3154
- if (transferables.length) {
3155
3128
  try {
3156
- worker.postMessage(message, transferables);
3157
- return true;
3129
+ worker.postMessage(message, [message.value.buffer]);
3158
3130
  } catch {
3159
- transferStreamsSupported = false;
3160
- message.readable = message.writable = null;
3161
3131
  worker.postMessage(message);
3162
3132
  }
3163
3133
  } else {
@@ -3306,7 +3276,7 @@
3306
3276
 
3307
3277
  async function runWorker(stream, workerOptions) {
3308
3278
  const { options, config } = workerOptions;
3309
- const { transferStreams, useWebWorkers, useCompressionStream, compressed, checkCrc32, computeCrc32, encrypted, format, codecURI } = options;
3279
+ const { useWebWorkers, useCompressionStream, compressed, checkCrc32, computeCrc32, encrypted, format, codecURI } = options;
3310
3280
  const { workerURI, createWorker, maxWorkers } = config;
3311
3281
  if (format) {
3312
3282
  if (codecURI) {
@@ -3314,7 +3284,6 @@
3314
3284
  }
3315
3285
  await ensureCodecStreams(format, options.codecURI);
3316
3286
  }
3317
- workerOptions.transferStreams = !format && (transferStreams || (transferStreams === UNDEFINED_VALUE && config.transferStreams));
3318
3287
  const streamCopy = !compressed && !checkCrc32 && !computeCrc32 && !encrypted;
3319
3288
  const workerSupported = format === UNDEFINED_VALUE || Boolean(options.codecURI);
3320
3289
  workerOptions.useWebWorkers = !streamCopy && workerSupported && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
@@ -5116,17 +5085,6 @@
5116
5085
  if (filename === UNDEFINED_VALUE) {
5117
5086
  filename = decodeText(rawFilename, rawFilenameEncoding);
5118
5087
  }
5119
- if (normalizeFilename) {
5120
- const normalizedFilename = normalizeFilename(filename);
5121
- if (normalizedFilename !== UNDEFINED_VALUE) {
5122
- filename = normalizedFilename;
5123
- }
5124
- }
5125
- if (isUnsafeFilename(filename, filenameValidation)) {
5126
- const error = new Error(ERR_UNSAFE_FILENAME);
5127
- error.filename = filename;
5128
- throw error;
5129
- }
5130
5088
  let comment = decode(rawComment, rawCommentEncoding, TEXT_TYPE_COMMENT);
5131
5089
  if (comment === UNDEFINED_VALUE) {
5132
5090
  comment = decodeText(rawComment, rawCommentEncoding);
@@ -5154,7 +5112,20 @@
5154
5112
  filename,
5155
5113
  comment
5156
5114
  });
5157
- if (readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6)) {
5115
+ const malformedExtraField = readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6);
5116
+ filename = fileEntry.filename;
5117
+ if (normalizeFilename) {
5118
+ const normalizedFilename = normalizeFilename(filename);
5119
+ if (normalizedFilename !== UNDEFINED_VALUE) {
5120
+ filename = fileEntry.filename = normalizedFilename;
5121
+ }
5122
+ }
5123
+ if (isUnsafeFilename(filename, filenameValidation)) {
5124
+ const error = new Error(ERR_UNSAFE_FILENAME);
5125
+ error.filename = filename;
5126
+ throw error;
5127
+ }
5128
+ if (malformedExtraField) {
5158
5129
  addWarning(warnings, WARNING_MALFORMED_EXTRA_FIELD, filename);
5159
5130
  }
5160
5131
  fileEntry.offset += prependedDataLength;
@@ -5558,7 +5529,6 @@
5558
5529
  encrypted,
5559
5530
  useWebWorkers: getOptionValue$1(zipEntry, options, OPTION_USE_WEB_WORKERS),
5560
5531
  useCompressionStream,
5561
- transferStreams: getOptionValue$1(zipEntry, options, OPTION_TRANSFER_STREAMS),
5562
5532
  deflate64,
5563
5533
  format: registeredCodec ? registeredCodec.format : UNDEFINED_VALUE,
5564
5534
  codecURI: registeredCodec ? registeredCodec.codecURI : UNDEFINED_VALUE,
@@ -5788,19 +5758,17 @@
5788
5758
  readExtraFieldNTFS(extraFieldNTFS, directory);
5789
5759
  directory.extraFieldNTFS = extraFieldNTFS;
5790
5760
  }
5791
- const extraFieldUnix = extraField.get(EXTRAFIELD_TYPE_UNIX);
5761
+ const extraFieldInfoZip = extraField.get(EXTRAFIELD_TYPE_INFOZIP);
5792
5762
  let unixIdsRead;
5763
+ if (extraFieldInfoZip) {
5764
+ unixIdsRead = readExtraFieldUnix(extraFieldInfoZip, directory, true);
5765
+ directory.extraFieldInfoZip = extraFieldInfoZip;
5766
+ }
5767
+ const extraFieldUnix = extraField.get(EXTRAFIELD_TYPE_UNIX);
5793
5768
  if (extraFieldUnix) {
5794
- unixIdsRead = readExtraFieldUnix(extraFieldUnix, directory, false);
5769
+ readExtraFieldUnix(extraFieldUnix, unixIdsRead ? {} : directory, false);
5795
5770
  directory.extraFieldUnix = extraFieldUnix;
5796
5771
  }
5797
- if (!unixIdsRead) {
5798
- const extraFieldInfoZip = extraField.get(EXTRAFIELD_TYPE_INFOZIP);
5799
- if (extraFieldInfoZip) {
5800
- readExtraFieldUnix(extraFieldInfoZip, directory, true);
5801
- directory.extraFieldInfoZip = extraFieldInfoZip;
5802
- }
5803
- }
5804
5772
  const extraFieldExtendedTimestamp = extraField.get(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
5805
5773
  if (extraFieldExtendedTimestamp) {
5806
5774
  readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory, localDirectory);
@@ -6687,6 +6655,7 @@
6687
6655
  rawExtraFieldExtendedTimestamp: EMPTY_UINT8_ARRAY,
6688
6656
  rawExtraFieldNTFS: EMPTY_UINT8_ARRAY,
6689
6657
  rawExtraFieldUnix: EMPTY_UINT8_ARRAY,
6658
+ rawCentralExtraFieldUnix: EMPTY_UINT8_ARRAY,
6690
6659
  rawExtraField,
6691
6660
  rawCentralExtraField: EMPTY_UINT8_ARRAY,
6692
6661
  headerArray,
@@ -7255,7 +7224,6 @@
7255
7224
  const ntfsTimestamp = getOptionValue(zipWriter, options, OPTION_NTFS_TIMESTAMP);
7256
7225
  const keepOrder = getOptionValue(zipWriter, options, OPTION_KEEP_ORDER, true);
7257
7226
  const useWebWorkers = getOptionValue(zipWriter, options, OPTION_USE_WEB_WORKERS);
7258
- const transferStreams = getOptionValue(zipWriter, options, OPTION_TRANSFER_STREAMS);
7259
7227
  const bufferedWrite = getOptionValue(zipWriter, options, OPTION_BUFFERED_WRITE);
7260
7228
  const createTempStream = getFunctionOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
7261
7229
  const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, true);
@@ -7321,7 +7289,6 @@
7321
7289
  ntfsTimestamp,
7322
7290
  keepOrder,
7323
7291
  useWebWorkers,
7324
- transferStreams,
7325
7292
  bufferedWrite,
7326
7293
  createTempStream,
7327
7294
  dataDescriptorSignature,
@@ -7380,7 +7347,7 @@
7380
7347
  if (reader) {
7381
7348
  reader = new GenericReader(reader);
7382
7349
  await initStream(reader);
7383
- if (!reader.readable && !reader.readUint8Array) {
7350
+ if (!reader.readUint8Array && !reader.readable) {
7384
7351
  throw new Error(ERR_INVALID_READER);
7385
7352
  }
7386
7353
  ({ size: contentSize } = reader);
@@ -7741,6 +7708,7 @@
7741
7708
  extraFieldExtendedTimestampTime,
7742
7709
  rawExtraFieldNTFS,
7743
7710
  rawExtraFieldUnix,
7711
+ rawCentralExtraFieldUnix,
7744
7712
  rawExtraFieldAES,
7745
7713
  } = headerInfo;
7746
7714
  const { dataDescriptorArray } = dataDescriptorInfo;
@@ -7765,7 +7733,6 @@
7765
7733
  rawExtraField,
7766
7734
  rawCentralExtraField,
7767
7735
  useWebWorkers,
7768
- transferStreams,
7769
7736
  onstart,
7770
7737
  onprogress,
7771
7738
  onend,
@@ -7807,6 +7774,7 @@
7807
7774
  rawExtraFieldExtendedTimestamp,
7808
7775
  rawExtraFieldNTFS,
7809
7776
  rawExtraFieldUnix,
7777
+ rawCentralExtraFieldUnix,
7810
7778
  rawExtraFieldAES,
7811
7779
  rawExtraField,
7812
7780
  rawCentralExtraField,
@@ -7853,7 +7821,6 @@
7853
7821
  encrypted: encrypted && !passThroughEncryption,
7854
7822
  useWebWorkers,
7855
7823
  useCompressionStream,
7856
- transferStreams,
7857
7824
  format,
7858
7825
  codecURI,
7859
7826
  compressionMethod
@@ -8031,6 +7998,7 @@
8031
7998
  rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = EMPTY_UINT8_ARRAY;
8032
7999
  }
8033
8000
  let rawExtraFieldUnix;
8001
+ let rawCentralExtraFieldUnix;
8034
8002
  try {
8035
8003
  const { uid, gid, unixExtraFieldType } = options;
8036
8004
  if (unixExtraFieldType == INFOZIP_EXTRA_FIELD_TYPE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
@@ -8045,7 +8013,7 @@
8045
8013
  extraFieldUnix.writeBytes(uidBytes);
8046
8014
  extraFieldUnix.writeUint8(gidBytes.length);
8047
8015
  extraFieldUnix.writeBytes(gidBytes);
8048
- rawExtraFieldUnix = extraFieldUnix.array;
8016
+ rawExtraFieldUnix = rawCentralExtraFieldUnix = extraFieldUnix.array;
8049
8017
  } else if (unixExtraFieldType == UNIX_EXTRA_FIELD_TYPE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
8050
8018
  const extraFieldUnix = createRecordWriter(8);
8051
8019
  extraFieldUnix.writeUint16(EXTRAFIELD_TYPE_UNIX);
@@ -8053,11 +8021,15 @@
8053
8021
  extraFieldUnix.writeUint16((uid === UNDEFINED_VALUE ? 0 : uid) & MAX_16_BITS);
8054
8022
  extraFieldUnix.writeUint16((gid === UNDEFINED_VALUE ? 0 : gid) & MAX_16_BITS);
8055
8023
  rawExtraFieldUnix = extraFieldUnix.array;
8024
+ const centralExtraFieldUnix = createRecordWriter(4);
8025
+ centralExtraFieldUnix.writeUint16(EXTRAFIELD_TYPE_UNIX);
8026
+ centralExtraFieldUnix.writeUint16(0);
8027
+ rawCentralExtraFieldUnix = centralExtraFieldUnix.array;
8056
8028
  } else {
8057
- rawExtraFieldUnix = EMPTY_UINT8_ARRAY;
8029
+ rawExtraFieldUnix = rawCentralExtraFieldUnix = EMPTY_UINT8_ARRAY;
8058
8030
  }
8059
8031
  } catch {
8060
- rawExtraFieldUnix = EMPTY_UINT8_ARRAY;
8032
+ rawExtraFieldUnix = rawCentralExtraFieldUnix = EMPTY_UINT8_ARRAY;
8061
8033
  }
8062
8034
  if (compressionMethod === UNDEFINED_VALUE) {
8063
8035
  compressionMethod = compressed ? COMPRESSION_METHOD_DEFLATE : COMPRESSION_METHOD_STORE;
@@ -8149,6 +8121,7 @@
8149
8121
  rawExtraFieldExtendedTimestamp,
8150
8122
  rawExtraFieldNTFS,
8151
8123
  rawExtraFieldUnix,
8124
+ rawCentralExtraFieldUnix,
8152
8125
  rawExtraFieldAES,
8153
8126
  extraFieldLength
8154
8127
  };
@@ -8324,7 +8297,7 @@
8324
8297
  rawExtraFieldAES,
8325
8298
  rawComment,
8326
8299
  rawExtraFieldNTFS,
8327
- rawExtraFieldUnix,
8300
+ rawCentralExtraFieldUnix,
8328
8301
  rawExtraField,
8329
8302
  rawCentralExtraField,
8330
8303
  extraFieldExtendedTimestampFlag,
@@ -8386,7 +8359,7 @@
8386
8359
  rawExtraFieldZip64,
8387
8360
  rawExtraFieldAES,
8388
8361
  rawExtraFieldNTFS,
8389
- rawExtraFieldUnix,
8362
+ rawCentralExtraFieldUnix,
8390
8363
  rawExtraFieldTimestamp,
8391
8364
  rawExtraField,
8392
8365
  rawCentralExtraField);
@@ -8415,7 +8388,7 @@
8415
8388
  rawExtraFieldAES,
8416
8389
  rawExtraFieldExtendedTimestamp,
8417
8390
  rawExtraFieldNTFS,
8418
- rawExtraFieldUnix,
8391
+ rawCentralExtraFieldUnix,
8419
8392
  rawExtraField,
8420
8393
  rawCentralExtraField,
8421
8394
  rawComment,
@@ -8432,7 +8405,7 @@
8432
8405
  uncompressedSize,
8433
8406
  compressedSize
8434
8407
  } = fileEntry;
8435
- const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField, rawCentralExtraField);
8408
+ const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawCentralExtraFieldUnix, rawExtraField, rawCentralExtraField);
8436
8409
  const directoryRecordLength = CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
8437
8410
  if (exceedsAvailableSize(writer, offset + directoryRecordLength - directoryDiskOffset)) {
8438
8411
  await writeData(writer, directoryArray.slice(directoryDiskOffset, offset));
@@ -8468,7 +8441,7 @@
8468
8441
  directoryRecord.writeBytes(rawExtraFieldAES);
8469
8442
  directoryRecord.writeBytes(rawExtraFieldExtendedTimestamp);
8470
8443
  directoryRecord.writeBytes(rawExtraFieldNTFS);
8471
- directoryRecord.writeBytes(rawExtraFieldUnix);
8444
+ directoryRecord.writeBytes(rawCentralExtraFieldUnix);
8472
8445
  directoryRecord.writeBytes(rawExtraField);
8473
8446
  directoryRecord.writeBytes(rawCentralExtraField);
8474
8447
  directoryRecord.writeBytes(rawComment);
@@ -9045,7 +9018,7 @@
9045
9018
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9046
9019
  */
9047
9020
 
9048
- const VERSION = "2.18.2";
9021
+ const VERSION = "2.19.0";
9049
9022
 
9050
9023
  /*
9051
9024
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.