npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

isomorphic-unzip

v1.1.5

Published

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

Downloads

7,416

Readme

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.