Class: ChefAPI::Multipart::MultiIO
- Inherits:
-
Object
- Object
- ChefAPI::Multipart::MultiIO
- Defined in:
- lib/chef-api/connection.rb
Instance Method Summary collapse
-
#initialize(*ios) ⇒ MultiIO
constructor
A new instance of MultiIO.
-
#read(length = nil, outbuf = nil) ⇒ Object
Read from IOs in order until
lengthbytes have been received. - #rewind ⇒ Object
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 |
#rewind ⇒ Object
579 580 581 582 |
# File 'lib/chef-api/connection.rb', line 579 def rewind @ios.each { |io| io.rewind } @index = 0 end |