You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
// 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
];
Please wrap your code using: const zipAndUpload = new Promise((resolve, reject) => {
//your zip code goes here
} );
await zipAndUpload;
//do what you want after
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.
The text was updated successfully, but these errors were encountered: