I am using archiver to create zip from list of files. and final goal is to stream archived file to azure storage.
Please find below code
{ const archiver = (await import('archiver')).default;
const archive = archiver('zip');
const p = new Promise((resolve, reject) => {
archive.on('finish', resolve);
archive.on('error', err => {
console.log('error while archiving', err);
reject(err);
});
archive.on('warning', err => {
if (err.code !== 'ENOENT') {
reject(err);
}
});
archive.on('data', chunk => {
appendFile(path.join(cwd, '.build/test2.zip'), chunk) // appending chunks to file , this simulates passing data to passthrough stream by pipe
});
archive.pipe(require('fs').createWriteStream('test1.zip')); // steaming to writeStream
for (const fileOrSubDirPath of filePaths) {
const relativePath = path.relative(cwd, fileOrSubDirPath);
archive.file(fileOrSubDirPath, { name: relativePath });
}
});
await archive.finalize();
await p;
}
Using passthrough stream to pass it to azure storage but same result as below,
here for simplicity I created 2 files
test1 -> created using writestream using pipe.
test2 -> created using "chunks" emitted by data event.
I can both files with same size , however I am able unzip test1 , and test2 file is corrupted.
would appreciate any help here :)
thanks in advance !
Hello
I am using archiver to create zip from list of files. and final goal is to stream archived file to azure storage.
Please find below code
Using passthrough stream to pass it to azure storage but same result as below, here for simplicity I created 2 files test1 -> created using writestream using pipe. test2 -> created using "chunks" emitted by data event.
I can both files with same size , however I am able unzip test1 , and test2 file is corrupted.
would appreciate any help here :) thanks in advance !