[Pkg-javascript-commits] [node-stream-splicer] 04/71: pipeline.obj, better objectMode handling

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 15 09:55:46 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 1c31d37a0788bbe79bd62970f2cb1411ab70acec
Author: James Halliday <mail at substack.net>
Date:   Sun Jun 8 04:46:19 2014 -0700

    pipeline.obj, better objectMode handling
---
 example/stream.js |  3 +--
 index.js          | 20 +++++++++++++++++++-
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/example/stream.js b/example/stream.js
index 6acb1bd..c32946d 100644
--- a/example/stream.js
+++ b/example/stream.js
@@ -12,5 +12,4 @@ var c = through.obj(function (row, enc, next) { this.push(row.x); next() });
 var d = through.obj(function (x, enc, next) { this.push(x * 111); next() });
 var e = stringify();
 
-var stream = pipeline([ a, b, c, d, e ], { objectMode: true });
-process.stdin.pipe(stream).pipe(process.stdout);
+pipeline([ process.stdin, a, b, c, d, e, process.stdout ]);
diff --git a/index.js b/index.js
index 6b4d3bc..42760e3 100644
--- a/index.js
+++ b/index.js
@@ -2,17 +2,35 @@ var isarray = require('isarray');
 var Duplex = require('readable-stream').Duplex;
 var Pass = require('readable-stream').PassThrough;
 var inherits = require('inherits');
+var isArray = require('isarray');
 
 module.exports = Pipeline;
 inherits(Pipeline, Duplex);
 
+module.exports.obj = function (streams, opts) {
+    if (!opts && !isArray(streams)) {
+        opts = streams;
+        streams = [];
+    }
+    if (!streams) streams = [];
+    if (!opts) opts = {};
+    opts.objectMode = true;
+    return new Pipeline(streams, opts);
+};
+
 function Pipeline (streams, opts) {
     if (!(this instanceof Pipeline)) return new Pipeline(streams, opts);
+    if (!opts && !isArray(streams)) {
+        opts = streams;
+        streams = [];
+    }
+    if (!streams) streams = [];
     if (!opts) opts = {};
     Duplex.call(this, opts);
     
     var self = this;
     this._options = opts;
+    this._wrapOptions = { objectMode: opts.objectMode !== false };
     this._streams = [];
     
     for (var i = 0; i < streams.length; i++) {
@@ -91,7 +109,7 @@ Pipeline.prototype.indexOf = function (stream) {
 
 Pipeline.prototype._wrapStream = function (stream) {
     if (typeof stream.read === 'function') return stream;
-    var d = (new Duplex(this._options)).wrap(stream);
+    var d = (new Duplex(this._wrapOptions)).wrap(stream);
     d._write = function (buf, enc, next) {
         stream.write(buf);
         next();

-- 
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