Module: IOExtensions

Defined in:
lib/archive/support/ioextensions.rb

Overview

IOExtensions provides convenience wrappers for certain IO functionality.

Class Method Summary collapse

Class Method Details

.read_exactly(io, length) ⇒ Object

Reads and returns exactly length bytes from io using the read method on io. If there is insufficient data available, an EOFError is raised.



7
8
9
10
11
12
13
# File 'lib/archive/support/ioextensions.rb', line 7

def self.read_exactly(io, length)
  result = io.read(length)
  if result.nil? || result.bytesize < length
    raise EOFError, 'unexpected end of file'
  end
  result
end