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

Fix `ZipWriter.add` returning unresolved promises #355

Closed 0f-0b closed 2 years ago

0f-0b commented 2 years ago

The code below only logs the first 4 zip files because the promise returned by the 5th call to ZipWriter.add never resolves. This PR fixes the bug.

configure({ maxWorkers: 4 });
await Promise.all(Array.from({ length: 5 }, async (_, index) => {
  const zipWriter = new ZipWriter(new BlobWriter());
  await zipWriter.add("hello.txt", new TextReader("hello world"));
  console.log(index, await zipWriter.close());
}));
gildas-lormeau commented 2 years ago

Good point! Thank you very much for your contribution and sorry for the inconvenience. I published the new version with your fix. I also added your test in the project.