@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
@@ -123,6 +123,7 @@ import { decodeText } from "./util/decode-text.js";
123
123
  import { getDataView } from "./util/array.js";
124
124
  import { addWarning } from "./util/warnings.js";
125
125
  import { toCompatibleReadable, streamToBlob } from "./util/compatible-streams.js";
126
+ import { isErrorObject } from "./util/error.js";
126
127
  import { Crc32 } from "./streams/codecs/crc32.js";
127
128
  import {
128
129
  PROPERTY_NAME_RAW_FILENAME,
@@ -1012,7 +1013,7 @@ class ZipEntry {
1012
1013
  readRanges
1013
1014
  });
1014
1015
  }
1015
- let writable, abortError;
1016
+ let writable, abortError, aborted;
1016
1017
  try {
1017
1018
  if (!checkOverlappingEntryOnly) {
1018
1019
  if (checkPasswordOnly) {
@@ -1028,18 +1029,22 @@ class ZipEntry {
1028
1029
  writer.size += writtenSize;
1029
1030
  }
1030
1031
  } catch (error) {
1031
- if (error.outputSize !== UNDEFINED_VALUE) {
1032
+ const { outputSize: failedOutputSize } = workerOptions;
1033
+ if (failedOutputSize !== UNDEFINED_VALUE) {
1034
+ writer.size += failedOutputSize;
1035
+ } else if (isErrorObject(error) && error.outputSize !== UNDEFINED_VALUE) {
1032
1036
  writer.size += error.outputSize;
1033
1037
  }
1034
- if (!checkPasswordOnly || error.message != ERR_ABORT_CHECK_PASSWORD) {
1038
+ if (!checkPasswordOnly || !isErrorObject(error) || error.message != ERR_ABORT_CHECK_PASSWORD) {
1035
1039
  abortError = error;
1040
+ aborted = true;
1036
1041
  throw error;
1037
1042
  }
1038
1043
  } finally {
1039
1044
  const preventClose = !ownsWritable(writer) && getOptionValue(zipEntry, options, OPTION_PREVENT_CLOSE);
1040
1045
  if (!preventClose && writable && !writable.locked) {
1041
1046
  const writableWriter = writable.getWriter();
1042
- if (abortError) {
1047
+ if (aborted) {
1043
1048
  try {
1044
1049
  await writableWriter.abort(abortError);
1045
1050
  } catch {
@@ -178,6 +178,7 @@ import { encodeText } from "./util/encode-text.js";
178
178
  import { concat, getDataView } from "./util/array.js";
179
179
  import { addWarning } from "./util/warnings.js";
180
180
  import { toCompatibleReadable, streamToBlob } from "./util/compatible-streams.js";
181
+ import { isErrorObject } from "./util/error.js";
181
182
  import {
182
183
  PROPERTY_NAME_LAST_MODIFICATION_DATE,
183
184
  PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE,
@@ -512,7 +513,7 @@ class ZipWriter {
512
513
  await Promise.allSettled(Array.from(pendingAddFileCalls));
513
514
  }
514
515
  await Promise.allSettled(zipWriter.pendingErrors.map(watcher => watcher.recorded));
515
- const unobservedWatchers = zipWriter.pendingErrors.filter(watcher => watcher.error && !watcher.observed);
516
+ const unobservedWatchers = zipWriter.pendingErrors.filter(watcher => watcher.failed && !watcher.observed);
516
517
  if (unobservedWatchers.length) {
517
518
  const unobservedErrors = unobservedWatchers.map(watcher => watcher.error);
518
519
  unobservedWatchers.forEach(watcher => watcher.observed = true);
@@ -621,7 +622,8 @@ function watchPromiseError(zipWriter, promise) {
621
622
  const watchedPromise = new WatchedPromise((resolve, reject) => Promise.prototype.then.call(promise, resolve, reject));
622
623
  const watcher = {};
623
624
  watchedPromise.watcher = watcher;
624
- watcher.recorded = Promise.prototype.then.call(watchedPromise, UNDEFINED_VALUE, error => watcher.error = error);
625
+ watcher.recorded = Promise.prototype.then.call(watchedPromise, UNDEFINED_VALUE,
626
+ error => Object.assign(watcher, { failed: true, error }));
625
627
  zipWriter.pendingErrors.push(watcher);
626
628
  return watchedPromise;
627
629
  }
@@ -1681,7 +1683,10 @@ async function createFileEntry(reader, writer, { diskNumberStart, lockFileEntry
1681
1683
  throw new Error(ERR_UNSUPPORTED_FORMAT);
1682
1684
  }
1683
1685
  } catch (error) {
1684
- if (error.outputSize !== UNDEFINED_VALUE) {
1686
+ const { outputSize: failedOutputSize } = workerOptions;
1687
+ if (failedOutputSize !== UNDEFINED_VALUE) {
1688
+ writer.size += failedOutputSize;
1689
+ } else if (isErrorObject(error) && error.outputSize !== UNDEFINED_VALUE) {
1685
1690
  writer.size += error.outputSize;
1686
1691
  }
1687
1692
  throw error;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A JavaScript library to zip and unzip files in the browser, Deno and Node.js",
4
4
  "author": "Gildas Lormeau",
5
5
  "license": "BSD-3-Clause",
6
- "version": "2.12.0",
6
+ "version": "2.13.0",
7
7
  "type": "module",
8
8
  "keywords": [
9
9
  "zip",
@@ -1,3 +1,3 @@
1
- const WORKER_MESSAGE_PROPERTY_NAMES = ["baseURI", "cause", "checkAuthenticationCode", "checkCrc32", "checkPasswordOnly", "chunkSize", "code", "codecImportFailed", "codecType", "codecURI", "compressed", "compressionMethod", "computeCrc32", "config", "crc32", "deflate64", "done", "encrypted", "encryptionStrength", "error", "format", "inputSize", "level", "message", "messageId", "name", "options", "outputSize", "password", "passwordVerification", "rawBitFlag", "rawPassword", "readable", "result", "stack", "transferStreams", "type", "useCompressionStream", "useWebWorkers", "value", "wasmURI", "workerStartupTimeout", "writable", "zipCrypto"];
1
+ const WORKER_MESSAGE_PROPERTY_NAMES = ["baseURI", "cause", "checkAuthenticationCode", "checkCrc32", "checkPasswordOnly", "chunkSize", "code", "codecImportFailed", "codecType", "codecURI", "compressed", "compressionMethod", "computeCrc32", "config", "crc32", "deflate64", "done", "encrypted", "encryptionStrength", "error", "errorValue", "format", "inputSize", "level", "message", "messageId", "name", "options", "outputSize", "password", "passwordVerification", "rawBitFlag", "rawPassword", "readable", "result", "stack", "transferStreams", "type", "useCompressionStream", "useWebWorkers", "value", "wasmURI", "workerStartupTimeout", "writable", "zipCrypto"];
2
2
 
3
3
  export { WORKER_MESSAGE_PROPERTY_NAMES };