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.

Methods
C
E
G
N
R
Class Public methods
new(io)
# File lib/rack/rewindable_input.rb, line 15
def initialize(io)
  @io = io
  @rewindable_io = nil
  @unlinked = false
end
Instance Public methods
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.

# File lib/rack/rewindable_input.rb, line 46
def close
  if @rewindable_io
    if @unlinked
      @rewindable_io.close
    else
      @rewindable_io.close!
    end
    @rewindable_io = nil
  end
end
each(&block)
# File lib/rack/rewindable_input.rb, line 31
def each(&block)
  make_rewindable unless @rewindable_io
  @rewindable_io.each(&block)
end
gets()
# File lib/rack/rewindable_input.rb, line 21
def gets
  make_rewindable unless @rewindable_io
  @rewindable_io.gets
end
read(*args)
# File lib/rack/rewindable_input.rb, line 26
def read(*args)
  make_rewindable unless @rewindable_io
  @rewindable_io.read(*args)
end
rewind()
# File lib/rack/rewindable_input.rb, line 36
def rewind
  make_rewindable unless @rewindable_io
  @rewindable_io.rewind
end