diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..7893f85 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,93 @@ +# Contributing +*This contributing guide was forked from [@PurpleBooth](https://gist.github.com/PurpleBooth/b24679402957c63ec426)* + +When contributing to this repository, please first discuss the change you wish to make via issue, +email, or any other method with the owners of this repository before making a change. + +Please note we have a code of conduct, please follow it in all your interactions with the project. + +## Pull Request Process + +1. Ensure any install or build dependencies are removed before the end of the layer when doing a + build. +2. Update the README.md with details of changes to the interface, this includes new environment + variables, exposed ports, useful file locations and container parameters. +3. Increase the version numbers in any examples files and the README.md to the new version that this + Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). +4. You may merge the Pull Request in once you have the sign-off of other developers, or if you + do not have permission to do that, you may request the reviewer to merge it for you. + +## Code of Conduct + +### Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +### Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or +advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +### Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +### Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +### Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at ulisesgascondev@gmail.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +### Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..08623f4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +The BSD 2-Clause License +Copyright © 2014 terrierscript +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index 12a99fb..dfd04bb 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,19 @@ -[![travis](https://travis-ci.org/inuscript/gulp-unzip.svg)](https://travis-ci.org/inuscript/gulp-unzip) +[![travis](https://travis-ci.org/terrierscript/gulp-unzip.svg)](https://travis-ci.org/terrierscript/gulp-unzip) +![dependencies](https://img.shields.io/david/terrierscript/gulp-unzip.svg) +![devDependencies](https://img.shields.io/david/dev/terrierscript/gulp-unzip.svg) +![Downloads per Week NPM](https://img.shields.io/npm/dw/gulp-unzip.svg) +![Open PRs](https://img.shields.io/github/issues-pr/terrierscript/gulp-unzip.svg) +![Open Issues](https://img.shields.io/github/issues-raw/terrierscript/gulp-unzip.svg) + + # gulp-unzip > gulp plugin for unzip file. -# Usage +### Usage + +```bash +npm install gulp-unzip --save +``` ```js var unzip = require('gulp-unzip') @@ -13,9 +24,9 @@ gulp.task('filter_sample', function(){ }) ``` -# Options +### Options -## filter +#### filter You can provide a `filter` option. It should be a function that gets an `entry` as an argument and returns `true` or `false`. @@ -35,7 +46,7 @@ gulp.task('filter_sample', function(){ }) ``` -## keepEmpty +#### keepEmpty You can provide `true` or `false` in `keepEmpty` for whether you want to extract empty files from the archive or not. Defaults to `false`. @@ -43,18 +54,25 @@ You can provide `true` or `false` in `keepEmpty` for whether you want to extract gulp.task('filter_sample', function(){ gulp.src("./download/bootstrap-3.1.1-dist.zip") .pipe(unzip({ keepEmpty : true })) - ... + //... }) ``` -# Entry +### Contributors + +If you want to contribute to the project, please check de [Contribution Guidelines](CONTRIBUTING.md) -For more info, go to [node-unzip](https://github.com/EvanOxfeld/node-unzip). +**Author** +- [terrierscript (@terrierscript)](https://github.com/terrierscript) -- `entry.size`, returns the file size -- `entry.type`, returns `Directory` or `File` -- `entry.path`, returns the file path in the zip file +**Maintainers** +- [Ulises Gascón (@ulisesGascon)](https://github.com/ulisesGascon) -# Known issue -- Cause `RangeError: Maximum call stack size exceeded` when open large zip file - - https://github.com/inuscript/gulp-unzip/issues/2 +**Contributors** +- [Joey Cozza (@joeycozza)](https://github.com/joeycozza) +- [Joe Pettersson (@Joe8Bit)](https://github.com/Joe8Bit) +- [Erik Vold (@erikvold)](https://github.com/erikvold) +- [hami (@hami-jp)](https://github.com/hami-jp) +- [Selwyn (@Selwyn)](https://github.com/Siilwyn) +- [João Moreno (@joaomoreno)](https://github.com/joaomoreno) +- [Evan Oxfeld (@EvanOxfeld)](https://github.com/EvanOxfeld) diff --git a/index.js b/index.js index c692d72..77b035d 100644 --- a/index.js +++ b/index.js @@ -1,50 +1,41 @@ -var through = require('through2'); -var unzip = require('unzipper') -var fs = require('fs') -var defaults = require('defaults') -var fancyLog = require('fancy-log') -var Vinyl = require('vinyl') +const through = require('through2').obj, + unzip = require('unzipper'), + Vinyl = require('vinyl'); -module.exports = function(options){ +module.exports = (options = {}) => { + function transform(file, enc, callback){ if (file.isNull()) { this.push(file); return callback(); } - var opts = {}; - options = options || {}; - opts.filter = options.filter || function () { return true; }; + const opts = {}; + opts.filter = options.filter || (() => true); opts.keepEmpty = options.keepEmpty || false; - // unzip file - var self = this file.pipe(unzip.Parse()) - .on('entry', function(entry){ - var chunks = [] + .on('entry', entry => { + const chunks = []; if(!opts.filter(entry)){ - entry.autodrain() - // skip entry - return + entry.autodrain(); + return; } - - entry.pipe(through.obj(function(chunk, enc, cb){ - // fancyLog("Find file: "+ entry.path) - chunks.push(chunk) - cb() - }, function(cb){ - if(entry.type == 'File' && (chunks.length > 0 || opts.keepEmpty)){ - self.push(new Vinyl({ + + entry.pipe(through((chunk, enc, cb) => { + chunks.push(chunk); + cb(); + }, cb => { + if(entry.type === 'File' && (chunks.length > 0 || opts.keepEmpty)){ + this.push(new Vinyl({ cwd : "./", path : entry.path, contents: Buffer.concat(chunks) - })) + })); } - cb() - })) - }).on('close', function(){ - callback() - }) + cb(); + })); + }).on('close', callback); } - return through.obj(transform); -} + return through(transform); +}; diff --git a/package.json b/package.json index 29d8103..24e84b8 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "gulp-unzip", - "version": "1.0.0", + "version": "1.0.1", "description": "gulp plugin for unzip", "main": "index.js", "repository": { "type": "git", - "url": "https://github.com/inuscript/gulp-unzip.git" + "url": "https://github.com/terrierscript/gulp-unzip.git" }, "scripts": { "test": "mocha" @@ -16,19 +16,47 @@ "zip", "package" ], - "author": "inuscript", + "author": { + "name": "terrierscript", + "url": "https://github.com/terrierscript" + }, + "contributors": [ + { + "name":"Joey Cozza", + "url": "https://github.com/joeycozza" + },{ + "name":"Joe Pettersson", + "url": "https://github.com/Joe8Bit" + },{ + "name":"Erik Vold", + "url": "https://github.com/erikvold" + },{ + "name":"hami", + "url": "https://github.com/hami-jp" + },{ + "name":"Selwyn", + "url": "https://github.com/Siilwyn" + },{ + "name":"João Moreno", + "url": "https://github.com/joaomoreno" + },{ + "name":"Evan Oxfeld", + "url": "https://github.com/EvanOxfeld" + },{ + "name": "Ulises Gascón", + "url": "https://github.com/ulisesGascon" + } + ], "license": "BSD-2-Clause", "dependencies": { - "defaults": "^1.0.0", - "fancy-log": "^1.3.2", - "through2": "^0.4.1", - "unzipper": "^0.7.1", - "vinyl": "^1.2.0" + "through2": "3.0.0", + "unzipper": "0.9.10", + "vinyl": "1.2.0" }, "devDependencies": { - "mocha": "^1.18.0", - "assert-plus": "^0.1.5", - "gulp-concat": "^2.2.0", - "minimatch": "^0.2.14" + "mocha": "5.2.0", + "assert-plus": "1.0.0", + "gulp-concat": "2.6.1", + "minimatch": "3.0.4" } } diff --git a/test.js b/test.js index 7587e52..bd1fe68 100644 --- a/test.js +++ b/test.js @@ -1,13 +1,13 @@ -var unzip = require('./index.js') -var fs = require('fs') -var assert = require('assert-plus') -var pj = require('path').join; -var minimatch = require('minimatch') -var Vinyl = require('vinyl'); +const unzip = require('./index.js'), + fs = require('fs'), + assert = require('assert-plus'), + pj = require('path').join, + minimatch = require('minimatch'), + Vinyl = require('vinyl'); function createVinyl(filename, contents) { - var base = pj(__dirname, 'fixture'); - var filePath = pj(base, filename); + const base = pj(__dirname, 'fixture'); + const filePath = pj(base, filename); return new Vinyl({ cwd: __dirname, @@ -17,108 +17,114 @@ function createVinyl(filename, contents) { }); } -describe('gulp-unzip', function(){ - it("null file", function(done){ - var stream = unzip() - var mock = new Vinyl() - stream.on('data', function(file){ - assert.deepEqual(file, mock) - done() - }) - stream.write(mock) - stream.end() - }) - it("basic", function(done){ - var stream = unzip() - var mock = createVinyl('basic/zipped.zip') - stream.on('data', function(file){ - var expect = fs.readFileSync('fixture/basic/' + file.path) - assert.deepEqual(expect, file.contents) - }).on('end', function(){ - done() - }) - stream.write(mock) - stream.end() - }) - it("large_file", function(done){ - var stream = unzip() - var mock = createVinyl('largefile/zipped.zip') - stream.on('data', function(file){ - var expect = fs.readFileSync('fixture/largefile/' + file.path) - assert.deepEqual(expect, file.contents) - }).on('end', function(){ - done() - }) - stream.write(mock) - stream.end() - }) - describe("filter option", function(){ - it("false filter", function(done){ - var stream = unzip({ - filter : function(){return false} - }) - var mock = createVinyl('basic/zipped.zip') - stream.on('data', function(file){ - throw "entried" - }).on('end', function(){ - done() - }) - stream.write(mock) - stream.end() - }) +describe('gulp-unzip', () => { + + describe('basic behaviour', () => { + + it("null file", done => { + const stream = unzip(); + const mock = new Vinyl(); + + stream.on('data', file => { + assert.deepEqual(file, mock); + done(); + }); + stream.write(mock); + stream.end(); + }); + + it("basic", done => { + const stream = unzip(); + const mock = createVinyl('basic/zipped.zip'); + + stream.on('data', file => { + const expect = fs.readFileSync('fixture/basic/' + file.path); + assert.deepEqual(expect, file.contents); + }).on('end', done); + stream.write(mock); + stream.end(); + }); + + it("large_file", done => { + const stream = unzip(); + const mock = createVinyl('largefile/zipped.zip'); + + stream.on('data', file => { + const expect = fs.readFileSync('fixture/largefile/' + file.path); + assert.deepEqual(expect, file.contents); + }).on('end', done); + stream.write(mock); + stream.end(); + }); + }); + + describe("filter option", () => { + + it("false filter", done => { + const stream = unzip({ + filter : () => false + }); + const mock = createVinyl('basic/zipped.zip'); + + stream.on('data', file => { + throw "entried"; + }).on('end', done); + stream.write(mock); + stream.end(); + }); - it("only extract css with filter", function(done){ - var stream = unzip({ - filter : function(entry){ - return minimatch(entry.path, "**/*.min.css") - } - }) - var mock = createVinyl('sometypes/bootstrap-3.1.1-dist.zip') - stream.on('data', function(file){ - assert.ok(/.*\.min\.css/.test(file.path)) - }).on('end', function(){ - done() - }) - stream.write(mock) - stream.end() - }) - }) + it("only extract css with filter", done => { + const stream = unzip({ + filter: entry => minimatch(entry.path, "**/*.min.css") + }); + const mock = createVinyl('sometypes/bootstrap-3.1.1-dist.zip'); + + stream.on('data', file => { + assert.ok(/.*\.min\.css/.test(file.path)); + }).on('end', done); + stream.write(mock); + stream.end(); + }); + }); - describe("keepEmpty option", function(){ - it("true", function(done){ - var stream = unzip({ keepEmpty: false }) - var didSeeEmpty = false - var mock = createVinyl('basic/zipped.zip') - stream.on('data', function(file){ + describe("keepEmpty option", () => { + + it("true", done => { + const stream = unzip({ keepEmpty: false }); + const mock = createVinyl('basic/zipped.zip'); + let didSeeEmpty = false; + + stream.on('data', file => { if (file.contents.length === 0) { didSeeEmpty = true; } - }).on('end', function(){ + }).on('end', () => { if (didSeeEmpty) { - throw new Error('saw empty') + throw new Error('saw empty'); } - done() - }) - stream.write(mock) - stream.end() - }) + done(); + }); + stream.write(mock); + stream.end(); + }); + + it("false", done => { + const stream = unzip({ keepEmpty: true }); + const mock = createVinyl('basic/zipped.zip'); + let didSeeEmpty = false; - it("false", function(done){ - var stream = unzip({ keepEmpty: true }) - var didSeeEmpty = false - var mock = createVinyl('basic/zipped.zip') - stream.on('data', function(file){ + stream.on('data', file => { if (file.contents.length === 0) { didSeeEmpty = true; } - }).on('end', function(){ + }).on('end', () => { if (!didSeeEmpty) { - throw new Error('did not see empty') + throw new Error('did not see empty'); } - done() - }) - stream.write(mock) - stream.end() - }) - }) -}) + done(); + }); + stream.write(mock); + stream.end(); + }); + }); +});