Class: Tus::Input
- Inherits:
-
Object
- Object
- Tus::Input
- Includes:
- Unicorn
- Defined in:
- lib/tus/input.rb,
lib/tus/input/unicorn.rb
Overview
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.
Defined Under Namespace
Modules: Unicorn
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(input, limit: nil) ⇒ Input
constructor
A new instance of Input.
- #pos ⇒ Object
- #read(length = nil, outbuf = nil) ⇒ Object
- #rewind ⇒ Object
- #rewindable? ⇒ Boolean
Constructor Details
#initialize(input, limit: nil) ⇒ Input
Returns a new instance of Input.
14 15 16 17 18 |
# File 'lib/tus/input.rb', line 14 def initialize(input, limit: nil) @input = input @limit = limit @pos = 0 end |
Instance Method Details
#close ⇒ Object
44 45 46 |
# File 'lib/tus/input.rb', line 44 def close # Rack input shouldn't be closed, we just support the interface end |
#pos ⇒ Object
29 30 31 |
# File 'lib/tus/input.rb', line 29 def pos @pos end |
#read(length = nil, outbuf = nil) ⇒ Object
20 21 22 23 24 25 26 27 |
# 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 ⇒ Object
33 34 35 36 |
# File 'lib/tus/input.rb', line 33 def rewind @input.rewind @pos = 0 end |
#rewindable? ⇒ Boolean
38 39 40 41 42 |
# 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 |