@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.
@@ -3078,7 +3078,7 @@ async function runWebWorker(workerData, config) {
3078
3078
  rejectResult = error => {
3079
3079
  const { outputSize, workerOptions } = workerData;
3080
3080
  workerOptions.outputSize = outputSize;
3081
- if (isErrorObject(error) && error.outputSize === UNDEFINED_VALUE) {
3081
+ if (isErrorObject(error)) {
3082
3082
  try {
3083
3083
  error.outputSize = outputSize;
3084
3084
  } catch {
@@ -3092,12 +3092,14 @@ async function runWebWorker(workerData, config) {
3092
3092
  reader: null,
3093
3093
  writer: null,
3094
3094
  outputSize: 0,
3095
+ destinationFailed: false,
3096
+ destinationError: null,
3095
3097
  resolveResult,
3096
3098
  rejectResult,
3097
3099
  result
3098
3100
  });
3099
3101
  const { readable, options } = workerData;
3100
- const { writable, closed, abortPipe } = watchClosedStream(workerData.writable);
3102
+ const { writable, closed, abortPipe } = watchClosedStream(workerData.writable, workerData);
3101
3103
  let streamsTransferred;
3102
3104
  try {
3103
3105
  streamsTransferred = sendMessage({
@@ -3140,7 +3142,18 @@ async function runWebWorker(workerData, config) {
3140
3142
  } catch {
3141
3143
  // ignored
3142
3144
  }
3143
- throw error;
3145
+ const { outputSize, workerOptions, destinationFailed, destinationError } = workerData;
3146
+ workerOptions.outputSize = outputSize;
3147
+ const workerFailed = isErrorObject(error) && (error.codecImportFailed || error.workerStartupFailed);
3148
+ const reportedError = destinationFailed && !workerFailed ? destinationError : error;
3149
+ if (isErrorObject(reportedError)) {
3150
+ try {
3151
+ reportedError.outputSize = outputSize;
3152
+ } catch {
3153
+ // ignored
3154
+ }
3155
+ }
3156
+ throw reportedError;
3144
3157
  }
3145
3158
 
3146
3159
  async function closeWritable() {
@@ -3154,12 +3167,27 @@ async function runWebWorker(workerData, config) {
3154
3167
  }
3155
3168
  }
3156
3169
 
3157
- function watchClosedStream(writableSource) {
3170
+ function watchClosedStream(writableSource, workerData) {
3158
3171
  const abortController = new AbortController();
3159
- const { writable, readable } = new TransformStream();
3172
+ let aborting;
3173
+ const { writable, readable } = new TransformStream({
3174
+ transform(chunk, controller) {
3175
+ workerData.outputSize += chunk.length;
3176
+ controller.enqueue(chunk);
3177
+ }
3178
+ });
3160
3179
  const closed = readable.pipeTo(writableSource, { preventClose: true, preventAbort: true, signal: abortController.signal });
3161
- closed.catch(() => { });
3162
- return { writable, closed, abortPipe: () => abortController.abort() };
3180
+ closed.catch(error => {
3181
+ if (!aborting) {
3182
+ Object.assign(workerData, { destinationFailed: true, destinationError: error });
3183
+ }
3184
+ });
3185
+ return {
3186
+ writable, closed, abortPipe: () => {
3187
+ aborting = true;
3188
+ abortController.abort();
3189
+ }
3190
+ };
3163
3191
  }
3164
3192
 
3165
3193
  function releaseWorkerStreams(workerData) {
@@ -3357,9 +3385,6 @@ async function onMessage({ data }, workerData) {
3357
3385
  const stale = () => workerData.generation != generation;
3358
3386
  try {
3359
3387
  if (error) {
3360
- if (error.outputSize !== UNDEFINED_VALUE) {
3361
- workerData.outputSize = error.outputSize;
3362
- }
3363
3388
  fail(getResponseError(error, errorValue));
3364
3389
  } else {
3365
3390
  if (type == MESSAGE_PULL) {
@@ -3372,7 +3397,6 @@ async function onMessage({ data }, workerData) {
3372
3397
  const chunk = new Uint8Array(value);
3373
3398
  await writer.ready;
3374
3399
  await writer.write(chunk);
3375
- workerData.outputSize += chunk.length;
3376
3400
  if (!stale()) {
3377
3401
  sendMessage({ type: MESSAGE_ACK_DATA, messageId }, workerData);
3378
3402
  }
@@ -9109,7 +9133,7 @@ function formatSupported(StreamClass, format) {
9109
9133
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9110
9134
  */
9111
9135
 
9112
- const VERSION = "2.13.0";
9136
+ const VERSION = "2.13.1";
9113
9137
 
9114
9138
  /*
9115
9139
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.