Adam Rensel b05888e79d Add the correct demo app | %!s(int64=9) %!d(string=hai) anos | |
---|---|---|
.. | ||
node_modules | %!s(int64=9) %!d(string=hai) anos | |
test | %!s(int64=9) %!d(string=hai) anos | |
.npmignore | %!s(int64=9) %!d(string=hai) anos | |
.travis.yml | %!s(int64=9) %!d(string=hai) anos | |
LICENSE | %!s(int64=9) %!d(string=hai) anos | |
README.md | %!s(int64=9) %!d(string=hai) anos | |
index.js | %!s(int64=9) %!d(string=hai) anos | |
package.json | %!s(int64=9) %!d(string=hai) anos |
filesystem bindings for tar-stream.
npm install tar-fs
tar-fs allows you to pack directories into tarballs and extract tarballs into directories.
var tar = require('tar-fs')
var fs = require('fs')
// packing a directory
tar.pack('./my-directory').pipe(fs.createWriteStream('my-tarball.tar'))
// extracting a directory
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
var pack = tar.pack('./my-directory', {
ignore: function(name) {
return path.extname(name) === '.bin' // ignore .bin files when packing
}
})
var extract = tar.extract('./my-other-directory', {
ignore: function(name) {
return path.extname(name) === '.bin' // ignore .bin files inside the tarball when extracing
}
})
If you want to modify the headers when packing/extracting add a map function to the options
var pack = tar.pack('./my-directory', {
map: function(header) {
header.name = 'prefixed/'+header.name
return header
}
})
var extract = tar.pack('./my-directory', {
map: function(header) {
header.name = 'another-prefix/'+header.name
return header
}
})
Similarly you can use mapStream
incase you wanna modify the input/output file streams
var pack = tar.pack('./my-directory', {
mapStream: function(fileStream) {
return fileStream.pipe(someTransform)
}
})
var extract = tar.extract('./my-directory', {
mapStream: function(fileStream) {
return fileStream.pipe(someTransform)
}
})
Set options.fmode
and options.dmode
to ensure that files/directories extracted have the corresponding modes
var extract = tar.extract('./my-directory', {
dmode: 0555, // all dirs and files should be readable
fmode: 0444
})
It can be useful to use dmode
and fmode
if you are packing/unpacking tarballs between *nix/windows to ensure that all files/directories unpacked are readable.
Copying a directory with permissions and mtime intact is as simple as
tar.pack('source-directory').pipe(tar.extract('dest-directory'))
Packing and extracting a 6.1 GB with 2496 directories and 2398 files yields the following results on my Macbook Air. See the benchmark here
MIT