blob: 809708b978da51a276351a39a10ecd57affceb5d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# frozen_string_literal: true
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
|