Class: Omnizip::Formats::Rar::Compression::Dispatcher
- Inherits:
-
Object
- Object
- Omnizip::Formats::Rar::Compression::Dispatcher
- Defined in:
- lib/omnizip/formats/rar/compression/dispatcher.rb
Overview
Algorithm dispatcher for RAR compression
Selects appropriate compression algorithm based on RAR method and dispatches to correct encoder/decoder.
Responsibilities:
- Algorithm selection based on compression method
- Dispatch to appropriate decoder/encoder
- Error handling for unsupported/unknown methods
Note: Does NOT perform actual compression/decompression (delegated to decoder/encoder classes)
Defined Under Namespace
Classes: CompressionError, DecompressionError, UnsupportedMethodError
Constant Summary collapse
- METHOD_STORE =
RAR compression methods
0x30- METHOD_FASTEST =
No compression
0x31- METHOD_FAST =
LZ77+Huffman (fast)
0x32- METHOD_NORMAL =
LZ77+Huffman
0x33- METHOD_GOOD =
LZ77+Huffman (default)
0x34- METHOD_BEST =
LZ77+Huffman or PPMd
0x35
Class Method Summary collapse
-
.compress(method, input, output, options = {}) ⇒ Object
Compress data using appropriate algorithm.
-
.decompress(method, input, output, options = {}) ⇒ Object
Decompress data using appropriate algorithm.
Class Method Details
.compress(method, input, output, options = {}) ⇒ Object
Compress data using appropriate algorithm
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/omnizip/formats/rar/compression/dispatcher.rb', line 74 def compress(method, input, output, = {}) case method when METHOD_STORE compress_store(input, output) when METHOD_FASTEST, METHOD_FAST, METHOD_NORMAL compress_lz77_huffman(input, output, ) when METHOD_GOOD compress_good(input, output, ) when METHOD_BEST compress_ppmd(input, output, ) else raise UnsupportedMethodError, "Unknown compression method: 0x#{method.to_s(16).upcase}" end rescue StandardError => e raise CompressionError, "Compression failed: #{e.}" unless e.is_a?(UnsupportedMethodError) || e.is_a?(NotImplementedError) raise end |
.decompress(method, input, output, options = {}) ⇒ Object
Decompress data using appropriate algorithm
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/omnizip/formats/rar/compression/dispatcher.rb', line 42 def decompress(method, input, output, = {}) case method when METHOD_STORE decompress_store(input, output) when METHOD_FASTEST, METHOD_FAST, METHOD_NORMAL decompress_lz77_huffman(input, output, ) when METHOD_GOOD decompress_good(input, output, ) when METHOD_BEST decompress_ppmd(input, output, ) else raise UnsupportedMethodError, "Unknown compression method: 0x#{method.to_s(16).upcase}" end rescue StandardError => e unless e.is_a?(UnsupportedMethodError) raise DecompressionError, "Decompression failed: #{e.}" end raise end |