-
-
Save mikecmpbll/1152878079ba0f175b24 to your computer and use it in GitHub Desktop.
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
def chunk | |
chunks = [] | |
break_points.each_cons(2) do |start_byte, end_byte| | |
chunk = @file.read(end_byte - start_byte) | |
if block_given? | |
# more memory efficient, process the chunks one by one | |
yield chunk | |
else | |
chunks << chunk | |
end | |
end | |
end | |
def chunk2 | |
# returns Enumerable lazy so we can process one chunk at a time. | |
break_points.each_cons(2).lazy.map do |start_byte, end_byte| | |
@file.read(end_byte - start_byte) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IMO rewrite this as: