{"id":19589775,"url":"https://github.com/supercharge/streams","last_synced_at":"2025-04-27T12:33:05.324Z","repository":{"id":57163611,"uuid":"211658990","full_name":"supercharge/streams","owner":"supercharge","description":"async/await-ready, chainable streaming utilities for Node.js","archived":false,"fork":false,"pushed_at":"2021-07-09T07:58:08.000Z","size":51,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T00:25:39.830Z","etag":null,"topics":["async-await","nodejs","pipeline","promises","stream","streams","supercharge","utilities"],"latest_commit_sha":null,"homepage":"https://superchargejs.com/docs/streams","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/supercharge.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":"2019-09-29T12:23:32.000Z","updated_at":"2023-03-15T20:01:40.000Z","dependencies_parsed_at":"2022-09-01T00:20:19.463Z","dependency_job_id":null,"html_url":"https://github.com/supercharge/streams","commit_stats":null,"previous_names":["superchargejs/streams"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fstreams","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fstreams/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fstreams/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fstreams/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/supercharge","download_url":"https://codeload.github.com/supercharge/streams/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251138934,"owners_count":21541976,"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":["async-await","nodejs","pipeline","promises","stream","streams","supercharge","utilities"],"created_at":"2024-11-11T08:20:44.978Z","updated_at":"2025-04-27T12:33:04.927Z","avatar_url":"https://github.com/supercharge.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\r\n  \u003ca href=\"https://superchargejs.com\"\u003e\r\n    \u003cimg width=\"471\" style=\"max-width:100%;\" src=\"https://superchargejs.com/images/supercharge-text.svg\" /\u003e\r\n  \u003c/a\u003e\r\n  \u003cbr/\u003e\r\n  \u003cbr/\u003e\r\n  \u003cp\u003e\r\n    \u003ch3\u003eStreams\u003c/h3\u003e\r\n  \u003c/p\u003e\r\n  \u003cp\u003e\r\n    Streaming utilities for Node.js based on promises, instead of events.\r\n  \u003c/p\u003e\r\n  \u003cbr/\u003e\r\n  \u003cp\u003e\r\n    \u003ca href=\"#installation\"\u003e\u003cstrong\u003eInstallation\u003c/strong\u003e\u003c/a\u003e ·\r\n    \u003ca href=\"#Docs\"\u003e\u003cstrong\u003eDocs\u003c/strong\u003e\u003c/a\u003e ·\r\n    \u003ca href=\"#usage\"\u003e\u003cstrong\u003eUsage\u003c/strong\u003e\u003c/a\u003e\r\n  \u003c/p\u003e\r\n  \u003cbr/\u003e\r\n  \u003cbr/\u003e\r\n  \u003cp\u003e\r\n    \u003ca href=\"https://www.npmjs.com/package/@supercharge/streams\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@supercharge/streams.svg\" alt=\"Latest Version\"\u003e\u003c/a\u003e\r\n    \u003ca href=\"https://www.npmjs.com/package/@supercharge/streams\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/@supercharge/streams.svg\" alt=\"Monthly downloads\"\u003e\u003c/a\u003e\r\n  \u003c/p\u003e\r\n  \u003cp\u003e\r\n    \u003cem\u003eFollow \u003ca href=\"http://twitter.com/marcuspoehls\"\u003e@marcuspoehls\u003c/a\u003e and \u003ca href=\"http://twitter.com/superchargejs\"\u003e@superchargejs\u003c/a\u003e for updates!\u003c/em\u003e\r\n  \u003c/p\u003e\r\n\u003c/div\u003e\r\n\r\n---\r\n\r\n## Introduction\r\nThe native Node.js stream implementation is based on event emitters. It’s hard to manage the control flow in your application when using events. If you want to actively wait for a stream to finish, you must wrap it into a promise.\r\n\r\nThis `@supercharge/streams` package wraps Node.js streams into promises to make them `async/await`-ready. It provides methods, like\r\n\r\n- `.map(callback)`\r\n- `.filter(callback)`\r\n- `.through(transformStream)`\r\n\r\nto interact with the input data.\r\n\r\n\r\n## Installation\r\n\r\n```\r\nnpm i @supercharge/streams\r\n```\r\n\r\n\r\n## Docs\r\nFind all the [details for `@supercharge/streams` in the extensive Supercharge docs](https://superchargejs.com/docs/streams).\r\n\r\n\r\n## Usage\r\nUsing `@supercharge/streams` is pretty straightforward. The package exports a function that accepts data or a read-stream as an input. If the input is not a stream, it transforms it into one.\r\n\r\nHere’s an example that takes an array with three items and runs it through a streaming pipeline to ultimately writing the result to a file:\r\n\r\n```js\r\nconst Stream = require('@supercharge/streams')\r\n\r\nawait Stream([1, 2, 3])\r\n  .inObjectMode()\r\n  .map(item =\u003e {\r\n    return item * 2\r\n  })\r\n  .filter(item =\u003e {\r\n    return item \u003e 3\r\n  })\r\n  .into(Fs.createWriteStream('./numbers-greater-then-three.csv'))\r\n```\r\n\r\nThe `.map()` and `.filter()` methods take a callback as an argument. Under the hood, `@supercharge/streams` creates a transform stream for these methods to run the provided callback.\r\n\r\n\r\n### Object Mode Streams\r\nObject mode streams come handy when working with arrays to retrieve each item from the array individually.\r\n\r\nBy default, a stream is not in object mode. You must actively chain the `.inObjectMode()` method in the pipeline:\r\n\r\n```js\r\nconst Fs = require('fs')\r\nconst Stream = require('@supercharge/streams')\r\n\r\nconst users = [\r\n  { name: 'Marcus', supercharged: true },\r\n  { name: 'Red John', supercharged: false }\r\n]\r\n\r\nawait Stream(users)\r\n  .inObjectMode()\r\n  .filter(user =\u003e user.supercharged)\r\n  .into(Fs.createWriteStream('./supercharged-users-export.csv'))\r\n```\r\n\r\n\r\n### Error Handling\r\nThe native Node.js streams use event emitters and this comes with separate channels for data and errors. The `@supercharge/streams` package transforms the event-based streams into promise-based streams. Promises have a single channel for data and errors.\r\n\r\nYou must actively catch errors if you don’t want them to bubble up in your appplication:\r\n\r\n```js\r\ntry {\r\n  await Stream(input)\r\n    .map(() =\u003e throw new Error('sh*t happens'))\r\n    .into(output)\r\n} catch (error) {\r\n  // handle error\r\n}\r\n```\r\n\r\nErrors will be thrown as soon as they appear. The stream will stop and clean up without processing the remaining data.\r\n\r\n\r\n## Contributing\r\nDo you miss a stream function? We very much appreciate your contribution! Please send in a pull request 😊\r\n\r\n1.  Create a fork\r\n2.  Create your feature branch: `git checkout -b my-feature`\r\n3.  Commit your changes: `git commit -am 'Add some feature'`\r\n4.  Push to the branch: `git push origin my-new-feature`\r\n5.  Submit a pull request 🚀\r\n\r\n\r\n## License\r\nMIT © [Supercharge](https://superchargejs.com)\r\n\r\n---\r\n\r\n\u003e [superchargejs.com](https://superchargejs.com) \u0026nbsp;\u0026middot;\u0026nbsp;\r\n\u003e GitHub [@supercharge](https://github.com/supercharge/) \u0026nbsp;\u0026middot;\u0026nbsp;\r\n\u003e Twitter [@superchargejs](https://twitter.com/superchargejs)\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupercharge%2Fstreams","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupercharge%2Fstreams","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupercharge%2Fstreams/lists"}