1.1.5 • Published 4 years ago

isomorphic-unzip v1.1.5

Weekly downloads
498
License
MIT
Repository
github
Last release
4 years ago

isomorphic-unzip

This is part of the project 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

npm i isomorphic-unzip
// 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.

// 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.

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), zip.js(browser)).

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.

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

1.1.5

4 years ago

1.1.1

6 years ago

1.1.0

7 years ago

1.0.28

7 years ago

1.0.27

7 years ago

1.0.26

7 years ago

1.0.25

7 years ago

1.0.24

7 years ago

1.0.23

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago