是否有任何 Node 模块可以在内存中创建zip?(我不想将zip文件保存在磁盘上),以便我们可以将这个创建的zip文件发送到其他服务器(从内存)。做这个的最好方式是什么? 这是我的例子:
var file_system = require('fs');
var archiver = require('archiver');
var dirToCompress = 'directoryToZIP';
module.exports = function (req, res, next) {
var archive = archiver.create('zip', {});
archive.on('error', function (err) {
throw err;
});
var output = file_system.createWriteStream('/testDir/myZip.zip',{flags:'a'});//I don't want this line
output.on('close', function () {
console.log(archive.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
});
archive.pipe(output);
archive.directory(dirToCompress);
archive.finalize();
};
最佳答案
我正在使用Adm-Zip :
// create archive
var zip = new AdmZip();
// add in-memory file
var content = "inner content of the file";
zip.addFile("test.txt", Buffer.alloc(content.length, content), "entry comment goes here");
// add file
zip.addLocalFile("/home/me/some_picture.png");
// get in-memory zip
var willSendthis = zip.toBuffer();
关于node.js - 使用任何 Node 模块在内存中创建 ZIP 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42992604/