Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tail -n 20 in pure Ruby #59

Merged
merged 1 commit into from
Aug 3, 2015
Merged

Implement tail -n 20 in pure Ruby #59

merged 1 commit into from
Aug 3, 2015

Conversation

mattbrictson
Copy link
Owner

I think full-blown tail implementation is overkill, so I went with a solution that should work 99% of the time (as long as the line lengths are not extremely long):

  • Read the last 8 KB of the file
  • Split that into lines
  • Return the last 20 of those lines

If for some reason the last 8 KB has fewer than 20 lines, it will not seek backwards to create a bigger buffer; instead it will just return the lines it already has.

Closes #31.

@mattbrictson
Copy link
Owner Author

@robd I think you were the one who originally suggested we replace tail -n 20 with a pure Ruby equivalent. I've implemented something like that in this PR. Do you mind taking a quick look?

@robd
Copy link
Contributor

robd commented Aug 3, 2015

@mattbrictson sorry for the delay here. Agree that full blown tail impl is overkill. This looks good to me.

mattbrictson added a commit that referenced this pull request Aug 3, 2015
Implement `tail -n 20` in pure Ruby
@mattbrictson mattbrictson merged commit 0363d45 into master Aug 3, 2015
@mattbrictson mattbrictson deleted the tail-ruby branch January 2, 2017 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants