Class: Omnizip::Algorithms::Zstandard::FSE::ForwardBitStream

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/algorithms/zstandard/fse/bitstream.rb

Overview

Forward bitstream reader (for Huffman decoding)

Reads bits in normal forward order from a starting position.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, start_byte = 0) ⇒ ForwardBitStream

Initialize bitstream with data

Parameters:

  • data (String)

    The compressed bitstream data

  • start_byte (Integer) (defaults to: 0)

    Starting byte position



129
130
131
132
# File 'lib/omnizip/algorithms/zstandard/fse/bitstream.rb', line 129

def initialize(data, start_byte = 0)
  @data = data.dup.force_encoding(Encoding::BINARY)
  @bit_position = start_byte * 8
end

Instance Attribute Details

#bit_positionInteger (readonly)

Returns Current bit position.

Returns:

  • (Integer)

    Current bit position



123
124
125
# File 'lib/omnizip/algorithms/zstandard/fse/bitstream.rb', line 123

def bit_position
  @bit_position
end

#dataString (readonly)

Returns The compressed data.

Returns:

  • (String)

    The compressed data



120
121
122
# File 'lib/omnizip/algorithms/zstandard/fse/bitstream.rb', line 120

def data
  @data
end

Instance Method Details

#byte_positionInteger

Get current byte position

Returns:

  • (Integer)


160
161
162
# File 'lib/omnizip/algorithms/zstandard/fse/bitstream.rb', line 160

def byte_position
  @bit_position / 8
end

#exhausted?Boolean

Check if bitstream is exhausted

Returns:

  • (Boolean)


153
154
155
# File 'lib/omnizip/algorithms/zstandard/fse/bitstream.rb', line 153

def exhausted?
  @bit_position >= @data.bytesize * 8
end

#read_bits(count) ⇒ Integer

Read bits from the stream (in forward order)

Bits are read from MSB to LSB within each byte.

Parameters:

  • count (Integer)

    Number of bits to read

Returns:

  • (Integer)

    The read bits



140
141
142
143
144
145
146
147
148
# File 'lib/omnizip/algorithms/zstandard/fse/bitstream.rb', line 140

def read_bits(count)
  return 0 if count.zero?

  result = 0
  count.times do
    result = (result << 1) | read_single_bit
  end
  result
end