bundle-new/spec/support/ruby_ext.rb

21 lines
481 B
Ruby
Raw Permalink Normal View History

2019-10-06 15:45:34 +00:00
class IO
def read_available_bytes(chunk_size = 16384, 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
while true
begin
IO.select([self], nil, nil, select_timeout)
break if eof? # stop raising :-(
buffer << self.readpartial(chunk_size)
rescue(EOFError)
break
end
end
return buffer.join
end
end