Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created October 9, 2018 20:59
Show Gist options
  • Save havenwood/cd200b40ad0d8ebb91f45ea9c9671858 to your computer and use it in GitHub Desktop.
Save havenwood/cd200b40ad0d8ebb91f45ea9c9671858 to your computer and use it in GitHub Desktop.
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