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

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

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Encoder

Returns a new instance of Encoder.



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(body)
end

Instance Method Details

#bytesizeObject



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_typeObject



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

def content_type
  "application/octet-stream"
end