class Overlook::ByteReader
Reads bytes from a given IO object.
Attributes
io[R]
Public Class Methods
new(io)
click to toggle source
# File lib/overlook/byte_reader.rb, line 10 def initialize(io) @io = io end
Public Instance Methods
byte()
click to toggle source
# File lib/overlook/byte_reader.rb, line 38 def byte io.read(1).ord end
char()
click to toggle source
# File lib/overlook/byte_reader.rb, line 42 def char byte.chr end
float()
click to toggle source
# File lib/overlook/byte_reader.rb, line 34 def float @io.read(4).unpack('<e').first end
read_int64()
click to toggle source
# File lib/overlook/byte_reader.rb, line 14 def read_int64 io.read(8).unpack("C*").each_with_index.reduce(0) do |sum, (byte, index)| sum + byte * (256 ** index) end end
Also aliased as: int64
read_short()
click to toggle source
# File lib/overlook/byte_reader.rb, line 21 def read_short io.read(2).unpack('S*').first end
Also aliased as: short
seek(len, type = IO::SEEK_CUR)
click to toggle source
# File lib/overlook/byte_reader.rb, line 30 def seek(len, type = IO::SEEK_CUR) io.seek(len, type) end
signed_int16()
click to toggle source
# File lib/overlook/byte_reader.rb, line 50 def signed_int16 io.read(2).unpack('<s*').first end
signed_int32()
click to toggle source
# File lib/overlook/byte_reader.rb, line 46 def signed_int32 io.read(4).unpack('<l*').first end
string(len)
click to toggle source
# File lib/overlook/byte_reader.rb, line 26 def string(len) io.read(len) end