【发布时间】:2017-12-24 13:15:06
【问题描述】:
我想将几个 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!'); });
【问题讨论】:
标签: node.js archiverjs