diff options
Diffstat (limited to 'node_modules/ordered-read-streams')
-rw-r--r-- | node_modules/ordered-read-streams/.npmignore | 16 | ||||
-rw-r--r-- | node_modules/ordered-read-streams/.travis.yml | 4 | ||||
-rw-r--r-- | node_modules/ordered-read-streams/LICENSE | 20 | ||||
-rw-r--r-- | node_modules/ordered-read-streams/README.md | 65 | ||||
-rw-r--r-- | node_modules/ordered-read-streams/index.js | 87 | ||||
-rw-r--r-- | node_modules/ordered-read-streams/package.json | 85 | ||||
-rw-r--r-- | node_modules/ordered-read-streams/test/main.js | 160 |
7 files changed, 437 insertions, 0 deletions
diff --git a/node_modules/ordered-read-streams/.npmignore b/node_modules/ordered-read-streams/.npmignore new file mode 100644 index 000000000..a74dcace8 --- /dev/null +++ b/node_modules/ordered-read-streams/.npmignore @@ -0,0 +1,16 @@ +lib-cov +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.gz + +coverage +pids +logs +results +node_modules + +npm-debug.log diff --git a/node_modules/ordered-read-streams/.travis.yml b/node_modules/ordered-read-streams/.travis.yml new file mode 100644 index 000000000..18ae2d89c --- /dev/null +++ b/node_modules/ordered-read-streams/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - "0.11" + - "0.10" diff --git a/node_modules/ordered-read-streams/LICENSE b/node_modules/ordered-read-streams/LICENSE new file mode 100644 index 000000000..16fd42818 --- /dev/null +++ b/node_modules/ordered-read-streams/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2014 Artem Medeusheyev + +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/ordered-read-streams/README.md b/node_modules/ordered-read-streams/README.md new file mode 100644 index 000000000..8f8be53b3 --- /dev/null +++ b/node_modules/ordered-read-streams/README.md @@ -0,0 +1,65 @@ +# ordered-read-streams [![NPM version](https://badge.fury.io/js/ordered-read-streams.png)](http://badge.fury.io/js/ordered-read-streams) [![Build Status](https://travis-ci.org/armed/ordered-read-streams.png?branch=master)](https://travis-ci.org/armed/ordered-read-streams) + +Combines array of streams into one read stream in strict order. + +## Installation + +`npm install ordered-read-streams` + +## Overview + +`ordered-read-streams` handles all data/errors from input streams in parallel, but emits data/errors in strict order in which streams are passed to constructor. This is `objectMode = true` stream. + +## Example + +```js +var through = require('through2'); +var Ordered = require('ordered-read-streams'); + +var s1 = through.obj(function (data, enc, next) { + var self = this; + setTimeout(function () { + self.push(data); + next(); + }, 200) +}); +var s2 = through.obj(function (data, enc, next) { + var self = this; + setTimeout(function () { + self.push(data); + next(); + }, 30) +}); +var s3 = through.obj(function (data, enc, next) { + var self = this; + setTimeout(function () { + self.push(data); + next(); + }, 100) +}); + +var streams = new Ordered([s1, s2, s3]); +streams.on('data', function (data) { + console.log(data); +}) + +s1.write('stream 1'); +s1.end(); + +s2.write('stream 2'); +s2.end(); + +s3.write('stream 3'); +s3.end(); +``` +Ouput will be: + +``` +stream 1 +stream 2 +stream 3 +``` + +## Licence + +MIT diff --git a/node_modules/ordered-read-streams/index.js b/node_modules/ordered-read-streams/index.js new file mode 100644 index 000000000..f58ccf1dd --- /dev/null +++ b/node_modules/ordered-read-streams/index.js @@ -0,0 +1,87 @@ +var Readable = require('stream').Readable; +var util = require('util'); + + +function addStream(streams, stream) +{ + if(!stream.readable) throw new Error('All input streams must be readable'); + + if(this._readableState.ended) throw new Error('Adding streams after ended'); + + + var self = this; + + stream._buffer = []; + + stream.on('data', function(chunk) + { + if(this === streams[0]) + self.push(chunk); + + else + this._buffer.push(chunk); + }); + + stream.on('end', function() + { + for(var stream = streams[0]; + stream && stream._readableState.ended; + stream = streams[0]) + { + while(stream._buffer.length) + self.push(stream._buffer.shift()); + + streams.shift(); + } + + if(!streams.length) self.push(null); + }); + + stream.on('error', this.emit.bind(this, 'error')); + + + streams.push(stream); +} + + +function OrderedStreams(streams, options) { + if (!(this instanceof(OrderedStreams))) { + return new OrderedStreams(streams, options); + } + + streams = streams || []; + options = options || {}; + + options.objectMode = true; + + Readable.call(this, options); + + + if(!Array.isArray(streams)) streams = [streams]; + if(!streams.length) return this.push(null); // no streams, close + + + var addStream_bind = addStream.bind(this, []); + + + this.concat = function() + { + Array.prototype.forEach.call(arguments, function(item) + { + if(Array.isArray(item)) + item.forEach(addStream_bind); + + else + addStream_bind(item); + }); + }; + + + this.concat(streams); +} +util.inherits(OrderedStreams, Readable); + +OrderedStreams.prototype._read = function () {}; + + +module.exports = OrderedStreams; diff --git a/node_modules/ordered-read-streams/package.json b/node_modules/ordered-read-streams/package.json new file mode 100644 index 000000000..6b406d781 --- /dev/null +++ b/node_modules/ordered-read-streams/package.json @@ -0,0 +1,85 @@ +{ + "_args": [ + [ + { + "raw": "ordered-read-streams@^0.1.0", + "scope": null, + "escapedName": "ordered-read-streams", + "name": "ordered-read-streams", + "rawSpec": "^0.1.0", + "spec": ">=0.1.0 <0.2.0", + "type": "range" + }, + "/home/dold/repos/taler/wallet-webex/node_modules/glob-stream" + ] + ], + "_from": "ordered-read-streams@>=0.1.0 <0.2.0", + "_id": "ordered-read-streams@0.1.0", + "_inCache": true, + "_location": "/ordered-read-streams", + "_npmUser": { + "name": "armed", + "email": "artem.medeusheyev@gmail.com" + }, + "_npmVersion": "1.4.14", + "_phantomChildren": {}, + "_requested": { + "raw": "ordered-read-streams@^0.1.0", + "scope": null, + "escapedName": "ordered-read-streams", + "name": "ordered-read-streams", + "rawSpec": "^0.1.0", + "spec": ">=0.1.0 <0.2.0", + "type": "range" + }, + "_requiredBy": [ + "/glob-stream" + ], + "_resolved": "https://registry.npmjs.org/ordered-read-streams/-/ordered-read-streams-0.1.0.tgz", + "_shasum": "fd565a9af8eb4473ba69b6ed8a34352cb552f126", + "_shrinkwrap": null, + "_spec": "ordered-read-streams@^0.1.0", + "_where": "/home/dold/repos/taler/wallet-webex/node_modules/glob-stream", + "author": { + "name": "Artem Medeusheyev", + "email": "artem.medeusheyev@gmail.com" + }, + "bugs": { + "url": "https://github.com/armed/ordered-read-streams/issues" + }, + "dependencies": {}, + "description": "Combines array of streams into one read stream in strict order", + "devDependencies": { + "jshint": "~2.4.1", + "mocha": "~1.17.0", + "pre-commit": "0.0.4", + "should": "~3.0.1", + "through2": "~0.4.0" + }, + "directories": {}, + "dist": { + "shasum": "fd565a9af8eb4473ba69b6ed8a34352cb552f126", + "tarball": "https://registry.npmjs.org/ordered-read-streams/-/ordered-read-streams-0.1.0.tgz" + }, + "gitHead": "0a7e487d8734978c0cc29d4dc3bfbdb8e82f865b", + "homepage": "https://github.com/armed/ordered-read-streams", + "license": "MIT", + "main": "index.js", + "maintainers": [ + { + "name": "armed", + "email": "artem.medeusheyev@gmail.com" + } + ], + "name": "ordered-read-streams", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git://github.com/armed/ordered-read-streams.git" + }, + "scripts": { + "test": "jshint *.js test/*.js && mocha -R spec" + }, + "version": "0.1.0" +} diff --git a/node_modules/ordered-read-streams/test/main.js b/node_modules/ordered-read-streams/test/main.js new file mode 100644 index 000000000..81f80403d --- /dev/null +++ b/node_modules/ordered-read-streams/test/main.js @@ -0,0 +1,160 @@ +var should = require('should'); +var through = require('through2'); +var OrderedStreams = require('../'); + +describe('ordered-read-streams', function () { + it('should end if no streams are given', function (done) { + var streams = OrderedStreams(); + streams.on('data', function () { + done('error'); + }); + streams.on('end', done); + }); + + it('should throw error if one or more streams are not readable', function (done) { + var writable = { readable: false }; + + try { + new OrderedStreams(writable); + } catch (e) { + e.message.should.equal('All input streams must be readable'); + done(); + } + }); + + it('should emit data from all streams', function(done) { + var s1 = through.obj(function (data, enc, next) { + this.push(data); + next(); + }); + var s2 = through.obj(function (data, enc, next) { + this.push(data); + next(); + }); + var s3 = through.obj(function (data, enc, next) { + this.push(data); + next(); + }); + + var streams = new OrderedStreams([s1, s2, s3]); + var results = []; + streams.on('data', function (data) { + results.push(data); + }); + streams.on('end', function () { + results.length.should.be.exactly(3); + results[0].should.equal('stream 1'); + results[1].should.equal('stream 2'); + results[2].should.equal('stream 3'); + done(); + }); + + s1.write('stream 1'); + s1.end(); + + s2.write('stream 2'); + s2.end(); + + s3.write('stream 3'); + s3.end(); + }); + + it('should emit all data event from each stream', function (done) { + var s = through.obj(function (data, enc, next) { + this.push(data); + next(); + }); + + var streams = new OrderedStreams(s); + var results = []; + streams.on('data', function (data) { + results.push(data); + }); + streams.on('end', function () { + results.length.should.be.exactly(3); + done(); + }); + + s.write('data1'); + s.write('data2'); + s.write('data3'); + s.end(); + }); + + it('should preserve streams order', function(done) { + var s1 = through.obj(function (data, enc, next) { + var self = this; + setTimeout(function () { + self.push(data); + next(); + }, 200); + }); + var s2 = through.obj(function (data, enc, next) { + var self = this; + setTimeout(function () { + self.push(data); + next(); + }, 30); + }); + var s3 = through.obj(function (data, enc, next) { + var self = this; + setTimeout(function () { + self.push(data); + next(); + }, 100); + }); + + var streams = new OrderedStreams([s1, s2, s3]); + var results = []; + streams.on('data', function (data) { + results.push(data); + }); + streams.on('end', function () { + results.length.should.be.exactly(3); + results[0].should.equal('stream 1'); + results[1].should.equal('stream 2'); + results[2].should.equal('stream 3'); + done(); + }); + + s1.write('stream 1'); + s1.end(); + + s2.write('stream 2'); + s2.end(); + + s3.write('stream 3'); + s3.end(); + }); + + it('should emit stream errors downstream', function (done) { + var s = through.obj(function (data, enc, next) { + this.emit('error', new Error('stahp!')); + next(); + }); + var s2 = through.obj(function (data, enc, next) { + this.push(data); + next(); + }); + + var errMsg; + var streamData; + var streams = new OrderedStreams([s, s2]); + streams.on('data', function (data) { + streamData = data; + }); + streams.on('error', function (err) { + errMsg = err.message; + }); + streams.on('end', function () { + errMsg.should.equal('stahp!'); + streamData.should.equal('Im ok!'); + done(); + }); + + s.write('go'); + s.end(); + s2.write('Im ok!'); + s2.end(); + }); +}); |