1. @sindresorhus/merge-streams
Merge multiple streams into a unified stream
@sindresorhus/merge-streams
Package: @sindresorhus/merge-streams
Created by: sindresorhus
Last modified: Sat, 04 May 2024 19:40:43 GMT
Version: 4.0.0
License: MIT
Downloads: 8,195,086
Repository: https://github.com/sindresorhus/merge-streams

Install

npm install @sindresorhus/merge-streams
yarn add @sindresorhus/merge-streams

merge-streams

Merge multiple streams into a unified stream

Install

 npm install @sindresorhus/merge-streams

Usage

 import mergeStreams from '@sindresorhus/merge-streams';

const stream = mergeStreams([streamA, streamB]);

for await (const chunk of stream) {
	console.log(chunk);
	//=> 'A1'
	//=> 'B1'
	//=> 'A2'
	//=> 'B2'
}

API

mergeStreams(streams: stream.Readable[]): MergedStream

Merges an array of readable streams and returns a new readable stream that emits data from the individual streams as it arrives.

If you provide an empty array, the stream remains open but can be manually ended.

MergedStream

Type: stream.Readable

A single stream combining the output of multiple streams.

MergedStream.add(stream: stream.Readable): void

Pipe a new readable stream.

Throws if MergedStream has already ended.

MergedStream.remove(stream: stream.Readable): Promise<boolean>

Unpipe a stream previously added using either mergeStreams(streams) or MergedStream.add(stream).

Returns false if the stream was not previously added, or if it was already removed by MergedStream.remove(stream).

The removed stream is not automatically ended.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code