From abd94a7f5a50f43c797a11b53549ae48fff667c3 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 10 Oct 2016 03:43:44 +0200 Subject: add node_modules to address #4364 --- node_modules/multipipe/.npmignore | 1 + node_modules/multipipe/.travis.yml | 3 + node_modules/multipipe/History.md | 25 ++++++ node_modules/multipipe/Makefile | 10 +++ node_modules/multipipe/Readme.md | 102 ++++++++++++++++++++++ node_modules/multipipe/index.js | 72 ++++++++++++++++ node_modules/multipipe/package.json | 81 ++++++++++++++++++ node_modules/multipipe/test/multipipe.js | 141 +++++++++++++++++++++++++++++++ 8 files changed, 435 insertions(+) create mode 100644 node_modules/multipipe/.npmignore create mode 100644 node_modules/multipipe/.travis.yml create mode 100644 node_modules/multipipe/History.md create mode 100644 node_modules/multipipe/Makefile create mode 100644 node_modules/multipipe/Readme.md create mode 100644 node_modules/multipipe/index.js create mode 100644 node_modules/multipipe/package.json create mode 100644 node_modules/multipipe/test/multipipe.js (limited to 'node_modules/multipipe') diff --git a/node_modules/multipipe/.npmignore b/node_modules/multipipe/.npmignore new file mode 100644 index 000000000..3c3629e64 --- /dev/null +++ b/node_modules/multipipe/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/node_modules/multipipe/.travis.yml b/node_modules/multipipe/.travis.yml new file mode 100644 index 000000000..6e5919de3 --- /dev/null +++ b/node_modules/multipipe/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - "0.10" diff --git a/node_modules/multipipe/History.md b/node_modules/multipipe/History.md new file mode 100644 index 000000000..52f6e8581 --- /dev/null +++ b/node_modules/multipipe/History.md @@ -0,0 +1,25 @@ + +0.1.1 / 2014-06-01 +================== + + * update duplexer2 dep + +0.1.0 / 2014-05-24 +================== + + * add optional callback + +0.0.2 / 2014-02-20 +================== + + * fix infinite loop + +0.0.1 / 2014-01-15 +================== + +* fix error bubbling + +0.0.0 / 2014-01-13 +================== + +* initial release diff --git a/node_modules/multipipe/Makefile b/node_modules/multipipe/Makefile new file mode 100644 index 000000000..d1df0ab3d --- /dev/null +++ b/node_modules/multipipe/Makefile @@ -0,0 +1,10 @@ + +node_modules: package.json + @npm install + +test: + @./node_modules/.bin/mocha \ + --reporter spec \ + --timeout 100 + +.PHONY: test \ No newline at end of file diff --git a/node_modules/multipipe/Readme.md b/node_modules/multipipe/Readme.md new file mode 100644 index 000000000..fe8c221a1 --- /dev/null +++ b/node_modules/multipipe/Readme.md @@ -0,0 +1,102 @@ +# multipipe + +A better `Stream#pipe` that creates duplex streams and lets you handle errors in one place. + +[![build status](https://secure.travis-ci.org/segmentio/multipipe.png)](http://travis-ci.org/segmentio/multipipe) + +## Example + +```js +var pipe = require('multipipe'); + +// pipe streams +var stream = pipe(streamA, streamB, streamC); + +// centralized error handling +stream.on('error', fn); + +// creates a new stream +source.pipe(stream).pipe(dest); + +// optional callback on finish or error +pipe(streamA, streamB, streamC, function(err){ + // ... +}); +``` + +## Duplex streams + + Write to the pipe and you'll really write to the first stream, read from the pipe and you'll read from the last stream. + +```js +var stream = pipe(a, b, c); + +source + .pipe(stream) + .pipe(destination); +``` + + In this example the flow of data is: + + * source -> + * a -> + * b -> + * c -> + * destination + +## Error handling + + Each `pipe` forwards the errors the streams it wraps emit, so you have one central place to handle errors: + +```js +var stream = pipe(a, b, c); + +stream.on('error', function(err){ + // called three times +}); + +a.emit('error', new Error); +b.emit('error', new Error); +c.emit('error', new Error); +``` + +## API + +### pipe(stream, ...) + +Pass a variable number of streams and each will be piped to the next one. + +A stream will be returned that wraps passed in streams in a way that errors will be forwarded and you can write to and/or read from it. + +Pass a function as last argument to be called on `error` or `finish` of the last stream. + +## Installation + +```bash +$ npm install multipipe +``` + +## License + +The MIT License (MIT) + +Copyright (c) 2014 Segment.io Inc. <friends@segment.io> +Copyright (c) 2014 Julian Gruber <julian@juliangruber.com> + +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/node_modules/multipipe/index.js b/node_modules/multipipe/index.js new file mode 100644 index 000000000..5e406db88 --- /dev/null +++ b/node_modules/multipipe/index.js @@ -0,0 +1,72 @@ + +/** + * Module dependencies. + */ + +var duplexer = require('duplexer2'); +var Stream = require('stream'); + +/** + * Slice reference. + */ + +var slice = [].slice; + +/** + * Duplexer options. + */ + +var opts = { + bubbleErrors: false +}; + +/** + * Expose `pipe`. + */ + +module.exports = pipe; + +/** + * Pipe. + * + * @param {Stream,...,[Function]} + * @return {Stream} + * @api public + */ + +function pipe(){ + if (arguments.length == 1) return arguments[0]; + var streams = slice.call(arguments); + var cb; + if ('function' == typeof streams[streams.length - 1]) { + cb = streams.splice(-1)[0]; + } + var first = streams[0]; + var last = streams[streams.length - 1]; + var ret; + + if (first.writable && last.readable) ret = duplexer(opts, first, last); + else if (first.writable) ret = first; + else if (last.readable) ret = last; + else ret = new Stream; + + streams.forEach(function(stream, i){ + var next = streams[i+1]; + if (next) stream.pipe(next); + if (stream != ret) stream.on('error', ret.emit.bind(ret, 'error')); + }); + + if (cb) { + var ended = false; + ret.on('error', end); + last.on('finish', end); + function end(err){ + if (ended) return; + ended = true; + cb(err); + } + } + + return ret; +} + diff --git a/node_modules/multipipe/package.json b/node_modules/multipipe/package.json new file mode 100644 index 000000000..fb4a5fad0 --- /dev/null +++ b/node_modules/multipipe/package.json @@ -0,0 +1,81 @@ +{ + "_args": [ + [ + { + "raw": "multipipe@^0.1.2", + "scope": null, + "escapedName": "multipipe", + "name": "multipipe", + "rawSpec": "^0.1.2", + "spec": ">=0.1.2 <0.2.0", + "type": "range" + }, + "/home/dold/repos/taler/wallet-webex/node_modules/gulp-util" + ] + ], + "_from": "multipipe@>=0.1.2 <0.2.0", + "_id": "multipipe@0.1.2", + "_inCache": true, + "_location": "/multipipe", + "_nodeVersion": "0.10.32", + "_npmUser": { + "name": "juliangruber", + "email": "julian@juliangruber.com" + }, + "_npmVersion": "2.1.5", + "_phantomChildren": {}, + "_requested": { + "raw": "multipipe@^0.1.2", + "scope": null, + "escapedName": "multipipe", + "name": "multipipe", + "rawSpec": "^0.1.2", + "spec": ">=0.1.2 <0.2.0", + "type": "range" + }, + "_requiredBy": [ + "/gulp-gzip/gulp-util", + "/gulp-sym/gulp-util", + "/gulp-util" + ], + "_resolved": "https://registry.npmjs.org/multipipe/-/multipipe-0.1.2.tgz", + "_shasum": "2a8f2ddf70eed564dff2d57f1e1a137d9f05078b", + "_shrinkwrap": null, + "_spec": "multipipe@^0.1.2", + "_where": "/home/dold/repos/taler/wallet-webex/node_modules/gulp-util", + "bugs": { + "url": "https://github.com/juliangruber/multipipe/issues" + }, + "dependencies": { + "duplexer2": "0.0.2" + }, + "description": "pipe streams with centralized error handling", + "devDependencies": { + "mocha": "~1.17.0" + }, + "directories": {}, + "dist": { + "shasum": "2a8f2ddf70eed564dff2d57f1e1a137d9f05078b", + "tarball": "https://registry.npmjs.org/multipipe/-/multipipe-0.1.2.tgz" + }, + "gitHead": "df434f568b85de914ee7f6ad714343b8736e3315", + "homepage": "https://github.com/juliangruber/multipipe", + "license": "MIT", + "maintainers": [ + { + "name": "juliangruber", + "email": "julian@juliangruber.com" + } + ], + "name": "multipipe", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+https://github.com/juliangruber/multipipe.git" + }, + "scripts": { + "test": "make test" + }, + "version": "0.1.2" +} diff --git a/node_modules/multipipe/test/multipipe.js b/node_modules/multipipe/test/multipipe.js new file mode 100644 index 000000000..078d2e031 --- /dev/null +++ b/node_modules/multipipe/test/multipipe.js @@ -0,0 +1,141 @@ +var assert = require('assert'); +var pipe = require('..'); +var Stream = require('stream'); + +describe('pipe(a)', function(){ + it('should return a', function(){ + var readable = Readable(); + var stream = pipe(readable); + assert.equal(stream, readable); + }); +}); + +describe('pipe(a, b, c)', function(){ + it('should pipe internally', function(done){ + pipe(Readable(), Transform(), Writable(done)); + }); + + it('should be writable', function(done){ + var stream = pipe(Transform(), Writable(done)); + assert(stream.writable); + Readable().pipe(stream); + }); + + it('should be readable', function(done){ + var stream = pipe(Readable(), Transform()); + assert(stream.readable); + stream.pipe(Writable(done)); + }); + + it('should be readable and writable', function(done){ + var stream = pipe(Transform(), Transform()); + assert(stream.readable); + assert(stream.writable); + Readable() + .pipe(stream) + .pipe(Writable(done)); + }); + + describe('errors', function(){ + it('should reemit', function(done){ + var a = Transform(); + var b = Transform(); + var c = Transform(); + var stream = pipe(a, b, c); + var err = new Error; + var i = 0; + + stream.on('error', function(_err){ + i++; + assert.equal(_err, err); + assert(i <= 3); + if (i == 3) done(); + }); + + a.emit('error', err); + b.emit('error', err); + c.emit('error', err); + }); + + it('should not reemit endlessly', function(done){ + var a = Transform(); + var b = Transform(); + var c = Transform(); + c.readable = false; + var stream = pipe(a, b, c); + var err = new Error; + var i = 0; + + stream.on('error', function(_err){ + i++; + assert.equal(_err, err); + assert(i <= 3); + if (i == 3) done(); + }); + + a.emit('error', err); + b.emit('error', err); + c.emit('error', err); + }); + }); +}); + +describe('pipe(a, b, c, fn)', function(){ + it('should call on finish', function(done){ + var finished = false; + var a = Readable(); + var b = Transform(); + var c = Writable(function(){ + finished = true; + }); + + pipe(a, b, c, function(err){ + assert(!err); + assert(finished); + done(); + }); + }); + + it('should call with error once', function(done){ + var a = Readable(); + var b = Transform(); + var c = Writable(); + var err = new Error; + + pipe(a, b, c, function(err){ + assert(err); + done(); + }); + + a.emit('error', err); + b.emit('error', err); + c.emit('error', err); + }); +}); + +function Readable(){ + var readable = new Stream.Readable({ objectMode: true }); + readable._read = function(){ + this.push('a'); + this.push(null); + }; + return readable; +} + +function Transform(){ + var transform = new Stream.Transform({ objectMode: true }); + transform._transform = function(chunk, _, done){ + done(null, chunk.toUpperCase()); + }; + return transform; +} + +function Writable(cb){ + var writable = new Stream.Writable({ objectMode: true }); + writable._write = function(chunk, _, done){ + assert.equal(chunk, 'A'); + done(); + cb(); + }; + return writable; +} -- cgit v1.2.3