class Tus::Input
Wrapper around the Rack input, which adds the ability to limit the amount of bytes that will be read from the Rack input. If there are more bytes in the Rack input than the specified limit, a Tus::MaxSizeExceeded exception is raised.
Public Class Methods
new(input, limit: nil)
click to toggle source
# File lib/tus/input.rb, line 14 def initialize(input, limit: nil) @input = input @limit = limit @pos = 0 end
Public Instance Methods
close()
click to toggle source
# File lib/tus/input.rb, line 44 def close # Rack input shouldn't be closed, we just support the interface end
pos()
click to toggle source
# File lib/tus/input.rb, line 29 def pos @pos end
read(length = nil, outbuf = nil)
click to toggle source
# File lib/tus/input.rb, line 20 def read(length = nil, outbuf = nil) data = @input.read(*length, *outbuf) @pos += data.bytesize if data raise MaxSizeExceeded if @limit && @pos > @limit data end
rewind()
click to toggle source
# File lib/tus/input.rb, line 33 def rewind @input.rewind @pos = 0 end
rewindable?()
click to toggle source
# File lib/tus/input.rb, line 38 def rewindable? @input.is_a?(Tempfile) || # Puma, Thin @input.is_a?(StringIO) || # WEBRick, Puma, Thin @input.class.name.end_with?("TeeInput") # Unicorn, Passenger end