当你知道它们的路径时,是否可以存档多个目录?让我们说:['/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();