@zip.js/zip.js 2.12.0 → 2.13.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 (41) hide show
  1. package/deno.json +1 -1
  2. package/dist/zip-core-external.js +126 -33
  3. package/dist/zip-core-external.min.js +1 -1
  4. package/dist/zip-core.js +126 -33
  5. package/dist/zip-core.min.js +1 -1
  6. package/dist/zip-fs-core-external.js +127 -34
  7. package/dist/zip-fs-core-external.min.js +1 -1
  8. package/dist/zip-fs-core.js +127 -34
  9. package/dist/zip-fs-core.min.js +1 -1
  10. package/dist/zip-fs-external.js +127 -34
  11. package/dist/zip-fs-external.min.js +1 -1
  12. package/dist/zip-fs-native.js +129 -36
  13. package/dist/zip-fs-native.min.js +1 -1
  14. package/dist/zip-fs.js +128 -35
  15. package/dist/zip-fs.min.js +1 -1
  16. package/dist/zip-legacy.js +128 -35
  17. package/dist/zip-legacy.min.js +1 -1
  18. package/dist/zip-native.js +128 -35
  19. package/dist/zip-native.min.js +1 -1
  20. package/dist/zip-web-worker-native.js +1 -1
  21. package/dist/zip-web-worker.js +1 -1
  22. package/dist/zip.js +127 -34
  23. package/dist/zip.min.js +1 -1
  24. package/index-native.cjs +129 -36
  25. package/index-native.min.js +1 -1
  26. package/index.cjs +128 -35
  27. package/index.d.cts +13 -7
  28. package/index.d.ts +13 -7
  29. package/index.min.js +1 -1
  30. package/lib/core/codec-worker-web.js +64 -22
  31. package/lib/core/codec-worker.js +15 -3
  32. package/lib/core/util/error.js +35 -0
  33. package/lib/core/version.js +1 -1
  34. package/lib/core/web-worker-base.js +43 -7
  35. package/lib/core/web-worker-inline-native.js +1 -1
  36. package/lib/core/web-worker-inline-wasm.js +1 -1
  37. package/lib/core/zip-fs.js +2 -1
  38. package/lib/core/zip-reader.js +9 -4
  39. package/lib/core/zip-writer.js +8 -3
  40. package/package.json +1 -1
  41. package/worker-message-property-names.js +1 -1
@@ -516,6 +516,39 @@ function getDataView(array) {
516
516
  return new DataView(array.buffer, array.byteOffset, array.byteLength);
517
517
  }
518
518
 
519
+ /*
520
+ Copyright (c) 2026 Gildas Lormeau. All rights reserved.
521
+
522
+ Redistribution and use in source and binary forms, with or without
523
+ modification, are permitted provided that the following conditions are met:
524
+
525
+ 1. Redistributions of source code must retain the above copyright notice,
526
+ this list of conditions and the following disclaimer.
527
+
528
+ 2. Redistributions in binary form must reproduce the above copyright
529
+ notice, this list of conditions and the following disclaimer in
530
+ the documentation and/or other materials provided with the distribution.
531
+
532
+ 3. The names of the authors may not be used to endorse or promote products
533
+ derived from this software without specific prior written permission.
534
+
535
+ THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
536
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
537
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
538
+ INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
539
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
540
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
541
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
542
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
543
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
544
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
545
+ */
546
+
547
+
548
+ function isErrorObject(error) {
549
+ return Boolean(error) && typeof error == "object";
550
+ }
551
+
519
552
  /*
520
553
  Copyright (c) 2022 Gildas Lormeau. All rights reserved.
521
554
 
@@ -2787,7 +2820,9 @@ function disableWebWorker(workerData) {
2787
2820
 
2788
2821
  class CodecWorker {
2789
2822
 
2790
- constructor(workerData, { readable, writable }, { options, config, streamOptions, useWebWorkers, transferStreams, workerURI, createWorker }, onTaskFinished) {
2823
+ constructor(workerData, { readable, writable }, workerOptions, onTaskFinished) {
2824
+ const { options, config, streamOptions, useWebWorkers, transferStreams, workerURI } = workerOptions;
2825
+ let { createWorker } = workerOptions;
2791
2826
  const { signal } = streamOptions;
2792
2827
  if (createWorkerFailed) {
2793
2828
  createWorker = UNDEFINED_VALUE;
@@ -2800,6 +2835,7 @@ class CodecWorker {
2800
2835
  .pipeThrough(new ProgressWatcherStream(streamOptions), { signal }),
2801
2836
  writable,
2802
2837
  options: Object.assign({}, options),
2838
+ workerOptions,
2803
2839
  workerURI,
2804
2840
  createWorker,
2805
2841
  transferStreams,
@@ -2881,7 +2917,7 @@ function createWorkerInterface(workerData, config) {
2881
2917
  };
2882
2918
  }
2883
2919
 
2884
- async function runWorker$1({ options, readable, writable, onTaskFinished }, config) {
2920
+ async function runWorker$1({ options, readable, writable, onTaskFinished, workerOptions }, config) {
2885
2921
  let codecStream, chunkStream;
2886
2922
  try {
2887
2923
  if (options.compressed && !options.format) {
@@ -2922,7 +2958,15 @@ async function runWorker$1({ options, readable, writable, onTaskFinished }, conf
2922
2958
  };
2923
2959
  } catch (error) {
2924
2960
  if (codecStream) {
2925
- error.outputSize = chunkStream ? chunkStream.outputSize : 0;
2961
+ const outputSize = chunkStream ? chunkStream.outputSize : 0;
2962
+ workerOptions.outputSize = outputSize;
2963
+ if (isErrorObject(error)) {
2964
+ try {
2965
+ error.outputSize = outputSize;
2966
+ } catch {
2967
+ // ignored
2968
+ }
2969
+ }
2926
2970
  }
2927
2971
  throw error;
2928
2972
  } finally {
@@ -3032,8 +3076,14 @@ async function runWebWorker(workerData, config) {
3032
3076
  const result = new Promise((resolve, reject) => {
3033
3077
  resolveResult = resolve;
3034
3078
  rejectResult = error => {
3035
- if (error && error.outputSize === UNDEFINED_VALUE) {
3036
- error.outputSize = workerData.outputSize;
3079
+ const { outputSize, workerOptions } = workerData;
3080
+ workerOptions.outputSize = outputSize;
3081
+ if (isErrorObject(error) && error.outputSize === UNDEFINED_VALUE) {
3082
+ try {
3083
+ error.outputSize = outputSize;
3084
+ } catch {
3085
+ // ignored
3086
+ }
3037
3087
  }
3038
3088
  reject(error);
3039
3089
  };
@@ -3302,21 +3352,15 @@ function sendMessage(message, { worker, writer, transferStreams, workerAlive })
3302
3352
  }
3303
3353
 
3304
3354
  async function onMessage({ data }, workerData) {
3305
- const { type, value, messageId, result, error } = data;
3355
+ const { type, value, messageId, result, error, errorValue } = data;
3306
3356
  const { reader, writer, resolveResult, rejectResult, onTaskFinished, generation } = workerData;
3307
3357
  const stale = () => workerData.generation != generation;
3308
3358
  try {
3309
3359
  if (error) {
3310
- const { message, stack, code, name, outputSize, cause, codecImportFailed } = error;
3311
- const responseError = new Error(message);
3312
- Object.assign(responseError, { stack, code, name, outputSize });
3313
- if (cause) {
3314
- responseError.cause = Object.assign(new Error(cause.message), { name: cause.name });
3315
- }
3316
- if (codecImportFailed) {
3317
- responseError.codecImportFailed = true;
3360
+ if (error.outputSize !== UNDEFINED_VALUE) {
3361
+ workerData.outputSize = error.outputSize;
3318
3362
  }
3319
- close(responseError);
3363
+ fail(getResponseError(error, errorValue));
3320
3364
  } else {
3321
3365
  if (type == MESSAGE_PULL) {
3322
3366
  const { value, done } = await reader.read();
@@ -3334,32 +3378,73 @@ async function onMessage({ data }, workerData) {
3334
3378
  }
3335
3379
  }
3336
3380
  if (type == MESSAGE_CLOSE) {
3337
- close(null, result);
3381
+ succeed(result);
3338
3382
  }
3339
3383
  }
3340
3384
  } catch (error) {
3341
3385
  if (!stale()) {
3342
3386
  terminateWorker$1(workerData);
3343
- close(error);
3387
+ fail(error);
3344
3388
  }
3345
3389
  }
3346
3390
 
3347
- function close(error, result) {
3348
- if (stale()) {
3349
- return;
3350
- }
3351
- if (error) {
3391
+ function fail(error) {
3392
+ if (!stale()) {
3352
3393
  rejectResult(error);
3353
- } else {
3394
+ releaseWriter();
3395
+ if (!(isErrorObject(error) && error.codecImportFailed)) {
3396
+ onTaskFinished();
3397
+ }
3398
+ }
3399
+ }
3400
+
3401
+ function succeed(result) {
3402
+ if (!stale()) {
3354
3403
  resolveResult(result);
3404
+ releaseWriter();
3405
+ onTaskFinished();
3355
3406
  }
3407
+ }
3408
+
3409
+ function releaseWriter() {
3356
3410
  if (writer) {
3357
3411
  writer.releaseLock();
3358
3412
  }
3359
- if (!(error && error.codecImportFailed)) {
3360
- onTaskFinished();
3413
+ }
3414
+ }
3415
+
3416
+ function getResponseError(errorData, errorValue) {
3417
+ const { message, stack, code, name, outputSize, cause, codecImportFailed } = errorData;
3418
+ let responseError;
3419
+ if (errorValue) {
3420
+ responseError = errorValue.value;
3421
+ } else {
3422
+ responseError = Object.assign(new Error(message), { stack, code, name });
3423
+ if (cause) {
3424
+ responseError.cause = Object.assign(new Error(cause.message), { name: cause.name });
3361
3425
  }
3362
3426
  }
3427
+ if (isErrorObject(responseError)) {
3428
+ try {
3429
+ if (outputSize !== UNDEFINED_VALUE) {
3430
+ responseError.outputSize = outputSize;
3431
+ }
3432
+ if (codecImportFailed) {
3433
+ responseError.codecImportFailed = true;
3434
+ }
3435
+ if (errorValue) {
3436
+ if (responseError.name !== name) {
3437
+ responseError.name = name;
3438
+ }
3439
+ if (responseError.code !== code) {
3440
+ responseError.code = code;
3441
+ }
3442
+ }
3443
+ } catch {
3444
+ // ignored
3445
+ }
3446
+ }
3447
+ return responseError;
3363
3448
  }
3364
3449
 
3365
3450
  /*
@@ -5641,7 +5726,7 @@ let ZipEntry$1 = class ZipEntry {
5641
5726
  readRanges
5642
5727
  });
5643
5728
  }
5644
- let writable, abortError;
5729
+ let writable, abortError, aborted;
5645
5730
  try {
5646
5731
  if (!checkOverlappingEntryOnly) {
5647
5732
  if (checkPasswordOnly) {
@@ -5657,18 +5742,22 @@ let ZipEntry$1 = class ZipEntry {
5657
5742
  writer.size += writtenSize;
5658
5743
  }
5659
5744
  } catch (error) {
5660
- if (error.outputSize !== UNDEFINED_VALUE) {
5745
+ const { outputSize: failedOutputSize } = workerOptions;
5746
+ if (failedOutputSize !== UNDEFINED_VALUE) {
5747
+ writer.size += failedOutputSize;
5748
+ } else if (isErrorObject(error) && error.outputSize !== UNDEFINED_VALUE) {
5661
5749
  writer.size += error.outputSize;
5662
5750
  }
5663
- if (!checkPasswordOnly || error.message != ERR_ABORT_CHECK_PASSWORD) {
5751
+ if (!checkPasswordOnly || !isErrorObject(error) || error.message != ERR_ABORT_CHECK_PASSWORD) {
5664
5752
  abortError = error;
5753
+ aborted = true;
5665
5754
  throw error;
5666
5755
  }
5667
5756
  } finally {
5668
5757
  const preventClose = !ownsWritable(writer) && getOptionValue$1(zipEntry, options, OPTION_PREVENT_CLOSE);
5669
5758
  if (!preventClose && writable && !writable.locked) {
5670
5759
  const writableWriter = writable.getWriter();
5671
- if (abortError) {
5760
+ if (aborted) {
5672
5761
  try {
5673
5762
  await writableWriter.abort(abortError);
5674
5763
  } catch {
@@ -6728,7 +6817,7 @@ class ZipWriter {
6728
6817
  await Promise.allSettled(Array.from(pendingAddFileCalls));
6729
6818
  }
6730
6819
  await Promise.allSettled(zipWriter.pendingErrors.map(watcher => watcher.recorded));
6731
- const unobservedWatchers = zipWriter.pendingErrors.filter(watcher => watcher.error && !watcher.observed);
6820
+ const unobservedWatchers = zipWriter.pendingErrors.filter(watcher => watcher.failed && !watcher.observed);
6732
6821
  if (unobservedWatchers.length) {
6733
6822
  const unobservedErrors = unobservedWatchers.map(watcher => watcher.error);
6734
6823
  unobservedWatchers.forEach(watcher => watcher.observed = true);
@@ -6837,7 +6926,8 @@ function watchPromiseError(zipWriter, promise) {
6837
6926
  const watchedPromise = new WatchedPromise((resolve, reject) => Promise.prototype.then.call(promise, resolve, reject));
6838
6927
  const watcher = {};
6839
6928
  watchedPromise.watcher = watcher;
6840
- watcher.recorded = Promise.prototype.then.call(watchedPromise, UNDEFINED_VALUE, error => watcher.error = error);
6929
+ watcher.recorded = Promise.prototype.then.call(watchedPromise, UNDEFINED_VALUE,
6930
+ error => Object.assign(watcher, { failed: true, error }));
6841
6931
  zipWriter.pendingErrors.push(watcher);
6842
6932
  return watchedPromise;
6843
6933
  }
@@ -7851,7 +7941,10 @@ async function createFileEntry(reader, writer, { diskNumberStart, lockFileEntry
7851
7941
  throw new Error(ERR_UNSUPPORTED_FORMAT);
7852
7942
  }
7853
7943
  } catch (error) {
7854
- if (error.outputSize !== UNDEFINED_VALUE) {
7944
+ const { outputSize: failedOutputSize } = workerOptions;
7945
+ if (failedOutputSize !== UNDEFINED_VALUE) {
7946
+ writer.size += failedOutputSize;
7947
+ } else if (isErrorObject(error) && error.outputSize !== UNDEFINED_VALUE) {
7855
7948
  writer.size += error.outputSize;
7856
7949
  }
7857
7950
  throw error;
@@ -9016,7 +9109,7 @@ function formatSupported(StreamClass, format) {
9016
9109
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9017
9110
  */
9018
9111
 
9019
- const VERSION = "2.12.0";
9112
+ const VERSION = "2.13.0";
9020
9113
 
9021
9114
  /*
9022
9115
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -10023,7 +10116,7 @@ class ZipFileEntry extends ZipEntry {
10023
10116
  }));
10024
10117
  return true;
10025
10118
  } catch (error) {
10026
- if (error.message == ERR_INVALID_PASSWORD) {
10119
+ if (isErrorObject(error) && error.message == ERR_INVALID_PASSWORD) {
10027
10120
  return false;
10028
10121
  } else {
10029
10122
  throw error;