Class: Omnizip::Algorithms::LZMA2XzEncoderAdapter
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::LZMA2XzEncoderAdapter
- Defined in:
- lib/omnizip/algorithms/lzma2/xz_encoder_adapter.rb
Overview
Adapter for XZ Encoder to work with LZMA2 chunking
Wraps the pure Ruby XZ encoder to provide LZMA2-compatible interface for chunked encoding with size limits.
Instance Method Summary collapse
-
#dict_size ⇒ Integer
Get dictionary size.
-
#encode_chunk(data, _limit = nil) ⇒ String
Encode data chunk.
-
#initialize(options = {}) ⇒ LZMA2XzEncoderAdapter
constructor
Initialize XZ encoder adapter.
-
#properties ⇒ Integer
Get LZMA properties byte.
Constructor Details
#initialize(options = {}) ⇒ LZMA2XzEncoderAdapter
Initialize XZ encoder adapter
38 39 40 41 42 43 |
# File 'lib/omnizip/algorithms/lzma2/xz_encoder_adapter.rb', line 38 def initialize( = {}) @options = @lc = [:lc] || 3 @lp = [:lp] || 0 @pb = [:pb] || 2 end |
Instance Method Details
#dict_size ⇒ Integer
Get dictionary size
75 76 77 |
# File 'lib/omnizip/algorithms/lzma2/xz_encoder_adapter.rb', line 75 def dict_size @options[:dict_size] || (1 << 23) # 8MB default end |
#encode_chunk(data, _limit = nil) ⇒ String
Encode data chunk
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/omnizip/algorithms/lzma2/xz_encoder_adapter.rb', line 50 def encode_chunk(data, _limit = nil) output = StringIO.new encoder = LZMA::XzEncoder.new(@options) # Encode with optional size limit # XZ encoder returns bytes written to output encoder.encode(data, output) # Return the encoded data string output.string end |
#properties ⇒ Integer
Get LZMA properties byte
Encodes lc, lp, pb into single byte using formula: (pb * 5 + lp) * 9 + lc
68 69 70 |
# File 'lib/omnizip/algorithms/lzma2/xz_encoder_adapter.rb', line 68 def properties (((@pb * 5) + @lp) * 9) + @lc end |