Class: Omnizip::Algorithms::Zstandard::HuffmanTableReader

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/omnizip/algorithms/zstandard/huffman.rb

Overview

Huffman table reader (RFC 8878 Section 4.2.1)

Reads compressed Huffman table description from input.

Constant Summary

Constants included from Constants

Constants::BLOCK_HEADER_SIZE, Constants::BLOCK_MAX_SIZE, Constants::BLOCK_TYPE_COMPRESSED, Constants::BLOCK_TYPE_RAW, Constants::BLOCK_TYPE_RESERVED, Constants::BLOCK_TYPE_RLE, Constants::BUFFER_SIZE, Constants::DEFAULT_LEVEL, Constants::DEFAULT_REPEAT_OFFSETS, Constants::FSE_MAX_ACCURACY_LOG, Constants::FSE_MIN_ACCURACY_LOG, Constants::HUFFMAN_MAX_BITS, Constants::HUFFMAN_MAX_CODE_LENGTH, Constants::HUFFMAN_MAX_LOG, Constants::HUFFMAN_STANDARD_TABLE_SIZE, Constants::LITERALS_BLOCK_COMPRESSED, Constants::LITERALS_BLOCK_RAW, Constants::LITERALS_BLOCK_RLE, Constants::LITERALS_BLOCK_TREELESS, Constants::LITERALS_LENGTH_ACCURACY_LOG, Constants::LITERAL_LENGTH_TABLE, Constants::MAGIC_BYTES, Constants::MAGIC_NUMBER, Constants::MATCH_LENGTH_ACCURACY_LOG, Constants::MATCH_LENGTH_TABLE, Constants::MAX_LEVEL, Constants::MIN_LEVEL, Constants::MODE_FSE, Constants::MODE_PREDEFINED, Constants::MODE_REPEAT, Constants::MODE_RLE, Constants::OFFSET_ACCURACY_LOG, Constants::PREDEFINED_LL_DISTRIBUTION, Constants::PREDEFINED_ML_DISTRIBUTION, Constants::PREDEFINED_OFFSET_DISTRIBUTION, Constants::REPEAT_OFFSET_1, Constants::REPEAT_OFFSET_2, Constants::REPEAT_OFFSET_3, Constants::SKIPPABLE_MAGIC_BASE, Constants::SKIPPABLE_MAGIC_MASK, Constants::WINDOW_LOG_MAX, Constants::WINDOW_LOG_MIN

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ HuffmanTableReader

Returns a new instance of HuffmanTableReader.



208
209
210
# File 'lib/omnizip/algorithms/zstandard/huffman.rb', line 208

def initialize(input)
  @input = input
end

Class Method Details

.read(input) ⇒ Huffman

Read Huffman table from input

Parameters:

  • input (IO)

    Input stream positioned at Huffman description

Returns:



203
204
205
206
# File 'lib/omnizip/algorithms/zstandard/huffman.rb', line 203

def self.read(input)
  reader = new(input)
  reader.read_table
end

Instance Method Details

#read_tableHuffman

Read and build Huffman table

Returns:



215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/omnizip/algorithms/zstandard/huffman.rb', line 215

def read_table
  # Read header
  header = @input.read(1).ord

  # FSE compressed or raw weights?
  fse_compressed = header.anybits?(0x80)

  if fse_compressed
    read_fse_compressed_weights(header)
  else
    read_raw_weights(header)
  end
end