Class PhusionPassenger::Utils::RewindableInput |
In: | lib/phusion_passenger/utils/rewindable_input.rb
Parent: | Object

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

- close
- each
- gets
- new
- read
- rewind
- size

Classes and Modules
Class PhusionPassenger::Utils::RewindableInput::Tempfile
Public Class methods
new(io)

[ show source ]

        # File lib/phusion_passenger/utils/rewindable_input.rb, line 18
    18:     def initialize(io)
    19:       @io = io
    20:       @rewindable_io = nil
    21:       @unlinked = false
    22:     end

Public Instance 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.

[ show source ]

        # File lib/phusion_passenger/utils/rewindable_input.rb, line 54
    54:     def close
    55:       if @rewindable_io
    56:         if @unlinked
    57:           @rewindable_io.close
    58:         else
    59:           @rewindable_io.close!
    60:         end
    61:         @rewindable_io = nil
    62:       end
    63:     end

each(&block)

[ show source ]

        # File lib/phusion_passenger/utils/rewindable_input.rb, line 34
    34:     def each(&block)
    35:       make_rewindable unless @rewindable_io
    36:       @rewindable_io.each(&block)
    37:     end

gets()

[ show source ]

        # File lib/phusion_passenger/utils/rewindable_input.rb, line 24
    24:     def gets
    25:       make_rewindable unless @rewindable_io
    26:       @rewindable_io.gets
    27:     end

read(*args)

[ show source ]

        # File lib/phusion_passenger/utils/rewindable_input.rb, line 29
    29:     def read(*args)
    30:       make_rewindable unless @rewindable_io
    31:       @rewindable_io.read(*args)
    32:     end

rewind()

[ show source ]

        # File lib/phusion_passenger/utils/rewindable_input.rb, line 39
    39:     def rewind
    40:       make_rewindable unless @rewindable_io
    41:       @rewindable_io.rewind
    42:     end

size()

[ show source ]

        # File lib/phusion_passenger/utils/rewindable_input.rb, line 44
    44:     def size
    45:       make_rewindable unless @rewindable_io
    46:       @rewindable_io.size
    47:     end