# isomorphic-unzip

> Unzipping files, simple wrap for zip.js(for browser) and yauzl(for nodejs), make the apis consistent for NodeJS/Webpack/Browserify.

Latest version **1.1.5** (published 2019-05-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install isomorphic-unzip
pnpm add isomorphic-unzip
yarn add isomorphic-unzip
bun add isomorphic-unzip
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2019-05-13 |
| First published | 2016-05-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 139 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | xiaoyuze88 |
| Maintainers | xiaoyuze88 |
| Keywords | Javascript, NodeJS, Browserify, WebPack, .apk, .ipa, manifest, parser |

## Links

- npm: https://www.npmjs.com/package/isomorphic-unzip
- Repository: https://github.com/TencentWSRD/isomorphic-unzip
- Issues: https://github.com/TencentWSRD/isomorphic-unzip/issues
- npm.io page: https://npm.io/package/isomorphic-unzip

## Dependencies (2)

- [yauzl](https://npm.io/package/yauzl.md) ^2.8.0
- [buffer](https://npm.io/package/buffer.md) ^5.0.7

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.1.5 (latest) — 2019-05-13
- 1.1.1 — 2016-08-05
- 1.1.0 — 2016-06-01
- 1.0.28 — 2016-05-24
- 1.0.27 — 2016-05-24
- 1.0.26 — 2016-05-14
- 1.0.25 — 2016-05-14
- 1.0.24 — 2016-05-14
- 1.0.23 — 2016-05-14
- 1.0.22 — 2016-05-13
- 1.0.21 — 2016-05-13
- 1.0.20 — 2016-05-13
- 1.0.19 — 2016-05-12
- 1.0.18 — 2016-05-12
- 1.0.17 — 2016-05-12
- … 19 more at https://npm.io/package/isomorphic-unzip/versions

## README

# isomorphic-unzip

This is part of the project [isomorphic-pkg-reader](https://npmjs.com/package/isomorphic-pkg-reader).

Now it's only provide a few simple apis for supporting `isomorphic-pkg-reader`,
it can read the specific entries from a .zip file and parse them to Buffer, it works both for NodeJS and Browsersify/Webpack.

Basically it's just a wrap for `yauzl`(NodeJS) and `zip.js`(browser), and make it has nearly consistence apis. 

### Install

``` js
npm i isomorphic-unzip
```

```javascript
// usage

var Unzip = require('isomorphic-unzip');

// In browser, pass a File/Blob into the constructor
var unzip = new Unzip(file /* or blob */);

// In NodeJS, pass the dest path of your file
var unzip = new Unzip('/location/to/your/path');

// They have the same api: getBuffer
unzip.getBuffer(['androidmanifest.xml', 'resources.arsc'], function(err, buffers) {
  if(err) throw err;


  // buffers it's like {'androidmanifest.xml': Buffer, 'resources.arsc': Buffer}
  console.log(buffers);
});

```

### API

#### unzip.getBuffer(whatYouNeed, callback)
`whatYouNeed` is an array of String/RegExp/Function that contains the entry name you want to access, the `callback` will receive two params as callback(error, buffers).
`buffers` is a object that use the entry name as key, Buffer object as value.

When an check function is passed into the `whatYouNeed` array, it will be called like: 
checkFunc(entryName), when it return `true`, means this is what you need, just like `Array.prototype.filter`.


#### unzip.getEntries(callback, onEnd)

Things become a little different here between NodeJS/browser because in Node we use `lazy read entry` feature,
that means you need go through the next entry by yourself.
   
##### So in NodeJS
The callback function will be called like: `callback(error, zipfile, entry, next)`,
you can get the entry's basic information by the `entry` param, also you can get this entry's data via a static method `Unzip.getEntryData`.

```javascript
// The eaisest example is just in the source code in 'zip-node.js - Unzip.prototype.getBuffer'
unzip.getEntries(function(error, zipfile, entry, next) {
  if (error) throw error;

  // Do some stuff with the entry, like find some specific entry out.
  if (entry.fileName) {
  
  }
});

```
 
##### In browser
It's more simpler in browser, the callback function will be called like: `callback(entries)`, all entries will be passed as an array to the callback function.
You can find more information from the `zip.js` document [here](http://gildas-lormeau.github.io/zip.js/core-api.html).


##### Notice
The `entry` object is different between NodeJS and browser, we havn't make it consistence yet, please checkout each documents for more details([yauzl(NodeJS)](https://www.npmjs.com/package/yauzl#class-entry), [zip.js(browser)](http://gildas-lormeau.github.io/zip.js/core-api.html)).


#### Unzip.getEntryData(zipfile, entry, callback)
(NodeJS only)

This method is only for NodeJS, basically you can just use it together with `unzip.getEntries` when you want to access this entry's data.

More information you can get from the `yauzl`'s [document](https://www.npmjs.com/package/yauzl#usage).

We haven't make it totally consistence between NodeJS/browser yet, maybe latter.

---
_Source: https://npm.io/package/isomorphic-unzip · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
