Open DavideMacchia opened 2 years ago
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.
using node 14, I'd hope the following would work, but it throws an error使用节点14,我希望下面的工作,但它抛出一个错误
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.我猜可能有多个文件,所以它可能无法很好地导入文件写入流。
same
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.