Class: Async::HTTP::Faraday::BodyReadWrapper

Inherits:
Protocol::HTTP::Body::Readable
  • Object
show all
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

Instance Method Summary collapse

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

#lengthObject (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

#readObject

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