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

How to wait till the zipping completed #663

Open
ViswanathCelitotech opened this issue May 16, 2023 · 2 comments
Open

How to wait till the zipping completed #663

ViswanathCelitotech opened this issue May 16, 2023 · 2 comments

Comments

@ViswanathCelitotech
Copy link

Hi Team,
I am using the below code to perform zipping of files. The zipping is happening fine.
I need to wait till zipping completed and so some action. This I want to achieve without using events.
Is there any way in achieving the requirement.

`const fs = require('fs');
const archiver = require('archiver');

// Create a new archive instance
const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level (optional)
});

// Specify the output file path and create a writable stream for the archive
const outputFilePath = '/path/to/output.zip';
const output = fs.createWriteStream(outputFilePath);

// Pipe the writable stream to the archive instance
archive.pipe(output);

// Add files to the archive
const files = [
{ path: '/path/to/file1.txt', name: 'file1.txt' },
{ path: '/path/to/file2.txt', name: 'file2.txt' },
// Add more files as needed
];

files.forEach(file => {
archive.file(file.path, { name: file.name });
});

// Finalize the archive
archive.finalize();`

//Need to do some action after the zipping completes with out using actions.

@punkuz
Copy link

punkuz commented Jul 27, 2023

Please wrap your code using: const zipAndUpload = new Promise((resolve, reject) => {
//your zip code goes here
} );
await zipAndUpload;
//do what you want after

@adevine
Copy link

adevine commented Nov 3, 2023

FWIW I added a suggestion here, #476 (comment), about how to overwrite the finalize method so it waits for streaming to complete.

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