/pread_lines.rb Secret
Created
October 9, 2018 20:59
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
offsets = File.open filename do |file| | |
line_offsets = [] | |
loop do | |
line_offsets << file.pos | |
file.readline | |
rescue EOFError | |
break line_offsets | |
end | |
end | |
File.open filename do |file| | |
offsets.each_cons(2).each do |start, finish| | |
puts file.pread finish - start, start | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment