UNPKG

1.46 kBMarkdownView Raw
1# decompress [![Build Status](https://secure.travis-ci.org/kevva/decompress.png?branch=master)](http://travis-ci.org/kevva/decompress)
2
3> Easily extract `.zip`, `.tar` and `.tar.gz` archives. Based on the extract utility in [Bower](https://github.com/bower/bower).
4
5## Install
6
7```bash
8npm install --save map-key
9```
10
11## Usage
12
13You'll only need to pass a type into `ext` and it'll figure the rest out for
14you.
15
16```js
17var decompress = require('decompress');
18var fs = require('fs');
19
20fs.createReadStream('foo.tar.gz').pipe(decompress({ ext: '.tar.gz' }));
21```
22
23## API
24
25### decompress(opts)
26
27Extract an archive using the `ext` option to determine which extractor to use.
28If no `path` is specified it'll extract it to your current location.
29
30### decompress.canExtract(src, mime)
31
32Determine if a file can be extracted or not by checking the file extension
33and/or the MIME type.
34
35```js
36decompress.canExtract('foo.zip');
37// => true
38
39decompress.canExtract('application/zip');
40// => true
41```
42
43## Options
44
45### `ext`
46
47Type: `String`
48Default: `''`
49
50String that can be a file name, URL, MIME type etc.
51
52### `path`
53
54Type: `String`
55Default: `process.cwd()`
56
57Path to extract the archive to. If no `path` is defined it'll extract it to your
58current location.
59
60### `strip`
61
62Type: `Number`
63Default: `0`
64
65Equivalent to `--strip-components` for tar.
66
67## License
68
69[MIT License](http://en.wikipedia.org/wiki/MIT_License) © [Kevin Mårtensson](http://kevinmartensson.com)