🚀 Launch Week Day 3:Introducing Supply Chain Attack Campaigns Tracking.Learn More →
Socket
Book a DemoInstallSign in
Socket

multicast-stream

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multicast-stream

Create a multicast stream that lets multiple consumers independently read the same data

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

multicast-stream logo

Create a multicast stream that lets multiple consumers independently read the same data

Install

npm install multicast-stream

Usage

Without this package

Using Readable#text() on a stream can only work with a single consumer. If you try to read the stream with multiple consumers, it will be empty as the stream can only be read once.

import {Readable} from 'node:stream';
import {text} from 'node:stream/consumers';

const sourceStream = Readable.from(['Hello', ' ', 'World']);
const [result1, result2] = await Promise.all([text(sourceStream), text(sourceStream)]);

console.log(result1); // 'Hello World'
console.log(result2); // ''

With this package

This package allows multiple consumers to independently read the same data from a single source stream.

import {Readable} from 'node:stream';
import {text} from 'node:stream/consumers';
import multicastStream from 'multicast-stream';

const sourceStream = Readable.from(['Hello', ' ', 'World']);
const createConsumer = multicastStream(sourceStream);

const consumer1 = createConsumer();
const consumer2 = createConsumer();

const [result1, result2] = await Promise.all([text(consumer1), text(consumer2)]);

console.log(result1); // 'Hello World'
console.log(result2); // 'Hello World'

API

multicastStream(sourceStream)

Creates a function that returns independent streams for each consumer.

Parameters

  • sourceStream (Readable): The source stream to multicast.

Returns

  • () => PassThrough: A function that returns a new PassThrough stream for each consumer.

Keywords

multicast

FAQs

Package last updated on 06 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts