所以我已经有了"targz“包中的一些代码,它将所有文件打包到一个目录中。现在我已经看到你可以忽略文件(而不是打包它们),我也想这样做。我就是想不出该怎么写忽略部分。下面是我的代码:
targz.compress({
src: "./" + this.sourcePath + "/",
dest: "./" + this.targetPath + "/" + "result.tar.gz",
tar: {
entries: this.fileArray,
ignore: function(name) {
return path.extname(name) === '.pdf'
}
},
gz: {
level: 6,
memLevel: 6,
}
}, function(err){
if(err) {
console.log(err);
reject(err);
} else {
resolve();
}
});有没有人能告诉我,我需要怎么写这个部分才能让它工作?我将不胜感激
发布于 2018-08-27 21:41:20
我认为entries和ignore的结合并没有像你预期的那样工作。无论ignore做什么,如果你在entries中包含一个文件,它都会被添加到你的存档中。
我不认为您需要手动指定entries,因为您已经指定了一个src。因此,删除entries应该可以做到这一点。
发布于 2018-08-27 20:41:44
例如,从您的代码中,您可以过滤具有.pdf扩展名的所有文件,您可以使用ignore函数作为过滤器。
您可以重写此函数来过滤所有文件,而不是您的特定文件:
ignore: function filter(name) {
const specificFilesToIgnore = ['some_specific.pdf', 'other_specific.pdf'];
return path.extname(file) === '.pdf' && !specificFilesToIgnore.includes(name);
}https://stackoverflow.com/questions/52039355
复制相似问题