lib/steam/byte_reader.rb in steamrb-0.1.0 vs lib/steam/byte_reader.rb in steamrb-0.1.1

- old
+ new

@@ -4,74 +4,38 @@ module Steam # Reads bytes from a given IO object. class ByteReader extend Forwardable - attr_reader :io - # Create a ByteReader object # # @param io [:read] an io object def initialize(io) @io = io end - # Reads an unsigned 64 bit integer from the stream - # - # @return [Integer] The 64 bit integer - def read_int64 - io.read(8).unpack('C*').each_with_index.reduce(0) do |sum, (byte, index)| - sum + byte * (256**index) - end - end - alias int64 read_int64 - - # Reads an unsigned short from the stream - # - # @return [Integer] The short - def read_short - io.read(2).unpack('S*').first - end - alias short read_short - # Reads a string of a given length from the stream # + # @param len [Integer] the number of bytes to read # @return [String] The read string def string(len) - io.read(len) + read(len) end - # Reads a single bytes from the stream - # - # @return [Integer] The byte - def byte - io.read(1).ord - end - # Reads an unsigned 32 bit integer from the stream # # @return [Integer] The 32 bit integer def unsigned_int32 - io.read(4).unpack('<I*').first + @io.read(4).unpack('<I*').first end # Reads an signed 32 bit integer from the stream # # @return [Integer] The 32 bit integer def signed_int32 - io.read(4).unpack('<i*').first + @io.read(4).unpack('<i*').first end - # Reads an signed 16 bit integer from the stream - # - # @return [Integer] The 16 bit integer - def signed_int16 - io.read(2).unpack('<s*').first - end - def_delegator :@io, :read, :read - def_delegator :@io, :readbyte, :readbyte def_delegator :@io, :eof?, :eof? - def_delegator :@io, :tell, :tell - def_delegator :@io, :lineno, :lineno end end