{"id":20614739,"url":"https://github.com/dashed/detour-stream","last_synced_at":"2025-04-15T07:33:32.901Z","repository":{"id":14255804,"uuid":"16963355","full_name":"dashed/detour-stream","owner":"dashed","description":"Use boolean expressions/functions to conditionally attach a stream as a detour or an alternative destination stream.","archived":false,"fork":false,"pushed_at":"2016-07-12T01:48:58.000Z","size":20,"stargazers_count":5,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T17:57:27.021Z","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":"github-archive/developer.github.com","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dashed.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-18T20:53:38.000Z","updated_at":"2019-11-15T00:43:10.000Z","dependencies_parsed_at":"2022-09-08T21:12:32.497Z","dependency_job_id":null,"html_url":"https://github.com/dashed/detour-stream","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Fdetour-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Fdetour-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Fdetour-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Fdetour-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dashed","download_url":"https://codeload.github.com/dashed/detour-stream/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248602302,"owners_count":21131615,"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-11-16T11:13:29.836Z","updated_at":"2025-04-15T07:33:32.872Z","avatar_url":"https://github.com/dashed.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"detour-stream\n=============\n\nUse boolean expressions/functions to conditionally attach a stream as a *detour* or an *alternative* destination stream.\n\nThis module is inspired by [gulp-if](https://github.com/robrich/gulp-if). The difference is that this module is not created for [gulp](https://github.com/gulpjs/gulp).\n\n![](img/flow.png)\n\nFollowing the above diagram, if **bool** is *unsatisfied*, then data from **stream A** will pass through to **Stream D**.\n\nOtherwise, data will pipe to **Stream B** whenever **bool** is *satisfied*.\n\nIf **branch** is true, then data will **not** be piped back to **Stream D**. This is useful when emulating *if/else* with streams.\n\nExample\n=======\n\n `detour-stream` is a function that creates a writable stream: https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options\n\nThe writable stream is created via `through2 v0.x.y`: https://github.com/rvagg/through2\n\n```js\nvar detour = require('detour-stream');\n\nstream = fs\n  .createReadStream(filepath)\n  .pipe(detour(someBoolean, decodeStream(someOptions))) // just pipe it\n  .pipe(writeStream);\n```\n\nAPI\n===\n\n## detour(bool, stream [, branch])\n\n`detour` will pipe data to stream appropriately whenever `bool` is satisfied.\n\n### Parameters\n\n#### bool\n\nType: `boolean`, or `function`\n\nIf a function is given, then the function is passed a data chunk. The function should return a `boolean`.\n\n#### stream\n\nStream for detour-stream to pipe data into whenever **bool** satisfies.\n\n#### branch\n\nType: `boolean`\n\nDefault: `false`\n\n`branch` controls the flow behavior of whether detour-stream should pipe `stream` back to the main stream (i.e. detour stream).\n\nIf `true`, then gulp-if **will not** pipe `stream` back to the main stream. This emulates *if/else* stream flow.\n\nLicense\n=======\n\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashed%2Fdetour-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdashed%2Fdetour-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashed%2Fdetour-stream/lists"}