@zip.js/zip.js 2.13.0 → 2.13.1

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.
package/index-native.cjs CHANGED
@@ -3043,7 +3043,7 @@ async function runWebWorker(workerData, config) {
3043
3043
  rejectResult = error => {
3044
3044
  const { outputSize, workerOptions } = workerData;
3045
3045
  workerOptions.outputSize = outputSize;
3046
- if (isErrorObject(error) && error.outputSize === UNDEFINED_VALUE) {
3046
+ if (isErrorObject(error)) {
3047
3047
  try {
3048
3048
  error.outputSize = outputSize;
3049
3049
  } catch {
@@ -3057,12 +3057,14 @@ async function runWebWorker(workerData, config) {
3057
3057
  reader: null,
3058
3058
  writer: null,
3059
3059
  outputSize: 0,
3060
+ destinationFailed: false,
3061
+ destinationError: null,
3060
3062
  resolveResult,
3061
3063
  rejectResult,
3062
3064
  result
3063
3065
  });
3064
3066
  const { readable, options } = workerData;
3065
- const { writable, closed, abortPipe } = watchClosedStream(workerData.writable);
3067
+ const { writable, closed, abortPipe } = watchClosedStream(workerData.writable, workerData);
3066
3068
  let streamsTransferred;
3067
3069
  try {
3068
3070
  streamsTransferred = sendMessage({
@@ -3105,7 +3107,18 @@ async function runWebWorker(workerData, config) {
3105
3107
  } catch {
3106
3108
  // ignored
3107
3109
  }
3108
- throw error;
3110
+ const { outputSize, workerOptions, destinationFailed, destinationError } = workerData;
3111
+ workerOptions.outputSize = outputSize;
3112
+ const workerFailed = isErrorObject(error) && (error.codecImportFailed || error.workerStartupFailed);
3113
+ const reportedError = destinationFailed && !workerFailed ? destinationError : error;
3114
+ if (isErrorObject(reportedError)) {
3115
+ try {
3116
+ reportedError.outputSize = outputSize;
3117
+ } catch {
3118
+ // ignored
3119
+ }
3120
+ }
3121
+ throw reportedError;
3109
3122
  }
3110
3123
 
3111
3124
  async function closeWritable() {
@@ -3119,12 +3132,27 @@ async function runWebWorker(workerData, config) {
3119
3132
  }
3120
3133
  }
3121
3134
 
3122
- function watchClosedStream(writableSource) {
3135
+ function watchClosedStream(writableSource, workerData) {
3123
3136
  const abortController = new AbortController();
3124
- const { writable, readable } = new TransformStream();
3137
+ let aborting;
3138
+ const { writable, readable } = new TransformStream({
3139
+ transform(chunk, controller) {
3140
+ workerData.outputSize += chunk.length;
3141
+ controller.enqueue(chunk);
3142
+ }
3143
+ });
3125
3144
  const closed = readable.pipeTo(writableSource, { preventClose: true, preventAbort: true, signal: abortController.signal });
3126
- closed.catch(() => { });
3127
- return { writable, closed, abortPipe: () => abortController.abort() };
3145
+ closed.catch(error => {
3146
+ if (!aborting) {
3147
+ Object.assign(workerData, { destinationFailed: true, destinationError: error });
3148
+ }
3149
+ });
3150
+ return {
3151
+ writable, closed, abortPipe: () => {
3152
+ aborting = true;
3153
+ abortController.abort();
3154
+ }
3155
+ };
3128
3156
  }
3129
3157
 
3130
3158
  function releaseWorkerStreams(workerData) {
@@ -3322,9 +3350,6 @@ async function onMessage({ data }, workerData) {
3322
3350
  const stale = () => workerData.generation != generation;
3323
3351
  try {
3324
3352
  if (error) {
3325
- if (error.outputSize !== UNDEFINED_VALUE) {
3326
- workerData.outputSize = error.outputSize;
3327
- }
3328
3353
  fail(getResponseError(error, errorValue));
3329
3354
  } else {
3330
3355
  if (type == MESSAGE_PULL) {
@@ -3337,7 +3362,6 @@ async function onMessage({ data }, workerData) {
3337
3362
  const chunk = new Uint8Array(value);
3338
3363
  await writer.ready;
3339
3364
  await writer.write(chunk);
3340
- workerData.outputSize += chunk.length;
3341
3365
  if (!stale()) {
3342
3366
  sendMessage({ type: MESSAGE_ACK_DATA, messageId }, workerData);
3343
3367
  }
@@ -9074,7 +9098,7 @@ function formatSupported(StreamClass, format) {
9074
9098
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9075
9099
  */
9076
9100
 
9077
- const VERSION = "2.13.0";
9101
+ const VERSION = "2.13.1";
9078
9102
 
9079
9103
  /*
9080
9104
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.