{"id":20122817,"url":"https://github.com/freaky/rust-linereader","last_synced_at":"2025-05-06T16:33:06.696Z","repository":{"id":62442265,"uuid":"128548593","full_name":"Freaky/rust-linereader","owner":"Freaky","description":"A fast Rust line reader","archived":false,"fork":false,"pushed_at":"2019-09-13T12:56:57.000Z","size":40,"stargazers_count":23,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-24T09:52:44.705Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","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/Freaky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-07T16:47:17.000Z","updated_at":"2025-01-09T14:26:22.000Z","dependencies_parsed_at":"2022-11-01T22:02:02.718Z","dependency_job_id":null,"html_url":"https://github.com/Freaky/rust-linereader","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freaky%2Frust-linereader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freaky%2Frust-linereader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freaky%2Frust-linereader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freaky%2Frust-linereader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Freaky","download_url":"https://codeload.github.com/Freaky/rust-linereader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252721090,"owners_count":21793750,"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-13T19:41:18.397Z","updated_at":"2025-05-06T16:33:06.449Z","avatar_url":"https://github.com/Freaky.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LineReader [![Build Status](https://travis-ci.org/Freaky/rust-linereader.svg?branch=master)](https://travis-ci.org/Freaky/rust-linereader)\n\n## Synopsis\n\n`LineReader` is a byte-delimiter-focused buffered reader for Rust, meant as a\nfaster, less error-prone alternative to `BufRead::read_until`.\n\nIt provides three main functions:\n\n### `next_line() -\u003e Option\u003cio::Result\u003c\u0026[u8]\u003e\u003e`\n\nReturns `None` on end-of-file, or an `io::Result`-wrapped byte slice of the next\nline from the reader.\n\nLine length is limited to the size of the internal buffer - longer lines will be\nspread across multiple reads.\n\nIn contrast with `read_until`, detecting end-of-file is more natural with the\nuse of `Option`; line length is naturally limited to some sensible value without\nthe use of `by_ref().take(limit)`; copying is minimised by returning borrowed\nslices; you'll never forget to call `buf.clear()`.\n\n### `next_batch() -\u003e Option\u003cio::Result\u003c\u0026[u8]\u003e\u003e`\n\nBehaves identically to `next_line()`, except it returns a slice of *all* the\ncomplete lines in the buffer.\n\n### `for_each() -\u003e io::Result\u003c()\u003e`\n\nCalls a closure on each line of the input, while the closure returns `Ok(true)`\nand no IO errors are detected.  Such errors terminate iteration and are returned\nfrom the function.\n\n## Example\n\n```rust\nextern crate linereader;\nuse linereader::LineReader;\n\nlet mut file = File::open(myfile).expect(\"open\");\n\n// Defaults to a 64 KiB buffer and b'\\n' delimiter; change with one of:\n//  * LineReader::with_capacity(usize);\n//  * LineReader::with_delimiter(u8);\n//  * LineReader::with_delimiter_and_capacity(u8, usize)\nlet mut reader = LineReader::new(file);\n\nwhile let Some(line) = reader.next_line() {\n    let line = line.expect(\"read error\");\n    // line is a \u0026[u8] owned by reader.\n}\n```\n\n## Safety\n\n`LineReader` contains no `unsafe` code, but it does hand out manually-calculated\nslice positions from an internal buffer, and the only enforcement Rust performs\nis to ensure they remain within that buffer.\n\nThere is no incomplete line detection, and as documented, lines that extend\nbeyond the configured buffer can be spread across multiple \"lines\", with only\nthe lack of a terminating delimiter as a hint.  Care should be taken that this\ndoesn't cause undesired behaviour in code using the library.\n\nMethods such as `get_mut()` offer direct access to the wrapped reader, and their\nuse without also calling `reset()` could result in undesired behaviour if the\nreader's state is changed.\n\n## Alternatives\n\n[bstr](https://crates.io/crates/bstr): as of 0.2.8 the `for_byte_line` and\n`for_byte_line_with_terminator` `BufRead` extension trait functions should\nperform similarly, without `LineReader`'s line length limitations.\n\n## Performance\n\nTests performed using ['Dickens_Charles_Pickwick_Papers.xml'](http://hur.st/Dickens_Charles_Pickwick_Papers.xml.xz),\nconcatinated to itself 480 times.  The resulting file is 976 MB and 10.3 million lines long.\n\n### Westmere Xeon 2.1GHz, FreeBSD/ZFS.\n\n| Method           |  Time   |  Lines/sec  |   Bandwidth   |\n|------------------|--------:|------------:|--------------:|\n| read()           |   0.25s |  41429738/s |  3907.62 MB/s |\n| LR::next_batch() |   0.27s |  38258946/s |  3608.55 MB/s |\n| LR::next_line()  |   1.51s |   6874006/s |   648.35 MB/s |\n| read_until()     |   1.94s |   5327387/s |   502.47 MB/s |\n| read_line()      |   2.54s |   4081562/s |   384.97 MB/s |\n| lines()          |   3.23s |   3199491/s |   301.77 MB/s |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreaky%2Frust-linereader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreaky%2Frust-linereader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreaky%2Frust-linereader/lists"}