Class: Tus::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/tus/input.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, limit: nil) ⇒ Input

Returns a new instance of Input.



6
7
8
9
10
# File 'lib/tus/input.rb', line 6

def initialize(input, limit: nil)
  @input = input
  @limit = limit
  @pos   = 0
end

Instance Method Details

#closeObject



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

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

#posObject



25
26
27
# File 'lib/tus/input.rb', line 25

def pos
  @pos
end

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



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tus/input.rb', line 12

def read(length = nil, outbuf = nil)
  data = @input.read(length, outbuf)

  @pos += data.bytesize if data
  raise MaxSizeExceeded if @limit && @pos > @limit

  data
rescue => exception
  raise unless exception.class.name == "Unicorn::ClientShutdown"
  outbuf = outbuf.to_s.clear
  outbuf unless length
end

#rewindObject



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

def rewind
  @input.rewind
  @pos = 0
end