Class: IO
Class Method Summary collapse
-
.copy_stream(input, output) ⇒ Object
IO.copy_stream backport.
Instance Method Summary collapse
-
#each_line_with_offset ⇒ Object
Iterate over each line of the stream, yielding the line and the byte offset of the start of the line in the file.
Class Method Details
.copy_stream(input, output) ⇒ Object
IO.copy_stream backport
9 10 11 12 13 |
# File 'lib/epitools/core_ext/io.rb', line 9 def self.copy_stream(input, output) while chunk = input.read(8192) output.write(chunk) end end |
Instance Method Details
#each_line_with_offset ⇒ Object
Iterate over each line of the stream, yielding the line and the byte offset of the start of the line in the file
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/epitools/core_ext/io.rb', line 19 def each_line_with_offset return to_enum(:each_line_with_offset) unless block_given? offset = 0 each_line do |line| yield line, offset offset += line.bytesize end end |