Class: Overlook::BitBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/overlook/bit_buffer.rb

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ BitBuffer

Returns a new instance of BitBuffer.



3
4
5
6
7
# File 'lib/overlook/bit_buffer.rb', line 3

def initialize(io)
  @io        = io
  @buffer    = 0
  @available = 0
end

Instance Method Details

#bits(numbits) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/overlook/bit_buffer.rb', line 13

def bits(numbits)
  if numbits == 8 && @available == 0
    byte = refresh_buffer
    @available = 0
    return byte
  end

  numbits.times.reduce(0) do |result, index|
    refresh_buffer unless available_bits?
    result |= getbit << index
  end
end

#bytes(num) ⇒ Object



9
10
11
# File 'lib/overlook/bit_buffer.rb', line 9

def bytes(num)
  @io.read(num)
end

#eof?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/overlook/bit_buffer.rb', line 26

def eof?
  @io.eof?
end

#skip(n) ⇒ Object



30
31
32
# File 'lib/overlook/bit_buffer.rb', line 30

def skip(n)
  @io.seek(n, IO::SEEK_CUR)
end