All Projects → bcremer → LineReader

bcremer / LineReader

Licence: MIT license
Read large files line by line in a memory efficient (constant) way.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to LineReader

WebBlocks
zero-to-mastery re-usable web component library.
Stars: ✭ 20 (-4.76%)
Mutual labels:  hacktoberfest2021
file manager
FileManager is a wonderful widget that allows you to manage files and folders, pick files and folders, and do a lot more. Designed to feel like part of the Flutter framework.
Stars: ✭ 38 (+80.95%)
Mutual labels:  hacktoberfest2021
DSA
Collection of DSA problems and solutions
Stars: ✭ 15 (-28.57%)
Mutual labels:  hacktoberfest2021
Top-Ethical-Hacking-Resources
Stay up-to-date with the latest and greatest ethical hacking tools and resources.
Stars: ✭ 22 (+4.76%)
Mutual labels:  hacktoberfest2021
Certificate-Generator-UI
This is the UI for an awesome Certificate Generator and this is a part of Hacktoberfest 2021.
Stars: ✭ 18 (-14.29%)
Mutual labels:  hacktoberfest2021
JavaScript-A-Z-Notes
Trying to document all of my knowledge about Javascript for future reference. Get your JS fundas in lucid English right here!
Stars: ✭ 306 (+1357.14%)
Mutual labels:  hacktoberfest2021
frontendstudygroup.github.io
Web application for the frontend study group from WomenWhoCode Frontend track.
Stars: ✭ 15 (-28.57%)
Mutual labels:  hacktoberfest2021
Dev-Essentials
A Chrome Extension, built to keep you updated with the latest happenings, upcoming contests and, new tech innovations.
Stars: ✭ 16 (-23.81%)
Mutual labels:  hacktoberfest2021
Awesome-Machine-Learning-Models
Contribute your amazing Machine Learning, Data Science, and Deep Learning repository
Stars: ✭ 16 (-23.81%)
Mutual labels:  hacktoberfest2021
sloped-edge
Sass mixin that helps you build sloped section edges with a consistent angle.
Stars: ✭ 85 (+304.76%)
Mutual labels:  hacktoberfest2021
PracticeApp
A "must-have a look" project for newcomers in android.
Stars: ✭ 38 (+80.95%)
Mutual labels:  hacktoberfest2021
Wizard-Of-Docs
A open source project to bring all the data structures and algorithms docs under one repository.
Stars: ✭ 19 (-9.52%)
Mutual labels:  hacktoberfest2021
Video-Chat
Video calling and chatting app (PWA) built using React.js, Web RTC and Socket.io
Stars: ✭ 305 (+1352.38%)
Mutual labels:  hacktoberfest2021
stopwatch
Stop watch using javascript
Stars: ✭ 18 (-14.29%)
Mutual labels:  hacktoberfest2021
HackFest21
Only valid pull requests will be allowed. Use python only and readme changes will not be accepted.
Stars: ✭ 53 (+152.38%)
Mutual labels:  hacktoberfest2021
react-carousel-minimal
React.js Responsive Minimal Carousel
Stars: ✭ 76 (+261.9%)
Mutual labels:  hacktoberfest2021
react-bootcamp-notes
Bu repo Kodluyoruz Earlybird Front-End Talent Bootcamp boyunca aldığım tüm notları saklar.
Stars: ✭ 60 (+185.71%)
Mutual labels:  hacktoberfest2021
blitz-guard
Blitz Guard - The centralized permission based authorization for Blitz.js
Stars: ✭ 118 (+461.9%)
Mutual labels:  hacktoberfest2021
Hacktober-Fest-2021
📜This repository is created to welcome all the open source enthusiasts to get introduced to beginner friendly projects they could work with in the festive season of HacktoberFest 2021🎇🙌.
Stars: ✭ 23 (+9.52%)
Mutual labels:  hacktoberfest2021
ru102js
Source code for the RU102JS Redis for JavaScript Developers Course
Stars: ✭ 21 (+0%)
Mutual labels:  hacktoberfest2021

LineReader

Latest Version on Packagist Software License Build Status

LineReader is a library to read large files line by line in a memory efficient (constant) way.

Install

Via Composer

$ composer require bcremer/line-reader

Usage

Given we have a textfile (some/file.txt) with lines like:

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

Also let's assume the namespace is imported to keep the examples dense:

use Bcremer\LineReader\LineReader;

Read forwards

foreach (LineReader::readLines('some/file.txt') as $line) {
    echo $line . "\n"
}

The output will be:

Line 1
Line 2
Line 3
Line 4
Line 5
...

To set an offset or a limit use the \LimitIterator:

$lineGenerator = LineReader::readLines('some/file.txt');
$lineGenerator = new \LimitIterator($lineGenerator, 2, 5);
foreach ($lineGenerator as $line) {
    echo $line . "\n"
}

Will output line 3 to 7

Line 3
Line 4
Line 5
Line 6
Line 7

Read backwards

foreach (LineReader::readLinesBackwards('some/file.txt') as $line) {
    echo $line;
}
Line 10
Line 9
Line 8
Line 7
Line 6
...

Example: Read the last 5 lines in forward order:

$lineGenerator = LineReader::readLinesBackwards('some/file.txt');
$lineGenerator = new \LimitIterator($lineGenerator, 0, 5);

$lines = array_reverse(iterator_to_array($lineGenerator));
foreach ($line as $line) {
    echo $line;
}
Line 6
Line 7
Line 8
Line 9
Line 10

Testing

$ composer test
$ TEST_MAX_LINES=200000 composer test

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].