class BitGirder::Event::File::EventFileReader

Public Instance Methods

each() { |ev| ... } click to toggle source
# File lib/bitgirder/event/file.rb, line 478
def each
    each_with_loc { |ev, loc| yield( ev ) }
end
each_with_loc() { |ev, loc| ... } click to toggle source
# File lib/bitgirder/event/file.rb, line 469
def each_with_loc
 
    until @io.eof?
        ev, loc = *( read_event )
        yield( ev, loc ) if loc
    end
end
read_event() click to toggle source

Returns the next [ ev, loc ] pair if there is one, EOFException if incomplete, and nil if this is the first read of a file which contains only a valid header.

# File lib/bitgirder/event/file.rb, line 453
def read_event
 
    read_file_header unless @read_file_header
    return nil if @io.eof?

    loc = @bin.pos

    len = @bin.read_int32
    buf = @bin.read_full( len )
    
    ev = @codec.decode_event( StringIO.new( buf, "r" ), len )

    [ ev, loc ]
end

Private Instance Methods

impl_initialize() click to toggle source
Calls superclass method
# File lib/bitgirder/event/file.rb, line 417
def impl_initialize
    
    super

    @bin = Io::BinaryReader.new( 
        :io => @io, 
        :order => Io::ORDER_LITTLE_ENDIAN 
    )

    @read_file_header = false
end
read_file_header() click to toggle source
# File lib/bitgirder/event/file.rb, line 430
def read_file_header
    
    begin
        unless ( magic = @bin.read_full( 8 ) ) == FILE_MAGIC
            raise FileMagicError, 
                  "Unrecognized file magic: #{magic.inspect}" 
        end
    rescue EOFError
        raise FileMagicError, "Missing or incomplete file magic"
    end

    unless ( ver_str = @bin.read_utf8 ) == FILE_VERSION
        raise FileVersionError, 
              "Unrecognized file version: #{ver_str.inspect}"
    end

    @read_file_header = true
end