[Pkg-javascript-commits] [node-end-of-stream] 01/03: New upstream version 1.4.0

Paolo Greppi paolog-guest at moszumanska.debian.org
Tue May 30 15:45:37 UTC 2017


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 0fdf9a65ff11a8d6a5e1279c78cf616a7f4f6919
Author: Paolo Greppi <paolo.greppi at libpf.com>
Date:   Tue May 30 17:39:42 2017 +0200

    New upstream version 1.4.0
---
 README.md    | 19 ++++++++++++-------
 index.js     | 12 ++++++------
 package.json |  7 +++++--
 test.js      | 29 +++++++++++++++++++----------
 4 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/README.md b/README.md
index df800c1..f2560c9 100644
--- a/README.md
+++ b/README.md
@@ -7,34 +7,35 @@ A node module that calls a callback when a readable/writable/duplex stream has c
 ## Usage
 
 Simply pass a stream and a callback to the `eos`.
-Both legacy streams and streams2 are supported.
+Both legacy streams, streams2 and stream3 are supported.
 
 ``` js
 var eos = require('end-of-stream');
 
 eos(readableStream, function(err) {
+  // this will be set to the stream instance
 	if (err) return console.log('stream had an error or closed early');
-	console.log('stream has ended');
+	console.log('stream has ended', this === readableStream);
 });
 
 eos(writableStream, function(err) {
 	if (err) return console.log('stream had an error or closed early');
-	console.log('stream has finished');
+	console.log('stream has finished', this === writableStream);
 });
 
 eos(duplexStream, function(err) {
 	if (err) return console.log('stream had an error or closed early');
-	console.log('stream has ended and finished');
+	console.log('stream has ended and finished', this === duplexStream);
 });
 
 eos(duplexStream, {readable:false}, function(err) {
 	if (err) return console.log('stream had an error or closed early');
-	console.log('stream has ended but might still be writable');
+	console.log('stream has finished but might still be readable');
 });
 
 eos(duplexStream, {writable:false}, function(err) {
 	if (err) return console.log('stream had an error or closed early');
-	console.log('stream has ended but might still be readable');
+	console.log('stream has ended but might still be writable');
 });
 
 eos(readableStream, {error:false}, function(err) {
@@ -44,4 +45,8 @@ eos(readableStream, {error:false}, function(err) {
 
 ## License
 
-MIT
\ No newline at end of file
+MIT
+
+## Related
+
+`end-of-stream` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one.
diff --git a/index.js b/index.js
index f92fc19..b3a9068 100644
--- a/index.js
+++ b/index.js
@@ -27,21 +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(exitCode ? new Error('exited with error code: ' + exitCode) : null);
+		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() {
@@ -80,4 +80,4 @@ var eos = function(stream, opts, callback) {
 	};
 };
 
-module.exports = eos;
\ No newline at end of file
+module.exports = eos;
diff --git a/package.json b/package.json
index 94b96ad..81315b6 100644
--- a/package.json
+++ b/package.json
@@ -1,17 +1,20 @@
 {
   "name": "end-of-stream",
-  "version": "1.1.0",
+  "version": "1.4.0",
   "description": "Call a callback when a readable/writable/duplex stream has completed or failed.",
   "repository": {
     "type": "git",
     "url": "git://github.com/mafintosh/end-of-stream.git"
   },
   "dependencies": {
-    "once": "~1.3.0"
+    "once": "^1.4.0"
   },
   "scripts": {
     "test": "node test.js"
   },
+  "files": [
+    "index.js"
+  ],
   "keywords": [
     "stream",
     "streams",
diff --git a/test.js b/test.js
index 03cb93e..f62f0c0 100644
--- a/test.js
+++ b/test.js
@@ -10,36 +10,41 @@ var ws = fs.createWriteStream('/dev/null');
 eos(ws, function(err) {
 	expected--;
 	assert(!!err);
+	assert(this === ws);
 	if (!expected) process.exit(0);
 });
 ws.close();
 
-var rs = fs.createReadStream('/dev/random');
-eos(rs, function(err) {
+var rs1 = fs.createReadStream('/dev/random');
+eos(rs1, function(err) {
 	expected--;
 	assert(!!err);
+	assert(this === rs1);
 	if (!expected) process.exit(0);
 });
-rs.close();
+rs1.close();
 
-var rs = fs.createReadStream(__filename);
-eos(rs, function(err) {
+var rs2 = fs.createReadStream(__filename);
+eos(rs2, function(err) {
 	expected--;
 	assert(!err);
+	assert(this === rs2);
 	if (!expected) process.exit(0);
 });
-rs.pipe(fs.createWriteStream('/dev/null'));
+rs2.pipe(fs.createWriteStream('/dev/null'));
 
-var rs = fs.createReadStream(__filename);
-eos(rs, function(err) {
-	throw new Error('no go')
+var rs3 = fs.createReadStream(__filename);
+eos(rs3, function(err) {
+	assert(this === rs);
+	throw new Error('no go');
 })();
-rs.pipe(fs.createWriteStream('/dev/null'));
+rs3.pipe(fs.createWriteStream('/dev/null'));
 
 var exec = cp.exec('echo hello world');
 eos(exec, function(err) {
 	expected--;
 	assert(!err);
+	assert(this === exec);
 	if (!expected) process.exit(0);
 });
 
@@ -47,6 +52,7 @@ var spawn = cp.spawn('echo', ['hello world']);
 eos(spawn, function(err) {
 	expected--;
 	assert(!err);
+	assert(this === spawn);
 	if (!expected) process.exit(0);
 });
 
@@ -54,12 +60,14 @@ var socket = net.connect(50000);
 eos(socket, function(err) {
 	expected--;
 	assert(!!err);
+	assert(this === socket);
 	if (!expected) process.exit(0);
 });
 
 var server = net.createServer(function(socket) {
 	eos(socket, function() {
 		expected--;
+		assert(this === socket);
 		if (!expected) process.exit(0);
 	});
 	socket.destroy();
@@ -67,6 +75,7 @@ var server = net.createServer(function(socket) {
 	var socket = net.connect(30000);
 	eos(socket, function() {
 		expected--;
+		assert(this === socket);
 		if (!expected) 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