/usr/lib/ruby/vendor_ruby/faraday/upload_io.rb is in ruby-faraday 0.9.2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | begin
require 'composite_io'
require 'parts'
require 'stringio'
rescue LoadError
$stderr.puts "Install the multipart-post gem."
raise
end
module Faraday
# Similar but not compatible with ::CompositeReadIO provided by multipart-post.
class CompositeReadIO
def initialize(*parts)
@parts = parts.flatten
@ios = @parts.map { |part| part.to_io }
@index = 0
end
def length
@parts.inject(0) { |sum, part| sum + part.length }
end
def rewind
@ios.each { |io| io.rewind }
@index = 0
end
# Read from IOs in order until `length` bytes have been received.
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
def close
@ios.each { |io| io.close }
end
def ensure_open_and_readable
# Rubinius compatibility
end
private
def current_io
@ios[@index]
end
def advance_io
@index += 1
end
end
UploadIO = ::UploadIO
Parts = ::Parts
end
|