@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.
@@ -3049,7 +3049,7 @@
3049
3049
  rejectResult = error => {
3050
3050
  const { outputSize, workerOptions } = workerData;
3051
3051
  workerOptions.outputSize = outputSize;
3052
- if (isErrorObject(error) && error.outputSize === UNDEFINED_VALUE) {
3052
+ if (isErrorObject(error)) {
3053
3053
  try {
3054
3054
  error.outputSize = outputSize;
3055
3055
  } catch {
@@ -3063,12 +3063,14 @@
3063
3063
  reader: null,
3064
3064
  writer: null,
3065
3065
  outputSize: 0,
3066
+ destinationFailed: false,
3067
+ destinationError: null,
3066
3068
  resolveResult,
3067
3069
  rejectResult,
3068
3070
  result
3069
3071
  });
3070
3072
  const { readable, options } = workerData;
3071
- const { writable, closed, abortPipe } = watchClosedStream(workerData.writable);
3073
+ const { writable, closed, abortPipe } = watchClosedStream(workerData.writable, workerData);
3072
3074
  let streamsTransferred;
3073
3075
  try {
3074
3076
  streamsTransferred = sendMessage({
@@ -3111,7 +3113,18 @@
3111
3113
  } catch {
3112
3114
  // ignored
3113
3115
  }
3114
- throw error;
3116
+ const { outputSize, workerOptions, destinationFailed, destinationError } = workerData;
3117
+ workerOptions.outputSize = outputSize;
3118
+ const workerFailed = isErrorObject(error) && (error.codecImportFailed || error.workerStartupFailed);
3119
+ const reportedError = destinationFailed && !workerFailed ? destinationError : error;
3120
+ if (isErrorObject(reportedError)) {
3121
+ try {
3122
+ reportedError.outputSize = outputSize;
3123
+ } catch {
3124
+ // ignored
3125
+ }
3126
+ }
3127
+ throw reportedError;
3115
3128
  }
3116
3129
 
3117
3130
  async function closeWritable() {
@@ -3125,12 +3138,27 @@
3125
3138
  }
3126
3139
  }
3127
3140
 
3128
- function watchClosedStream(writableSource) {
3141
+ function watchClosedStream(writableSource, workerData) {
3129
3142
  const abortController = new AbortController();
3130
- const { writable, readable } = new TransformStream();
3143
+ let aborting;
3144
+ const { writable, readable } = new TransformStream({
3145
+ transform(chunk, controller) {
3146
+ workerData.outputSize += chunk.length;
3147
+ controller.enqueue(chunk);
3148
+ }
3149
+ });
3131
3150
  const closed = readable.pipeTo(writableSource, { preventClose: true, preventAbort: true, signal: abortController.signal });
3132
- closed.catch(() => { });
3133
- return { writable, closed, abortPipe: () => abortController.abort() };
3151
+ closed.catch(error => {
3152
+ if (!aborting) {
3153
+ Object.assign(workerData, { destinationFailed: true, destinationError: error });
3154
+ }
3155
+ });
3156
+ return {
3157
+ writable, closed, abortPipe: () => {
3158
+ aborting = true;
3159
+ abortController.abort();
3160
+ }
3161
+ };
3134
3162
  }
3135
3163
 
3136
3164
  function releaseWorkerStreams(workerData) {
@@ -3328,9 +3356,6 @@
3328
3356
  const stale = () => workerData.generation != generation;
3329
3357
  try {
3330
3358
  if (error) {
3331
- if (error.outputSize !== UNDEFINED_VALUE) {
3332
- workerData.outputSize = error.outputSize;
3333
- }
3334
3359
  fail(getResponseError(error, errorValue));
3335
3360
  } else {
3336
3361
  if (type == MESSAGE_PULL) {
@@ -3343,7 +3368,6 @@
3343
3368
  const chunk = new Uint8Array(value);
3344
3369
  await writer.ready;
3345
3370
  await writer.write(chunk);
3346
- workerData.outputSize += chunk.length;
3347
3371
  if (!stale()) {
3348
3372
  sendMessage({ type: MESSAGE_ACK_DATA, messageId }, workerData);
3349
3373
  }
@@ -9080,7 +9104,7 @@
9080
9104
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9081
9105
  */
9082
9106
 
9083
- const VERSION = "2.13.0";
9107
+ const VERSION = "2.13.1";
9084
9108
 
9085
9109
  /*
9086
9110
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.