class Rack::RewindableInput
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.
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.
Public Class Methods
Source
# File lib/rack/rewindable_input.rb, line 28 def initialize(io) @io = io @rewindable_io = nil @unlinked = false end
Public Instance Methods
Source
# File lib/rack/rewindable_input.rb, line 64 def close if @rewindable_io if @unlinked @rewindable_io.close else @rewindable_io.close! end @rewindable_io = nil end end
Closes this RewindableInput
object without closing the originally wrapped IO object. Cleans up any temporary resources that this RewindableInput
has created.
This method may be called multiple times. It does nothing on subsequent calls.
Source
# File lib/rack/rewindable_input.rb, line 44 def each(&block) make_rewindable unless @rewindable_io @rewindable_io.each(&block) end
Source
# File lib/rack/rewindable_input.rb, line 34 def gets make_rewindable unless @rewindable_io @rewindable_io.gets end
Source
# File lib/rack/rewindable_input.rb, line 39 def read(*args) make_rewindable unless @rewindable_io @rewindable_io.read(*args) end
Source
# File lib/rack/rewindable_input.rb, line 49 def rewind make_rewindable unless @rewindable_io @rewindable_io.rewind end
Source
# File lib/rack/rewindable_input.rb, line 54 def size make_rewindable unless @rewindable_io @rewindable_io.size end