Skip to content

Commit a056624

Browse files
committed
chore: updated readme
1 parent eac3454 commit a056624

File tree

5 files changed

+1713
-637
lines changed

5 files changed

+1713
-637
lines changed

README.md

Lines changed: 35 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,55 @@
1-
# tar-fs
1+
# js-virtualtar
22

3-
filesystem bindings for [tar-stream](https://github.com/mafintosh/tar-stream).
3+
VirtualTar is a library used to create tar files using a virtual file system or a file tree. This library aims to provide a platform-agnostic generator-parser pair to create tar files without the reliance on a file system.
44

5-
```
6-
npm 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-
13-
tar-fs allows you to pack directories into tarballs and extract tarballs into directories.
14-
15-
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.
16-
17-
``` js
18-
var tar = require('tar-fs')
19-
var fs = require('fs')
20-
21-
// packing a directory
22-
tar.pack('./my-directory').pipe(fs.createWriteStream('my-tarball.tar'))
23-
24-
// extracting a directory
25-
fs.createReadStream('my-other-tarball.tar').pipe(tar.extract('./my-other-directory'))
26-
```
27-
28-
To ignore various files when packing or extracting add a ignore function to the options. `ignore`
29-
is also an alias for `filter`. Additionally you get `header` if you use ignore while extracting.
30-
That way you could also filter by metadata.
31-
32-
``` js
33-
var pack = tar.pack('./my-directory', {
34-
ignore: function(name) {
35-
return path.extname(name) === '.bin' // ignore .bin files when packing
36-
}
37-
})
38-
39-
var 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-
45-
var 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-
53-
You can also specify which entries to pack using the `entries` option
5+
## Installation
546

55-
```js
56-
var pack = tar.pack('./my-directory', {
57-
entries: ['file1', 'subdir/file2'] // only the specific entries will be packed
58-
})
7+
```sh
8+
npm install --save @matrixai/virtualtar
599
```
6010

61-
If you want to modify the headers when packing/extracting add a map function to the options
62-
63-
``` js
64-
var pack = tar.pack('./my-directory', {
65-
map: function(header) {
66-
header.name = 'prefixed/'+header.name
67-
return header
68-
}
69-
})
11+
## Usage
7012

71-
var extract = tar.extract('./my-directory', {
72-
map: function(header) {
73-
header.name = 'another-prefix/'+header.name
74-
return header
75-
}
76-
})
77-
```
13+
See the example usage in [tests](tests).
7814

79-
Similarly you can use `mapStream` incase you wanna modify the input/output file streams
15+
## Development
8016

81-
``` js
82-
var pack = tar.pack('./my-directory', {
83-
mapStream: function(fileStream, header) {
84-
if (path.extname(header.name) === '.js') {
85-
return fileStream.pipe(someTransform)
86-
}
87-
return fileStream;
88-
}
89-
})
17+
Run `nix develop`, and once you're inside, you can use:
9018

91-
var extract = tar.extract('./my-directory', {
92-
mapStream: function(fileStream, header) {
93-
if (path.extname(header.name) === '.js') {
94-
return fileStream.pipe(someTransform)
95-
}
96-
return fileStream;
97-
}
98-
})
19+
```sh
20+
# install (or reinstall packages from package.json)
21+
npm install
22+
# build the dist objects
23+
npm run build
24+
# run the repl (this allows you to import from ./src)
25+
npm run tsx
26+
# run the tests
27+
npm run test
28+
# lint the source code
29+
npm run lint
30+
# automatically fix the source
31+
npm run lintfix
9932
```
10033

101-
Set `options.fmode` and `options.dmode` to ensure that files/directories extracted have the corresponding modes
34+
### Docs Generation
10235

103-
``` js
104-
var extract = tar.extract('./my-directory', {
105-
dmode: parseInt(555, 8), // all dirs should be readable
106-
fmode: parseInt(444, 8) // all files should be readable
107-
})
36+
```sh
37+
npm run docs
10838
```
10939

110-
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.
111-
112-
Alternatively you can set `options.readable` and/or `options.writable` to set the dmode and fmode to readable/writable.
113-
114-
``` js
115-
var extract = tar.extract('./my-directory', {
116-
readable: true, // all dirs and files should be readable
117-
writable: true, // all dirs and files should be writable
118-
})
119-
```
120-
121-
Set `options.strict` to `false` if you want to ignore errors due to unsupported entry types (like device files)
122-
123-
To dereference symlinks (pack the contents of the symlink instead of the link itself) set `options.dereference` to `true`.
124-
125-
## Copy a directory
40+
See the docs at: https://matrixai.github.io/js-virtualtar/
12641

127-
Copying a directory with permissions and mtime intact is as simple as
42+
### Publishing
12843

129-
``` js
130-
tar.pack('source-directory').pipe(tar.extract('dest-directory'))
44+
```sh
45+
# npm login
46+
npm version patch # major/minor/patch
47+
npm run build
48+
npm publish --access public
49+
git push
50+
git push --tags
13151
```
13252

133-
## Interaction with [`tar-stream`](https://github.com/mafintosh/tar-stream)
134-
135-
Use `finalize: false` and the `finish` hook to
136-
leave the pack stream open for further entries (see
137-
[`tar-stream#pack`](https://github.com/mafintosh/tar-stream#packing)),
138-
and use `pack` to pass an existing pack stream.
139-
140-
``` js
141-
var mypack = tar.pack('./my-directory', {
142-
finalize: false,
143-
finish: function(sameAsMypack) {
144-
mypack.entry({name: 'generated-file.txt'}, "hello")
145-
tar.pack('./other-directory', {
146-
pack: sameAsMypack
147-
})
148-
}
149-
})
150-
```
151-
152-
153-
## Performance
154-
155-
Packing and extracting a 6.1 GB with 2496 directories and 2398 files yields the following results on my Macbook Air.
156-
[See the benchmark here](https://gist.github.com/mafintosh/8102201)
157-
158-
* tar-fs: 34.261 ms
159-
* [node-tar](https://github.com/isaacs/node-tar): 366.123 ms (or 10x slower)
160-
16153
## License
16254

163-
MIT
55+
`js-virtualtar` is licensed under Apache-2.0, you may read the terms of the license [here](LICENSE).

0 commit comments

Comments
 (0)