[Pkg-javascript-commits] [node-stream-splicer] 28/71: fix for the empty case

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 15 09:55:49 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-stream-splicer.

commit d5d612d2013eb16aead73ef5ff6f99fbbb0ca2a2
Author: James Halliday <mail at substack.net>
Date:   Mon Jun 9 13:59:22 2014 -0700

    fix for the empty case
---
 index.js | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/index.js b/index.js
index 7b9d948..1dc916a 100644
--- a/index.js
+++ b/index.js
@@ -48,9 +48,8 @@ function Pipeline (streams, opts) {
 
 Pipeline.prototype._read = function () {
     var self = this;
-    if (this._streams.length === 0) {
-        this._streams.push(new Pass(this._options));
-    }
+    this._notEmpty();
+    
     var r = this._streams[this._streams.length-1];
     var buf, reads = 0;
     while ((buf = r.read()) !== null) {
@@ -69,12 +68,23 @@ Pipeline.prototype._read = function () {
 };
 
 Pipeline.prototype._write = function (buf, enc, next) {
-    if (this._streams.length === 0) {
-        this._streams.push(new Pass(this._options));
-    }
+    this._notEmpty();
     this._streams[0]._write(buf, enc, next);
 };
 
+Pipeline.prototype._notEmpty = function () {
+    var self = this;
+    if (this._streams.length > 0) return;
+    var stream = new Pass(this._options);
+    stream.once('end', function () {
+        var ix = self._streams.indexOf(stream);
+        if (ix >= 0 && ix === self._streams.length - 1) {
+            Duplex.prototype.push.call(self, null);
+        }
+    });
+    this._streams.push(stream);
+};
+
 Pipeline.prototype.push = function (stream) {
     this.splice(this._streams.length, 0, stream);
     return this._streams.length;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stream-splicer.git



More information about the Pkg-javascript-commits mailing list