Class: Factorix::Transfer::Uploader::CombinedIO
- Inherits:
-
Object
- Object
- Factorix::Transfer::Uploader::CombinedIO
- Defined in:
- lib/factorix/transfer/uploader.rb
Overview
Combined IO that concatenates multiple IO streams
Instance Method Summary collapse
-
#close ⇒ void
Close all IO streams.
-
#eof? ⇒ Boolean
Check if all streams are exhausted.
-
#initialize(*ios) ⇒ CombinedIO
constructor
A new instance of CombinedIO.
-
#read(length = nil, outbuf = nil) ⇒ String?
Read from current IO, advancing to next when exhausted.
-
#rewind ⇒ void
Rewind all streams.
-
#size ⇒ Integer
Get total size of all streams.
Constructor Details
#initialize(*ios) ⇒ CombinedIO
Returns a new instance of CombinedIO.
186 187 188 189 |
# File 'lib/factorix/transfer/uploader.rb', line 186 def initialize(*ios) @ios = ios @index = 0 end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Close all IO streams
215 |
# File 'lib/factorix/transfer/uploader.rb', line 215 def close = @ios.each(&:close) |
#eof? ⇒ Boolean
Check if all streams are exhausted
210 |
# File 'lib/factorix/transfer/uploader.rb', line 210 def eof? = @index >= @ios.size |
#read(length = nil, outbuf = nil) ⇒ String?
Read from current IO, advancing to next when exhausted
196 197 198 199 200 201 202 203 204 205 |
# File 'lib/factorix/transfer/uploader.rb', line 196 def read(length=nil, outbuf=nil) return nil if @index >= @ios.size data = @ios[@index].read(length, outbuf) if data.nil? || data.empty? @index += 1 return read(length, outbuf) end data end |
#rewind ⇒ void
This method returns an undefined value.
Rewind all streams
220 221 222 223 |
# File 'lib/factorix/transfer/uploader.rb', line 220 def rewind @ios.each(&:rewind) @index = 0 end |
#size ⇒ Integer
Get total size of all streams
228 |
# File 'lib/factorix/transfer/uploader.rb', line 228 def size = @ios.sum(&:size) |