Class: Omnizip::Formats::Rar::Rar5::Compression::Lzss
- Inherits:
-
Object
- Object
- Omnizip::Formats::Rar::Rar5::Compression::Lzss
- Defined in:
- lib/omnizip/formats/rar/rar5/compression/lzss.rb
Overview
RAR5 LZSS compression method
RAR5 compression methods 1-5 use a proprietary LZSS-based algorithm with Huffman coding. This is the algorithm used by official RAR tools.
Based on libarchive/archive_read_support_format_rar5.c
Defined Under Namespace
Classes: BitReader, Decoder, HuffmanTable
Constant Summary collapse
- METHOD_STORE =
Compression method identifiers
0- METHOD_FASTEST =
1- METHOD_FAST =
2- METHOD_NORMAL =
3- METHOD_GOOD =
4- METHOD_BEST =
5- HUFF_BC =
Huffman code constants (from libarchive)
20- HUFF_NC =
Number of bit length codes
306- HUFF_DC =
Number of literal/length codes
64- HUFF_LDC =
Number of distance codes
16- HUFF_RC =
Number of low distance codes
44- HUFF_TABLE_SIZE =
Number of repeat codes
HUFF_NC + HUFF_DC + HUFF_LDC + HUFF_RC
- DIST_CACHE_SIZE =
Distance cache size
4- MIN_MATCH =
Minimum match length
3
Class Method Summary collapse
-
.available? ⇒ Boolean
Check if LZSS compression is available for official RAR compatibility.
-
.compress(data, options = {}) ⇒ Hash
Compress data using RAR5 LZSS.
-
.compression_info(level = METHOD_NORMAL) ⇒ Integer
Get compression info VINT value.
-
.decompress(data, options = {}) ⇒ String
Decompress RAR5 LZSS data.
-
.method_id(level = METHOD_NORMAL) ⇒ Integer
Get compression method identifier.
Class Method Details
.available? ⇒ Boolean
Check if LZSS compression is available for official RAR compatibility
44 45 46 47 48 |
# File 'lib/omnizip/formats/rar/rar5/compression/lzss.rb', line 44 def available? # Full LZSS decoder is now implemented # Encoder is not yet compatible with official RAR tools true end |
.compress(data, options = {}) ⇒ Hash
Compress data using RAR5 LZSS
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/omnizip/formats/rar/rar5/compression/lzss.rb', line 57 def compress(data, = {}) level = [:level] || METHOD_NORMAL [:dict_size] || dictionary_size_for_level(level) # For now, use STORE method until encoder is compatible # with official RAR tools { data: data, properties: nil, method: METHOD_STORE, } end |
.compression_info(level = METHOD_NORMAL) ⇒ Integer
Get compression info VINT value
97 98 99 100 |
# File 'lib/omnizip/formats/rar/rar5/compression/lzss.rb', line 97 def compression_info(level = METHOD_NORMAL) method = method_id(level) method & 0x3F end |
.decompress(data, options = {}) ⇒ String
Decompress RAR5 LZSS data
77 78 79 80 81 82 83 |
# File 'lib/omnizip/formats/rar/rar5/compression/lzss.rb', line 77 def decompress(data, = {}) uncompressed_size = [:uncompressed_size] window_size = [:window_size] || (1 << 20) # Default 1MB decoder = Decoder.new(data, window_size) decoder.decode(uncompressed_size) end |
.method_id(level = METHOD_NORMAL) ⇒ Integer
Get compression method identifier
89 90 91 |
# File 'lib/omnizip/formats/rar/rar5/compression/lzss.rb', line 89 def method_id(level = METHOD_NORMAL) level.clamp(METHOD_FASTEST, METHOD_BEST) end |