cthackers/adm-zip — pull request #96 by greggman (2014-06-26 07:02:51+00:00)
Title: add an optional filter to addLocalFolder

The filter can be a RegExp or a Function. If `RegExp.test(path)` or
`filter(path)` returns true the file is included.

It seemed better to include the filter in addLocalFolder
than roll my own loop since addLocalFilter deals with windows
backslash for example and any other cross platform weirdness
could be added there.

I tested it by hand with this test. I wasn't sure if I was supposed
to add that test somewhere or not.

var Zip = require("../adm-zip");

var printEntries = function(label, zip) {
console.log("----: " + label);
zip.getEntries().forEach(function(entry, ii) {
console.log("" + ii + ": " + entry.entryName);
});
};

var zip = new Zip();
zip.addLocalFolder(__dirname);
printEntries("zip1", zip);

var zip = new Zip();
zip.addLocalFolder(__dirname, "", /\.txt$/);
printEntries("zip2", zip);

var zip = new Zip();
zip.addLocalFolder(__dirname, "", function(f) { return f.substring(f.length - 4) == ".zip"; });
printEntries("zip3", zip);

Which printed

----: zip1
0: addlocalfolder-test.js
1: assets/attributes_test/New folder/hidden.txt
2: assets/attributes_test/New folder/hidden_readonly.txt
3: assets/attributes_test/New folder/readonly.txt
4: assets/attributes_test/New folder/somefile.txt
5: assets/attributes_test/New folder/
6: assets/attributes_test/asd/New Text Document.txt
7: assets/attributes_test/asd/
8: assets/attributes_test/blank file.txt
9: assets/attributes_test/
10: assets/attributes_test.zip
11: assets/fast.zip
12: assets/fastest.zip
13: assets/linux_arc.zip
14: assets/maximum.zip
15: assets/normal.zip
16: assets/store.zip
17: assets/ultra.zip
18: assets/
19: index.js
----: zip2
0: assets/attributes_test/New folder/hidden.txt
1: assets/attributes_test/New folder/hidden_readonly.txt
2: assets/attributes_test/New folder/readonly.txt
3: assets/attributes_test/New folder/somefile.txt
4: assets/attributes_test/asd/New Text Document.txt
5: assets/attributes_test/blank file.txt
----: zip3
0: assets/attributes_test.zip
1: assets/fast.zip
2: assets/fastest.zip
3: assets/linux_arc.zip
4: assets/maximum.zip
5: assets/normal.zip
6: assets/store.zip