Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

decompress

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decompress - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

149

cli.js

@@ -6,58 +6,36 @@ #!/usr/bin/env node

var fs = require('fs');
var nopt = require('nopt');
var pkg = require('./package.json');
var meow = require('meow');
var stdin = require('get-stdin');
/**
* Options
* Initialize CLI
*/
var opts = nopt({
help: Boolean,
mode: Number,
strip: String,
version: Boolean
var cli = meow({
requireInput: process.stdin.isTTY,
help: [
' Usage',
' decompress <file> [directory]',
' cat <file> | decompress [directory]',
'',
' Example',
' decompress --strip 1 file.zip out',
' cat file.zip | decompress out',
'',
' Options',
' -m, --mode Set mode on the extracted files',
' -s, --strip Equivalent to --strip-components for tar'
].join('\n')
}, {
h: '--help',
m: '--mode',
s: '--strip',
v: '--version'
string: [
'mode',
'strip'
],
alias: {
m: 'mode',
s: 'strip'
}
});
/**
* Help screen
*/
function help() {
console.log(pkg.description);
console.log('');
console.log('Usage');
console.log(' $ decompress <file> [directory]');
console.log('');
console.log('Example');
console.log(' $ decompress --strip 1 file.zip out');
console.log('');
console.log('Options');
console.log(' -m, --mode Set mode on the extracted files');
console.log(' -s, --strip Equivalent to --strip-components for tar');
}
/**
* Show help
*/
if (opts.help) {
help();
return;
}
/**
* Show package version
*/
if (opts.version) {
console.log(pkg.version);
return;
}
/**
* Check if path is a file

@@ -70,11 +48,11 @@ *

function isFile(path) {
if (/^[^\s]+\.\w*$/g.test(path)) {
return true;
}
if (/^[^\s]+\.\w*$/g.test(path)) {
return true;
}
try {
return fs.statSync(path).isFile();
} catch (e) {
return false;
}
try {
return fs.statSync(path).isFile();
} catch (e) {
return false;
}
}

@@ -87,19 +65,21 @@

* @param {String} dest
* @param {Object} opts
* @api private
*/
function run(src, dest) {
var decompress = new Decompress(opts)
.src(src)
.dest(dest)
.use(Decompress.tar(opts))
.use(Decompress.targz(opts))
.use(Decompress.zip(opts));
function run(src, dest, opts) {
var decompress = new Decompress(opts)
.src(src)
.dest(dest)
.use(Decompress.tar(opts))
.use(Decompress.tarbz2(opts))
.use(Decompress.targz(opts))
.use(Decompress.zip(opts));
decompress.run(function (err) {
if (err) {
console.error(err);
process.exit(1);
}
});
decompress.run(function (err) {
if (err) {
console.error(err);
process.exit(1);
}
});
}

@@ -111,15 +91,24 @@

var src = opts.argv.remain;
var dest = process.cwd();
if (process.stdin.isTTY) {
var src = cli.input;
var dest = process.cwd();
if (!src.length) {
help();
return;
}
if (!isFile(src[src.length - 1])) {
dest = src[src.length - 1];
src.pop();
}
if (!isFile(src[src.length - 1])) {
dest = src[src.length - 1];
src.pop();
run(src, dest, cli.flags);
} else {
var dest = cli.input;
if (dest.length && !isFile(dest[dest.length - 1])) {
dest = dest[dest.length - 1];
} else {
dest = process.cwd();
}
stdin.buffer(function (buf) {
run(buf, dest, cli.flags);
});
}
run(src, dest);

@@ -17,9 +17,8 @@ 'use strict';

function Decompress(opts) {
if (!(this instanceof Decompress)) {
return new Decompress();
}
if (!(this instanceof Decompress)) {
return new Decompress(opts);
}
this.opts = opts || {};
this.opts.mode = parseInt(this.opts.mode, 8) || null;
this.streams = [];
this.opts = opts || {};
this.streams = [];
}

@@ -35,8 +34,8 @@

Decompress.prototype.src = function (file) {
if (!arguments.length) {
return this._src;
}
if (!arguments.length) {
return this._src;
}
this._src = file;
return this;
this._src = file;
return this;
};

@@ -52,8 +51,8 @@

Decompress.prototype.dest = function (dir) {
if (!arguments.length) {
return this._dest;
}
if (!arguments.length) {
return this._dest;
}
this._dest = dir;
return this;
this._dest = dir;
return this;
};

@@ -69,4 +68,4 @@

Decompress.prototype.use = function (plugin) {
this.streams.push(plugin);
return this;
this.streams.push(plugin);
return this;
};

@@ -82,20 +81,16 @@

Decompress.prototype.run = function (cb) {
cb = cb || function () {};
this.streams.unshift(this.read(this.src()));
cb = cb || function () {};
this.streams.unshift(this.read(this.src()));
if (this.dest()) {
this.streams.push(fs.dest(this.dest(), this.opts));
}
if (this.dest()) {
this.streams.push(fs.dest(this.dest(), this.opts));
}
var pipe = combine(this.streams);
var end = concat(function (file) {
cb(null, file);
});
var pipe = combine(this.streams);
var end = concat(function (file) {
cb(null, file, pipe);
});
pipe.on('error', function (err) {
cb(err);
return;
});
pipe.pipe(end);
pipe.on('error', cb);
pipe.pipe(end);
};

@@ -111,15 +106,13 @@

Decompress.prototype.read = function (src) {
if (Buffer.isBuffer(src)) {
var stream = through.obj(function (file, enc, cb) {
cb(null, file);
});
if (Buffer.isBuffer(src)) {
var stream = through.obj();
stream.end(new File({
contents: src
}));
stream.end(new File({
contents: src
}));
return stream;
}
return stream;
}
return fs.src(src);
return fs.src(src);
};

@@ -126,0 +119,0 @@

{
"name": "decompress",
"version": "2.0.0",
"description": "Easily extract archives",
"version": "2.1.0",
"description": "Extracting archives made easy",
"license": "MIT",

@@ -42,3 +42,4 @@ "repository": "kevva/decompress",

"decompress-unzip": "^2.0.0",
"nopt": "^3.0.1",
"get-stdin": "^3.0.0",
"meow": "^1.0.0",
"stream-combiner": "^0.2.1",

@@ -50,4 +51,5 @@ "through2": "^0.6.1",

"devDependencies": {
"ava": "0.0.4"
"ava": "0.0.4",
"rimraf": "^2.2.8"
}
}
# decompress [![Build Status](http://img.shields.io/travis/kevva/decompress.svg?style=flat)](https://travis-ci.org/kevva/decompress)
> Easily extract archives
> Extracting archives made easy

@@ -16,13 +16,13 @@ ## Install

var decompress = new Decompress({ mode: 755 })
.src('foo.zip')
.dest('destFolder')
.use(Decompress.zip({ strip: 1 }));
var decompress = new Decompress({ mode: '755' })
.src('foo.zip')
.dest('destFolder')
.use(Decompress.zip({ strip: 1 }));
decompress.run(function (err) {
if (err) {
throw err;
}
if (err) {
throw err;
}
console.log('Archive extracted successfully!');
console.log('Archive extracted successfully!');
});

@@ -39,7 +39,10 @@ ```

Set the files to be decompress. Takes a buffer, glob string or an array of glob
strings as argument.
Type: `Array|Buffer|String`
Set the files to be extracted.
### .dest(path)
Type: `String`
Set the destination to where your file will be extracted to.

@@ -49,2 +52,4 @@

Type: `Function`
Add a `plugin` to the middleware stack.

@@ -54,4 +59,11 @@

Type: `Function`
Extract your file with the given settings.
#### cb(err, files, stream)
The callback will return an array of vinyl files in `files` and a Readable/Writable
stream in `stream`.
## Options

@@ -61,6 +73,11 @@

Type: `String`
Set mode on the extracted files, i.e `{ mode: '755' }`.
### strip
Type: `Number`
Default: `null`
Set mode on the extracted files.
Equivalent to `--strip-components` for tar.

@@ -72,3 +89,3 @@ ## Plugins

* [tar](#tar) — Extract TAR files.
* [tar.bz](#tarbz) — Extract TAR.BZ files.
* [tar.bz2](#tarbz2) — Extract TAR.BZ files.
* [tar.gz](#targz) — Extract TAR.GZ files.

@@ -85,6 +102,6 @@ * [zip](#zip) — Extract ZIP files.

var decompress = new Decompress()
.use(Decompress.tar({ strip: 1 }));
.use(Decompress.tar({ strip: 1 }));
```
### .tarbz()
### .tarbz2()

@@ -97,3 +114,3 @@ Extract TAR.BZ files.

var decompress = new Decompress()
.use(Decompress.tarbz({ strip: 1 }));
.use(Decompress.tarbz2({ strip: 1 }));
```

@@ -109,3 +126,3 @@

var decompress = new Decompress()
.use(Decompress.targz({ strip: 1 }));
.use(Decompress.targz({ strip: 1 }));
```

@@ -121,3 +138,3 @@

var decompress = new Decompress()
.use(Decompress.zip({ strip: 1 }));
.use(Decompress.zip({ strip: 1 }));
```

@@ -135,6 +152,8 @@

Usage
$ decompress <file> [directory]
decompress <file> [directory]
cat <file> | decompress [directory]
Example
$ decompress --strip 1 file.zip out
decompress --strip 1 file.zip out
cat file.zip | decompress out

@@ -141,0 +160,0 @@ Options

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc