Class: IO

Inherits:
Object show all
Defined in:
lib/epitools/core_ext/io.rb

Class Method Summary collapse

Instance Method Summary collapse

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_offsetObject

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