Class: Protocol::Rack::Body::InputWrapper

Inherits:
HTTP::Body::Readable
  • Object
show all
Defined in:
lib/protocol/rack/body/input_wrapper.rb

Overview

Used for wrapping a generic ‘rack.input` object into a readable body.

Constant Summary collapse

BLOCK_SIZE =
1024*4

Instance Method Summary collapse

Constructor Details

#initialize(io, block_size: BLOCK_SIZE) ⇒ InputWrapper

Returns a new instance of InputWrapper.



16
17
18
19
20
21
# File 'lib/protocol/rack/body/input_wrapper.rb', line 16

def initialize(io, block_size: BLOCK_SIZE)
	@io = io
	@block_size = block_size
	
	super()
end

Instance Method Details

#close(error = nil) ⇒ Object



23
24
25
26
27
28
# File 'lib/protocol/rack/body/input_wrapper.rb', line 23

def close(error = nil)
	if @io
		@io.close
		@io = nil
	end
end

#readObject

def join @io.read.tap do |buffer| buffer.force_encoding(Encoding::BINARY) end end



36
37
38
# File 'lib/protocol/rack/body/input_wrapper.rb', line 36

def read
	@io&.read(@block_size)
end