Class: Factorix::Transfer::Uploader::ProgressIO
- Inherits:
-
Object
- Object
- Factorix::Transfer::Uploader::ProgressIO
- Defined in:
- lib/factorix/transfer/uploader.rb
Overview
Wrapper IO that tracks read progress
Instance Method Summary collapse
-
#close ⇒ void
Close underlying IO.
-
#eof? ⇒ Boolean
Check if at end of stream.
-
#initialize(io, total_size) {|Integer| ... } ⇒ ProgressIO
constructor
A new instance of ProgressIO.
-
#read(length = nil, outbuf = nil) ⇒ String?
Read data from underlying IO and track progress.
-
#rewind ⇒ void
Rewind underlying IO.
-
#size ⇒ Integer
Get current size.
Constructor Details
#initialize(io, total_size) {|Integer| ... } ⇒ ProgressIO
Returns a new instance of ProgressIO.
138 139 140 141 142 143 |
# File 'lib/factorix/transfer/uploader.rb', line 138 def initialize(io, total_size, &block) @io = io @total_size = total_size @current = 0 @callback = block end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Close underlying IO
167 |
# File 'lib/factorix/transfer/uploader.rb', line 167 def close = @io.close |
#eof? ⇒ Boolean
Check if at end of stream
162 |
# File 'lib/factorix/transfer/uploader.rb', line 162 def eof? = @io.eof? |
#read(length = nil, outbuf = nil) ⇒ String?
Read data from underlying IO and track progress
150 151 152 153 154 155 156 157 |
# File 'lib/factorix/transfer/uploader.rb', line 150 def read(length=nil, outbuf=nil) data = @io.read(length, outbuf) if data @current += data.bytesize @callback&.call(@current) end data end |
#rewind ⇒ void
This method returns an undefined value.
Rewind underlying IO
172 173 174 175 |
# File 'lib/factorix/transfer/uploader.rb', line 172 def rewind @io.rewind @current = 0 end |
#size ⇒ Integer
Get current size
180 |
# File 'lib/factorix/transfer/uploader.rb', line 180 def size = @total_size |