# File lib/aws/s3/data_options.rb, line 21
      def data_stream_from options, &block

        validate_data!(options, block)

        # block format
        if block_given?
          buffer = StringIO.new
          yield(buffer)
          buffer.rewind
          return buffer
        end

        # string, pathname, file, io-like object, etc
        data = options[:data]
        file_opts = ["rb"]
        file_opts << { :encoding => "BINARY" } if Object.const_defined?(:Encoding)
        case
        when data.is_a?(String)
          data.force_encoding("BINARY") if data.respond_to?(:force_encoding)
          StringIO.new(data)
        when data.is_a?(Pathname) then File.open(data.to_s, *file_opts)
        when options[:file]       then File.open(options[:file], *file_opts)
        else data
        end

      end