[Pkg-javascript-commits] [node-stream-splicer] 02/71: example, nearly works

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 75ad8e4f6868149eeec5f7bdda9aa13a385150cf
Author: James Halliday <mail at substack.net>
Date:   Sun Jun 8 04:09:21 2014 -0700

    example, nearly works
---
 example/stream.js | 16 ++++++++++++++++
 index.js          |  6 +++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/example/stream.js b/example/stream.js
new file mode 100644
index 0000000..6acb1bd
--- /dev/null
+++ b/example/stream.js
@@ -0,0 +1,16 @@
+var pipeline = require('../');
+var through = require('through2');
+var stringify = require('JSONStream').stringify;
+var split = require('split');
+
+var a = split();
+var b = through.obj(function (row, enc, next) {
+    this.push(JSON.parse(row));
+    next();
+});
+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);
diff --git a/index.js b/index.js
index 27096a0..cca53ea 100644
--- a/index.js
+++ b/index.js
@@ -59,7 +59,7 @@ Pipeline.prototype.push = function (stream) {
         err.stream = this;
         self.emit('error', err);
     });
-    stream = wrapStream(stream);
+    stream = this._wrapStream(stream);
     
     if (this._streams.length > 0) {
         this._streams[this._streams.length-1].pipe(stream);
@@ -89,9 +89,9 @@ Pipeline.prototype.indexOf = function (stream) {
     return this._streams.indexOf(stream);
 };
 
-function wrapStream (stream) {
+Pipeline.prototype._wrapStream = function (stream) {
     if (typeof stream.read === 'function') return stream;
-    var d = (new Duplex).wrap(stream);
+    var d = (new Duplex(this._options)).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