6 $stderr.puts "Install the multipart-post gem."
11 # Similar but not compatible with ::CompositeReadIO provided by multipart-post.
13 def initialize(*parts)
14 @parts = parts.flatten
15 @ios = @parts.map { |part| part.to_io }
20 @parts.inject(0) { |sum, part| sum + part.length }
24 @ios.each { |io| io.rewind }
28 # Read from IOs in order until `length` bytes have been received.
29 def read(length = nil, outbuf = nil)
31 outbuf = outbuf ? outbuf.replace("") : ""
34 if result = io.read(length)
35 got_result ||= !result.nil?
36 result.force_encoding("BINARY") if result.respond_to?(:force_encoding)
38 length -= result.length if length
43 (!got_result && length) ? nil : outbuf
47 @ios.each { |io| io.close }
50 def ensure_open_and_readable
51 # Rubinius compatibility