class Google::Apis::Core::CompositeIO
Public Class Methods
new(*ios)
click to toggle 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
pos()
click to toggle source
# File lib/google/apis/core/composite_io.rb, line 69 def pos @pos end
pos=(pos)
click to toggle 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
read(length = nil, buf = nil)
click to toggle 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
rewind()
click to toggle source
# File lib/google/apis/core/composite_io.rb, line 91 def rewind self.pos = 0 end
size()
click to toggle source
# File lib/google/apis/core/composite_io.rb, line 63 def size @sizes.reduce(:+) end
Also aliased as: length