Class: HTTPX::Transcoder::Body::Encoder
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- HTTPX::Transcoder::Body::Encoder
- Defined in:
- lib/httpx/transcoder/body.rb
Instance Method Summary collapse
- #bytesize ⇒ Object
- #content_type ⇒ Object
-
#initialize(body) ⇒ Encoder
constructor
A new instance of Encoder.
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
#bytesize ⇒ Object
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_type ⇒ Object
34 35 36 |
# File 'lib/httpx/transcoder/body.rb', line 34 def content_type "application/octet-stream" end |