Socket
Socket
Sign inDemoInstall

collect-stream

Package Overview
Dependencies
13
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 1.2.0

8

index.js
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 @@

@@ -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);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc