-
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.
- Loading branch information
1 parent
43311cf
commit 3b094cc
Showing
4 changed files
with
1,496 additions
and
132 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,51 +1,52 @@ | ||
const Stream = require('stream'), | ||
through = require('through2').obj, | ||
unzip = require('unzipper'), | ||
Vinyl = require('vinyl'); | ||
const Stream = require('stream') | ||
|
||
module.exports = (options = {}) => { | ||
|
||
const through = require('through2').obj | ||
|
||
const unzip = require('unzipper') | ||
|
||
const Vinyl = require('vinyl') | ||
|
||
function transform(file, enc, callback){ | ||
module.exports = (options = {}) => { | ||
function transform (file, enc, callback) { | ||
if (file.isNull()) { | ||
this.push(file); | ||
return callback(); | ||
this.push(file) | ||
return callback() | ||
} | ||
|
||
let stream = new Stream.PassThrough(); | ||
let stream = new Stream.PassThrough() | ||
|
||
if ( file.isBuffer() && !file.pipe ) { | ||
stream.end( file.contents ); | ||
} else { | ||
stream = file; | ||
if (file.isBuffer() && !file.pipe) { | ||
stream.end(file.contents) | ||
} else { | ||
stream = file | ||
} | ||
|
||
const opts = {}; | ||
opts.filter = options.filter || (() => true); | ||
opts.keepEmpty = options.keepEmpty || false; | ||
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.