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.



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

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

Instance Method Details

#close(error = nil) ⇒ Object



40
41
42
43
44
45
# File 'lib/protocol/rack/body/input_wrapper.rb', line 40

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



53
54
55
# File 'lib/protocol/rack/body/input_wrapper.rb', line 53

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