\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /proc/self/root/opt/chef/embedded/lib/ruby/gems/2.7.0/gems/faraday-1.0.1/lib/faraday/

Viewing File: file_part.rb

# frozen_string_literal: true

require 'stringio'

# multipart-post gem
require 'composite_io'
require 'parts'

module Faraday
  # Multipart value used to POST a binary data from a file or
  #
  # @example
  #   payload = { file: Faraday::FilePart.new("file_name.ext", "content/type") }
  #   http.post("/upload", payload)
  #

  # @!method initialize(filename_or_io, content_type, filename = nil, opts = {})
  #
  #   @param filename_or_io [String, IO] Either a String filename to a local
  #     file or an open IO object.
  #   @param content_type [String] String content type of the file data.
  #   @param filename [String] Optional String filename, usually to add context
  #     to a given IO object.
  #   @param opts [Hash] Optional Hash of String key/value pairs to describethis
  #     this uploaded file. Expected Header keys include:
  #     * Content-Transfer-Encoding - Defaults to "binary"
  #     * Content-Disposition - Defaults to "form-data"
  #     * Content-Type - Defaults to the content_type argument.
  #     * Content-ID - Optional.
  #
  # @return [Faraday::FilePart]
  #
  # @!attribute [r] content_type
  # The uploaded binary data's content type.
  #
  # @return [String]
  #
  # @!attribute [r] original_filename
  # The base filename, taken either from the filename_or_io or filename
  # arguments in #initialize.
  #
  # @return [String]
  #
  # @!attribute [r] opts
  # Extra String key/value pairs to make up the header for this uploaded file.
  #
  # @return [Hash]
  #
  # @!attribute [r] io
  # The open IO object for the uploaded file.
  #
  # @return [IO]
  FilePart = ::UploadIO

  # Multipart value used to POST a file.
  #
  # @deprecated Use FilePart instead of this class. It behaves identically, with
  #   a matching name to ParamPart.
  UploadIO = ::UploadIO

  Parts = ::Parts

  # Similar to, but not compatible with CompositeReadIO provided by the
  # multipart-post gem.
  # https://github.com/nicksieger/multipart-post/blob/master/lib/composite_io.rb
  class CompositeReadIO
    def initialize(*parts)
      @parts = parts.flatten
      @ios = @parts.map(&:to_io)
      @index = 0
    end

    # @return [Integer] sum of the lengths of all the parts
    def length
      @parts.inject(0) { |sum, part| sum + part.length }
    end

    # Rewind each of the IOs and reset the index to 0.
    #
    # @return [void]
    def rewind
      @ios.each(&:rewind)
      @index = 0
    end

    # Read from IOs in order until `length` bytes have been received.
    #
    # @param length [Integer, nil]
    # @param outbuf [String, nil]
    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&.zero?
        end
        advance_io
      end
      !got_result && length ? nil : outbuf
    end

    # Close each of the IOs.
    #
    # @return [void]
    def close
      @ios.each(&:close)
    end

    def ensure_open_and_readable
      # Rubinius compatibility
    end

    private

    def current_io
      @ios[@index]
    end

    def advance_io
      @index += 1
    end
  end
end