Class: ChefAPI::Multipart::MultiIO

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*ios) ⇒ MultiIO

Returns a new instance of MultiIO.



43
44
45
46
# File 'lib/chef-api/multipart.rb', line 43

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

Instance Attribute Details

#iosObject (readonly)

Returns the value of attribute ios.



41
42
43
# File 'lib/chef-api/multipart.rb', line 41

def ios
  @ios
end

Instance Method Details

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

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/chef-api/multipart.rb', line 49

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



67
68
69
70
# File 'lib/chef-api/multipart.rb', line 67

def rewind
  @ios.each(&:rewind)
  @index = 0
end