{"id":13828610,"url":"https://github.com/bcremer/LineReader","last_synced_at":"2025-07-09T06:32:23.693Z","repository":{"id":55900768,"uuid":"64876040","full_name":"bcremer/LineReader","owner":"bcremer","description":"Read large files line by line in a memory efficient (constant) way.","archived":false,"fork":false,"pushed_at":"2023-01-27T12:18:16.000Z","size":37,"stargazers_count":30,"open_issues_count":0,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-11-09T03:46:59.534Z","etag":null,"topics":["large-files","linereader","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/bcremer.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":"2016-08-03T20:11:22.000Z","updated_at":"2024-11-06T16:57:40.000Z","dependencies_parsed_at":"2023-02-15T09:01:26.056Z","dependency_job_id":null,"html_url":"https://github.com/bcremer/LineReader","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcremer%2FLineReader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcremer%2FLineReader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcremer%2FLineReader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcremer%2FLineReader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bcremer","download_url":"https://codeload.github.com/bcremer/LineReader/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225492420,"owners_count":17482869,"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":["large-files","linereader","php"],"created_at":"2024-08-04T09:02:54.863Z","updated_at":"2024-11-20T08:30:52.118Z","avatar_url":"https://github.com/bcremer.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# LineReader\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE.md)\n[![Build Status][ico-ghactions]][link-ghactions]\n\nLineReader is a library to read large files line by line in a memory efficient (constant) way.\n\n## Install\n\nVia Composer\n\n```bash\n$ composer require bcremer/line-reader\n```\n\n## Usage\n\nGiven we have a textfile (`some/file.txt`) with lines like:\n\n```\nLine 1\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nLine 8\nLine 9\nLine 10\n```\n\nAlso let's assume the namespace is imported to keep the examples dense:\n\n```\nuse Bcremer\\LineReader\\LineReader;\n```\n\n### Read forwards\n\n```php\nforeach (LineReader::readLines('some/file.txt') as $line) {\n    echo $line . \"\\n\"\n}\n```\n\nThe output will be:\n\n```\nLine 1\nLine 2\nLine 3\nLine 4\nLine 5\n...\n```\n\nTo set an offset or a limit use the `\\LimitIterator`:\n\n```php\n$lineGenerator = LineReader::readLines('some/file.txt');\n$lineGenerator = new \\LimitIterator($lineGenerator, 2, 5);\nforeach ($lineGenerator as $line) {\n    echo $line . \"\\n\"\n}\n```\n\nWill output line 3 to 7\n\n```\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\n```\n\n### Read backwards\n\n```php\nforeach (LineReader::readLinesBackwards('some/file.txt') as $line) {\n    echo $line;\n}\n```\n\n```\nLine 10\nLine 9\nLine 8\nLine 7\nLine 6\n...\n```\n\nExample: Read the last 5 lines in forward order:\n\n```php\n$lineGenerator = LineReader::readLinesBackwards('some/file.txt');\n$lineGenerator = new \\LimitIterator($lineGenerator, 0, 5);\n\n$lines = array_reverse(iterator_to_array($lineGenerator));\nforeach ($line as $line) {\n    echo $line;\n}\n```\n\n```\nLine 6\nLine 7\nLine 8\nLine 9\nLine 10\n```\n\n## Testing\n\n```bash\n$ composer test\n```\n\n```bash\n$ TEST_MAX_LINES=200000 composer test\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/bcremer/line-reader.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[link-packagist]: https://packagist.org/packages/bcremer/line-reader\n[ico-ghactions]: https://github.com/bcremer/LineReader/workflows/Build/badge.svg\n[link-ghactions]: https://github.com/bcremer/LineReader/actions?query=workflow%3ABuild\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbcremer%2FLineReader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbcremer%2FLineReader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbcremer%2FLineReader/lists"}