Class: IO

Inherits:
Object
  • Object
show all
Defined in:
lib/postgres-pr/message.rb

Instance Method Summary collapse

Instance Method Details

#read_exactly_n_bytes(n) ⇒ Object

Raises:

  • (EOFError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/postgres-pr/message.rb', line 9

def read_exactly_n_bytes(n)
  buf = read(n)
  raise EOFError if buf == nil
  return buf if buf.size == n

  n -= buf.size

  while n > 0
    str = read(n)
    raise EOFError if str == nil
    buf << str
    n -= str.size 
  end
  return buf
end