[Pkg-javascript-commits] [node-end-of-stream] 01/04: New upstream version 1.1.0
Paolo Greppi
paolog-guest at moszumanska.debian.org
Fri Dec 2 09:50:54 UTC 2016
This is an automated email from the git hooks/post-receive script.
paolog-guest pushed a commit to branch master
in repository node-end-of-stream.
commit a1e8f2cb92c639ac01e9ff82cb425b8146fe16ff
Author: Paolo Greppi <paolo.greppi at libpf.com>
Date: Fri Dec 2 09:41:55 2016 +0000
New upstream version 1.1.0
---
LICENSE | 21 +++++++++++++++++++++
index.js | 24 +++++++++++++++++++++++-
package.json | 2 +-
test.js | 26 ++++++++++++++++++++++----
4 files changed, 67 insertions(+), 6 deletions(-)
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..757562e
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2014 Mathias Buus
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
\ No newline at end of file
diff --git a/index.js b/index.js
index b9fbec0..f92fc19 100644
--- a/index.js
+++ b/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 = {};
@@ -31,6 +35,10 @@ var eos = function(stream, opts, callback) {
if (!writable) callback();
};
+ var onexit = function(exitCode) {
+ callback(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'));
@@ -50,12 +58,26 @@ 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);
stream.on('close', onclose);
- return stream;
+ return function() {
+ stream.removeListener('complete', onfinish);
+ stream.removeListener('abort', onclose);
+ stream.removeListener('request', onrequest);
+ if (stream.req) stream.req.removeListener('finish', onfinish);
+ 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
diff --git a/package.json b/package.json
index 1f64886..94b96ad 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "end-of-stream",
- "version": "0.1.5",
+ "version": "1.1.0",
"description": "Call a callback when a readable/writable/duplex stream has completed or failed.",
"repository": {
"type": "git",
diff --git a/test.js b/test.js
index 277f1ce..03cb93e 100644
--- a/test.js
+++ b/test.js
@@ -1,8 +1,9 @@
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');
var ws = fs.createWriteStream('/dev/null');
@@ -29,6 +30,26 @@ eos(rs, function(err) {
});
rs.pipe(fs.createWriteStream('/dev/null'));
+var rs = fs.createReadStream(__filename);
+eos(rs, function(err) {
+ throw new Error('no go')
+})();
+rs.pipe(fs.createWriteStream('/dev/null'));
+
+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);
eos(socket, function(err) {
expected--;
@@ -36,7 +57,6 @@ eos(socket, function(err) {
if (!expected) process.exit(0);
});
-
var server = net.createServer(function(socket) {
eos(socket, function() {
expected--;
@@ -51,8 +71,6 @@ var server = net.createServer(function(socket) {
});
});
-
-
setTimeout(function() {
assert(expected === 0);
process.exit(0);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-end-of-stream.git
More information about the Pkg-javascript-commits
mailing list