summaryrefslogtreecommitdiff
path: root/spec/support/ruby_ext.rb
blob: 9c5b08c9e5c5f89e48486a988b2b0e33751bc3c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class IO
  def read_available_bytes(chunk_size = 16_384, select_timeout = 0.02)
    buffer = []

    return "" if closed? || eof?
    # IO.select cannot be used here due to the fact that it
    # just does not work on windows
    loop do
      begin
        IO.select([self], nil, nil, select_timeout)
        break if eof? # stop raising :-(
        buffer << readpartial(chunk_size)
      rescue(EOFError)
        break
      end
    end

    buffer.join
  end
end