Async::HTTP::FaradaySourceAsyncHTTPFaradayBodyReadWrapper

class BodyReadWrapper

This is a simple wrapper around Faraday's body that allows it to be read in chunks.

Definitions

def initialize(body, block_size: 4096)

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.

Signature

parameter body Interface(:read)

The input body to wrap.

parameter block_size Integer

The size of the blocks to read from the body.

Implementation

def initialize(body, block_size: 4096)
	@body = body
	@block_size = block_size
end

def close(error = nil)

Close the body if possible.

Implementation

def close(error = nil)
	@body.close if @body.respond_to?(:close)
ensure
	super
end

def read

Read from the body in chunks.

Implementation

def read
	@body.read(@block_size)
end