I use the following source code to create a ZIP archive from several non-empty files:
const zipWriter = new zip.ZipWriter(new zip.BlobWriter("application/zip"), { bufferedWrite: true });
const filePromises = values.map(file => zipWriter.add(file.name, new zip.BlobReader(file), {}));
return Promise.all(filePromises)
.then(() => zipWriter.close())
.then(zipBlob => {
const archiveDocumentFileUrl = URL.createObjectURL(zipBlob);
const anchorElement = document.createElement("a");
anchorElement.href = archiveDocumentFileUrl;
anchorElement.download = "archive.zip";
anchorElement.click();
URL.revokeObjectURL(archiveDocumentFileUrl);
return Promise.resolve(anchorElement.download);
})
.catch(err => console.error(err));
I use the library "zip.js". I cannot use async and await because NetBeans 17 doesn't handle those keywords correctly. I have the following error in Mozilla Firefox 110:
TypeError: Can not close stream after closing or error
It happens in this part of zip.js source code, even in the full (without minification) version:
await o.pipeThrough(f).pipeTo(c,{preventAbort:!0});try{await c.close()}catch(e){}
C is a WritableStream. Is it an expected error? How can I get rid of it? By the way, it doesn't prevent the library from working but maybe there's something really wrong in my source code above.
This bug has been fixed in lib.js 2.6.83.