Method: Async::IO::Stream#read_exactly

Defined in:
lib/async/io/stream.rb

#read_exactly(size, exception: EOFError) ⇒ Object

Raises:

  • (exception)


105
106
107
108
109
110
111
112
113
114
115
# File 'lib/async/io/stream.rb', line 105

def read_exactly(size, exception: EOFError)
  if buffer = read(size)
    if buffer.bytesize != size
      raise exception, "could not read enough data"
    end
    
    return buffer
  end
  
  raise exception, "encountered eof while reading data"
end