Class: Datadog::Core::Vendor::Multipart::Post::CompositeReadIO

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/vendor/multipart-post/multipart/post/composite_read_io.rb

Instance Method Summary collapse

Constructor Details

#initialize(*ios) ⇒ CompositeReadIO

Create a new composite-read IO from the arguments, all of which should respond to #read in a manner consistent with IO.



23
24
25
26
# File 'lib/datadog/core/vendor/multipart-post/multipart/post/composite_read_io.rb', line 23

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

Instance Method Details

#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/datadog/core/vendor/multipart-post/multipart/post/composite_read_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

#rewindObject



46
47
48
49
# File 'lib/datadog/core/vendor/multipart-post/multipart/post/composite_read_io.rb', line 46

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