Class: Async::HTTP::Faraday::BodyReadWrapper
- Inherits:
-
Protocol::HTTP::Body::Readable
- Object
- Protocol::HTTP::Body::Readable
- Async::HTTP::Faraday::BodyReadWrapper
- Defined in:
- lib/async/http/faraday/adapter.rb
Overview
This is a simple wrapper around Faraday's body that allows it to be read in chunks.
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
- #The total length of the body, or `nil` if the length is unknown.(totallengthofthebody) ⇒ Object readonly
Instance Method Summary collapse
-
#close(error = nil) ⇒ Object
Close the body if possible.
-
#initialize(body, length = nil, block_size: 4096) ⇒ BodyReadWrapper
constructor
Create a new wrapper around the given body.
-
#read ⇒ Object
Read from the body in chunks.
Constructor Details
#initialize(body, length = nil, block_size: 4096) ⇒ BodyReadWrapper
Create a new wrapper around the given body.
The body must respond to #read and #close and is often an instance of IO or Faraday::Multipart::CompositeReadIO.
37 38 39 40 41 |
# File 'lib/async/http/faraday/adapter.rb', line 37 def initialize(body, length = nil, block_size: 4096) @body = body @length = length @block_size = block_size end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
44 45 46 |
# File 'lib/async/http/faraday/adapter.rb', line 44 def length @length end |
#The total length of the body, or `nil` if the length is unknown.(totallengthofthebody) ⇒ Object (readonly)
44 |
# File 'lib/async/http/faraday/adapter.rb', line 44 attr :length |
Instance Method Details
#close(error = nil) ⇒ Object
Close the body if possible.
47 48 49 50 51 |
# File 'lib/async/http/faraday/adapter.rb', line 47 def close(error = nil) @body.close if @body.respond_to?(:close) ensure super end |
#read ⇒ Object
Read from the body in chunks.
54 55 56 |
# File 'lib/async/http/faraday/adapter.rb', line 54 def read @body.read(@block_size) end |