Class: ChefAPI::Multipart::MultiIO

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-api/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(*ios) ⇒ MultiIO

Returns a new instance of MultiIO.



555
556
557
558
# File 'lib/chef-api/connection.rb', line 555

def initialize(*ios)
  @ios = ios
  @index = 0
end

Instance Method Details

#read(length = nil, outbuf = nil) ⇒ Object

Read from IOs in order until length bytes have been received.



561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
# File 'lib/chef-api/connection.rb', line 561

def read(length = nil, outbuf = nil)
  got_result = false
  outbuf = outbuf ? outbuf.replace('') : ''

  while io = current_io
    if result = io.read(length)
      got_result ||= !result.nil?
      result.force_encoding('BINARY') if result.respond_to?(:force_encoding)
      outbuf << result
      length -= result.length if length
      break if length == 0
    end
    advance_io
  end

  (!got_result && length) ? nil : outbuf
end

#rewindObject



579
580
581
582
# File 'lib/chef-api/connection.rb', line 579

def rewind
  @ios.each { |io| io.rewind }
  @index = 0
end