Sha256: cd32bf956d4be16f95bdf4ea4112dc6ea852df1b27dabf5e1f7fb85f37d1a699

Contents?: true

Size: 1.38 KB

Versions: 99

Compression:

Stored size: 1.38 KB

Contents

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

Version data entries

99 entries across 91 versions & 11 rubygems

Version Path
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/upload_io.rb
logstash-output-scalyr-0.1.9 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/upload_io.rb
logstash-output-scalyr-0.1.8 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/upload_io.rb
logstash-output-scalyr-0.1.7 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/upload_io.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/faraday-0.17.3/lib/faraday/upload_io.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/faraday-0.17.4/lib/faraday/upload_io.rb
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/upload_io.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/faraday-0.17.3/lib/faraday/upload_io.rb
faraday-0.17.4 lib/faraday/upload_io.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/upload_io.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/upload_io.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/upload_io.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/faraday-0.17.0/lib/faraday/upload_io.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/upload_io.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/faraday-0.17.0/lib/faraday/upload_io.rb
faraday-0.17.3 lib/faraday/upload_io.rb
tdiary-5.1.0 vendor/bundle/gems/faraday-0.17.1/lib/faraday/upload_io.rb
faraday-0.17.1 lib/faraday/upload_io.rb
faraday-0.17.0 lib/faraday/upload_io.rb
tdiary-5.0.13 vendor/bundle/gems/faraday-0.15.4/lib/faraday/upload_io.rb