Class: Faraday::CompositeReadIO
- Defined in:
- lib/puppet/feature/faraday/upload_io.rb
Overview
Similar but not compatible with ::CompositeReadIO provided by multipart-post.
Instance Method Summary collapse
- #close ⇒ Object
- #ensure_open_and_readable ⇒ Object
-
#initialize(*parts) ⇒ CompositeReadIO
constructor
A new instance of CompositeReadIO.
- #length ⇒ Object
-
#read(length = nil, outbuf = nil) ⇒ Object
Read from IOs in order until ‘length` bytes have been received.
- #rewind ⇒ Object
Constructor Details
#initialize(*parts) ⇒ CompositeReadIO
Returns a new instance of CompositeReadIO.
13 14 15 16 17 |
# File 'lib/puppet/feature/faraday/upload_io.rb', line 13 def initialize(*parts) @parts = parts.flatten @ios = @parts.map { |part| part.to_io } @index = 0 end |
Instance Method Details
#close ⇒ Object
46 47 48 |
# File 'lib/puppet/feature/faraday/upload_io.rb', line 46 def close @ios.each { |io| io.close } end |
#ensure_open_and_readable ⇒ Object
50 51 52 |
# File 'lib/puppet/feature/faraday/upload_io.rb', line 50 def ensure_open_and_readable # Rubinius compatibility end |
#length ⇒ Object
19 20 21 |
# File 'lib/puppet/feature/faraday/upload_io.rb', line 19 def length @parts.inject(0) { |sum, part| sum + part.length } end |
#read(length = nil, outbuf = nil) ⇒ Object
Read from IOs in order until ‘length` bytes have been received.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/puppet/feature/faraday/upload_io.rb', line 29 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
23 24 25 26 |
# File 'lib/puppet/feature/faraday/upload_io.rb', line 23 def rewind @ios.each { |io| io.rewind } @index = 0 end |