我想将一些 readeableStreams 压缩到一个 writableStream 中。目的是在内存中完成所有操作,而不是在磁盘上创建实际的 zip 文件。
为此我正在使用归档器
let bufferOutput = Buffer.alloc(5000);
let archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});
archive.pipe(bufferOutput);
archive.append(someReadableStread, { name: test.txt});
archive.finalize();
我在网上遇到错误archive.pipe(bufferOutput);
。
这是错误:“dest.on 不是函数”
我究竟做错了什么?谢谢
更新:
我正在运行以下代码进行测试,并且未正确创建 ZIP 文件。我错过了什么?
const fs = require('fs'),
archiver = require('archiver'),
streamBuffers = require('stream-buffers');
let outputStreamBuffer = new streamBuffers.WritableStreamBuffer({
initialSize: (1000 * 1024), // start at 1000 kilobytes.
incrementAmount: (1000 * 1024) // grow by 1000 kilobytes each time buffer overflows.
});
let archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});
archive.pipe(outputStreamBuffer);
archive.append("this is a test", { name: "test.txt"});
archive.finalize();
outputStreamBuffer.end();
fs.writeFile('output.zip', outputStreamBuffer.getContents(), function() { console.log('done!'); });