0
我使用JsZip和exceljs包。 ExcelJs可以將excel文檔寫入node.js流,jszip可以從流中讀取文件並將其添加到存檔中。我如何在它之間進行流式傳輸以方便使用它?我有這樣的解決方案,但我認爲它不好的柺杖......如何在node.js中傳輸流?
const stream2 = new Writable();
stream2.result = [];
stream2._write = function (chunk, enc, next) {
this.result.push(chunk);
next();
};
const stream1 = new Readable();
stream1._read = function() {
stream1.push(stream2.result.shift() || null);
};
let promise = new Promise((resolve, reject) => {
excelDoc.write(stream2).then(() => {
zip.file('excelDoc.xlsx', stream1);
resolve(true);
});
});