Skip to content

Commit

Permalink
Merge pull request #26 from terrierscript/development
Browse files Browse the repository at this point in the history
v1.1.0 - Gulp@4 Compatibility!
  • Loading branch information
terrierscript committed Jun 1, 2019
2 parents 53a84d6 + 583983f commit c0fedb5
Show file tree
Hide file tree
Showing 5 changed files with 2,485 additions and 144 deletions.
Binary file added file.zip
Binary file not shown.
65 changes: 38 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,52 @@
const through = require('through2').obj,
unzip = require('unzipper'),
Vinyl = require('vinyl');
const Stream = require('stream')

const through = require('through2').obj

const unzip = require('unzipper')

const Vinyl = require('vinyl')

module.exports = (options = {}) => {

function transform(file, enc, callback){
function transform (file, enc, callback) {
if (file.isNull()) {
this.push(file);
return callback();
this.push(file)
return callback()
}

const opts = {};
opts.filter = options.filter || (() => true);
opts.keepEmpty = options.keepEmpty || false;
let stream = new Stream.PassThrough()

file.pipe(unzip.Parse())
if (file.isBuffer() && !file.pipe) {
stream.end(file.contents)
} else {
stream = file
}

const opts = {}
opts.filter = options.filter || (() => true)
opts.keepEmpty = options.keepEmpty || false

stream.pipe(unzip.Parse())
.on('entry', entry => {
const chunks = [];
if(!opts.filter(entry)){
entry.autodrain();
return;
const chunks = []
if (!opts.filter(entry)) {
entry.autodrain()
return
}

entry.pipe(through((chunk, enc, cb) => {
chunks.push(chunk);
cb();
chunks.push(chunk)
cb()
}, cb => {
if(entry.type === 'File' && (chunks.length > 0 || opts.keepEmpty)){
if (entry.type === 'File' && (chunks.length > 0 || opts.keepEmpty)) {
this.push(new Vinyl({
cwd : "./",
path : entry.path,
cwd: './',
path: entry.path,
contents: Buffer.concat(chunks)
}));
}))
}
cb();
}));
}).on('close', callback);
cb()
}))
}).on('close', callback)
}
return through(transform);
};
return through(transform)
}

0 comments on commit c0fedb5

Please sign in to comment.