decompress-tarbz2
Advanced tools
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)); | ||
}; |
{ | ||
"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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
4
1
2963
13
43
+ Addeddecompress-tar@^4.0.0
+ Addedfile-type@^3.8.0
+ Addedpify@^2.3.0
+ Addeddecompress-tar@4.1.1(transitive)
+ Addedfile-type@3.9.05.2.0(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedpify@2.3.0(transitive)
- Removedis-bzip2@^1.0.0
- Removedobject-assign@^2.0.0
- Removedstrip-dirs@^1.0.0
- Removedtar-stream@^1.1.1
- Removedthrough2@^0.6.1
- Removedvinyl@^0.4.3
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedchalk@1.1.3(transitive)
- Removedclone@0.2.0(transitive)
- Removedclone-stats@0.0.1(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedis-absolute@0.1.7(transitive)
- Removedis-bzip2@1.0.0(transitive)
- Removedis-natural-number@2.1.1(transitive)
- Removedis-relative@0.1.3(transitive)
- Removedisarray@0.0.1(transitive)
- Removedminimist@1.2.8(transitive)
- Removedobject-assign@2.1.1(transitive)
- Removedreadable-stream@1.0.34(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedstrip-dirs@1.1.1(transitive)
- Removedsum-up@1.0.3(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedthrough2@0.6.5(transitive)
- Removedvinyl@0.4.6(transitive)
Updatedseek-bzip@^1.0.5