Class: Omnizip::Formats::Rar::Rar5::Solid::SolidEncoder
- Inherits:
-
Object
- Object
- Omnizip::Formats::Rar::Rar5::Solid::SolidEncoder
- Defined in:
- lib/omnizip/formats/rar/rar5/solid/solid_encoder.rb
Overview
Solid LZMA encoder with persistent dictionary
This encoder maintains LZMA dictionary state across multiple files, allowing later files to reference data from earlier files. This is the core technique behind solid compression's improved ratios.
Unlike normal compression where each file is independent, solid compression treats all files as one continuous stream, maximizing dictionary-based compression efficiency.
Defined Under Namespace
Classes: LzmaOptions
Instance Attribute Summary collapse
-
#level ⇒ Integer
readonly
Compression level (1-5).
-
#lzma_options ⇒ Hash
readonly
LZMA options.
Instance Method Summary collapse
-
#build_lzma_options(level) ⇒ LzmaOptions
Build LZMA options for solid compression.
-
#compress_stream(data) ⇒ String
Compress data with persistent dictionary.
-
#decompress_stream(data) ⇒ String
Decompress solid stream.
-
#initialize(options = {}) ⇒ SolidEncoder
constructor
Initialize solid encoder.
Constructor Details
#initialize(options = {}) ⇒ SolidEncoder
Initialize solid encoder
34 35 36 37 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_encoder.rb', line 34 def initialize( = {}) @level = [:level] || 3 @lzma_options = (@level) end |
Instance Attribute Details
#level ⇒ Integer (readonly)
Returns Compression level (1-5).
25 26 27 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_encoder.rb', line 25 def level @level end |
#lzma_options ⇒ Hash (readonly)
Returns LZMA options.
28 29 30 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_encoder.rb', line 28 def @lzma_options end |
Instance Method Details
#build_lzma_options(level) ⇒ LzmaOptions
Build LZMA options for solid compression
Solid compression benefits from larger dictionaries since we're compressing more data at once.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_encoder.rb', line 79 def (level) # Use larger dictionaries for solid mode # This allows better cross-file references dict_size = 1 << case level when 1 then 20 # 1 MB (fastest) when 2 then 22 # 4 MB (fast) when 3 then 24 # 16 MB (normal) when 4 then 25 # 32 MB (good) when 5 then 26 # 64 MB (best) else 24 # default: 16 MB end LzmaOptions.new(level, dict_size) end |
#compress_stream(data) ⇒ String
Compress data with persistent dictionary
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_encoder.rb', line 43 def compress_stream(data) input = StringIO.new(data) output = StringIO.new output.set_encoding(Encoding::BINARY) # Create LZMA encoder lzma = Algorithms::LZMA.new # Compress entire stream at once (maintains dictionary) lzma.compress(input, output, @lzma_options) output.string end |
#decompress_stream(data) ⇒ String
Decompress solid stream
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/omnizip/formats/rar/rar5/solid/solid_encoder.rb', line 61 def decompress_stream(data) input = StringIO.new(data) output = StringIO.new output.set_encoding(Encoding::BINARY) lzma = Algorithms::LZMA.new lzma.decompress(input, output) output.string end |