Git Product home page Git Product logo

decompress-unzip's Introduction

decompress-unzip Build Status

zip decompress plugin

Install

$ npm install --save decompress-unzip

Usage

const decompress = require('decompress');
const decompressUnzip = require('decompress-unzip');

decompress('unicorn.zip', 'dist', {
	plugins: [
		decompressUnzip()
	]
}).then(() => {
	console.log('Files decompressed');
});

API

decompressUnzip()(buf)

buf

Type: Buffer

Buffer to decompress.

License

MIT © Kevin Mårtensson

decompress-unzip's People

Contributors

kevva avatar shinnn avatar trysound avatar wtgtybhertgeghgtwtg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

decompress-unzip's Issues

Unzip benchmark

I created a benchmark to see which unzip module is the fastest.

modules

benchmark script

(Using matcha)

'use strict';

var fs = require('fs');

var rimraf = require('rimraf');

var AdmZip = require('adm-zip');
var DecompressZip = require('decompress-zip');
var extractZip = require('extract-zip');
var unzip = require('unzip');

var FIXTURE_PATH = 'fixture.zip'; // path to a ZIP file

suite('Extract all files from a ZIP archive', function() {
  set('iterations', 10);

  before(rimraf.bind(null, 'tmp'));

  bench('adm-zip', function() {
    new AdmZip(FIXTURE_PATH).extractAllTo('tmp/adm-zip', true);
  });

  bench('decompress-zip', function(next) {
    new DecompressZip(FIXTURE_PATH)
    .on('extract', next)
    .on('error', next)
    .extract({path: 'tmp/decompress-zip'});
  });

  bench('extract-zip', function(next) {
    extractZip(FIXTURE_PATH, {dir: 'tmp/extract-zip'}, next);
  });

  bench('node-unzip', function(next) {
    var extract = new unzip.Extract({path: 'tmp/unzip/'})
    .on('finish', next)
    .on('error', next);

    fs.createReadStream(FIXTURE_PATH).pipe(extract);
  });
});

result

                      Extract all files from a ZIP archive
              43 op/s » adm-zip
             112 op/s » decompress-zip
              70 op/s » extract-zip
              49 op/s » node-unzip

I think we should replace adm-zip with another module.

Wrong stat

var Decompress = require('decompress'),
    unzip = require('decompress-unzip');

new Decompress()
    .src('master.zip')
    .use(unzip({ strip: 1 }))
    .run(function (err, files) {
        files.forEach(function (file) {
            console.log(file.stat.isFile(), file.path);
        });
    });

master.zip here

Directory mistaken for file

I've encountered an error unzipping an archive that appears to be a special case. I'm actually using gulp-decompress but the cause appears to be in this module.

Symptoms:

  1. One of the directories within the zip file is incorrectly identified as a file instead of a directory.
  2. An empty file is created instead of a directory.
  3. The unzip operation fails when it then attempts to unzip the files within that directory as the OS attempts to create a directory of the same name as the file.

Possible cause:

  1. The entry in question has a externalFileAttributes value of 0x00110000. This fails the equality comparison with16 because 0x00100000 is set.

I don't know enough about what the 0x00100000 bit is for to know if getType(entry, mode) should really be just checking for 0x00010000 being set, rather than an exact equality.

I tested using new zip archives that I created with 7zip and Windows right-click > Send to > Compressed (zipped) folder. Both of them worked correctly.

I am unable to share the zip file here as it's an installer for licensed software. I also have no idea how it was produced. However, I am happy to answer any questions or run additional tests as needed.

Default permission mode

Need to add default permission mode for prevent files blocking

var mode = new Mode(file.stat)
// 755
mode.owner.read = true;
mode.owner.write = true;
mode.owner.execute = true;
mode.group.read = true;
mode.group.execute = true;
mode.others.read = true;
mode.others.execute = true;

No Stream Support?

Of the default decompress plugins, this seems to be the only one that doesn't seem to support streamed input.

Is there a particular reason why streaming is not supported for unzip? There is already a dependency on get-stream, so it seems reasonable to just put that in front of the yauzl call.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.