# @sindresorhus/merge-streams

> Merge multiple streams into a unified stream

Latest version **4.0.0** (published 2024-05-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @sindresorhus/merge-streams
pnpm add @sindresorhus/merge-streams
yarn add @sindresorhus/merge-streams
bun add @sindresorhus/merge-streams
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2024-05-04 |
| First published | 2023-10-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 11.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 65 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | merge, stream, streams, readable, passthrough, interleave, interleaved, unify, unified |

## Links

- npm: https://www.npmjs.com/package/@sindresorhus/merge-streams
- Repository: https://github.com/sindresorhus/merge-streams
- Homepage: https://github.com/sindresorhus/merge-streams#readme
- Issues: https://github.com/sindresorhus/merge-streams/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/@sindresorhus/merge-streams

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2024-05-04
- 3.0.0 — 2024-02-20
- 2.3.0 — 2024-02-19
- 2.2.1 — 2024-02-14
- 2.2.0 — 2024-02-12
- 2.1.0 — 2024-02-03
- 2.0.3 — 2024-01-30
- 2.0.2 — 2024-01-29
- 2.0.1 — 2024-01-23
- 2.0.0 — 2024-01-22
- 1.0.0 — 2023-10-27

## README

# merge-streams

> Merge multiple streams into a unified stream

## Install

```sh
npm install @sindresorhus/merge-streams
```

## Usage

```js
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](https://nodejs.org/api/stream.html#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](https://nodejs.org/api/stream.html#writableendchunk-encoding-callback).

#### `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)`](#mergestreamsstreams-streamreadable-mergedstream) or [`MergedStream.add(stream)`](#mergedstreamaddstream-streamreadable-void).

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.

---
_Source: https://npm.io/package/@sindresorhus/merge-streams · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
