Socket
Socket
Sign inDemoInstall

decompress-unzip

Package Overview
Dependencies
10
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.4.0 to 4.0.0

156

index.js
'use strict';
const getStream = require('get-stream');
const isZip = require('is-zip');
const pify = require('pify');
const yauzl = require('yauzl');
var fs = require('fs');
var isZip = require('is-zip');
var StatMode = require('stat-mode');
var readAllStream = require('read-all-stream');
var stripDirs = require('strip-dirs');
var through = require('through2');
var Vinyl = require('vinyl');
var yauzl = require('yauzl');
const getType = (entry, mode) => {
const IFMT = 61440;
const IFDIR = 16384;
const IFLNK = 40960;
const madeBy = entry.versionMadeBy >> 8;
module.exports = function (opts) {
opts = opts || {};
opts.strip = Number(opts.strip) || 0;
if ((mode & IFMT) === IFLNK) {
return 'symlink';
}
return through.obj(function (file, enc, cb) {
var self = this;
if ((mode & IFMT) === IFDIR || (madeBy === 0 && entry.externalFileAttributes === 16)) {
return 'directory';
}
if (file.isNull()) {
cb(null, file);
return;
}
return 'file';
};
if (file.isStream()) {
cb(new Error('Streaming is not supported'));
return;
}
const extractEntry = (entry, zip) => {
const file = {
mode: (entry.externalFileAttributes >> 16) & 0xFFFF,
mtime: entry.getLastModDate(),
path: entry.fileName
};
if (!file.extract || !isZip(file.contents)) {
cb(null, file);
return;
}
file.type = getType(entry, file.mode);
yauzl.fromBuffer(file.contents, function (err, zipFile) {
var count = 0;
if (file.mode === 0 && file.type === 'directory') {
file.mode = 493;
}
if (err) {
cb(err);
return;
}
if (file.mode === 0) {
file.mode = 420;
}
zipFile.on('error', cb);
zipFile.on('entry', function (entry) {
var filePath = stripDirs(entry.fileName, opts.strip);
return pify(zip.openReadStream.bind(zip))(entry)
.then(getStream.buffer)
.then(buf => {
file.data = buf;
if (filePath === '.') {
if (++count === zipFile.entryCount) {
cb();
}
if (file.type === 'symlink') {
file.linkname = buf.toString();
}
return;
}
return file;
})
.catch(err => {
zip.close();
throw err;
});
};
var stat = new fs.Stats();
var mode = (entry.externalFileAttributes >> 16) & 0xFFFF;
const extractFile = zip => new Promise((resolve, reject) => {
const files = [];
stat.mode = mode;
zip.readEntry();
if (entry.getLastModDate()) {
stat.mtime = entry.getLastModDate();
}
zip.on('entry', entry => {
extractEntry(entry, zip)
.catch(reject)
.then(file => {
files.push(file);
zip.readEntry();
});
});
if (entry.fileName.charAt(entry.fileName.length - 1) === '/') {
if (!mode) {
new StatMode(stat).isDirectory(true);
}
zip.on('error', reject);
zip.on('end', () => resolve(files));
});
self.push(new Vinyl({
path: filePath,
stat: stat
}));
module.exports = () => buf => {
if (!Buffer.isBuffer(buf)) {
return Promise.reject(new TypeError('Expected a buffer'));
}
if (++count === zipFile.entryCount) {
cb();
}
if (!isZip(buf)) {
return Promise.resolve([]);
}
return;
}
zipFile.openReadStream(entry, function (err, readStream) {
if (err) {
cb(err);
return;
}
readAllStream(readStream, null, function (err, data) {
if (err) {
cb(err);
return;
}
if (!mode) {
new StatMode(stat).isFile(true);
}
self.push(new Vinyl({
contents: data,
path: filePath,
stat: stat
}));
if (++count === zipFile.entryCount) {
cb();
}
});
});
});
});
});
return pify(yauzl.fromBuffer)(buf, {lazyEntries: true}).then(extractFile);
};
{
"name": "decompress-unzip",
"version": "3.4.0",
"version": "4.0.0",
"description": "decompress zip plugin",

@@ -13,3 +13,3 @@ "license": "MIT",

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},

@@ -26,22 +26,18 @@ "scripts": {

"extract",
"gulpplugin",
"zip"
],
"dependencies": {
"get-stream": "^2.2.0",
"is-zip": "^1.0.0",
"read-all-stream": "^3.0.0",
"stat-mode": "^0.2.0",
"strip-dirs": "^1.0.0",
"through2": "^2.0.0",
"vinyl": "^1.0.0",
"yauzl": "^2.2.1"
"pify": "^2.3.0",
"yauzl": "^2.4.2"
},
"devDependencies": {
"ava": "^0.2.0",
"buffer-equal": "^0.0.1",
"got": "^4.2.0",
"ava": "*",
"is-jpg": "^1.0.0",
"vinyl-file": "^1.1.0",
"xo": "*"
},
"xo": {
"esnext": true
}
}

@@ -16,24 +16,11 @@ # decompress-unzip [![Build Status](https://travis-ci.org/kevva/decompress-unzip.svg?branch=master)](https://travis-ci.org/kevva/decompress-unzip)

```js
const Decompress = require('decompress');
const decompress = require('decompress');
const decompressUnzip = require('decompress-unzip');
new Decompress()
.src('foo.zip')
.dest('dest')
.use(decompressUnzip({strip: 1}))
.run();
```
You can also use this plugin with [gulp](http://gulpjs.com):
```js
const decompressUnzip = require('decompress-unzip');
const gulp = require('gulp');
const vinylAssign = require('vinyl-assign');
gulp.task('default', () => {
return gulp.src('foo.zip')
.pipe(vinylAssign({extract: true}))
.pipe(decompressUnzip({strip: 1}))
.pipe(gulp.dest('dest'));
decompress('unicorn.zip', 'dist', {
plugins: [
decompressUnzip()
]
}).then(() => {
console.log('Files decompressed');
});

@@ -45,10 +32,9 @@ ```

### decompressUnzip(options)
### decompressUnzip()(buf)
#### options.strip
#### buf
Type: `number`
Default: `0`
Type: `Buffer`
Remove leading directory components from extracted files.
Buffer to decompress.

@@ -55,0 +41,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc