collect-stream
Advanced tools
Comparing version
16
index.js
@@ -1,17 +0,11 @@ | ||
var concat = require('concat-stream'); | ||
var once = require('once'); | ||
import { default as concat } from 'concat-stream'; | ||
import { default as once } from 'once'; | ||
/** | ||
* Collect output and errors of `stream`. | ||
* | ||
* @param {Stream} stream | ||
* @param {Function} fn | ||
*/ | ||
module.exports = function collect(stream, fn) { | ||
export default function collect(stream, fn) { | ||
fn = once(fn); | ||
stream.on('error', fn); | ||
stream.pipe(concat(function(data) { | ||
stream.pipe(concat(data => { | ||
fn(null, data); | ||
})); | ||
}; | ||
{ | ||
"name": "collect-stream", | ||
"description": "Collect a readable stream's output and errors", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"repository": { | ||
@@ -10,5 +10,5 @@ "type": "git", | ||
"homepage": "https://github.com/juliangruber/collect-stream", | ||
"main": "index.js", | ||
"main": "build.js", | ||
"scripts": { | ||
"test": "tape test.js" | ||
"test": "make test" | ||
}, | ||
@@ -20,2 +20,3 @@ "dependencies": { | ||
"devDependencies": { | ||
"babel": "^5.8.21", | ||
"tape": "~2.1.0", | ||
@@ -35,2 +36,2 @@ "through": "~2.3.4" | ||
"license": "MIT" | ||
} | ||
} |
@@ -14,13 +14,13 @@ | ||
```js | ||
var collect = require('collect-stream'); | ||
import collect from 'collect-stream'; | ||
collect(stringStream, function(err, data) { | ||
collect(stringStream, (err, data) => { | ||
console.log(data); // one string | ||
}); | ||
collect(bufferStream, function(err, data) { | ||
collect(bufferStream, (err, data) => { | ||
console.log(data); // one buffer | ||
}); | ||
collect(objectStream, function(err, data) { | ||
collect(objectStream, (err, data) => { | ||
console.log(data); // an array of objects | ||
@@ -38,2 +38,2 @@ }); | ||
MIT | ||
MIT |
32
test.js
@@ -1,6 +0,6 @@ | ||
var test = require('tape'); | ||
var through = require('through'); | ||
var collect = require('./'); | ||
import { default as test } from 'tape'; | ||
import { default as through } from 'through'; | ||
import collect from './'; | ||
test('string', function(t) { | ||
test('string', t => { | ||
t.plan(2); | ||
@@ -10,3 +10,3 @@ | ||
process.nextTick(function() { | ||
process.nextTick(() => { | ||
stream.queue('foo'); | ||
@@ -17,3 +17,3 @@ stream.queue('bar'); | ||
collect(stream, function(err, data) { | ||
collect(stream, (err, data) => { | ||
t.error(err); | ||
@@ -24,3 +24,3 @@ t.deepEqual(data, 'foobar'); | ||
test('buffer', function(t) { | ||
test('buffer', t => { | ||
t.plan(3); | ||
@@ -30,3 +30,3 @@ | ||
process.nextTick(function() { | ||
process.nextTick(() => { | ||
stream.queue(new Buffer('foo')); | ||
@@ -37,3 +37,3 @@ stream.queue(new Buffer('bar')); | ||
collect(stream, function(err, data) { | ||
collect(stream, (err, data) => { | ||
t.error(err); | ||
@@ -45,3 +45,3 @@ t.ok(Buffer.isBuffer(data)); | ||
test('object', function(t) { | ||
test('object', t => { | ||
t.plan(2); | ||
@@ -51,3 +51,3 @@ | ||
process.nextTick(function() { | ||
process.nextTick(() => { | ||
stream.queue({ foo: true }); | ||
@@ -58,3 +58,3 @@ stream.queue({ bar: true }); | ||
collect(stream, function(err, data) { | ||
collect(stream, (err, data) => { | ||
t.error(err); | ||
@@ -68,13 +68,13 @@ t.deepEqual(data, [ | ||
test('error', function(t) { | ||
test('error', t => { | ||
t.plan(1); | ||
var stream = through(); | ||
process.nextTick(function() { | ||
process.nextTick(() => { | ||
stream.emit('error', new Error); | ||
}); | ||
collect(stream, function(err, data) { | ||
collect(stream, (err, data) => { | ||
t.ok(err); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
8
14.29%38
2.7%3
50%65
-7.14%