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
|
8 | npm install --save map-key
|
9 | ```
|
10 |
|
11 | ## Usage
|
12 |
|
13 | You'll only need to pass a type into `ext` and it'll figure the rest out for
|
14 | you.
|
15 |
|
16 | ```js
|
17 | var decompress = require('decompress');
|
18 | var fs = require('fs');
|
19 |
|
20 | fs.createReadStream('foo.tar.gz').pipe(decompress({ ext: '.tar.gz' }));
|
21 | ```
|
22 |
|
23 | ## API
|
24 |
|
25 | ### decompress(opts)
|
26 |
|
27 | Extract an archive using the `ext` option to determine which extractor to use.
|
28 | If no `path` is specified it'll extract it to your current location.
|
29 |
|
30 | ### decompress.canExtract(src, mime)
|
31 |
|
32 | Determine if a file can be extracted or not by checking the file extension
|
33 | and/or the MIME type.
|
34 |
|
35 | ```js
|
36 | decompress.canExtract('foo.zip');
|
37 | // => true
|
38 |
|
39 | decompress.canExtract('application/zip');
|
40 | // => true
|
41 | ```
|
42 |
|
43 | ## Options
|
44 |
|
45 | ### `ext`
|
46 |
|
47 | Type: `String`
|
48 | Default: `''`
|
49 |
|
50 | String that can be a file name, URL, MIME type etc.
|
51 |
|
52 | ### `path`
|
53 |
|
54 | Type: `String`
|
55 | Default: `process.cwd()`
|
56 |
|
57 | Path to extract the archive to. If no `path` is defined it'll extract it to your
|
58 | current location.
|
59 |
|
60 | ### `strip`
|
61 |
|
62 | Type: `Number`
|
63 | Default: `0`
|
64 |
|
65 | Equivalent 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)
|