diff options
Diffstat (limited to 'node_modules/end-of-stream/index.js')
-rw-r--r-- | node_modules/end-of-stream/index.js | 21 |
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; |