lib/buildbox/command.rb
# Reads data from an IO object while it can, returning the data it reads.
# When it encounters a case when it can't read anymore, it returns the
# data.
#
# @return [String]
Reads data from an IO object while it can, returning the data it reads.
When it encounters a case when it can't read anymore, it returns the
data.
Reads data from an IO object while it can returning the data it reads . When it encounters a case when it can ' t read anymore it returns the data .
def read_io(io)
      data = ""
      while true
        begin
          if Platform.windows?
            results = IO.select([io], nil, nil, 0.1)
            break if !results || results[0].empty?
            data << io.readpartial(READ_CHUNK_SIZE)
          else
            data << io.read_nonblock(READ_CHUNK_SIZE)
          end
        rescue Exception => e
          breakable = false
          if e.is_a?(EOFError) || e.is_a?(Errno::EIO)
            breakable = true
          elsif defined?(IO::WaitReadable) && e.is_a?(IO::WaitReadable)
            breakable = true
          elsif e.is_a?(Errno::EAGAIN) || e.is_a?(Errno::EWOULDBLOCK)
            breakable = true
          end
          break if breakable
          raise
        end
      end
      data
    end
def read_io ( io ) data = "" while true begin if Platform . windows? results = IO . select ( [ io ] , nil , nil , 0.1 ) break if ! results || results [ 0 ] . empty? data << io . readpartial ( READ_CHUNK_SIZE ) else data << io . read_nonblock ( READ_CHUNK_SIZE ) end rescue Exception => e breakable = false if e . is_a? ( EOFError ) || e . is_a? ( Errno :: EIO ) breakable = true elsif defined? ( IO :: WaitReadable ) && e . is_a? ( IO :: WaitReadable ) breakable = true elsif e . is_a? ( Errno :: EAGAIN ) || e . is_a? ( Errno :: EWOULDBLOCK ) breakable = true end break if breakable raise end end data end
Reads data from an IO object while it can, returning the data it reads.
Reads data from an IO object while it can returning the data it reads .
# Windows doesn't support non-blocking reads on # file descriptors or pipes so we have to get # a bit more creative. # Check if data is actually ready on this IO device. # We have to do this since `readpartial` will actually block # until data is available, which can cause blocking forever # in some cases. # Read! # Do a simple non-blocking read on the IO object # The catch-all rescue here is to support multiple Ruby versions, # since we use some Ruby 1.9 specific exceptions. # EOFError from OSX, EIO is raised by ubuntu # An `EOFError` means this IO object is done! # IO::WaitReadable is only available on Ruby 1.9+ # An IO::WaitReadable means there may be more IO but this # IO object is not ready to be read from yet. No problem, # we read as much as we can, so we break. # Otherwise, we just look for the EAGAIN error which should be # all that IO::WaitReadable does in Ruby 1.9. # Break out if we're supposed to. Otherwise re-raise the error # because it is a real problem.
None
String
io