highland-process
Advanced tools
Comparing version 1.0.0 to 1.0.1
44
index.js
@@ -12,7 +12,47 @@ var _ = require('highland'); | ||
return function(stream) { | ||
stream.pipe(process.stdin); | ||
return exports.from(process); | ||
var out, | ||
pipe; | ||
out = exports.from(process); | ||
// like `_.pipe` but separate errors | ||
pipe = stream.consume(function(error, value, push, next) { | ||
if (error) { | ||
// send errors to the out directly | ||
out.write(new StreamError(error)); | ||
return next(); | ||
} | ||
if (value === nil) { | ||
return process.stdin.end(); | ||
} | ||
if (process.stdin.write(value) !== false) { | ||
next(); | ||
} | ||
}); | ||
process.stdin.on('drain', onConsumerDrain); | ||
stream._destructors.push(function () { | ||
process.stdin.removeListener('drain', onConsumerDrain); | ||
}); | ||
function onConsumerDrain() { | ||
pipe.resume(); | ||
} | ||
pipe.resume(); | ||
return out; | ||
}; | ||
}; | ||
// TODO(ibash) remove this in favor of using the actual StreamError from highland | ||
// ref: https://github.com/Datahero/datahero-node/issues/9676 | ||
function StreamError(err) { | ||
this.__HighlandStreamError__ = true; | ||
this.error = err; | ||
} | ||
function errorConsumer() { | ||
@@ -19,0 +59,0 @@ var message = ''; |
{ | ||
"name": "highland-process", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Utility that lets you turn a process into a highland stream.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -19,2 +19,25 @@ var _ = require('highland'), | ||
}); | ||
it('passes through errors', function(done) { | ||
var isErrorPassed = false, | ||
stream = _(function(push, next) { | ||
push(null, 'hello'); | ||
push(new Error('find me!')); | ||
push(null, ' bye'); | ||
push(null, _.nil); | ||
next(); | ||
}), | ||
tee = spawn('tee'); | ||
stream | ||
.through(through(tee)) | ||
.errors(function(error, push) { | ||
isErrorPassed = error.message === 'find me!'; | ||
}) | ||
.toArray(function(results) { | ||
assert.equal(results[0].toString('utf8'), 'hello bye'); | ||
assert.isTrue(isErrorPassed); | ||
done(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4840
129