diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
commit | abd94a7f5a50f43c797a11b53549ae48fff667c3 (patch) | |
tree | ab8ed457f65cdd72e13e0571d2975729428f1551 /node_modules/stream-consume | |
parent | a0247c6a3fd6a09a41a7e35a3441324c4dcb58be (diff) | |
download | wallet-core-abd94a7f5a50f43c797a11b53549ae48fff667c3.tar.xz |
add node_modules to address #4364
Diffstat (limited to 'node_modules/stream-consume')
-rw-r--r-- | node_modules/stream-consume/.npmignore | 1 | ||||
-rw-r--r-- | node_modules/stream-consume/README.md | 53 | ||||
-rw-r--r-- | node_modules/stream-consume/index.js | 14 | ||||
-rw-r--r-- | node_modules/stream-consume/package.json | 82 | ||||
-rw-r--r-- | node_modules/stream-consume/test/tests.js | 180 |
5 files changed, 330 insertions, 0 deletions
diff --git a/node_modules/stream-consume/.npmignore b/node_modules/stream-consume/.npmignore new file mode 100644 index 000000000..3c3629e64 --- /dev/null +++ b/node_modules/stream-consume/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/node_modules/stream-consume/README.md b/node_modules/stream-consume/README.md new file mode 100644 index 000000000..d7c9c909b --- /dev/null +++ b/node_modules/stream-consume/README.md @@ -0,0 +1,53 @@ +# stream-consume + +A node module ensures a Readable stream continues flowing if it's not piped to +another destination. + + npm install stream-consume + +## Usage + +Simply pass a stream to `stream-consume`. +Both legacy streams and streams2 are supported. + +``` js +var consume = require('stream-consume'); + +consume(readableStream); +``` + +## Details + +Only Readable streams are processed (as determined by presence of `readable` +property and a `resume` property that is a function). If called with anything +else, it's a NOP. + +For a streams2 stream (as determined by presence of a `_readableState` +property), nothing is done if the stream has already been piped to at least +one other destination. + +`resume()` is used to cause the stream to continue flowing. + +## License + +The MIT License (MIT) + +Copyright (c) 2014 Aron Nopanen + +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/stream-consume/index.js b/node_modules/stream-consume/index.js new file mode 100644 index 000000000..122edb18a --- /dev/null +++ b/node_modules/stream-consume/index.js @@ -0,0 +1,14 @@ +module.exports = function(stream) { + if (stream.readable && typeof stream.resume === 'function') { + var state = stream._readableState; + if (!state || state.pipesCount === 0) { + // Either a classic stream or streams2 that's not piped to another destination + try { + stream.resume(); + } catch (err) { + console.error("Got error: " + err); + // If we can't, it's not worth dying over + } + } + } +}; diff --git a/node_modules/stream-consume/package.json b/node_modules/stream-consume/package.json new file mode 100644 index 000000000..701b6d4c9 --- /dev/null +++ b/node_modules/stream-consume/package.json @@ -0,0 +1,82 @@ +{ + "_args": [ + [ + { + "raw": "stream-consume@~0.1.0", + "scope": null, + "escapedName": "stream-consume", + "name": "stream-consume", + "rawSpec": "~0.1.0", + "spec": ">=0.1.0 <0.2.0", + "type": "range" + }, + "/home/dold/repos/taler/wallet-webex/node_modules/orchestrator" + ] + ], + "_from": "stream-consume@>=0.1.0 <0.2.0", + "_id": "stream-consume@0.1.0", + "_inCache": true, + "_location": "/stream-consume", + "_npmUser": { + "name": "aroneous", + "email": "aron.nopanen@gmail.com" + }, + "_npmVersion": "1.5.0-alpha-3", + "_phantomChildren": {}, + "_requested": { + "raw": "stream-consume@~0.1.0", + "scope": null, + "escapedName": "stream-consume", + "name": "stream-consume", + "rawSpec": "~0.1.0", + "spec": ">=0.1.0 <0.2.0", + "type": "range" + }, + "_requiredBy": [ + "/orchestrator" + ], + "_resolved": "https://registry.npmjs.org/stream-consume/-/stream-consume-0.1.0.tgz", + "_shasum": "a41ead1a6d6081ceb79f65b061901b6d8f3d1d0f", + "_shrinkwrap": null, + "_spec": "stream-consume@~0.1.0", + "_where": "/home/dold/repos/taler/wallet-webex/node_modules/orchestrator", + "author": { + "name": "Aron Nopanen" + }, + "bugs": { + "url": "https://github.com/aroneous/stream-consume/issues" + }, + "dependencies": {}, + "description": "Consume a stream to ensure it keeps flowing", + "devDependencies": { + "mocha": "^1.20.1", + "should": "^4.0.4", + "through2": "^0.5.1" + }, + "directories": {}, + "dist": { + "shasum": "a41ead1a6d6081ceb79f65b061901b6d8f3d1d0f", + "tarball": "https://registry.npmjs.org/stream-consume/-/stream-consume-0.1.0.tgz" + }, + "gitHead": "54496fd47e0f10bf6924728ef405b72a4bbad6de", + "homepage": "https://github.com/aroneous/stream-consume", + "license": "MIT", + "main": "index.js", + "maintainers": [ + { + "name": "aroneous", + "email": "aron.nopanen@gmail.com" + } + ], + "name": "stream-consume", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+https://github.com/aroneous/stream-consume.git" + }, + "scripts": { + "test": "mocha" + }, + "version": "0.1.0" +} diff --git a/node_modules/stream-consume/test/tests.js b/node_modules/stream-consume/test/tests.js new file mode 100644 index 000000000..660e37a11 --- /dev/null +++ b/node_modules/stream-consume/test/tests.js @@ -0,0 +1,180 @@ +/*jshint node:true */ +/*global describe:false, it:false */ +"use strict"; + +var consume = require('../'); +var Stream = require('stream'); +var Readable = Stream.Readable; +var Writable = Stream.Writable; +var Duplex = Stream.Duplex; +var should = require('should'); +var through = require('through2'); +require('mocha'); + +describe('stream-consume', function() { + + it('should cause a Readable stream to complete if it\'s not piped anywhere', function(done) { + var rs = new Readable({highWaterMark: 2}); + var a = 0; + var ended = false; + rs._read = function() { + if (a++ < 100) { + rs.push(a + ""); + } else { + ended = true; + rs.push(null); + } + }; + + rs.on("end", function() { + a.should.be.above(99); + ended.should.be.true; + done(); + }); + + consume(rs); + }); + + it('should work with Readable streams in objectMode', function(done) { + var rs = new Readable({highWaterMark: 2, objectMode: true}); + var a = 0; + var ended = false; + rs._read = function() { + if (a++ < 100) { + rs.push(a); + } else { + ended = true; + rs.push(null); + } + }; + + rs.on("end", function() { + a.should.be.above(99); + ended.should.be.true; + done(); + }); + + consume(rs); + }); + + it('should not interfere with a Readable stream that is piped somewhere', function(done) { + var rs = new Readable({highWaterMark: 2}); + var a = 0; + var ended = false; + rs._read = function() { + if (a++ < 100) { + rs.push("."); + } else { + ended = true; + rs.push(null); + } + }; + + var sizeRead = 0; + var ws = new Writable({highWaterMark: 2}); + ws._write = function(chunk, enc, next) { + sizeRead += chunk.length; + next(); + } + + ws.on("finish", function() { + a.should.be.above(99); + ended.should.be.true; + sizeRead.should.equal(100); + done(); + }); + + rs.pipe(ws); + + consume(rs); + }); + + it('should not interfere with a Writable stream', function(done) { + var rs = new Readable({highWaterMark: 2}); + var a = 0; + var ended = false; + rs._read = function() { + if (a++ < 100) { + rs.push("."); + } else { + ended = true; + rs.push(null); + } + }; + + var sizeRead = 0; + var ws = new Writable({highWaterMark: 2}); + ws._write = function(chunk, enc, next) { + sizeRead += chunk.length; + next(); + } + + ws.on("finish", function() { + a.should.be.above(99); + ended.should.be.true; + sizeRead.should.equal(100); + done(); + }); + + rs.pipe(ws); + + consume(ws); + }); + + it('should handle a Transform stream', function(done) { + var rs = new Readable({highWaterMark: 2}); + var a = 0; + var ended = false; + rs._read = function() { + if (a++ < 100) { + rs.push("."); + } else { + ended = true; + rs.push(null); + } + }; + + var sizeRead = 0; + var flushed = false; + var ts = through({highWaterMark: 2}, function(chunk, enc, cb) { + sizeRead += chunk.length; + this.push(chunk); + cb(); + }, function(cb) { + flushed = true; + cb(); + }); + + ts.on("end", function() { + a.should.be.above(99); + ended.should.be.true; + sizeRead.should.equal(100); + flushed.should.be.true; + done(); + }); + + rs.pipe(ts); + + consume(ts); + }); + + it('should handle a classic stream', function(done) { + var rs = new Stream(); + var ended = false; + var i; + + rs.on("end", function() { + ended.should.be.true; + done(); + }); + + consume(rs); + + for (i = 0; i < 100; i++) { + rs.emit("data", i); + } + ended = true; + rs.emit("end"); + }); + +}); |