Skip to content

Commit

Permalink
Fix: Attempt to fix "write after end" with duplexer2 (closes #25)
Browse files Browse the repository at this point in the history
  • Loading branch information
yocontra authored and phated committed Nov 28, 2017
1 parent 23fa7ee commit d613385
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var _ = require('lodash');
var defaults = _.defaults;

var duplex = require('duplexer2');
var through = require('through2');
var gs = require('glob-stream');
var File = require('vinyl');
Expand All @@ -15,9 +16,16 @@ function createFile (globFile, enc, cb) {
}

function src(glob, opt) {
var pass = through.obj();

if (!isValidGlob(glob)) {
throw new Error('Invalid glob argument: ' + glob);
}
// return dead stream if empty array
if (Array.isArray(glob) && glob.length === 0) {
process.nextTick(pass.end.bind(pass));
return pass;
}

var options = defaults({}, opt, {
read: true,
Expand All @@ -36,17 +44,15 @@ function src(glob, opt) {
.pipe(getContents(options));
}

return outputStream
.pipe(through.obj());
outputStream = outputStream.pipe(pass);

return duplex(pass, outputStream);
}

function isValidGlob(glob) {
if (typeof glob === 'string') {
return true;
}
if (Array.isArray(glob) && glob.length !== 0) {
return true;
}
return false;
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"author": "Fractal <contact@wearefractal.com> (http://wearefractal.com/)",
"main": "./index.js",
"dependencies": {
"duplexer2": "0.0.2",
"glob-stream": "^3.1.5",
"glob-watcher": "^0.0.6",
"graceful-fs": "^3.0.0",
Expand Down

0 comments on commit d613385

Please sign in to comment.