Skip to content

Commit

Permalink
ignore by metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
chpio committed Feb 27, 2016
1 parent 1bb6875 commit bd1bbff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -25,7 +25,9 @@ tar.pack('./my-directory').pipe(fs.createWriteStream('my-tarball.tar'))
fs.createReadStream('my-other-tarball.tar').pipe(tar.extract('./my-other-directory'))
```

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

``` js
var pack = tar.pack('./my-directory', {
Expand All @@ -39,6 +41,13 @@ var extract = tar.extract('./my-other-directory', {
return path.extname(name) === '.bin' // ignore .bin files inside the tarball when extracing
}
})

var extractFilesDirs = tar.extract('./my-other-other-directory', {
ignore: function(_, header) {
// pass files & directories, ignore e.g. symlinks
return header.type !== 'file' && header.type !== 'directory'
}
})
```

You can also specify which entries to pack using the `entries` option
Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -221,7 +221,7 @@ exports.extract = function (cwd, opts) {
header.name = normalize(header.name)
var name = path.join(cwd, path.join('/', header.name))

if (ignore(name)) {
if (ignore(name, header)) {
stream.resume()
return next()
}
Expand Down

0 comments on commit bd1bbff

Please sign in to comment.