class FPM::Fry::JoinedIO
Joins together multiple IOs
Public Class Methods
new(*ios)
click to toggle source
@param [IO] ios
# File lib/fpm/fry/joined_io.rb, line 7 def initialize(*ios) @ios = ios @pos = 0 @readbytes = 0 end
Public Instance Methods
close()
click to toggle source
Closes all IOs.
# File lib/fpm/fry/joined_io.rb, line 74 def close @ios.each(&:close) end
eof?()
click to toggle source
@return [true,false]
# File lib/fpm/fry/joined_io.rb, line 69 def eof? @pos == @ios.size end
pos()
click to toggle source
@return [Numeric] number bytes read
# File lib/fpm/fry/joined_io.rb, line 64 def pos @readbytes end
read( len = nil )
click to toggle source
Reads length bytes or all if length is nil. @param [Numeric, nil] len @return [String] resulting bytes
# File lib/fpm/fry/joined_io.rb, line 16 def read( len = nil ) buf = [] if len.nil? while chunk = readpartial(512) buf << chunk @readbytes += chunk.bytesize end return buf.join else con = 0 while con < len chunk = readpartial(len - con) if chunk.nil? if con == 0 return nil else return buf.join end end @readbytes += chunk.bytesize con += chunk.bytesize buf << chunk end return buf.join end end
readpartial( length )
click to toggle source
Reads up to length bytes. @param [Numeric] length @return [String] chunk @return [nil] at eof
# File lib/fpm/fry/joined_io.rb, line 47 def readpartial( length ) while (io = @ios[@pos]) r = io.read( length ) if r.nil? @pos = @pos + 1 next else if io.eof? @pos = @pos + 1 end return r end end return nil end