Class: HTTPX::Transcoder::Body::Encoder

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/httpx/transcoder/body.rb,
sig/transcoder/body.rbs

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Encoder

Returns a new instance of Encoder.

Parameters:

  • body (Object)


12
13
14
15
16
# File 'lib/httpx/transcoder/body.rb', line 12

def initialize(body)
  body = body.open(File::RDONLY, encoding: Encoding::BINARY) if Object.const_defined?(:Pathname) && body.is_a?(Pathname)
  @body = body
  super
end

Instance Method Details

#bytesizeInteger, Float

Returns:

  • (Integer, Float)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/httpx/transcoder/body.rb', line 18

def bytesize
  if @body.respond_to?(:bytesize)
    @body.bytesize
  elsif @body.respond_to?(:to_ary)
    @body.sum(&:bytesize)
  elsif @body.respond_to?(:size)
    @body.size || Float::INFINITY
  elsif @body.respond_to?(:length)
    @body.length || Float::INFINITY
  elsif @body.respond_to?(:each)
    Float::INFINITY
  else
    raise Error, "cannot determine size of body: #{@body.inspect}"
  end
end

#content_typeString

Returns:

  • (String)


34
35
36
# File 'lib/httpx/transcoder/body.rb', line 34

def content_type
  "application/octet-stream"
end

#to_sString

Returns:

  • (String)


14
# File 'sig/transcoder/body.rbs', line 14

def to_s: () -> String