Class: PhusionPassenger::Utils::RewindableInput
- Inherits:
-
Object
- Object
- PhusionPassenger::Utils::RewindableInput
- Defined in:
- lib/phusion_passenger/utils/rewindable_input.rb
Overview
Class which can make any IO object rewindable, including non-rewindable ones. It does this by buffering the data into a tempfile, which is rewindable.
rack.input is required to be rewindable, so if your input stream IO is non-rewindable by nature (e.g. a pipe or a socket) then you can wrap it in an object of this class to easily make it rewindable.
Don't forget to call #close when you're done. This frees up temporary resources that RewindableInput uses, though it does not close the original IO object.
Defined Under Namespace
Classes: Tempfile
Instance Method Summary (collapse)
-
- (Object) close
Closes this RewindableInput object without closing the originally wrapped IO oject.
- - (Object) each(&block)
- - (Object) gets
-
- (RewindableInput) initialize(io)
constructor
A new instance of RewindableInput.
- - (Object) read(*args)
- - (Object) rewind
- - (Object) size
Constructor Details
- (RewindableInput) initialize(io)
A new instance of RewindableInput
18 19 20 21 22 |
# File 'lib/phusion_passenger/utils/rewindable_input.rb', line 18 def initialize(io) @io = io @rewindable_io = nil @unlinked = false end |
Instance Method Details
- (Object) close
Closes this RewindableInput object without closing the originally wrapped IO oject. Cleans up any temporary resources that this RewindableInput has created.
This method may be called multiple times. It does nothing on subsequent calls.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/phusion_passenger/utils/rewindable_input.rb', line 54 def close if @rewindable_io if @unlinked @rewindable_io.close else @rewindable_io.close! end @rewindable_io = nil end end |
- (Object) each(&block)
34 35 36 37 |
# File 'lib/phusion_passenger/utils/rewindable_input.rb', line 34 def each(&block) make_rewindable unless @rewindable_io @rewindable_io.each(&block) end |
- (Object) gets
24 25 26 27 |
# File 'lib/phusion_passenger/utils/rewindable_input.rb', line 24 def gets make_rewindable unless @rewindable_io @rewindable_io.gets end |
- (Object) read(*args)
29 30 31 32 |
# File 'lib/phusion_passenger/utils/rewindable_input.rb', line 29 def read(*args) make_rewindable unless @rewindable_io @rewindable_io.read(*args) end |
- (Object) rewind
39 40 41 42 |
# File 'lib/phusion_passenger/utils/rewindable_input.rb', line 39 def rewind make_rewindable unless @rewindable_io @rewindable_io.rewind end |
- (Object) size
44 45 46 47 |
# File 'lib/phusion_passenger/utils/rewindable_input.rb', line 44 def size make_rewindable unless @rewindable_io @rewindable_io.size end |