Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit bd1bbff

Browse files
committed
ignore by metadata
1 parent 1bb6875 commit bd1bbff

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ tar.pack('./my-directory').pipe(fs.createWriteStream('my-tarball.tar'))
2525
fs.createReadStream('my-other-tarball.tar').pipe(tar.extract('./my-other-directory'))
2626
```
2727

28-
To ignore various files when packing or extracting add a ignore function to the options. `ignore` is also an alias for `filter`.
28+
To ignore various files when packing or extracting add a ignore function to the options. `ignore`
29+
is also an alias for `filter`. Additionally you get `header` if you use ignore while extracting.
30+
That way you could also filter by metadata.
2931

3032
``` js
3133
var pack = tar.pack('./my-directory', {
@@ -39,6 +41,13 @@ var extract = tar.extract('./my-other-directory', {
3941
return path.extname(name) === '.bin' // ignore .bin files inside the tarball when extracing
4042
}
4143
})
44+
45+
var extractFilesDirs = tar.extract('./my-other-other-directory', {
46+
ignore: function(_, header) {
47+
// pass files & directories, ignore e.g. symlinks
48+
return header.type !== 'file' && header.type !== 'directory'
49+
}
50+
})
4251
```
4352

4453
You can also specify which entries to pack using the `entries` option

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ exports.extract = function (cwd, opts) {
221221
header.name = normalize(header.name)
222222
var name = path.join(cwd, path.join('/', header.name))
223223

224-
if (ignore(name)) {
224+
if (ignore(name, header)) {
225225
stream.resume()
226226
return next()
227227
}

0 commit comments

Comments
 (0)