gildas-lormeau/zip.js

Program stays alive for a while after writing the zip file in Deno

mybearworld opened this issue · 1 comments

I apologize if I'm misusing the library in some way- but when I use the code below, the file gets written quickly, but the program stays awake for a few seconds before closing. It doesn't happen when not writing the zip file or when writing something else, or if no file gets added to the zip archive. Do you know why this might be?

import { BlobWriter, ZipWriter } from "@zip-js/zip-js";

const blobWriter = new BlobWriter();
const zipWriter = new ZipWriter(blobWriter);
await zipWriter.add(
  "file.txt",
  new Blob([new TextEncoder().encode("Hello, world!")]).stream()
);
await zipWriter.close();
Deno.writeFile("out.zip", (await blobWriter.getData()).stream());

This is due to the fact that web workers stay alive 5 seconds (default value). You can terminate them after await zipWriter.close() by calling await terminateWorkers().