[Pkg-javascript-commits] [node-stream-combiner2] 21/41: streams2
Bastien Roucariès
rouca at moszumanska.debian.org
Wed Sep 6 09:57:53 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-combiner2.
commit f738fb5b71c21717ccef8938f0c2c46a4a61a527
Author: James Halliday <mail at substack.net>
Date: Thu Jul 3 11:31:12 2014 -0700
streams2
---
README.md | 12 ++++++++++--
index.js | 17 +++++++++++++++--
test/index.js | 2 +-
3 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 014f071..5b92a87 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,20 @@
-# stream-combiner
+# stream-combiner2
-<img src=https://secure.travis-ci.org/dominictarr/stream-combiner.png?branch=master>
+This is a sequel to
+[stream-combiner](https://npmjs.org/package/stream-combiner)
+for streams2.
+
+``` js
+var combine = require('stream-combiner2')
+```
## Combine (stream1,...,streamN)
Turn a pipeline into a single stream. `Combine` returns a stream that writes to the first stream
and reads from the last stream.
+Streams1 streams are automatically upgraded to be streams2 streams.
+
Listening for 'error' will recieve errors from all streams inside the pipe.
```js
diff --git a/index.js b/index.js
index e23374c..aca8e22 100644
--- a/index.js
+++ b/index.js
@@ -1,5 +1,5 @@
-var duplexer = require('duplexer')
-var through = require('through')
+var duplexer = require('duplexer2')
+var through = require('through2')
module.exports = function () {
var streams
@@ -10,6 +10,9 @@ module.exports = function () {
streams = [].slice.call(arguments)
}
+ for (var i = 0; i < streams.length; i++)
+ streams[i] = wrap(streams[i])
+
if(streams.length == 0)
return through()
else if(streams.length == 1)
@@ -43,3 +46,13 @@ module.exports = function () {
return thepipe
}
+
+function wrap (tr) {
+ if (typeof tr.read === 'function') return tr
+ var opts = tr._options || {}
+ var input = through(opts), output = through(opts)
+ input.pipe(tr).pipe(output)
+ var dup = duplexer(input, output)
+ tr.on('error', function (err) { dup.emit('error') });
+ return dup;
+}
diff --git a/test/index.js b/test/index.js
index 97cd73e..59fdaae 100644
--- a/test/index.js
+++ b/test/index.js
@@ -56,7 +56,7 @@ test('0 argument through stream', function (test) {
, expected = [ 'beep', 'boop', 'robots' ]
pipe.pipe(es.through(function(data) {
- test.equal(data, expected.shift())
+ test.equal(data.toString('utf8'), expected.shift())
}))
pipe.write('beep')
pipe.write('boop')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stream-combiner2.git
More information about the Pkg-javascript-commits
mailing list