Add example of writing to file
This commit is contained in:
parent
58ff1564b7
commit
6fa71636de
1 changed files with 34 additions and 0 deletions
34
README.md
34
README.md
|
@ -127,6 +127,40 @@ oldTarballStream.pipe(extract)
|
||||||
pack.pipe(newTarballStream)
|
pack.pipe(newTarballStream)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Saving tarball to fs
|
||||||
|
|
||||||
|
|
||||||
|
``` js
|
||||||
|
var fs = require('fs');
|
||||||
|
var tar = require('tar-stream');
|
||||||
|
|
||||||
|
var pack = tar.pack(); // pack is a streams2 stream
|
||||||
|
var path = 'YourTarBall.tar';
|
||||||
|
var yourTarball = fs.createWriteStream(path);
|
||||||
|
|
||||||
|
// add a file called YourFile.txt with the content "Hello World!"
|
||||||
|
pack.entry({
|
||||||
|
name: 'YourFile.txt'
|
||||||
|
}, 'Hello World!', () => {
|
||||||
|
pack.finalize();
|
||||||
|
});
|
||||||
|
|
||||||
|
// pipe the pack stream to your file
|
||||||
|
pack.pipe(yourTarball);
|
||||||
|
|
||||||
|
yourTarball.on('close', () => {
|
||||||
|
console.log(path + ' has been written');
|
||||||
|
fs.stat(path, function(err, stats) {
|
||||||
|
if (err) {
|
||||||
|
return console.error(err);
|
||||||
|
}
|
||||||
|
console.log(stats);
|
||||||
|
console.log("Got file info successfully!");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
## Performance
|
## Performance
|
||||||
|
|
||||||
[See tar-fs for a performance comparison with node-tar](https://github.com/mafintosh/tar-fs/blob/master/README.md#performance)
|
[See tar-fs for a performance comparison with node-tar](https://github.com/mafintosh/tar-fs/blob/master/README.md#performance)
|
||||||
|
|
Loading…
Reference in a new issue