Class: StringIO

Inherits:
Object
  • Object
show all
Defined in:
lib/postgres_connection.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#readbytes(n) ⇒ Object Also known as: read_exactly_n_bytes

Reads exactly n bytes.

If the data read is nil an EOFError is raised.

If the data read is too short a TruncatedDataError is raised and the read data is obtainable via its #data method.



14
15
16
17
18
19
20
21
22
23
# File 'lib/postgres_connection.rb', line 14

def readbytes(n)
  str = read(n)
  if str == nil
    raise EOFError, "End of file reached"
  end
  if str.size < n
    raise TruncatedDataError.new("data truncated", str) 
  end
  str
end