{"id":15547301,"url":"https://github.com/uhop/stream-fork","last_synced_at":"2025-04-23T18:24:10.761Z","repository":{"id":57371984,"uuid":"135243244","full_name":"uhop/stream-fork","owner":"uhop","description":"Fork a writable stream into several parallel writable streams.","archived":false,"fork":false,"pushed_at":"2020-11-12T00:52:26.000Z","size":37,"stargazers_count":11,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-21T06:09:28.376Z","etag":null,"topics":["stream-processing","streams"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uhop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-29T05:00:37.000Z","updated_at":"2024-04-25T10:42:25.000Z","dependencies_parsed_at":"2022-09-26T16:41:14.015Z","dependency_job_id":null,"html_url":"https://github.com/uhop/stream-fork","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhop%2Fstream-fork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhop%2Fstream-fork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhop%2Fstream-fork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhop%2Fstream-fork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uhop","download_url":"https://codeload.github.com/uhop/stream-fork/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250354499,"owners_count":21416752,"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":["stream-processing","streams"],"created_at":"2024-10-02T13:08:35.612Z","updated_at":"2025-04-23T18:24:10.743Z","avatar_url":"https://github.com/uhop.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# stream-fork [![NPM version][npm-img]][npm-url]\n\n[npm-img]: https://img.shields.io/npm/v/stream-fork.svg\n[npm-url]: https://npmjs.org/package/stream-fork\n\n`stream-fork` is a [Writable stream](https://nodejs.org/api/stream.html#stream_writable_streams), which writes into dependent Writable streams properly handling [backpressure](https://nodejs.org/en/docs/guides/backpressuring-in-streams/). It is a way to make forks in a linear pipeline of streams.\n\nOriginally `stream-fork` was used internally with [stream-chain](https://www.npmjs.com/package/stream-chain) and [stream-json](https://www.npmjs.com/package/stream-json) to create flexible data processing pipelines.\n\n`stream-fork` is a lightweight, no-dependencies micro-package. It is distributed under New BSD license.\n\n## Intro\n\n```js\nconst Fork = require('stream-fork');\nconst fs = require('fs');\nconst zlib = require('zlib');\n\nconst gzip = zlib.createGzip();\ngzip.pipe(fs.createWriteStream('log.txt.gz'));\n\n// push data to both the gzip chain and stdout\nconst forkStream = new Fork([gzip, process.stdout], {});\ndataSource.pipe(forkStream);\n\n// now we have data on our screen and as a compressed log file\n```\n\n## Installation\n\n```bash\nnpm i --save stream-fork\n# or: yarn add stream-fork\n```\n\n## Documentation\n\n`Fork`, which is returned by `require('stream-fork')`, is a specialized [Writable](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream. It propagates every piece of data downstream to its dependent Writable streams (including [Transform](https://nodejs.org/api/stream.html#stream_class_stream_transform) and [Duplex](https://nodejs.org/api/stream.html#stream_class_stream_duplex) streams).\n\nMany details about this package can be discovered by looking at test files located in `tests/` and in the source code (`main.js`).\n\n### Constructor: `new Fork(outputs[, options])`\n\nThe constructor accepts following arguments:\n\n* `outputs` is an array of Writable streams, which will be used duplicate written chunks or items.\n* `options` is an options object, which is used to create a Writable stream. Read all about it in [Implementing a Writable stream](https://nodejs.org/api/stream.html#stream_implementing_a_writable_stream). If it is not specified or falsy, `{objectMode: true}` is assumed. This default is useful for creating object mode streams.\n  * Additionally following custom options are recognized:\n    * `ignoreErrors` is a flag. When its value is truthy, a `Fork` instance never fails on `write()` silently ignoring downstream errors. Otherwise, the first encountered downstream error is reported upstream as its own error. The default: `false`.\n\n```js\nconst forkObj = new Fork(streams);     // object mode\nconst forkChk = new Fork(streams, {}); // chunk mode (text or buffers)\n```\n\n### Property: `outputs`\n\nIt is an array of Writable streams supplied in the constructor above. If a stream fails on writing a chunk, eventually it will be removed from the array.\n\n```js\nconst forkStream = new Fork(streams);\nforkStream.outputs.length === streams.length; // true\n```\n\n### Method: `isEmpty()`\n\nIt returns `true` if `outputs` property is empty, and `false` otherwise. If `isEmpty()` is `true`, it means that the stream do not duplicate data.\n\n```js\nconst forkStream = new Fork([]);\nforkStream.isEmpty(); // true\n```\n\n### Static method: `fork(outputs[, options])`\n\nIt is a factory function, which accepts the same arguments as the constructor, and returns a fully constructed `Fork` object.\n\n```js\n// replicating the introduction example above\nconst {fork} = require('stream-fork');\ndataSource.pipe(fork([gzip, process.stdout], {}));\n```\n\n## Release History\n\n- 1.0.5 *technical release.*\n- 1.0.4 *bugfix: forward errors correctly, thx [dbubovych](https://github.com/dbubovych).*\n- 1.0.3 *technical release to support Node 14.*\n- 1.0.2 *workaround for Node 6: use `'finish'` event instead of `_final()`.*\n- 1.0.1 *improved documentation.*\n- 1.0.0 *the initial release.*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuhop%2Fstream-fork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuhop%2Fstream-fork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuhop%2Fstream-fork/lists"}