Search code examples
javascriptnode.jstarpacking

Ignore certain files while packing a .tar.gz file in node JS


So I already have some code from the "targz" package that packs all the files inside of a directory. Now I have seen that you can somehow ignore files (not pack them) and I wanted to do it as well. I just can't figure out how I should write the ignore section. Here is my code:

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();
    }
});

Can somebody tell me how I need to write that section so it works? It would be greatly appreciated


Solution

  • I think the combination of entries and ignore is not working as you expect. If you include a file in entries it will be added to your archive, no matter what ignore does.

    I don't think you need to specify the entries manually since you already specify a src. So removing the entries should do the trick.