tar-stream
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "tar-stream", | ||
"version": "0.1.0", | ||
"description": "tar-stream is an alternative tar parser. It is streams2, does not have a fstream dependency and does not do any file io.", | ||
"version": "0.1.1", | ||
"description": "tar-stream is a streaming tar parser and generator and nothing else. It is streams2 and operates purely using streams which means easily you can extract/parse tarballs without ever hitting the file system.", | ||
"repository": "git://github.com:mafintosh/tar-stream.git", | ||
@@ -10,3 +10,19 @@ "author": "Mathias Buus <mathiasbuus@gmail.com>", | ||
"bl": "~0.6.0" | ||
} | ||
}, | ||
"keywords": [ | ||
"tar", | ||
"tarball", | ||
"parse", | ||
"parser", | ||
"generate", | ||
"generator", | ||
"stream", | ||
"stream2", | ||
"streams", | ||
"streams2", | ||
"streaming", | ||
"pack", | ||
"extract", | ||
"modify" | ||
] | ||
} |
# tar-stream | ||
tar-stream is an alternative tar parser. It is streams2, does not have a fstream dependency and does not do any file io. | ||
tar-stream is a streaming tar parser and generator and nothing else. It is streams2 and operates purely using streams which means easily you can extract/parse tarballs without ever hitting the file system. | ||
@@ -17,9 +17,9 @@ npm install tar-stream | ||
var tar = require('tar-stream'); | ||
var p = tar.pack(); // p is a streams2 stream | ||
var pack = tar.pack(); // p is a streams2 stream | ||
// add a file called my-test.txt with the content "Hello World!" | ||
p.entry({ name: 'my-test.txt' }, 'Hello World!'); | ||
pack.entry({ name: 'my-test.txt' }, 'Hello World!'); | ||
// add a file called my-stream-test.txt from a stream | ||
myStream.pipe(p.entry({ name: 'my-stream-test.txt' }, function(err) { | ||
myStream.pipe(pack.entry({ name: 'my-stream-test.txt' }, function(err) { | ||
// the stream was added | ||
@@ -29,6 +29,6 @@ })); | ||
// no more entries | ||
p.finalize(); | ||
pack.finalize(); | ||
// pipe the pack stream somewhere | ||
p.pipe(process.stdout); | ||
pack.pipe(process.stdout); | ||
``` | ||
@@ -41,5 +41,5 @@ | ||
``` js | ||
var e = tar.extract(); | ||
var extract = tar.extract(); | ||
e.on('entry', function(header, stream, callback) { | ||
extract.on('entry', function(header, stream, callback) { | ||
// header is the tar header | ||
@@ -55,7 +55,7 @@ // stream is the content body (might be an empty stream) | ||
e.on('finish', function() { | ||
extract.on('finish', function() { | ||
// all entries read | ||
}); | ||
packStream.pipe(e); | ||
pack.pipe(extract); | ||
``` | ||
@@ -83,4 +83,32 @@ | ||
## Modifying existing tarballs | ||
Using tar-stream it is easy to rewrite paths / change modes etc in an existing tarball. | ||
``` js | ||
var extract = tar.extract(); | ||
var pack = tar.pack(); | ||
var path = require('path'); | ||
extract.on('entry', function(header, stream, callback) { | ||
// let's prefix all names with 'tmp' | ||
header.name = path.join('tmp', header.name); | ||
// write the new entry to the pack stream | ||
stream.pipe(pack.entry(header, callback)); | ||
}); | ||
extract.on('finish', function() { | ||
// all entries done - lets finalize it | ||
pack.finalize(); | ||
}); | ||
// pipe the old tarball to the extractor | ||
oldTarball.pipe(extract); | ||
// pipe the new tarball the another stream | ||
pack.pipe(newTarball); | ||
``` | ||
# License | ||
MIT | ||
MIT |
12401
110