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

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

Overview

Wraps a Rack input object into a readable body. This class provides a consistent interface for reading from Rack input streams, which may be any IO-like object that responds to ‘read` and `close`.

Constant Summary collapse

BLOCK_SIZE =

The default block size for reading from the input stream.

1024*4

Instance Method Summary collapse

Constructor Details

#initialize(io, block_size: BLOCK_SIZE) ⇒ InputWrapper

Initialize the input wrapper.



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

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

Instance Method Details

#close(error = nil) ⇒ Object

Close the input stream. If the input object responds to ‘close`, it will be called.



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

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

#readObject

Read the next chunk from the input stream. Returns nil when there is no more data to read.



45
46
47
# File 'lib/protocol/rack/body/input_wrapper.rb', line 45

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