blob: 4ee71089cf3a31fdbf0ba45efe15146fe78ddf3a [file] [log] [blame] [view]
Paul Lewis911c1b82019-12-02 12:46:151# extract-zip
2
3Unzip written in pure JavaScript. Extracts a zip into a directory. Available as a library or a command line program.
4
5Uses the [`yauzl`](http://npmjs.org/yauzl) ZIP parser.
6
Tim van der Lippe40875022020-05-07 09:40:377[![NPM](https://nodei.co/npm/extract-zip.png?global=true)](https://npm.im/extract-zip)
8[![Uses JS Standard Style](https://cdn.jsdelivr.net/gh/standard/standard/badge.svg)](https://github.com/standard/standard)
9[![Build Status](https://github.com/maxogden/extract-zip/workflows/CI/badge.svg)](https://github.com/maxogden/extract-zip/actions?query=workflow%3ACI)
Paul Lewis911c1b82019-12-02 12:46:1510
11## Installation
12
Tim van der Lippe40875022020-05-07 09:40:3713Make sure you have Node 10 or greater installed.
14
Paul Lewis911c1b82019-12-02 12:46:1515Get the library:
16
17```
18npm install extract-zip --save
19```
20
21Install the command line program:
22
23```
24npm install extract-zip -g
25```
26
27## JS API
28
Tim van der Lippe40875022020-05-07 09:40:3729```javascript
30const extract = require('extract-zip')
31
Tim van der Lippe2a1ede52020-06-24 12:21:0632async function main () {
Tim van der Lippe40875022020-05-07 09:40:3733 try {
34 await extract(source, { dir: target })
35 console.log('Extraction complete')
36 } catch (err) {
37 // handle any errors
38 }
39}
Paul Lewis911c1b82019-12-02 12:46:1540```
41
42### Options
43
Tim van der Lippe40875022020-05-07 09:40:3744- `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 Lewis911c1b82019-12-02 12:46:1547- `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
49Default modes are only used if no permissions are set in the zip file.
50
51## CLI Usage
52
53```
54extract-zip foo.zip <targetDirectory>
55```
56
57If not specified, `targetDirectory` will default to `process.cwd()`.