Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zip.compress promise does not resolve if compressing 3 or more files #20

Open
mbertogliati opened this issue Nov 28, 2024 · 1 comment

Comments

@mbertogliati
Copy link

mbertogliati commented Nov 28, 2024

This one is tricky, it took me a while to find the cause of it.
If I have an array of 3 files, and then compress them and wrap them in a Promise.all(), that promise does not resolve.
Minimal reproducible example:

import { zip } from "jsr:@deno-library/compress";
import { describe, it} from "jsr:@std/testing/bdd";

describe("zip", () => {
  it("should compress N files in a row", async () => {
    const N = 3;
    await Deno.mkdir("/tmp/zip-test", { recursive: true });
    const files: string[] = Array.from({ length: N }, (_, i) => `/tmp/zip-test/file_${i}.txt`);
    await Promise.all(files.map((file, i) => Deno.writeTextFile(file, `Hello, World! ${i}`)));
    await Promise.all(files.map((file, i) => zip.compress(file, `/tmp/zip-test/file_${i}.zip`)));
    await Deno.remove("/tmp/zip-test", { recursive: true });
  });
});

For any N >= 3 this test does not pass as the compress promise does not resolve. The compressed files do appear where they are supposed to, but the promise hangs.
Maybe I'm doing something wrong here, so I would be glad if someone can point me in the right direction.

@fuxingZhang
Copy link
Contributor

fuxingZhang commented Nov 28, 2024

The parameter of zip.compress is a file or a directory, and if you want to compress multiple independent files, you should use jsr:@zip-js/zip-js.

https://jsr.io/@zip-js/zip-js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants