Skip to content

Commit e91a3b7

Browse files
committed
not maintaining benches atm, still fast tho
1 parent 6d66143 commit e91a3b7

File tree

1 file changed

+23
-34
lines changed

1 file changed

+23
-34
lines changed

README.md

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
# tar-fs
22

3-
filesystem bindings for [tar-stream](https://github.com/mafintosh/tar-stream).
3+
Filesystem bindings for [tar-stream](https://github.com/mafintosh/tar-stream).
44

55
```
66
npm install tar-fs
77
```
88

9-
[![build status](https://secure.travis-ci.org/mafintosh/tar-fs.png)](http://travis-ci.org/mafintosh/tar-fs)
10-
119
## Usage
1210

1311
tar-fs allows you to pack directories into tarballs and extract tarballs into directories.
1412

1513
It doesn't gunzip for you, so if you want to extract a `.tar.gz` with this you'll need to use something like [gunzip-maybe](https://github.com/mafintosh/gunzip-maybe) in addition to this.
1614

1715
``` js
18-
var tar = require('tar-fs')
19-
var fs = require('fs')
16+
const tar = require('tar-fs')
17+
const fs = require('fs')
2018

2119
// packing a directory
2220
tar.pack('./my-directory').pipe(fs.createWriteStream('my-tarball.tar'))
@@ -30,20 +28,20 @@ is also an alias for `filter`. Additionally you get `header` if you use ignore w
3028
That way you could also filter by metadata.
3129

3230
``` js
33-
var pack = tar.pack('./my-directory', {
34-
ignore: function(name) {
31+
const pack = tar.pack('./my-directory', {
32+
ignore (name) {
3533
return path.extname(name) === '.bin' // ignore .bin files when packing
3634
}
3735
})
3836

39-
var extract = tar.extract('./my-other-directory', {
40-
ignore: function(name) {
37+
const extract = tar.extract('./my-other-directory', {
38+
ignore (name) {
4139
return path.extname(name) === '.bin' // ignore .bin files inside the tarball when extracing
4240
}
4341
})
4442

45-
var extractFilesDirs = tar.extract('./my-other-other-directory', {
46-
ignore: function(_, header) {
43+
const extractFilesDirs = tar.extract('./my-other-other-directory', {
44+
ignore (_, header) {
4745
// pass files & directories, ignore e.g. symlinks
4846
return header.type !== 'file' && header.type !== 'directory'
4947
}
@@ -53,23 +51,23 @@ var extractFilesDirs = tar.extract('./my-other-other-directory', {
5351
You can also specify which entries to pack using the `entries` option
5452

5553
```js
56-
var pack = tar.pack('./my-directory', {
54+
const pack = tar.pack('./my-directory', {
5755
entries: ['file1', 'subdir/file2'] // only the specific entries will be packed
5856
})
5957
```
6058

6159
If you want to modify the headers when packing/extracting add a map function to the options
6260

6361
``` js
64-
var pack = tar.pack('./my-directory', {
65-
map: function(header) {
62+
const pack = tar.pack('./my-directory', {
63+
map (header) {
6664
header.name = 'prefixed/'+header.name
6765
return header
6866
}
6967
})
7068

71-
var extract = tar.extract('./my-directory', {
72-
map: function(header) {
69+
const extract = tar.extract('./my-directory', {
70+
map (header) {
7371
header.name = 'another-prefix/'+header.name
7472
return header
7573
}
@@ -79,31 +77,31 @@ var extract = tar.extract('./my-directory', {
7977
Similarly you can use `mapStream` incase you wanna modify the input/output file streams
8078

8179
``` js
82-
var pack = tar.pack('./my-directory', {
83-
mapStream: function(fileStream, header) {
80+
const pack = tar.pack('./my-directory', {
81+
mapStream (fileStream, header) {
8482
// NOTE: the returned stream HAS to have the same length as the input stream.
8583
// If not make sure to update the size in the header passed in here.
8684
if (path.extname(header.name) === '.js') {
8785
return fileStream.pipe(someTransform)
8886
}
89-
return fileStream;
87+
return fileStream
9088
}
9189
})
9290

93-
var extract = tar.extract('./my-directory', {
94-
mapStream: function(fileStream, header) {
91+
const extract = tar.extract('./my-directory', {
92+
mapStream (fileStream, header) {
9593
if (path.extname(header.name) === '.js') {
9694
return fileStream.pipe(someTransform)
9795
}
98-
return fileStream;
96+
return fileStream
9997
}
10098
})
10199
```
102100

103101
Set `options.fmode` and `options.dmode` to ensure that files/directories extracted have the corresponding modes
104102

105103
``` js
106-
var extract = tar.extract('./my-directory', {
104+
const extract = tar.extract('./my-directory', {
107105
dmode: parseInt(555, 8), // all dirs should be readable
108106
fmode: parseInt(444, 8) // all files should be readable
109107
})
@@ -140,9 +138,9 @@ leave the pack stream open for further entries (see
140138
and use `pack` to pass an existing pack stream.
141139

142140
``` js
143-
var mypack = tar.pack('./my-directory', {
141+
const mypack = tar.pack('./my-directory', {
144142
finalize: false,
145-
finish: function(sameAsMypack) {
143+
finish (sameAsMypack) {
146144
mypack.entry({name: 'generated-file.txt'}, "hello")
147145
tar.pack('./other-directory', {
148146
pack: sameAsMypack
@@ -151,15 +149,6 @@ var mypack = tar.pack('./my-directory', {
151149
})
152150
```
153151

154-
155-
## Performance
156-
157-
Packing and extracting a 6.1 GB with 2496 directories and 2398 files yields the following results on my Macbook Air.
158-
[See the benchmark here](https://gist.github.com/mafintosh/8102201)
159-
160-
* tar-fs: 34.261 seconds
161-
* [node-tar](https://github.com/isaacs/node-tar): 366.123 seconds (or 10x slower)
162-
163152
## License
164153

165154
MIT

0 commit comments

Comments
 (0)