Class: UploadProgress

Inherits:
Object
  • Object
show all
Defined in:
lib/vpsmatrix/upload_progress.rb

Overview

the code is used from gem ‘net-http-uploadprogress’

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(req, &block) ⇒ UploadProgress

Returns a new instance of UploadProgress.



6
7
8
9
10
11
12
# File 'lib/vpsmatrix/upload_progress.rb', line 6

def initialize(req, &block)
  @req = req
  @callback = block
  @upload_size = 0
  @io = req.body_stream
  req.body_stream = self
end

Instance Attribute Details

#upload_sizeObject (readonly)

Returns the value of attribute upload_size.



4
5
6
# File 'lib/vpsmatrix/upload_progress.rb', line 4

def upload_size
  @upload_size
end

Instance Method Details

#readpartial(maxlen, outbuf) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/vpsmatrix/upload_progress.rb', line 14

def readpartial(maxlen, outbuf)
  begin
    str = @io.readpartial(maxlen, outbuf)
  ensure
    @callback.call(self) unless @upload_size.zero?
  end
  @upload_size += str.length
  str
end