Class: Stark::Rack::Metadata::RewindableInput
- Inherits:
-
Object
- Object
- Stark::Rack::Metadata::RewindableInput
- Defined in:
- lib/stark/rack/metadata.rb
Instance Method Summary collapse
-
#initialize(io) ⇒ RewindableInput
constructor
A new instance of RewindableInput.
- #read(n) ⇒ Object
- #rewind ⇒ Object
Constructor Details
#initialize(io) ⇒ RewindableInput
Returns a new instance of RewindableInput.
59 60 61 62 |
# File 'lib/stark/rack/metadata.rb', line 59 def initialize(io) @io = io @buffered = StringIO.new end |
Instance Method Details
#read(n) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/stark/rack/metadata.rb', line 64 def read(n) if @io @io.read(n).tap do |s| if s @buffered.write s else @io.close @io = nil end end else @buffered.read(n) end end |
#rewind ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/stark/rack/metadata.rb', line 79 def rewind if @io @io = CompositeReadIO.new([StringIO.new(@buffered.string), @io]) @buffered = StringIO.new else @buffered.rewind end end |