source: node_modules/tar-fs/README.md@ 62b2964

finki-main main
Last change on this file since 62b2964 was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 4.8 KB
Line 
1# tar-fs
2
3filesystem bindings for [tar-stream](https://github.com/mafintosh/tar-stream).
4
5```
6npm install tar-fs
7```
8
9[![build status](https://secure.travis-ci.org/mafintosh/tar-fs.png)](http://travis-ci.org/mafintosh/tar-fs)
10
11## Usage
12
13tar-fs allows you to pack directories into tarballs and extract tarballs into directories.
14
15It 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.
16
17``` js
18var tar = require('tar-fs')
19var fs = require('fs')
20
21// packing a directory
22tar.pack('./my-directory').pipe(fs.createWriteStream('my-tarball.tar'))
23
24// extracting a directory
25fs.createReadStream('my-other-tarball.tar').pipe(tar.extract('./my-other-directory'))
26```
27
28To ignore various files when packing or extracting add a ignore function to the options. `ignore`
29is also an alias for `filter`. Additionally you get `header` if you use ignore while extracting.
30That way you could also filter by metadata.
31
32``` js
33var pack = tar.pack('./my-directory', {
34 ignore: function(name) {
35 return path.extname(name) === '.bin' // ignore .bin files when packing
36 }
37})
38
39var extract = tar.extract('./my-other-directory', {
40 ignore: function(name) {
41 return path.extname(name) === '.bin' // ignore .bin files inside the tarball when extracing
42 }
43})
44
45var extractFilesDirs = tar.extract('./my-other-other-directory', {
46 ignore: function(_, header) {
47 // pass files & directories, ignore e.g. symlinks
48 return header.type !== 'file' && header.type !== 'directory'
49 }
50})
51```
52
53You can also specify which entries to pack using the `entries` option
54
55```js
56var pack = tar.pack('./my-directory', {
57 entries: ['file1', 'subdir/file2'] // only the specific entries will be packed
58})
59```
60
61If you want to modify the headers when packing/extracting add a map function to the options
62
63``` js
64var pack = tar.pack('./my-directory', {
65 map: function(header) {
66 header.name = 'prefixed/'+header.name
67 return header
68 }
69})
70
71var extract = tar.extract('./my-directory', {
72 map: function(header) {
73 header.name = 'another-prefix/'+header.name
74 return header
75 }
76})
77```
78
79Similarly you can use `mapStream` incase you wanna modify the input/output file streams
80
81``` js
82var pack = tar.pack('./my-directory', {
83 mapStream: function(fileStream, header) {
84 // NOTE: the returned stream HAS to have the same length as the input stream.
85 // If not make sure to update the size in the header passed in here.
86 if (path.extname(header.name) === '.js') {
87 return fileStream.pipe(someTransform)
88 }
89 return fileStream;
90 }
91})
92
93var extract = tar.extract('./my-directory', {
94 mapStream: function(fileStream, header) {
95 if (path.extname(header.name) === '.js') {
96 return fileStream.pipe(someTransform)
97 }
98 return fileStream;
99 }
100})
101```
102
103Set `options.fmode` and `options.dmode` to ensure that files/directories extracted have the corresponding modes
104
105``` js
106var extract = tar.extract('./my-directory', {
107 dmode: parseInt(555, 8), // all dirs should be readable
108 fmode: parseInt(444, 8) // all files should be readable
109})
110```
111
112It 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.
113
114Alternatively you can set `options.readable` and/or `options.writable` to set the dmode and fmode to readable/writable.
115
116``` js
117var extract = tar.extract('./my-directory', {
118 readable: true, // all dirs and files should be readable
119 writable: true, // all dirs and files should be writable
120})
121```
122
123Set `options.strict` to `false` if you want to ignore errors due to unsupported entry types (like device files)
124
125To dereference symlinks (pack the contents of the symlink instead of the link itself) set `options.dereference` to `true`.
126
127## Copy a directory
128
129Copying a directory with permissions and mtime intact is as simple as
130
131``` js
132tar.pack('source-directory').pipe(tar.extract('dest-directory'))
133```
134
135## Interaction with [`tar-stream`](https://github.com/mafintosh/tar-stream)
136
137Use `finalize: false` and the `finish` hook to
138leave the pack stream open for further entries (see
139[`tar-stream#pack`](https://github.com/mafintosh/tar-stream#packing)),
140and use `pack` to pass an existing pack stream.
141
142``` js
143var mypack = tar.pack('./my-directory', {
144 finalize: false,
145 finish: function(sameAsMypack) {
146 mypack.entry({name: 'generated-file.txt'}, "hello")
147 tar.pack('./other-directory', {
148 pack: sameAsMypack
149 })
150 }
151})
152```
153
154
155## Performance
156
157Packing 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
163## License
164
165MIT
Note: See TracBrowser for help on using the repository browser.