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.33k stars 506 forks source link

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

Closed mybearworld closed 1 month ago

mybearworld commented 1 month ago

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());
gildas-lormeau commented 1 month ago

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().