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.
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 45 45: def close 46: if @rewindable_io 47: if @unlinked 48: @rewindable_io.close 49: else 50: @rewindable_io.close! 51: end 52: @rewindable_io = nil 53: end 54: end
(Not documented)
# File lib/rack/rewindable_input.rb, line 30 30: def each(&block) 31: make_rewindable unless @rewindable_io 32: @rewindable_io.each(&block) 33: end
(Not documented)
# File lib/rack/rewindable_input.rb, line 20 20: def gets 21: make_rewindable unless @rewindable_io 22: @rewindable_io.gets 23: end
(Not documented)
# File lib/rack/rewindable_input.rb, line 94 94: def filesystem_has_posix_semantics? 95: RUBY_PLATFORM !~ /(mswin|mingw|cygwin|java)/ 96: end
(Not documented)
# File lib/rack/rewindable_input.rb, line 67 67: def make_rewindable 68: # Buffer all data into a tempfile. Since this tempfile is private to this 69: # RewindableInput object, we chmod it so that nobody else can read or write 70: # it. On POSIX filesystems we also unlink the file so that it doesn't 71: # even have a file entry on the filesystem anymore, though we can still 72: # access it because we have the file handle open. 73: @rewindable_io = Tempfile.new('RackRewindableInput') 74: @rewindable_io.chmod(0000) 75: if filesystem_has_posix_semantics? 76: @rewindable_io.unlink 77: @unlinked = true 78: end 79: 80: buffer = "" 81: while @io.read(1024 * 4, buffer) 82: entire_buffer_written_out = false 83: while !entire_buffer_written_out 84: written = @rewindable_io.write(buffer) 85: entire_buffer_written_out = written == buffer.size 86: if !entire_buffer_written_out 87: buffer.slice!(0 .. written - 1) 88: end 89: end 90: end 91: @rewindable_io.rewind 92: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.