gildas-lormeau / zip.js

JavaScript library to zip and unzip files supporting multi-core compression, compression streams, zip64, split files and encryption.
https://gildas-lormeau.github.io/zip.js
BSD 3-Clause "New" or "Revised" License
3.38k stars 510 forks source link

Uncaught (in promise) TypeError: Failed to fetch #370

Closed nickmaddren closed 1 year ago

nickmaddren commented 1 year ago

Hey 👋 thanks for providing such a useful library.

I have a question about an error that occurs when I abort the zip writer:

const handleZip = async (files: FileWithPath[], abortController) => {
  const blobWriter = new BlobWriter('application/zip');
  const zipWriter = new ZipWriter(blobWriter, { bufferedWrite: true, signal: abortController.signal });

  // write the zip
  await Promise.all(
    files.map(file => {
      return zipWriter.add(file.path, new BlobReader(file), {
        lastModDate: new Date(file.lastModified),
      });
    })
  );

  await zipWriter.close(null);
  // get blob and return new zip file
  const blob = await blobWriter.getData();
  return new File([blob], 'files.zip', { type: 'application/zip' });
};

If I pass multiple files and then use abortController.abort() I see this error:

1 Uncaught (in promise) TypeError: Failed to fetch

There is no stack trace.

If I remove bufferedWrite: true this error does not occur.

I'm using the latest version of the library.

Any idea why this error occurs and how I stop it from throwing?

gildas-lormeau commented 1 year ago

Thank you, the bug should be fixed in the version 2.6.37 I just published.

nickmaddren commented 1 year ago

Thank you so much!

gildas-lormeau commented 1 year ago

You're welcome :)

heatherBoveri commented 1 year ago

Wow thanks so much @gildas-lormeau !