class Google::Apis::Core::CompositeIO
Public Class Methods
Source
# File lib/google/apis/core/composite_io.rb, line 37 def initialize(*ios) @ios = ios.flatten @pos = 0 @index = 0 @sizes = @ios.map(&:size) end
Public Instance Methods
Source
# File lib/google/apis/core/composite_io.rb, line 73 def pos=(pos) fail ArgumentError, "Position can not be negative" if pos < 0 @pos = pos new_index = nil @ios.each_with_index do |io,idx| size = io.size if pos <= size new_index ||= idx io.pos = pos pos = 0 else io.pos = size pos -= size end end @index = new_index unless new_index.nil? end
Source
# File lib/google/apis/core/composite_io.rb, line 44 def read(length = nil, buf = nil) buf = buf ? buf.replace('') : '' begin io = @ios[@index] break if io.nil? result = io.read(length) if result buf << result if length length -= result.length break if length == 0 end end @index += 1 end while @index < @ios.length buf.length > 0 ? buf : nil end