@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
package/dist/zip-core.js CHANGED
@@ -489,6 +489,39 @@
489
489
  return new DataView(array.buffer, array.byteOffset, array.byteLength);
490
490
  }
491
491
 
492
+ /*
493
+ Copyright (c) 2026 Gildas Lormeau. All rights reserved.
494
+
495
+ Redistribution and use in source and binary forms, with or without
496
+ modification, are permitted provided that the following conditions are met:
497
+
498
+ 1. Redistributions of source code must retain the above copyright notice,
499
+ this list of conditions and the following disclaimer.
500
+
501
+ 2. Redistributions in binary form must reproduce the above copyright
502
+ notice, this list of conditions and the following disclaimer in
503
+ the documentation and/or other materials provided with the distribution.
504
+
505
+ 3. The names of the authors may not be used to endorse or promote products
506
+ derived from this software without specific prior written permission.
507
+
508
+ THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
509
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
510
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
511
+ INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
512
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
513
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
514
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
515
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
516
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
517
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
518
+ */
519
+
520
+
521
+ function isErrorObject(error) {
522
+ return Boolean(error) && typeof error == "object";
523
+ }
524
+
492
525
  /*
493
526
  Copyright (c) 2022 Gildas Lormeau. All rights reserved.
494
527
 
@@ -2756,7 +2789,9 @@
2756
2789
 
2757
2790
  class CodecWorker {
2758
2791
 
2759
- constructor(workerData, { readable, writable }, { options, config, streamOptions, useWebWorkers, transferStreams, workerURI, createWorker }, onTaskFinished) {
2792
+ constructor(workerData, { readable, writable }, workerOptions, onTaskFinished) {
2793
+ const { options, config, streamOptions, useWebWorkers, transferStreams, workerURI } = workerOptions;
2794
+ let { createWorker } = workerOptions;
2760
2795
  const { signal } = streamOptions;
2761
2796
  if (createWorkerFailed) {
2762
2797
  createWorker = UNDEFINED_VALUE;
@@ -2769,6 +2804,7 @@
2769
2804
  .pipeThrough(new ProgressWatcherStream(streamOptions), { signal }),
2770
2805
  writable,
2771
2806
  options: Object.assign({}, options),
2807
+ workerOptions,
2772
2808
  workerURI,
2773
2809
  createWorker,
2774
2810
  transferStreams,
@@ -2850,7 +2886,7 @@
2850
2886
  };
2851
2887
  }
2852
2888
 
2853
- async function runWorker$1({ options, readable, writable, onTaskFinished }, config) {
2889
+ async function runWorker$1({ options, readable, writable, onTaskFinished, workerOptions }, config) {
2854
2890
  let codecStream, chunkStream;
2855
2891
  try {
2856
2892
  if (options.compressed && !options.format) {
@@ -2891,7 +2927,15 @@
2891
2927
  };
2892
2928
  } catch (error) {
2893
2929
  if (codecStream) {
2894
- error.outputSize = chunkStream ? chunkStream.outputSize : 0;
2930
+ const outputSize = chunkStream ? chunkStream.outputSize : 0;
2931
+ workerOptions.outputSize = outputSize;
2932
+ if (isErrorObject(error)) {
2933
+ try {
2934
+ error.outputSize = outputSize;
2935
+ } catch {
2936
+ // ignored
2937
+ }
2938
+ }
2895
2939
  }
2896
2940
  throw error;
2897
2941
  } finally {
@@ -3001,8 +3045,14 @@
3001
3045
  const result = new Promise((resolve, reject) => {
3002
3046
  resolveResult = resolve;
3003
3047
  rejectResult = error => {
3004
- if (error && error.outputSize === UNDEFINED_VALUE) {
3005
- error.outputSize = workerData.outputSize;
3048
+ const { outputSize, workerOptions } = workerData;
3049
+ workerOptions.outputSize = outputSize;
3050
+ if (isErrorObject(error) && error.outputSize === UNDEFINED_VALUE) {
3051
+ try {
3052
+ error.outputSize = outputSize;
3053
+ } catch {
3054
+ // ignored
3055
+ }
3006
3056
  }
3007
3057
  reject(error);
3008
3058
  };
@@ -3271,21 +3321,15 @@
3271
3321
  }
3272
3322
 
3273
3323
  async function onMessage({ data }, workerData) {
3274
- const { type, value, messageId, result, error } = data;
3324
+ const { type, value, messageId, result, error, errorValue } = data;
3275
3325
  const { reader, writer, resolveResult, rejectResult, onTaskFinished, generation } = workerData;
3276
3326
  const stale = () => workerData.generation != generation;
3277
3327
  try {
3278
3328
  if (error) {
3279
- const { message, stack, code, name, outputSize, cause, codecImportFailed } = error;
3280
- const responseError = new Error(message);
3281
- Object.assign(responseError, { stack, code, name, outputSize });
3282
- if (cause) {
3283
- responseError.cause = Object.assign(new Error(cause.message), { name: cause.name });
3284
- }
3285
- if (codecImportFailed) {
3286
- responseError.codecImportFailed = true;
3329
+ if (error.outputSize !== UNDEFINED_VALUE) {
3330
+ workerData.outputSize = error.outputSize;
3287
3331
  }
3288
- close(responseError);
3332
+ fail(getResponseError(error, errorValue));
3289
3333
  } else {
3290
3334
  if (type == MESSAGE_PULL) {
3291
3335
  const { value, done } = await reader.read();
@@ -3303,32 +3347,73 @@
3303
3347
  }
3304
3348
  }
3305
3349
  if (type == MESSAGE_CLOSE) {
3306
- close(null, result);
3350
+ succeed(result);
3307
3351
  }
3308
3352
  }
3309
3353
  } catch (error) {
3310
3354
  if (!stale()) {
3311
3355
  terminateWorker$1(workerData);
3312
- close(error);
3356
+ fail(error);
3313
3357
  }
3314
3358
  }
3315
3359
 
3316
- function close(error, result) {
3317
- if (stale()) {
3318
- return;
3319
- }
3320
- if (error) {
3360
+ function fail(error) {
3361
+ if (!stale()) {
3321
3362
  rejectResult(error);
3322
- } else {
3363
+ releaseWriter();
3364
+ if (!(isErrorObject(error) && error.codecImportFailed)) {
3365
+ onTaskFinished();
3366
+ }
3367
+ }
3368
+ }
3369
+
3370
+ function succeed(result) {
3371
+ if (!stale()) {
3323
3372
  resolveResult(result);
3373
+ releaseWriter();
3374
+ onTaskFinished();
3324
3375
  }
3376
+ }
3377
+
3378
+ function releaseWriter() {
3325
3379
  if (writer) {
3326
3380
  writer.releaseLock();
3327
3381
  }
3328
- if (!(error && error.codecImportFailed)) {
3329
- onTaskFinished();
3382
+ }
3383
+ }
3384
+
3385
+ function getResponseError(errorData, errorValue) {
3386
+ const { message, stack, code, name, outputSize, cause, codecImportFailed } = errorData;
3387
+ let responseError;
3388
+ if (errorValue) {
3389
+ responseError = errorValue.value;
3390
+ } else {
3391
+ responseError = Object.assign(new Error(message), { stack, code, name });
3392
+ if (cause) {
3393
+ responseError.cause = Object.assign(new Error(cause.message), { name: cause.name });
3394
+ }
3395
+ }
3396
+ if (isErrorObject(responseError)) {
3397
+ try {
3398
+ if (outputSize !== UNDEFINED_VALUE) {
3399
+ responseError.outputSize = outputSize;
3400
+ }
3401
+ if (codecImportFailed) {
3402
+ responseError.codecImportFailed = true;
3403
+ }
3404
+ if (errorValue) {
3405
+ if (responseError.name !== name) {
3406
+ responseError.name = name;
3407
+ }
3408
+ if (responseError.code !== code) {
3409
+ responseError.code = code;
3410
+ }
3411
+ }
3412
+ } catch {
3413
+ // ignored
3330
3414
  }
3331
3415
  }
3416
+ return responseError;
3332
3417
  }
3333
3418
 
3334
3419
  /*
@@ -5590,7 +5675,7 @@
5590
5675
  readRanges
5591
5676
  });
5592
5677
  }
5593
- let writable, abortError;
5678
+ let writable, abortError, aborted;
5594
5679
  try {
5595
5680
  if (!checkOverlappingEntryOnly) {
5596
5681
  if (checkPasswordOnly) {
@@ -5606,18 +5691,22 @@
5606
5691
  writer.size += writtenSize;
5607
5692
  }
5608
5693
  } catch (error) {
5609
- if (error.outputSize !== UNDEFINED_VALUE) {
5694
+ const { outputSize: failedOutputSize } = workerOptions;
5695
+ if (failedOutputSize !== UNDEFINED_VALUE) {
5696
+ writer.size += failedOutputSize;
5697
+ } else if (isErrorObject(error) && error.outputSize !== UNDEFINED_VALUE) {
5610
5698
  writer.size += error.outputSize;
5611
5699
  }
5612
- if (!checkPasswordOnly || error.message != ERR_ABORT_CHECK_PASSWORD) {
5700
+ if (!checkPasswordOnly || !isErrorObject(error) || error.message != ERR_ABORT_CHECK_PASSWORD) {
5613
5701
  abortError = error;
5702
+ aborted = true;
5614
5703
  throw error;
5615
5704
  }
5616
5705
  } finally {
5617
5706
  const preventClose = !ownsWritable(writer) && getOptionValue$1(zipEntry, options, OPTION_PREVENT_CLOSE);
5618
5707
  if (!preventClose && writable && !writable.locked) {
5619
5708
  const writableWriter = writable.getWriter();
5620
- if (abortError) {
5709
+ if (aborted) {
5621
5710
  try {
5622
5711
  await writableWriter.abort(abortError);
5623
5712
  } catch {
@@ -6677,7 +6766,7 @@
6677
6766
  await Promise.allSettled(Array.from(pendingAddFileCalls));
6678
6767
  }
6679
6768
  await Promise.allSettled(zipWriter.pendingErrors.map(watcher => watcher.recorded));
6680
- const unobservedWatchers = zipWriter.pendingErrors.filter(watcher => watcher.error && !watcher.observed);
6769
+ const unobservedWatchers = zipWriter.pendingErrors.filter(watcher => watcher.failed && !watcher.observed);
6681
6770
  if (unobservedWatchers.length) {
6682
6771
  const unobservedErrors = unobservedWatchers.map(watcher => watcher.error);
6683
6772
  unobservedWatchers.forEach(watcher => watcher.observed = true);
@@ -6786,7 +6875,8 @@
6786
6875
  const watchedPromise = new WatchedPromise((resolve, reject) => Promise.prototype.then.call(promise, resolve, reject));
6787
6876
  const watcher = {};
6788
6877
  watchedPromise.watcher = watcher;
6789
- watcher.recorded = Promise.prototype.then.call(watchedPromise, UNDEFINED_VALUE, error => watcher.error = error);
6878
+ watcher.recorded = Promise.prototype.then.call(watchedPromise, UNDEFINED_VALUE,
6879
+ error => Object.assign(watcher, { failed: true, error }));
6790
6880
  zipWriter.pendingErrors.push(watcher);
6791
6881
  return watchedPromise;
6792
6882
  }
@@ -7702,7 +7792,10 @@
7702
7792
  throw new Error(ERR_UNSUPPORTED_FORMAT);
7703
7793
  }
7704
7794
  } catch (error) {
7705
- if (error.outputSize !== UNDEFINED_VALUE) {
7795
+ const { outputSize: failedOutputSize } = workerOptions;
7796
+ if (failedOutputSize !== UNDEFINED_VALUE) {
7797
+ writer.size += failedOutputSize;
7798
+ } else if (isErrorObject(error) && error.outputSize !== UNDEFINED_VALUE) {
7706
7799
  writer.size += error.outputSize;
7707
7800
  }
7708
7801
  throw error;
@@ -8867,7 +8960,7 @@
8867
8960
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8868
8961
  */
8869
8962
 
8870
- const VERSION = "2.12.0";
8963
+ const VERSION = "2.13.0";
8871
8964
 
8872
8965
  /*
8873
8966
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.