collect-stream
Advanced tools
Comparing version 1.1.1 to 1.2.0
import { default as concat } from 'concat-stream'; | ||
import { default as once } from 'once'; | ||
export default function collect(stream, fn) { | ||
export default function collect(stream, opts, fn) { | ||
if (typeof opts === 'function') { | ||
fn = opts; | ||
opts = {}; | ||
} | ||
fn = once(fn); | ||
stream.on('error', fn); | ||
stream.pipe(concat(data => { | ||
stream.pipe(concat(opts, data => { | ||
fn(null, data); | ||
@@ -9,0 +13,0 @@ })); |
{ | ||
"name": "collect-stream", | ||
"description": "Collect a readable stream's output and errors", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
@@ -29,2 +29,14 @@ | ||
Give it options and it will pass them to [concat-stream](https://github.com/maxogden/concat-stream/). | ||
```js | ||
import collect from 'collect-stream'; | ||
collect(someStream, { | ||
encoding: 'object' | ||
}, (err, data) => { | ||
console.log(data) // forced to be an array of objects | ||
}); | ||
``` | ||
## Installation | ||
@@ -31,0 +43,0 @@ |
21
test.js
@@ -60,2 +60,23 @@ import { default as test } from 'tape'; | ||
test('concat-stream options', t => { | ||
t.plan(2); | ||
var stream = through(); | ||
process.nextTick(() => { | ||
stream.queue([{ foo: true }]); | ||
stream.queue([{ bar: true }]); | ||
stream.queue(null); | ||
}); | ||
collect(stream, { | ||
encoding: 'object' | ||
}, (err, data) => { | ||
t.error(err); | ||
t.deepEqual(data, [ | ||
[{ foo: true }], | ||
[{ bar: true }] | ||
]); | ||
}); | ||
}); | ||
test('error', t => { | ||
@@ -62,0 +83,0 @@ t.plan(1); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3976
87
50
8