Class: BitGirder::Io::BinaryReader

Inherits:
BinaryIo
  • Object
show all
Defined in:
lib/bitgirder/io.rb

Instance Attribute Summary

Attributes inherited from BinaryIo

#conv, #pos

Instance Method Summary collapse

Methods inherited from BinaryIo

#close

Instance Method Details

#eof?Boolean

Returns:

  • (Boolean)


838
839
840
# File 'lib/bitgirder/io.rb', line 838

def eof?
    @io.eof?
end

#peek_int8Object



855
856
857
# File 'lib/bitgirder/io.rb', line 855

def peek_int8
    peekc.unpack( 'c' )[ 0 ]
end

#peekcObject



843
844
845
846
847
848
849
850
851
852
# File 'lib/bitgirder/io.rb', line 843

def peekc
    
    res = @io.getc.tap { |c| @io.ungetc( c ) }

    case res
    when String then res
    when Fixnum then res.chr
    else raise "Unexpected getc val: #{res.class}"
    end
end

#read(*argv) ⇒ Object



865
866
867
# File 'lib/bitgirder/io.rb', line 865

def read( *argv )
    @io.read( *argv ).tap { |res| @pos += res.bytesize }
end

#read_boolObject Also known as: read_boolean



885
886
887
# File 'lib/bitgirder/io.rb', line 885

def read_bool
    read_int8 != 0
end

#read_buffer32Object



892
893
894
# File 'lib/bitgirder/io.rb', line 892

def read_buffer32
    read_full( read_int32 )
end

#read_full(len, buf = nil) ⇒ Object



860
861
862
# File 'lib/bitgirder/io.rb', line 860

def read_full( len, buf = nil )
    Io.read_full( @io, len, buf ).tap { @pos += len }
end

#read_utf8Object



897
898
899
900
901
902
903
904
905
906
# File 'lib/bitgirder/io.rb', line 897

def read_utf8
 
    len = read_int32

    str = "" * len
    read_full( len, str )
    RubyVersions.when_19x { str.force_encoding( "utf-8" ) }

    str
end