jszip
jszip copied to clipboard
Read zip file as stream
Is there a way to read a zip file one file by one as a stream? I noticed that JSzip.loadAsync take in input a NodeJS.ReadableStream but it's not clear to me how to use it.
using node 14, I'd hope the following would work, but it throws an error
const fs = require('fs');
const JSZip = require('jszip');
// const zip = new JSZip();
const { promisify } = require('util');
const pipeline = promisify(require('stream').pipeline);
(async () => {
const fp = 'results.zip';
const rs = fs.createReadStream(fp);
const ws = fs.createWriteStream('temp');
// rs.pipe(JSZip.loadAsync).pipe(ws);
await pipeline(
rs,
async function* (readStream) {
return JSZip.loadAsync(readStream)
},
ws
);
let a;
})();
throws
(node:33289) UnhandledPromiseRejectionWarning: Error: JSZip can't accept a stream when loading a zip file.
I guess there could be multiple files so it probably won't be able to pipe into file write stream nicely.