{"id":28560651,"url":"https://github.com/borewit/read-next-line","last_synced_at":"2026-02-13T09:31:23.332Z","repository":{"id":272346464,"uuid":"916284932","full_name":"Borewit/read-next-line","owner":"Borewit","description":"Utility for reading lines from a `ReadableStream` in JavaScript","archived":false,"fork":false,"pushed_at":"2025-04-07T06:51:32.000Z","size":275,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-09T09:15:37.693Z","etag":null,"topics":["bom","esm","line","promise","read","stream","stream-api","streamreadable","text","utf-16"],"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/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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"Borewit","buy_me_a_coffee":"borewit"}},"created_at":"2025-01-13T19:58:20.000Z","updated_at":"2025-03-02T13:34:07.000Z","dependencies_parsed_at":"2025-01-13T21:19:17.347Z","dependency_job_id":"6d0e680a-360b-4f12-8f3f-b17f4f9c25dc","html_url":"https://github.com/Borewit/read-next-line","commit_stats":null,"previous_names":["borewit/stream-line-reader"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Fread-next-line","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Fread-next-line/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Fread-next-line/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Fread-next-line/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Borewit","download_url":"https://codeload.github.com/Borewit/read-next-line/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Borewit%2Fread-next-line/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259049803,"owners_count":22798031,"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":["bom","esm","line","promise","read","stream","stream-api","streamreadable","text","utf-16"],"created_at":"2025-06-10T09:37:30.225Z","updated_at":"2026-02-13T09:31:18.293Z","avatar_url":"https://github.com/Borewit.png","language":"JavaScript","readme":"[![Node.js CI](https://github.com/Borewit/read-next-line/actions/workflows/nodejs-ci.yml/badge.svg)](https://github.com/Borewit/read-next-line/actions/workflows/nodejs-ci.yml)\n[![NPM version](https://img.shields.io/npm/v/read-next-line.svg)](https://npmjs.org/package/read-next-line)\n[![npm downloads](http://img.shields.io/npm/dm/read-next-line.svg)](https://npmcharts.com/compare/read-next-line)\n\n# `read-next-line`\nIs s a lightweight, efficient utility for reading lines from a [ReadableStream](https://developer.mozilla.org/docs/Web/API/ReadableStream) in JavaScript.\nThe primary goal of this module is to enable memory-efficient line-by-line processing of large data streams,\nsuch as logs, files, or real-time data feeds.\n\n## Features\n\n- **Line-based processing**: Reads lines directly from any [ReadableStream](https://developer.mozilla.org/docs/Web/API/ReadableStream).\n- **Memory efficiency**: Keeps memory usage low by processing one line at a time.\n- **Browser compatibility**: Works seamlessly with modern web browsers.\n- **Node.js compatibility**: Works seamlessly with [Node.js Web Streams API](https://nodejs.org/api/webstreams.html#web-streams-api).\n- Supports the following **text encoding**:\n  - UTF-8 (default)\n  - UTF-8 with the BOM field set\n  - UTF-16LE with the BOM field is set\n  - UTF-16BE with the BOM field is set\n- Supports different [line endings](https://en.wikipedia.org/wiki/Newline):\n\n  | Type                | Abbreviation | Escape sequence |\n  |---------------------|--------------|-----------------|\n  | Windows             | `CR LF`      | `\\r\\n`          |\n  | Unix                | `LF`         | `\\n`            |\n  | Acorn BBC / RISC OS | `LF CR`      | `\\n\\r`          |\n  | classic Mac OS      | `CR`         | `\\r`            |\n\n## Installation\n\nInstall the package via npm:\n\n```bash\nnpm install read-next-line\n```\n\n## Compatibility\n\n**read-next-line** is a hybrid JavaScript module, supporting:\n- ECMAScript Module (ESM)\n- CommonJS backwards compatibility support\n\nDesigned to work with Works seamlessly with either:\n- [Node.js Readable streams](https://nodejs.org/api/stream.html#readable-streams)\n- [Node.js Web Streams API](https://nodejs.org/api/webstreams.html#web-streams-api)\n- [Streams-API](https://developer.mozilla.org/docs/Web/API/Streams_API) in the browser\n\nCompatible with modern web browsers or Node.js ≥ 18.\n\n## Usage\n\nImport and use `StreamLineReader` in your project:\n\nIn ESM projects or any TypeScript project use:\n```js\nimport {ReadNextLine} from 'read-next-line';\n```\n\nIn CommonJS projects use:\n```js\nconst {ReadNextLine} = require('read-next-line');\n```\n\nUsing **read-next-line** to read lines of text of a binary [ReadableStream](https://developer.mozilla.org/docs/Web/API/ReadableStream) or [Node.js Readable streams](https://nodejs.org/api/stream.html#readable-streams):\n```js\nasync function processStream(stream) {\n\tconst reader = new ReadNextLine(stream);\n\n\tlet line;\n\twhile ((line = await reader.readLine()) !== null) {\n\t\tconsole.log(line); // Process each line as needed\n\t}\n}\n```\n\nYou may as well use the `LineSplitter` which is a [`TransformStream\u003cUint8Array, string\u003e`](https://developer.mozilla.org/docs/Web/API/TransformStream),\nconverting a binary stream into stream of lines (strings).\n\n```js\nimport {LineSplitter} from 'read-next-line';\n\nconst lineStream = webStream.pipeThrough(lineSplitter);\nconst lineReader = lineStream.getReader();\n```\n\n### Parsing a Blob/File\n\nTo process a file input, wrap the file's stream with `ReadNextLine`:\n\n```js\nasync function proccessTextFile(blob) {\n\tconst reader = new ReadNextLine(blob.stream());\n\ttry {\n\t\tlet line;\n\t\tdo {\n\t\t\tline = await reader.readLine();\n\t\t\tconsole.log(line);\n\t\t}\n\t\twhile (line !== null);\n\t} finally {\n\t\treader.release();\n\t}\n}\nconst file = document.querySelector('#fileInput').files[0];\nproccessTextFile(file);\n```\n\nOnline example can be found here: https://playcode.io/2226348\n\n## API\n\n### `StreamLineReader` Class\n\n#### Constructor\n\n```ts\nnew StreamLineReader(stream: ReadableStream\u003cUint8Array\u003e);\n```\n\n- **stream**: The `ReadableStream` to process.\n\n#### Methods\n\n- **`readLine(): Promise\u003cstring | null\u003e`**\n\t- Reads the next line from the stream. Returns `null` if the stream ends.\n- **`release(): void`**\n    - Release the internal [Reader](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader/releaseLock).\n\n\n## License\n\nThis project is licensed under the MIT License. Feel free to use, modify, and distribute as needed.\n","funding_links":["https://github.com/sponsors/Borewit","https://buymeacoffee.com/borewit"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborewit%2Fread-next-line","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborewit%2Fread-next-line","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborewit%2Fread-next-line/lists"}