Class: Omnizip::Algorithms::Zstandard::LiteralsDecoder
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::Zstandard::LiteralsDecoder
- Includes:
- Constants
- Defined in:
- lib/omnizip/algorithms/zstandard/literals.rb
Overview
Literals section decoder (RFC 8878 Section 3.1.1.3.1)
Decodes the literals section of a compressed block. Can be raw, RLE, Huffman compressed, or treeless.
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
Instance Attribute Summary collapse
-
#huffman_table ⇒ Huffman?
readonly
Huffman table for future treeless blocks.
-
#literals ⇒ String
readonly
Decoded literals.
Class Method Summary collapse
-
.decode(input, previous_table = nil) ⇒ LiteralsDecoder
Parse and decode literals section.
Instance Method Summary collapse
-
#decode_section ⇒ void
Decode the literals section.
-
#initialize(input, previous_table = nil) ⇒ LiteralsDecoder
constructor
Initialize decoder.
Constructor Details
#initialize(input, previous_table = nil) ⇒ LiteralsDecoder
Initialize decoder
54 55 56 57 58 59 |
# File 'lib/omnizip/algorithms/zstandard/literals.rb', line 54 def initialize(input, previous_table = nil) @input = input @previous_table = previous_table @literals = String.new(encoding: Encoding::BINARY) @huffman_table = previous_table end |
Instance Attribute Details
#huffman_table ⇒ Huffman? (readonly)
Returns Huffman table for future treeless blocks.
37 38 39 |
# File 'lib/omnizip/algorithms/zstandard/literals.rb', line 37 def huffman_table @huffman_table end |
#literals ⇒ String (readonly)
Returns Decoded literals.
34 35 36 |
# File 'lib/omnizip/algorithms/zstandard/literals.rb', line 34 def literals @literals end |
Class Method Details
.decode(input, previous_table = nil) ⇒ LiteralsDecoder
Parse and decode literals section
44 45 46 47 48 |
# File 'lib/omnizip/algorithms/zstandard/literals.rb', line 44 def self.decode(input, previous_table = nil) decoder = new(input, previous_table) decoder.decode_section decoder end |
Instance Method Details
#decode_section ⇒ void
This method returns an undefined value.
Decode the literals section
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/omnizip/algorithms/zstandard/literals.rb', line 64 def decode_section # Read literals header (1-3 bytes) header1 = @input.read(1).ord block_type = (header1 >> 6) & 0x03 case block_type when LITERALS_BLOCK_RAW decode_raw(header1) when LITERALS_BLOCK_RLE decode_rle(header1) when LITERALS_BLOCK_COMPRESSED decode_compressed(header1) when LITERALS_BLOCK_TREELESS decode_treeless(header1) end end |