@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.
@@ -125,7 +125,7 @@ async function runWebWorker(workerData, config) {
125
125
  rejectResult = error => {
126
126
  const { outputSize, workerOptions } = workerData;
127
127
  workerOptions.outputSize = outputSize;
128
- if (isErrorObject(error) && error.outputSize === UNDEFINED_VALUE) {
128
+ if (isErrorObject(error)) {
129
129
  try {
130
130
  error.outputSize = outputSize;
131
131
  } catch {
@@ -139,12 +139,14 @@ async function runWebWorker(workerData, config) {
139
139
  reader: null,
140
140
  writer: null,
141
141
  outputSize: 0,
142
+ destinationFailed: false,
143
+ destinationError: null,
142
144
  resolveResult,
143
145
  rejectResult,
144
146
  result
145
147
  });
146
148
  const { readable, options } = workerData;
147
- const { writable, closed, abortPipe } = watchClosedStream(workerData.writable);
149
+ const { writable, closed, abortPipe } = watchClosedStream(workerData.writable, workerData);
148
150
  let streamsTransferred;
149
151
  try {
150
152
  streamsTransferred = sendMessage({
@@ -187,7 +189,18 @@ async function runWebWorker(workerData, config) {
187
189
  } catch {
188
190
  // ignored
189
191
  }
190
- throw error;
192
+ const { outputSize, workerOptions, destinationFailed, destinationError } = workerData;
193
+ workerOptions.outputSize = outputSize;
194
+ const workerFailed = isErrorObject(error) && (error.codecImportFailed || error.workerStartupFailed);
195
+ const reportedError = destinationFailed && !workerFailed ? destinationError : error;
196
+ if (isErrorObject(reportedError)) {
197
+ try {
198
+ reportedError.outputSize = outputSize;
199
+ } catch {
200
+ // ignored
201
+ }
202
+ }
203
+ throw reportedError;
191
204
  }
192
205
 
193
206
  async function closeWritable() {
@@ -201,12 +214,27 @@ async function runWebWorker(workerData, config) {
201
214
  }
202
215
  }
203
216
 
204
- function watchClosedStream(writableSource) {
217
+ function watchClosedStream(writableSource, workerData) {
205
218
  const abortController = new AbortController();
206
- const { writable, readable } = new TransformStream();
219
+ let aborting;
220
+ const { writable, readable } = new TransformStream({
221
+ transform(chunk, controller) {
222
+ workerData.outputSize += chunk.length;
223
+ controller.enqueue(chunk);
224
+ }
225
+ });
207
226
  const closed = readable.pipeTo(writableSource, { preventClose: true, preventAbort: true, signal: abortController.signal });
208
- closed.catch(() => { });
209
- return { writable, closed, abortPipe: () => abortController.abort() };
227
+ closed.catch(error => {
228
+ if (!aborting) {
229
+ Object.assign(workerData, { destinationFailed: true, destinationError: error });
230
+ }
231
+ });
232
+ return {
233
+ writable, closed, abortPipe: () => {
234
+ aborting = true;
235
+ abortController.abort();
236
+ }
237
+ };
210
238
  }
211
239
 
212
240
  function releaseWorkerStreams(workerData) {
@@ -404,9 +432,6 @@ async function onMessage({ data }, workerData) {
404
432
  const stale = () => workerData.generation != generation;
405
433
  try {
406
434
  if (error) {
407
- if (error.outputSize !== UNDEFINED_VALUE) {
408
- workerData.outputSize = error.outputSize;
409
- }
410
435
  fail(getResponseError(error, errorValue));
411
436
  } else {
412
437
  if (type == MESSAGE_PULL) {
@@ -419,7 +444,6 @@ async function onMessage({ data }, workerData) {
419
444
  const chunk = new Uint8Array(value);
420
445
  await writer.ready;
421
446
  await writer.write(chunk);
422
- workerData.outputSize += chunk.length;
423
447
  if (!stale()) {
424
448
  sendMessage({ type: MESSAGE_ACK_DATA, messageId }, workerData);
425
449
  }
@@ -26,6 +26,6 @@
26
26
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
 
29
- const VERSION = "2.13.0";
29
+ const VERSION = "2.13.1";
30
30
 
31
31
  export { VERSION };
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.13.0",
6
+ "version": "2.13.1",
7
7
  "type": "module",
8
8
  "keywords": [
9
9
  "zip",