Class: Omnizip::Formats::Rar::Compression::LZ77Huffman::Decoder
- Inherits:
-
Object
- Object
- Omnizip::Formats::Rar::Compression::LZ77Huffman::Decoder
- Defined in:
- lib/omnizip/formats/rar/compression/lz77_huffman/decoder.rb
Overview
RAR LZ77+Huffman decoder
Orchestrates the decoding of RAR METHOD_NORMAL compressed data. Combines Huffman coding with LZ77 sliding window compression.
Responsibilities:
- ONE responsibility: Orchestrate LZ77+Huffman decoding
- Parse Huffman trees from bit stream
- Decode symbols using Huffman coder
- Process LZ77 matches via sliding window
- Manage decoder state and output
RAR LZ77+Huffman Format:
- Block header with Huffman tree definitions
- Compressed data stream
- Symbols: literals (0-255), matches (length+distance), end marker
Constant Summary collapse
- LITERAL_SYMBOLS =
Symbol ranges
(0..255)
- END_OF_BLOCK =
256- MATCH_SYMBOLS =
(257..511)
- MIN_MATCH_LENGTH =
Match parameters
3- MAX_MATCH_LENGTH =
257- DEFAULT_WINDOW_SIZE =
Window size for RAR4
64 * 1024
Instance Method Summary collapse
-
#decode(max_output = nil) ⇒ String
Decode compressed data.
-
#initialize(input, options = {}) ⇒ Decoder
constructor
Initialize LZ77+Huffman decoder.
-
#window_size ⇒ Integer
Get window size.
Constructor Details
#initialize(input, options = {}) ⇒ Decoder
Initialize LZ77+Huffman decoder
62 63 64 65 66 67 |
# File 'lib/omnizip/formats/rar/compression/lz77_huffman/decoder.rb', line 62 def initialize(input, = {}) @bit_stream = BitStream.new(input, :read) @window = SlidingWindow.new([:window_size] || DEFAULT_WINDOW_SIZE) @huffman = HuffmanCoder.new @output = String.new(encoding: Encoding::BINARY) end |
Instance Method Details
#decode(max_output = nil) ⇒ String
Decode compressed data
Main decoding loop:
- Parse Huffman tree (simplified for MVP)
- Decode symbols until end-of-block
- Process literals and matches
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/omnizip/formats/rar/compression/lz77_huffman/decoder.rb', line 78 def decode(max_output = nil) @output.clear # Parse Huffman tree (simplified - real RAR has complex structure) parse_huffman_trees # Decode symbols until end-of-block or max output loop do break if max_output && @output.bytesize >= max_output symbol = @huffman.decode_symbol(@bit_stream) break if symbol.nil? || symbol == END_OF_BLOCK process_symbol(symbol) end @output rescue EOFError @output end |
#window_size ⇒ Integer
Get window size
102 103 104 |
# File 'lib/omnizip/formats/rar/compression/lz77_huffman/decoder.rb', line 102 def window_size @window.size end |