0

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

Rado86
  • 13
  • 2
  • I would assume by not specifying them in the `src` section, at least nothing else is stated in the docs https://www.npmjs.com/package/targz. Did you try using wildcards in there, like `*.php` to only include php files? If glob file matching is supported, this question might be helpful: https://stackoverflow.com/questions/23557305/glob-matching-exclude-all-js-files – Capricorn Aug 27 '18 at 12:33
  • Thanks, I tried it with wildcards right now but still nothing. I more or less copy pasted the ignore section into my code, so I am confused as to why it wont work now. – Rado86 Aug 27 '18 at 13:06

2 Answers2

1

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.

fknx
  • 1,775
  • 13
  • 19
  • Just tested it, thank you now it does filter out the pdf files. So I guess I have to edit the entries instead and cant work with ignore. Well, gotta do what you gotta do – Rado86 Aug 27 '18 at 14:05
0

You got the ignore function which acts as a filter, for example from your code you are filtering all the files that have the .pdf extension.

You can rewrite this function to filter all the files and not your specific ones:

ignore: function filter(name) {
  const specificFilesToIgnore = ['some_specific.pdf', 'other_specific.pdf'];

  return path.extname(file) === '.pdf' && !specificFilesToIgnore.includes(name); 
}
Alexandru Olaru
  • 6,842
  • 6
  • 27
  • 53
  • Thanks for your input, but I think I did not explain myself properly. The code under the ignore fuction does not work, and I am trying to get it to work AT ALL first of. It will still pack '.pdf' files inside of my .tar.gz and I want to change that – Rado86 Aug 27 '18 at 13:02