Class: Factorix::Transfer::Uploader::CombinedIO

Inherits:
Object
  • Object
show all
Defined in:
lib/factorix/transfer/uploader.rb

Overview

Combined IO that concatenates multiple IO streams

Instance Method Summary collapse

Constructor Details

#initialize(*ios) ⇒ CombinedIO

Returns a new instance of CombinedIO.

Parameters:

  • ios (Array<IO>)

    IO streams to concatenate



186
187
188
189
# File 'lib/factorix/transfer/uploader.rb', line 186

def initialize(*ios)
  @ios = ios
  @index = 0
end

Instance Method Details

#closevoid

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

Returns:

  • (Boolean)

    true if at EOF



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

Parameters:

  • length (Integer, nil) (defaults to: nil)

    number of bytes to read

  • outbuf (String, nil) (defaults to: nil)

    output buffer

Returns:

  • (String, nil)

    read data or nil at EOF



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

#rewindvoid

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

#sizeInteger

Get total size of all streams

Returns:

  • (Integer)

    total size



228
# File 'lib/factorix/transfer/uploader.rb', line 228

def size = @ios.sum(&:size)