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.



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

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

#readObject

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