{"id":15042484,"url":"https://github.com/sindresorhus/multicast-stream","last_synced_at":"2025-10-31T16:30:23.782Z","repository":{"id":254685021,"uuid":"847271283","full_name":"sindresorhus/multicast-stream","owner":"sindresorhus","description":"Create a multicast stream that lets multiple consumers independently read the same data","archived":false,"fork":false,"pushed_at":"2024-08-25T10:55:51.000Z","size":99,"stargazers_count":120,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-09T23:02:18.847Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2024-08-25T10:50:23.000Z","updated_at":"2025-01-07T20:11:53.000Z","dependencies_parsed_at":"2024-08-25T11:06:45.156Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/multicast-stream","commit_stats":null,"previous_names":["sindresorhus/multicast-stream"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmulticast-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmulticast-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmulticast-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmulticast-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/multicast-stream/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238633970,"owners_count":19504763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T20:47:22.968Z","updated_at":"2025-10-31T16:30:23.631Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","readme":"\u003ch1 align=\"center\" title=\"multicast-stream\"\u003e\n\t\u003cimg src=\"media/logo.jpg\" alt=\"multicast-stream logo\"\u003e\n\u003c/h1\u003e\n\n\u003e Create a multicast stream that lets multiple consumers independently read the same data\n\n## Install\n\n```sh\nnpm install multicast-stream\n```\n\n## Usage\n\n**Without this package**\n\nUsing [`Readable#text()`](https://nodejs.org/api/webstreams.html#streamconsumerstextstream) 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.\n\n```js\nimport {Readable} from 'node:stream';\nimport {text} from 'node:stream/consumers';\n\nconst sourceStream = Readable.from(['Hello', ' ', 'World']);\nconst [result1, result2] = await Promise.all([text(sourceStream), text(sourceStream)]);\n\nconsole.log(result1); // 'Hello World'\nconsole.log(result2); // ''\n```\n\n**With this package**\n\nThis package allows multiple consumers to independently read the same data from a single source stream.\n\n```js\nimport {Readable} from 'node:stream';\nimport {text} from 'node:stream/consumers';\nimport multicastStream from 'multicast-stream';\n\nconst sourceStream = Readable.from(['Hello', ' ', 'World']);\nconst createConsumer = multicastStream(sourceStream);\n\nconst consumer1 = createConsumer();\nconst consumer2 = createConsumer();\n\nconst [result1, result2] = await Promise.all([text(consumer1), text(consumer2)]);\n\nconsole.log(result1); // 'Hello World'\nconsole.log(result2); // 'Hello World'\n```\n\n## API\n\n### `multicastStream(sourceStream)`\n\nCreates a function that returns independent streams for each consumer.\n\n#### Parameters\n\n- `sourceStream` (`Readable`): The source stream to multicast.\n\n#### Returns\n\n- `() =\u003e PassThrough`: A function that returns a new `PassThrough` stream for each consumer.\n","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["🔧 Utilities \u0026 Miscellaneous","JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fmulticast-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fmulticast-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fmulticast-stream/lists"}