-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from terrierscript/development
v1.1.0 - Gulp@4 Compatibility!
- Loading branch information
Showing
5 changed files
with
2,485 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.