Paul Lewis | 911c1b8 | 2019-12-02 12:46:15 | [diff] [blame] | 1 | # extract-zip |
| 2 | |
| 3 | Unzip written in pure JavaScript. Extracts a zip into a directory. Available as a library or a command line program. |
| 4 | |
| 5 | Uses the [`yauzl`](http://npmjs.org/yauzl) ZIP parser. |
| 6 | |
Tim van der Lippe | 4087502 | 2020-05-07 09:40:37 | [diff] [blame] | 7 | [](https://npm.im/extract-zip) |
| 8 | [](https://github.com/standard/standard) |
| 9 | [](https://github.com/maxogden/extract-zip/actions?query=workflow%3ACI) |
Paul Lewis | 911c1b8 | 2019-12-02 12:46:15 | [diff] [blame] | 10 | |
| 11 | ## Installation |
| 12 | |
Tim van der Lippe | 4087502 | 2020-05-07 09:40:37 | [diff] [blame] | 13 | Make sure you have Node 10 or greater installed. |
| 14 | |
Paul Lewis | 911c1b8 | 2019-12-02 12:46:15 | [diff] [blame] | 15 | Get the library: |
| 16 | |
| 17 | ``` |
| 18 | npm install extract-zip --save |
| 19 | ``` |
| 20 | |
| 21 | Install the command line program: |
| 22 | |
| 23 | ``` |
| 24 | npm install extract-zip -g |
| 25 | ``` |
| 26 | |
| 27 | ## JS API |
| 28 | |
Tim van der Lippe | 4087502 | 2020-05-07 09:40:37 | [diff] [blame] | 29 | ```javascript |
| 30 | const extract = require('extract-zip') |
| 31 | |
Tim van der Lippe | 2a1ede5 | 2020-06-24 12:21:06 | [diff] [blame] | 32 | async function main () { |
Tim van der Lippe | 4087502 | 2020-05-07 09:40:37 | [diff] [blame] | 33 | try { |
| 34 | await extract(source, { dir: target }) |
| 35 | console.log('Extraction complete') |
| 36 | } catch (err) { |
| 37 | // handle any errors |
| 38 | } |
| 39 | } |
Paul Lewis | 911c1b8 | 2019-12-02 12:46:15 | [diff] [blame] | 40 | ``` |
| 41 | |
| 42 | ### Options |
| 43 | |
Tim van der Lippe | 4087502 | 2020-05-07 09:40:37 | [diff] [blame] | 44 | - `dir` (required) - the path to the directory where the extracted files are written |
| 45 | - `defaultDirMode` - integer - Directory Mode (permissions), defaults to `0o755` |
| 46 | - `defaultFileMode` - integer - File Mode (permissions), defaults to `0o644` |
Paul Lewis | 911c1b8 | 2019-12-02 12:46:15 | [diff] [blame] | 47 | - `onEntry` - function - if present, will be called with `(entry, zipfile)`, entry is every entry from the zip file forwarded from the `entry` event from yauzl. `zipfile` is the `yauzl` instance |
| 48 | |
| 49 | Default modes are only used if no permissions are set in the zip file. |
| 50 | |
| 51 | ## CLI Usage |
| 52 | |
| 53 | ``` |
| 54 | extract-zip foo.zip <targetDirectory> |
| 55 | ``` |
| 56 | |
| 57 | If not specified, `targetDirectory` will default to `process.cwd()`. |