lib/scout/open/stream.rb in scout-gear-5.2.0 vs lib/scout/open/stream.rb in scout-gear-6.0.0

- old
+ new

@@ -368,6 +368,36 @@ end def self.tee_stream(stream) tee_stream_thread(stream) end + + def self.read_stream(stream, size) + str = nil + Thread.pass while IO.select([stream],nil,nil,1).nil? + while not str = stream.read(size) + IO.select([stream],nil,nil,1) + Thread.pass + raise ClosedStream if stream.eof? + end + + while str.length < size + raise ClosedStream if stream.eof? + IO.select([stream],nil,nil,1) + if new = stream.read(size-str.length) + str << new + end + end + str + end + + def self.read_stream(stream, size) + str = "" + while str.length < size + missing = size - str.length + more = stream.read(missing) + str << more + end + str + end + end