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.
39 40 41 42 43 |
# File 'lib/async/http/faraday/adapter.rb', line 39 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.
46 47 48 |
# File 'lib/async/http/faraday/adapter.rb', line 46 def length @length end |
#The total length of the body, or `nil` if the length is unknown.(totallengthofthebody) ⇒ Object (readonly)
46 |
# File 'lib/async/http/faraday/adapter.rb', line 46 attr :length |
Instance Method Details
#close(error = nil) ⇒ Object
Close the body if possible.
49 50 51 52 53 |
# File 'lib/async/http/faraday/adapter.rb', line 49 def close(error = nil) @body.close if @body.respond_to?(:close) ensure super end |
#read ⇒ Object
Read from the body in chunks.
56 57 58 |
# File 'lib/async/http/faraday/adapter.rb', line 56 def read @body.read(@block_size) end |