Class: Tus::Input

Inherits:
Object
  • Object
show all
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

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

#closeObject



38
39
40
# File 'lib/tus/input.rb', line 38

def close
  # Rack input shouldn't be closed, we just support the interface
end

#posObject



29
30
31
# File 'lib/tus/input.rb', line 29

def pos
  @pos
end

#read(length = nil, outbuf = nil) ⇒ Object

Raises:



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

#rewindObject



33
34
35
36
# File 'lib/tus/input.rb', line 33

def rewind
  @input.rewind
  @pos = 0
end