Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

concat-streams

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

concat-streams - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

12

index.js
'use strict'
const EventEmitter = require('events')
function concatStreams (streams) {
function concatStreams (streams, event) {
if (!streams || !Array.isArray(streams)) throw new Error(`Invaild stream array: ${streams}`)
event = event ? String(event) : 'error'

@@ -13,11 +14,6 @@ streams = streams.filter(isStream)

stream.on('error', function (error) {
nextStream.emit('error', error)
stream.on(event, function () {
nextStream.emit.apply(nextStream, [event].concat(Array.prototype.slice.call(arguments)))
})
}
for (let i = 0; i < streams.length - 1; i++) {
let stream = streams[i]
let nextStream = streams[i + 1]
stream.pipe(nextStream)

@@ -24,0 +20,0 @@ }

{
"name": "concat-streams",
"version": "1.0.1",
"version": "2.0.0",
"description": "Concat streams by piping and pass the `error` event through to the end.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -6,3 +6,3 @@ # concat-streams

Concat streams by piping and pass the `error` event through to the end.
Concat streams by piping and pass the specified event through to the end.

@@ -21,3 +21,3 @@ ## Installation

concatStream([stream1, stream2, stream3])
concatStream([stream1, stream2, stream3], 'error').on('error', console.error)
// Equal to:

@@ -28,2 +28,3 @@ // stream1.pipe(stream2)

// stream2.on('error', (err) => stream3.emit(err))
// stream3.on('error', console.error)
```

@@ -33,6 +34,7 @@

### concatStream(streams)
### concatStream(streams, event)
- streams: Array<stream> an array of streams
- streams: `Array`<`stream`> an array of streams
- event: `String` name of the event you want to pipe through, by default it is `'error'`.
Concat all streams in array by `pipe` and once an error occurred in one stream, all streams after will get it. Return the last stream in the array.
Concat all streams in array by `pipe` and once the `event` occurred in one stream, all streams after will get it. Return the last stream in the array.

@@ -62,3 +62,3 @@ 'use strict'

it('should pipe all error down', (done) => {
concatStreams(streams)
concatStreams(streams, 'error')

@@ -65,0 +65,0 @@ stream2.on('error', (error) => {

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc