end-of-stream
Advanced tools
Comparing version 1.0.0 to 1.1.0
11
index.js
@@ -9,2 +9,6 @@ var once = require('once'); | ||
var isChildProcess = function(stream) { | ||
return stream.stdio && Array.isArray(stream.stdio) && stream.stdio.length === 3 | ||
}; | ||
var eos = function(stream, opts, callback) { | ||
@@ -35,2 +39,6 @@ if (typeof opts === 'function') return eos(stream, null, opts); | ||
var onexit = function(exitCode) { | ||
callback(exitCode ? new Error('exited with error code: ' + exitCode) : null); | ||
}; | ||
var onclose = function() { | ||
@@ -55,2 +63,4 @@ if (readable && !(rs && rs.ended)) return callback(new Error('premature close')); | ||
if (isChildProcess(stream)) stream.on('exit', onexit); | ||
stream.on('end', onend); | ||
@@ -69,2 +79,3 @@ stream.on('finish', onfinish); | ||
stream.removeListener('finish', onfinish); | ||
stream.removeListener('exit', onexit); | ||
stream.removeListener('end', onend); | ||
@@ -71,0 +82,0 @@ stream.removeListener('error', callback); |
{ | ||
"name": "end-of-stream", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Call a callback when a readable/writable/duplex stream has completed or failed.", | ||
@@ -5,0 +5,0 @@ "repository": { |
17
test.js
var assert = require('assert'); | ||
var eos = require('./index'); | ||
var expected = 6; | ||
var expected = 8; | ||
var fs = require('fs'); | ||
var cp = require('child_process'); | ||
var net = require('net'); | ||
@@ -38,2 +39,16 @@ | ||
var exec = cp.exec('echo hello world'); | ||
eos(exec, function(err) { | ||
expected--; | ||
assert(!err); | ||
if (!expected) process.exit(0); | ||
}); | ||
var spawn = cp.spawn('echo', ['hello world']); | ||
eos(spawn, function(err) { | ||
expected--; | ||
assert(!err); | ||
if (!expected) process.exit(0); | ||
}); | ||
var socket = net.connect(50000); | ||
@@ -40,0 +55,0 @@ eos(socket, function(err) { |
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
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
6956
6
132
2