module IO::Stream::Readable
def read_partial(size = nil, buffer = nil)
@parameter buffer [String | Nil] An optional buffer to fill with data instead of allocating a new string.
@parameter size [Integer | Nil] The number of bytes to read. If nil, read all available data.
Read at most `size` bytes from the stream. Will avoid reading from the underlying stream if possible.
def read_partial(size = nil, buffer = nil) if size == 0 if buffer buffer.clear buffer.force_encoding(Encoding::BINARY) return buffer else return String.new(encoding: Encoding::BINARY) end end if !@finished and @read_buffer.empty? fill_read_buffer end return consume_read_buffer(size, buffer) end