[Pkg-javascript-commits] [node-stream-combiner2] 01/41: initial

Bastien Roucariès rouca at moszumanska.debian.org
Wed Sep 6 09:57:51 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 ac790c63aeb45c62efb75a2f51b17d1000fe55ef
Author: Dominic Tarr <dominic.tarr at gmail.com>
Date:   Mon Nov 26 23:24:55 2012 -0800

    initial
---
 .gitignore    |  3 +++
 .travis.yml   |  4 ++++
 LICENSE       | 22 ++++++++++++++++++++++
 README.md     | 29 +++++++++++++++++++++++++++++
 index.js      | 39 +++++++++++++++++++++++++++++++++++++++
 package.json  | 21 +++++++++++++++++++++
 test/index.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 170 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..13abef4
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+node_modules
+node_modules/*
+npm_debug.log
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..895dbd3
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+  - 0.6
+  - 0.8
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..6d03581
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 'Dominic Tarr'
+
+Permission is hereby granted, free of charge, 
+to any person obtaining a copy of this software and 
+associated documentation files (the "Software"), to 
+deal in the Software without restriction, including 
+without limitation the rights to use, copy, modify, 
+merge, publish, distribute, sublicense, and/or sell 
+copies of the Software, and to permit persons to whom 
+the Software is furnished to do so, 
+subject to the following conditions:
+
+The above copyright notice and this permission notice 
+shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..d0c129c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,29 @@
+# stream-combiner
+
+<img src=https://secure.travis-ci.org/dominictarr/stream-combiner.png?branch=master>
+
+## pipeline (stream1,...,streamN)
+
+Turn a pipeline into a single stream. `pipeline` returns a stream that writes to the first stream
+and reads from the last stream. 
+
+Listening for 'error' will recieve errors from all streams inside the pipe.
+
+> `connect` is an alias for `pipeline`.
+
+``` js
+
+  es.pipeline(                         //connect streams together with `pipe`
+    process.openStdin(),              //open stdin
+    es.split(),                       //split stream to break on newlines
+    es.map(function (data, callback) {//turn this async function into a stream
+      callback(null
+        , inspect(JSON.parse(data)))  //render it nicely
+    }),
+    process.stdout                    // pipe it to stdout !
+    )
+```
+
+## License
+
+MIT
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..99cf5b6
--- /dev/null
+++ b/index.js
@@ -0,0 +1,39 @@
+var duplexer = require('duplexer')
+
+module.exports = function () {
+
+  var streams = [].slice.call(arguments)
+    , first = streams[0]
+    , last = streams[streams.length - 1]
+    , thepipe = duplexer(first, last)
+
+  if(streams.length == 1)
+    return streams[0]
+  else if (!streams.length)
+    throw new Error('connect called with empty args')
+
+  //pipe all the streams together
+
+  function recurse (streams) {
+    if(streams.length < 2)
+      return
+    streams[0].pipe(streams[1])
+    recurse(streams.slice(1))  
+  }
+  
+  recurse(streams)
+ 
+  function onerror () {
+    var args = [].slice.call(arguments)
+    args.unshift('error')
+    thepipe.emit.apply(thepipe, args)
+  }
+  
+  //es.duplex already reemits the error from the first and last stream.
+  //add a listener for the inner streams in the pipeline.
+  for(var i = 1; i < streams.length - 1; i ++)
+    streams[i].on('error', onerror)
+
+  return thepipe
+}
+
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..ccaca1d
--- /dev/null
+++ b/package.json
@@ -0,0 +1,21 @@
+{
+  "name": "stream-combiner",
+  "version": "0.0.0",
+  "homepage": "https://github.com/dominictarr/stream-combiner",
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/dominictarr/stream-combiner.git"
+  },
+  "dependencies": {
+    "duplexer": "0.0.2"
+  },
+  "devDependencies": {
+    "tape": "0.0.4",
+    "event-stream": "~3.0.7"
+  },
+  "scripts": {
+    "test": "set -e; for t in test/*.js; do node $t; done"
+  },
+  "author": "'Dominic Tarr' <dominic.tarr at gmail.com> (http://dominictarr.com)",
+  "license": "MIT"
+}
diff --git a/test/index.js b/test/index.js
new file mode 100644
index 0000000..d17ddad
--- /dev/null
+++ b/test/index.js
@@ -0,0 +1,52 @@
+var es = require('event-stream')
+var combine = require('..')
+var test = require('tape')
+
+test('do not duplicate errors', function (test) {
+
+  var errors = 0;
+  var pipe = combine(
+    es.through(function(data) {
+      return this.emit('data', data);
+    }),
+    es.through(function(data) {
+      return this.emit('error', new Error(data));
+    })
+  )
+
+  pipe.on('error', function(err) {
+    errors++
+    test.ok(errors, 'expected error count')
+      process.nextTick(function () {
+        return test.end();
+      })
+  })
+
+  return pipe.write('meh');
+})
+
+test('3 pipe do not duplicate errors', function (test) {
+
+  var errors = 0;
+  var pipe = combine(
+    es.through(function(data) {
+      return this.emit('data', data);
+    }),
+    es.through(function(data) {
+      return this.emit('error', new Error(data));
+    }),
+    es.through()
+  )
+
+  pipe.on('error', function(err) {
+    errors++
+    test.ok(errors, 'expected error count')
+      process.nextTick(function () {
+        return test.end();
+      })
+  })
+
+  return pipe.write('meh');
+
+})
+

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