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

decompress-tarbz2

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decompress-tarbz2 - npm Package Compare versions

Comparing version 3.1.0 to 4.0.0

67

index.js
'use strict';
const decompressTar = require('decompress-tar');
const fileType = require('file-type');
const seekBzip = require('seek-bzip');
var bz2 = require('seek-bzip');
var File = require('vinyl');
var fs = require('fs');
var isBzip2 = require('is-bzip2');
var objectAssign = require('object-assign');
var stripDirs = require('strip-dirs');
var tar = require('tar-stream');
var through = require('through2');
module.exports = () => buf => {
if (!Buffer.isBuffer(buf)) {
return Promise.reject(new TypeError(`Expected a Buffer, got ${typeof buf}`));
}
module.exports = function (opts) {
opts = opts || {};
opts.strip = +opts.strip || 0;
if (!fileType(buf) || fileType(buf).ext !== 'bz2') {
return Promise.resolve([]);
}
return through.obj(function (file, enc, cb) {
var self = this;
var extract = tar.extract();
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new Error('Streaming is not supported'));
return;
}
if (!file.extract || !isBzip2(file.contents)) {
cb(null, file);
return;
}
extract.on('entry', function (header, stream, done) {
var chunk = [];
var len = 0;
stream.on('data', function (data) {
chunk.push(data);
len += data.length;
});
stream.on('end', function () {
if (header.type !== 'directory') {
self.push(new File({
contents: Buffer.concat(chunk, len),
path: stripDirs(header.name, opts.strip),
stat: objectAssign(new fs.Stats(), header)
}));
}
done();
});
});
extract.on('error', cb);
extract.on('finish', cb);
extract.end(bz2.decode(file.contents));
});
return decompressTar()(seekBzip.decode(buf));
};

25

package.json
{
"name": "decompress-tarbz2",
"version": "3.1.0",
"version": "4.0.0",
"description": "decompress tar.bz2 plugin",

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

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "node test/test.js"
"test": "xo && ava"
},

@@ -27,3 +27,2 @@ "files": [

"extract",
"gulpplugin",
"tar",

@@ -34,15 +33,15 @@ "tar.bz2",

"dependencies": {
"is-bzip2": "^1.0.0",
"object-assign": "^2.0.0",
"seek-bzip": "^1.0.3",
"strip-dirs": "^1.0.0",
"tar-stream": "^1.1.1",
"through2": "^0.6.1",
"vinyl": "^0.4.3"
"decompress-tar": "^4.0.0",
"file-type": "^3.8.0",
"pify": "^2.3.0",
"seek-bzip": "^1.0.5"
},
"devDependencies": {
"ava": "0.0.4",
"ava": "*",
"is-jpg": "^1.0.0",
"vinyl-file": "^1.1.0"
"xo": "*"
},
"xo": {
"esnext": true
}
}

@@ -1,54 +0,39 @@

# decompress-tarbz2 [![Build Status](http://img.shields.io/travis/kevva/decompress-tarbz2.svg?style=flat)](https://travis-ci.org/kevva/decompress-tarbz2)
# decompress-tarbz2 [![Build Status](https://travis-ci.org/kevva/decompress-tarbz2.svg?branch=master)](https://travis-ci.org/kevva/decompress-tarbz2)
> tar.bz2 decompress plugin
## Install
```sh
```
$ npm install --save decompress-tarbz2
```
## Usage
```js
var Decompress = require('decompress');
var tarbz2 = require('decompress-tarbz2');
const decompress = require('decompress');
const decompressTarbz = require('decompress-tarbz2');
var decompress = new Decompress()
.src('foo.tar.bz2')
.dest('dest')
.use(tarbz2({strip: 1}));
decompress.run(function (err, files) {
if (err) {
throw err;
}
console.log('Files extracted successfully!');
decompress('unicorn.tar.gz', 'dist', {
plugins: [
decompressTarbz()
]
}).then(() => {
console.log('Files decompressed');
});
```
You can also use this plugin with [gulp](http://gulpjs.com):
```js
var gulp = require('gulp');
var tarbz2 = require('decompress-tarbz2');
var vinylAssign = require('vinyl-assign');
## API
gulp.task('default', function () {
return gulp.src('foo.tar.bz2')
.pipe(vinylAssign({extract: true}))
.pipe(tarbz2({strip: 1}))
.pipe(gulp.dest('dest'));
});
```
### decompressTarbz()(buf)
## Options
#### buf
### strip
Type: `Buffer`
Type: `Number`
Default: `0`
Buffer to decompress.
Equivalent to `--strip-components` for tar.

@@ -55,0 +40,0 @@ ## License

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