Class: Zapp::InputStream
- Inherits:
-
Object
- Object
- Zapp::InputStream
- Defined in:
- lib/zapp/input_stream.rb
Overview
Represents an input stream with the HTTP data passed to rack.input Read the Input Stream part of the Rack Specification here github.com/rack/rack/blob/master/SPEC.rdoc#label-The+Input+Stream
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #gets ⇒ Object
-
#initialize(string:) ⇒ InputStream
constructor
A new instance of InputStream.
- #read(length = nil, buffer = nil) ⇒ Object
- #rewind ⇒ Object
Constructor Details
#initialize(string:) ⇒ InputStream
Returns a new instance of InputStream.
7 8 9 10 |
# File 'lib/zapp/input_stream.rb', line 7 def initialize(string:) @string = string @next_index_to_read = 0 end |
Instance Method Details
#each(&block) ⇒ Object
27 28 29 |
# File 'lib/zapp/input_stream.rb', line 27 def each(&block) [read].each(&block) end |
#gets ⇒ Object
31 32 33 34 35 |
# File 'lib/zapp/input_stream.rb', line 31 def gets return unless @next_index_to_read < @string.length read end |
#read(length = nil, buffer = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/zapp/input_stream.rb', line 12 def read(length = nil, buffer = nil) returning = if length.nil? raw_read else string = raw_read(end_index: @next_index_to_read + length) string == "" ? nil : string end if buffer.nil? returning else buffer << returning end end |
#rewind ⇒ Object
37 38 39 |
# File 'lib/zapp/input_stream.rb', line 37 def rewind @next_index_to_read = 0 end |