aboutsummaryrefslogtreecommitdiff
path: root/node_modules/end-of-stream/index.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/end-of-stream/index.js
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
node_modules
Diffstat (limited to 'node_modules/end-of-stream/index.js')
-rw-r--r--node_modules/end-of-stream/index.js21
1 files changed, 16 insertions, 5 deletions
diff --git a/node_modules/end-of-stream/index.js b/node_modules/end-of-stream/index.js
index 9f61ed5af..b3a906863 100644
--- a/node_modules/end-of-stream/index.js
+++ b/node_modules/end-of-stream/index.js
@@ -6,6 +6,10 @@ var isRequest = function(stream) {
return stream.setHeader && typeof stream.abort === 'function';
};
+var isChildProcess = function(stream) {
+ return stream.stdio && Array.isArray(stream.stdio) && stream.stdio.length === 3
+};
+
var eos = function(stream, opts, callback) {
if (typeof opts === 'function') return eos(stream, null, opts);
if (!opts) opts = {};
@@ -23,17 +27,21 @@ var eos = function(stream, opts, callback) {
var onfinish = function() {
writable = false;
- if (!readable) callback();
+ if (!readable) callback.call(stream);
};
var onend = function() {
readable = false;
- if (!writable) callback();
+ if (!writable) callback.call(stream);
+ };
+
+ var onexit = function(exitCode) {
+ callback.call(stream, exitCode ? new Error('exited with error code: ' + exitCode) : null);
};
var onclose = function() {
- if (readable && !(rs && rs.ended)) return callback(new Error('premature close'));
- if (writable && !(ws && ws.ended)) return callback(new Error('premature close'));
+ if (readable && !(rs && rs.ended)) return callback.call(stream, new Error('premature close'));
+ if (writable && !(ws && ws.ended)) return callback.call(stream, new Error('premature close'));
};
var onrequest = function() {
@@ -50,6 +58,8 @@ var eos = function(stream, opts, callback) {
stream.on('close', onlegacyfinish);
}
+ if (isChildProcess(stream)) stream.on('exit', onexit);
+
stream.on('end', onend);
stream.on('finish', onfinish);
if (opts.error !== false) stream.on('error', callback);
@@ -63,10 +73,11 @@ var eos = function(stream, opts, callback) {
stream.removeListener('end', onlegacyfinish);
stream.removeListener('close', onlegacyfinish);
stream.removeListener('finish', onfinish);
+ stream.removeListener('exit', onexit);
stream.removeListener('end', onend);
stream.removeListener('error', callback);
stream.removeListener('close', onclose);
};
};
-module.exports = eos; \ No newline at end of file
+module.exports = eos;