@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
package/dist/zip-core.js CHANGED
@@ -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));
@@ -5096,17 +5065,6 @@
5096
5065
  if (filename === UNDEFINED_VALUE) {
5097
5066
  filename = decodeText(rawFilename, rawFilenameEncoding);
5098
5067
  }
5099
- if (normalizeFilename) {
5100
- const normalizedFilename = normalizeFilename(filename);
5101
- if (normalizedFilename !== UNDEFINED_VALUE) {
5102
- filename = normalizedFilename;
5103
- }
5104
- }
5105
- if (isUnsafeFilename(filename, filenameValidation)) {
5106
- const error = new Error(ERR_UNSAFE_FILENAME);
5107
- error.filename = filename;
5108
- throw error;
5109
- }
5110
5068
  let comment = decode(rawComment, rawCommentEncoding, TEXT_TYPE_COMMENT);
5111
5069
  if (comment === UNDEFINED_VALUE) {
5112
5070
  comment = decodeText(rawComment, rawCommentEncoding);
@@ -5134,7 +5092,20 @@
5134
5092
  filename,
5135
5093
  comment
5136
5094
  });
5137
- if (readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6)) {
5095
+ const malformedExtraField = readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6);
5096
+ filename = fileEntry.filename;
5097
+ if (normalizeFilename) {
5098
+ const normalizedFilename = normalizeFilename(filename);
5099
+ if (normalizedFilename !== UNDEFINED_VALUE) {
5100
+ filename = fileEntry.filename = normalizedFilename;
5101
+ }
5102
+ }
5103
+ if (isUnsafeFilename(filename, filenameValidation)) {
5104
+ const error = new Error(ERR_UNSAFE_FILENAME);
5105
+ error.filename = filename;
5106
+ throw error;
5107
+ }
5108
+ if (malformedExtraField) {
5138
5109
  addWarning(warnings, WARNING_MALFORMED_EXTRA_FIELD, filename);
5139
5110
  }
5140
5111
  fileEntry.offset += prependedDataLength;
@@ -5538,7 +5509,6 @@
5538
5509
  encrypted,
5539
5510
  useWebWorkers: getOptionValue$1(zipEntry, options, OPTION_USE_WEB_WORKERS),
5540
5511
  useCompressionStream,
5541
- transferStreams: getOptionValue$1(zipEntry, options, OPTION_TRANSFER_STREAMS),
5542
5512
  deflate64,
5543
5513
  format: registeredCodec ? registeredCodec.format : UNDEFINED_VALUE,
5544
5514
  codecURI: registeredCodec ? registeredCodec.codecURI : UNDEFINED_VALUE,
@@ -5768,19 +5738,17 @@
5768
5738
  readExtraFieldNTFS(extraFieldNTFS, directory);
5769
5739
  directory.extraFieldNTFS = extraFieldNTFS;
5770
5740
  }
5771
- const extraFieldUnix = extraField.get(EXTRAFIELD_TYPE_UNIX);
5741
+ const extraFieldInfoZip = extraField.get(EXTRAFIELD_TYPE_INFOZIP);
5772
5742
  let unixIdsRead;
5743
+ if (extraFieldInfoZip) {
5744
+ unixIdsRead = readExtraFieldUnix(extraFieldInfoZip, directory, true);
5745
+ directory.extraFieldInfoZip = extraFieldInfoZip;
5746
+ }
5747
+ const extraFieldUnix = extraField.get(EXTRAFIELD_TYPE_UNIX);
5773
5748
  if (extraFieldUnix) {
5774
- unixIdsRead = readExtraFieldUnix(extraFieldUnix, directory, false);
5749
+ readExtraFieldUnix(extraFieldUnix, unixIdsRead ? {} : directory, false);
5775
5750
  directory.extraFieldUnix = extraFieldUnix;
5776
5751
  }
5777
- if (!unixIdsRead) {
5778
- const extraFieldInfoZip = extraField.get(EXTRAFIELD_TYPE_INFOZIP);
5779
- if (extraFieldInfoZip) {
5780
- readExtraFieldUnix(extraFieldInfoZip, directory, true);
5781
- directory.extraFieldInfoZip = extraFieldInfoZip;
5782
- }
5783
- }
5784
5752
  const extraFieldExtendedTimestamp = extraField.get(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
5785
5753
  if (extraFieldExtendedTimestamp) {
5786
5754
  readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory, localDirectory);
@@ -6667,6 +6635,7 @@
6667
6635
  rawExtraFieldExtendedTimestamp: EMPTY_UINT8_ARRAY,
6668
6636
  rawExtraFieldNTFS: EMPTY_UINT8_ARRAY,
6669
6637
  rawExtraFieldUnix: EMPTY_UINT8_ARRAY,
6638
+ rawCentralExtraFieldUnix: EMPTY_UINT8_ARRAY,
6670
6639
  rawExtraField,
6671
6640
  rawCentralExtraField: EMPTY_UINT8_ARRAY,
6672
6641
  headerArray,
@@ -7235,7 +7204,6 @@
7235
7204
  const ntfsTimestamp = getOptionValue(zipWriter, options, OPTION_NTFS_TIMESTAMP);
7236
7205
  const keepOrder = getOptionValue(zipWriter, options, OPTION_KEEP_ORDER, true);
7237
7206
  const useWebWorkers = getOptionValue(zipWriter, options, OPTION_USE_WEB_WORKERS);
7238
- const transferStreams = getOptionValue(zipWriter, options, OPTION_TRANSFER_STREAMS);
7239
7207
  const bufferedWrite = getOptionValue(zipWriter, options, OPTION_BUFFERED_WRITE);
7240
7208
  const createTempStream = getFunctionOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
7241
7209
  const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, true);
@@ -7301,7 +7269,6 @@
7301
7269
  ntfsTimestamp,
7302
7270
  keepOrder,
7303
7271
  useWebWorkers,
7304
- transferStreams,
7305
7272
  bufferedWrite,
7306
7273
  createTempStream,
7307
7274
  dataDescriptorSignature,
@@ -7360,7 +7327,7 @@
7360
7327
  if (reader) {
7361
7328
  reader = new GenericReader(reader);
7362
7329
  await initStream(reader);
7363
- if (!reader.readable && !reader.readUint8Array) {
7330
+ if (!reader.readUint8Array && !reader.readable) {
7364
7331
  throw new Error(ERR_INVALID_READER);
7365
7332
  }
7366
7333
  ({ size: contentSize } = reader);
@@ -7623,6 +7590,7 @@
7623
7590
  extraFieldExtendedTimestampTime,
7624
7591
  rawExtraFieldNTFS,
7625
7592
  rawExtraFieldUnix,
7593
+ rawCentralExtraFieldUnix,
7626
7594
  rawExtraFieldAES,
7627
7595
  } = headerInfo;
7628
7596
  const { dataDescriptorArray } = dataDescriptorInfo;
@@ -7647,7 +7615,6 @@
7647
7615
  rawExtraField,
7648
7616
  rawCentralExtraField,
7649
7617
  useWebWorkers,
7650
- transferStreams,
7651
7618
  onstart,
7652
7619
  onprogress,
7653
7620
  onend,
@@ -7689,6 +7656,7 @@
7689
7656
  rawExtraFieldExtendedTimestamp,
7690
7657
  rawExtraFieldNTFS,
7691
7658
  rawExtraFieldUnix,
7659
+ rawCentralExtraFieldUnix,
7692
7660
  rawExtraFieldAES,
7693
7661
  rawExtraField,
7694
7662
  rawCentralExtraField,
@@ -7735,7 +7703,6 @@
7735
7703
  encrypted: encrypted && !passThroughEncryption,
7736
7704
  useWebWorkers,
7737
7705
  useCompressionStream,
7738
- transferStreams,
7739
7706
  format,
7740
7707
  codecURI,
7741
7708
  compressionMethod
@@ -7913,6 +7880,7 @@
7913
7880
  rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = EMPTY_UINT8_ARRAY;
7914
7881
  }
7915
7882
  let rawExtraFieldUnix;
7883
+ let rawCentralExtraFieldUnix;
7916
7884
  try {
7917
7885
  const { uid, gid, unixExtraFieldType } = options;
7918
7886
  if (unixExtraFieldType == INFOZIP_EXTRA_FIELD_TYPE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
@@ -7927,7 +7895,7 @@
7927
7895
  extraFieldUnix.writeBytes(uidBytes);
7928
7896
  extraFieldUnix.writeUint8(gidBytes.length);
7929
7897
  extraFieldUnix.writeBytes(gidBytes);
7930
- rawExtraFieldUnix = extraFieldUnix.array;
7898
+ rawExtraFieldUnix = rawCentralExtraFieldUnix = extraFieldUnix.array;
7931
7899
  } else if (unixExtraFieldType == UNIX_EXTRA_FIELD_TYPE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
7932
7900
  const extraFieldUnix = createRecordWriter(8);
7933
7901
  extraFieldUnix.writeUint16(EXTRAFIELD_TYPE_UNIX);
@@ -7935,11 +7903,15 @@
7935
7903
  extraFieldUnix.writeUint16((uid === UNDEFINED_VALUE ? 0 : uid) & MAX_16_BITS);
7936
7904
  extraFieldUnix.writeUint16((gid === UNDEFINED_VALUE ? 0 : gid) & MAX_16_BITS);
7937
7905
  rawExtraFieldUnix = extraFieldUnix.array;
7906
+ const centralExtraFieldUnix = createRecordWriter(4);
7907
+ centralExtraFieldUnix.writeUint16(EXTRAFIELD_TYPE_UNIX);
7908
+ centralExtraFieldUnix.writeUint16(0);
7909
+ rawCentralExtraFieldUnix = centralExtraFieldUnix.array;
7938
7910
  } else {
7939
- rawExtraFieldUnix = EMPTY_UINT8_ARRAY;
7911
+ rawExtraFieldUnix = rawCentralExtraFieldUnix = EMPTY_UINT8_ARRAY;
7940
7912
  }
7941
7913
  } catch {
7942
- rawExtraFieldUnix = EMPTY_UINT8_ARRAY;
7914
+ rawExtraFieldUnix = rawCentralExtraFieldUnix = EMPTY_UINT8_ARRAY;
7943
7915
  }
7944
7916
  if (compressionMethod === UNDEFINED_VALUE) {
7945
7917
  compressionMethod = compressed ? COMPRESSION_METHOD_DEFLATE : COMPRESSION_METHOD_STORE;
@@ -8031,6 +8003,7 @@
8031
8003
  rawExtraFieldExtendedTimestamp,
8032
8004
  rawExtraFieldNTFS,
8033
8005
  rawExtraFieldUnix,
8006
+ rawCentralExtraFieldUnix,
8034
8007
  rawExtraFieldAES,
8035
8008
  extraFieldLength
8036
8009
  };
@@ -8206,7 +8179,7 @@
8206
8179
  rawExtraFieldAES,
8207
8180
  rawComment,
8208
8181
  rawExtraFieldNTFS,
8209
- rawExtraFieldUnix,
8182
+ rawCentralExtraFieldUnix,
8210
8183
  rawExtraField,
8211
8184
  rawCentralExtraField,
8212
8185
  extraFieldExtendedTimestampFlag,
@@ -8268,7 +8241,7 @@
8268
8241
  rawExtraFieldZip64,
8269
8242
  rawExtraFieldAES,
8270
8243
  rawExtraFieldNTFS,
8271
- rawExtraFieldUnix,
8244
+ rawCentralExtraFieldUnix,
8272
8245
  rawExtraFieldTimestamp,
8273
8246
  rawExtraField,
8274
8247
  rawCentralExtraField);
@@ -8297,7 +8270,7 @@
8297
8270
  rawExtraFieldAES,
8298
8271
  rawExtraFieldExtendedTimestamp,
8299
8272
  rawExtraFieldNTFS,
8300
- rawExtraFieldUnix,
8273
+ rawCentralExtraFieldUnix,
8301
8274
  rawExtraField,
8302
8275
  rawCentralExtraField,
8303
8276
  rawComment,
@@ -8314,7 +8287,7 @@
8314
8287
  uncompressedSize,
8315
8288
  compressedSize
8316
8289
  } = fileEntry;
8317
- const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField, rawCentralExtraField);
8290
+ const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawCentralExtraFieldUnix, rawExtraField, rawCentralExtraField);
8318
8291
  const directoryRecordLength = CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
8319
8292
  if (exceedsAvailableSize(writer, offset + directoryRecordLength - directoryDiskOffset)) {
8320
8293
  await writeData(writer, directoryArray.slice(directoryDiskOffset, offset));
@@ -8350,7 +8323,7 @@
8350
8323
  directoryRecord.writeBytes(rawExtraFieldAES);
8351
8324
  directoryRecord.writeBytes(rawExtraFieldExtendedTimestamp);
8352
8325
  directoryRecord.writeBytes(rawExtraFieldNTFS);
8353
- directoryRecord.writeBytes(rawExtraFieldUnix);
8326
+ directoryRecord.writeBytes(rawCentralExtraFieldUnix);
8354
8327
  directoryRecord.writeBytes(rawExtraField);
8355
8328
  directoryRecord.writeBytes(rawCentralExtraField);
8356
8329
  directoryRecord.writeBytes(rawComment);
@@ -8927,7 +8900,7 @@
8927
8900
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8928
8901
  */
8929
8902
 
8930
- const VERSION = "2.18.2";
8903
+ const VERSION = "2.19.0";
8931
8904
 
8932
8905
  /*
8933
8906
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.