node.js - node-archiver:归档多个目录

标签 node.js zip node-archiver

当您知道它们的路径时,是否可以归档多个目录?比方说:['/dir1','dir2', .., 'dirX']。我现在正在做的是将目录复制到一个目录中,比方说:/dirToZip 并执行以下操作:

var archive = archiver.create('zip', {});
archive.on('error', function(err){
    throw err;
});
archive.directory('/dirToZip','').finalize(); 

是否有一种方法可以将目录附加到存档中,而不是使用批量所需的特定模式?提前致谢!

最佳答案

您可以使用 bulk(mappings) .尝试:

var output = fs.createWriteStream(__dirname + '/bulk-output.zip');
var archive = archiver('zip');

output.on('close', function() {
    console.log(archive.pointer() + ' total bytes');
    console.log('archiver has been finalized and the output file descriptor has closed.');
});

archive.on('error', function(err) {
    throw err;
});

archive.pipe(output);

archive.bulk([
    { expand: true, cwd: 'views/', src: ['*'] },
    { expand: true, cwd: 'uploads/', src: ['*'] }
]);

archive.finalize();

已更新

或者你可以做得更简单:

var output = fs.createWriteStream(__dirname + '/bulk-output.zip');
var archive = archiver('zip');

output.on('close', function() {
    console.log(archive.pointer() + ' total bytes');
    console.log('archiver has been finalized and the output file descriptor has closed.');
});

archive.on('error', function(err) {
    throw err;
});

archive.pipe(output);

archive.directory('views', true, { date: new Date() });
archive.directory('uploads', true, { date: new Date() });

archive.finalize();

关于node.js - node-archiver:归档多个目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34335326/

相关文章:

node.js - 如何在 aws lambda 函数中使用 dynamoose?

node.js - 如何获取用户所属的组?

javascript - Node js中的Heroku html子页面

node.js - 如何在 Nodejs 中使用密码保护 zip 文件?

node.js - 使用 NodeJs 获取输出 zip 文件的大小

node.js - fatal error : Evacuation Allocation failed - process out of memory

java - 如何在Java中对不同数字的字符串进行正确排序?

angular - 使用 angular2 在网络浏览器上显示 shapefile map

java - 如何创建具有最大文件大小限制的 java zip 存档