[go: nahoru, domu]

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 failed when process.exit() after await archive.finalize() #555

Closed
xkn1ght opened this issue Nov 4, 2021 · 3 comments
Closed

zip failed when process.exit() after await archive.finalize() #555

xkn1ght opened this issue Nov 4, 2021 · 3 comments

Comments

@xkn1ght
Copy link
xkn1ght commented Nov 4, 2021

Discovered a likely bug.

when I want to await the archive.finalize() and exit my program, my zip file would be broken when unzipping it.

here is my case

my node version is v14.17.4

please tell me if i used it in a wrong way

@xkn1ght
Copy link
Author
xkn1ght commented Nov 8, 2021

core code here

import archiver from 'archiver';
import fs from 'fs';

async function zip(from: string, to: string,): Promise<void> {
    const ZIP_LEVEL = 9;
    const archive = archiver('zip', { zlib: { level: ZIP_LEVEL } });
    const stream = fs.createWriteStream(to);
    archive
        .directory(from, false)
        .on('error', err => {
            throw err;
        })
        .pipe(stream);

    await archive.finalize();
}

async function main(){
    await zip('./test','out.zip');
    process.exit();
}

main();

@jasrusable
Copy link

Try resolve your promise only after the stream has closed, like this example: #494 (comment)

@xkn1ght
Copy link
Author
xkn1ght commented Nov 16, 2021

Try resolve your promise only after the stream has closed, like this example: #494 (comment)

thx~

@xkn1ght xkn1ght closed this as completed Nov 16, 2021
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