{"id":17970229,"url":"https://github.com/borewit/t-readable","last_synced_at":"2025-03-25T10:32:54.610Z","repository":{"id":36930319,"uuid":"231089383","full_name":"Borewit/t-readable","owner":"Borewit","description":"Split a readable-stream into 2 or more readable-streams","archived":false,"fork":false,"pushed_at":"2023-02-03T03:23:25.000Z","size":572,"stargazers_count":1,"open_issues_count":12,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-29T16:57:50.223Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/Borewit.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":"2019-12-31T12:58:56.000Z","updated_at":"2022-07-26T09:22:11.000Z","dependencies_parsed_at":"2023-02-18T05:40:14.724Z","dependency_job_id":null,"html_url":"https://github.com/Borewit/t-readable","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/Borewit%2Ft-readable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Ft-readable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Ft-readable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Ft-readable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Borewit","download_url":"https://codeload.github.com/Borewit/t-readable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245444616,"owners_count":20616416,"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-10-29T15:02:09.086Z","updated_at":"2025-03-25T10:32:53.740Z","avatar_url":"https://github.com/Borewit.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/Borewit/t-readable.svg?branch=master)](https://travis-ci.org/Borewit/t-readable)\n[![NPM version](https://badge.fury.io/js/t-readable.svg)](https://npmjs.org/package/t-readable)\n[![npm downloads](http://img.shields.io/npm/dm/t-readable.svg)](https://npmcharts.com/compare/t-readable?start=1200\u0026interval=30)\n[![Total alerts](https://img.shields.io/lgtm/alerts/g/Borewit/t-readable.svg?logo=lgtm\u0026logoWidth=18)](https://lgtm.com/projects/g/Borewit/t-readable/alerts/)\n[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/Borewit/t-readable.svg?logo=lgtm\u0026logoWidth=18)](https://lgtm.com/projects/g/Borewit/t-readable/context:javascript)\n\n# t-readable\nSplit one [_readable stream_](https://nodejs.org/api/stream.html#stream_readable_streams) into multiple [_readable streams_](https://nodejs.org/api/stream.html#stream_readable_streams).\n\n## Installation\n\nUsing [npm](https://www.npmjs.com/get-npm):\n```sh\nnpm install t-readable\n```\nor [yarn](https://yarnpkg.com/):\n```sh\nyarn add t-readable\n```\n\n## Usage\n\n```js\nconst { tee } = require('t-readable');\nconst got = require('got');\n\nconst url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';\n\n/**\n * Counts the number of bytes in the givent stream\n * @param readable {stream.Readable} - Readable stream\n * @return {Promise\u003cnumber\u003e} - Number of bytes until the end of stream is reached\n */\nasync function countBytes(readable) {\n  let bytesRead = 0;\n\n  return new Promise((resolve, reject) =\u003e {\n    readable.on('data', chunk =\u003e {\n      bytesRead += chunk.length;\n    });\n    readable.on('end', () =\u003e {\n      resolve(bytesRead);\n    });\n    readable.on('error', error =\u003e {\n      reject(error);\n    });\n  });\n}\n\n(async () =\u003e {\n  const stream = got.stream(url); // stream is an instance of class stream.Readable\n\n  const teedStreams = tee(stream);\n  \n  // Count the number of bytes received in each teed stream\n  const counts = await Promise.all(teedStreams.map(readable =\u003e countBytes(readable)));\n  console.log('Counts: ' + counts.join(', ')); // Counts: 27661, 27661\n})();\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborewit%2Ft-readable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborewit%2Ft-readable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborewit%2Ft-readable/lists"}