{"id":16758442,"url":"https://github.com/kessler/buffering-duplex-stream","last_synced_at":"2025-03-16T08:21:22.686Z","repository":{"id":57124439,"uuid":"292605994","full_name":"kessler/buffering-duplex-stream","owner":"kessler","description":"a duplex stream that serves as a dam or a buffer, holding written data until a certain threshold is met then releasing it to the read side","archived":false,"fork":false,"pushed_at":"2020-09-05T05:35:24.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-08T08:12:39.981Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kessler.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":"2020-09-03T15:17:01.000Z","updated_at":"2020-09-05T05:35:26.000Z","dependencies_parsed_at":"2022-08-31T17:01:00.092Z","dependency_job_id":null,"html_url":"https://github.com/kessler/buffering-duplex-stream","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fbuffering-duplex-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fbuffering-duplex-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fbuffering-duplex-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fbuffering-duplex-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kessler","download_url":"https://codeload.github.com/kessler/buffering-duplex-stream/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243842144,"owners_count":20356612,"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-13T04:05:19.437Z","updated_at":"2025-03-16T08:21:22.640Z","avatar_url":"https://github.com/kessler.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @kessler/buffering-duplex-stream\n\nA duplex stream that serves as a dam or a buffer, holding written data until a certain threshold is met then releasing it to the read side\n\nThis is basically a flow control stream.\n\n## Install\n```\nnpm i @kessler/buffering-duplex-stream\n```\n\n## Example\n```js\nconst BufferingDuplexStream = require('./index.js')\nconst { promisify } = require('util')\nconst { Readable, pipeline: callbackPipeline } = require('stream')\nconst pipeline = promisify(callbackPipeline)\n\n/**\n * outputs:\n *\n *  \"00000\" = 5 bytes\n *  \"00000\" = 5 bytes\n *  \"11111\" = 5 bytes\n *  \"11111\" = 5 bytes\n *  \"22222\" = 5 bytes\n *  \"22222\" = 5 bytes\n *  \"33333\" = 5 bytes\n *  \"33333\" = 5 bytes\n *\n */\nasync function main() {\n    const bfStream = BufferingDuplexStream.create({\n        flushThreshold: 5 //bytes\n    })\n\n    const source = Readable.from(generateData())\n\n    pipeline(source, bfStream)\n\n    for await (const chunk of bfStream) {\n        console.log(`\"${chunk.toString()}\" = ${Buffer.byteLength(chunk)} bytes`)\n    }\n}\n\nmain()\n\nasync function* generateData() {\n    for (let i = 0; i \u003c 4; i++) {\n        for (let x = 0; x \u003c 10; x++) {\n            yield i.toString()\n        }\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkessler%2Fbuffering-duplex-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkessler%2Fbuffering-duplex-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkessler%2Fbuffering-duplex-stream/lists"}