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 · 3 comments
Open

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

@gmzacharydovel
Copy link

This looks like if you call zip.compress more than 3 times the library freezes. I'm seeing this as well as I'm trying to create a zip file for each lambda entry point for AWS.

I'm trying the other library you posted @fuxingZhang , but this seems like a pretty big bug where the command must be storing something internally and not clearing it between command calls.

@fuxingZhang
Copy link
Contributor

@gmzacharydovel Thank you for your feedback.

This library is designed for compressing a folder or a single file. If you are looking to manually add specific files to a zip file, you might want to consider using a lower-level library like jsr:@zip-js/zip-js.

https://jsr.io/@zip-js/zip-js
This library is not posted by me. I just used it.

This library has 3.6k stars, which indicates it’s generally reliable, so any issues may stem from the way it’s being used. I recommend reviewing the documentation carefully. If you still encounter problems, please open an issue on the library's GitHub page and provide your code, so the developers can verify and assist with your issue.

https://github.com/gildas-lormeau/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

3 participants