Class: Omnizip::Algorithms::LZMA::Encoder
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::LZMA::Encoder
- Includes:
- Constants
- Defined in:
- lib/omnizip/algorithms/lzma/encoder.rb
Overview
LZMA Encoder - Factory for LZMA compression implementations
This class provides a unified interface for LZMA encoding, delegating to the appropriate implementation based on the target format:
- SDK-compatible (default): For 7-Zip containers, uses 7-Zip SDK implementation
- XZ-compatible: For XZ/LZMA files, uses XZ Utils implementation
The encoder produces a stream that consists of:
- Property byte (lc, lp, pb parameters)
- Dictionary size (4 bytes)
- Uncompressed size (8 bytes)
- Compressed data
Constant Summary
Constants included from Constants
Constants::BIT_MODEL_TOTAL, Constants::COMPRESSION_LEVEL_DEFAULT, Constants::COMPRESSION_LEVEL_MAX, Constants::COMPRESSION_LEVEL_MIN, Constants::DICT_SIZE_MAX, Constants::DICT_SIZE_MIN, Constants::DIST_ALIGN_BITS, Constants::DIST_ALIGN_SIZE, Constants::DIST_SLOT_FAST_LIMIT, Constants::END_POS_MODEL_INDEX, Constants::EOS_MARKER, Constants::INIT_PROBS, Constants::LEN_HIGH_SYMBOLS, Constants::LEN_LOW_SYMBOLS, Constants::LEN_MID_SYMBOLS, Constants::LIT_SIZE_MAX, Constants::MATCH_LEN_MAX, Constants::MATCH_LEN_MIN, Constants::MOVE_BITS, Constants::NUM_DIRECT_BITS, Constants::NUM_DIST_SLOTS, Constants::NUM_DIST_SLOT_BITS, Constants::NUM_FULL_DISTANCES, Constants::NUM_LEN_HIGH_BITS, Constants::NUM_LEN_LOW_BITS, Constants::NUM_LEN_MID_BITS, Constants::NUM_LEN_TO_POS_STATES, Constants::NUM_LIT_CONTEXT_BITS_MAX, Constants::NUM_LIT_POS_BITS_MAX, Constants::NUM_POS_BITS_MAX, Constants::NUM_STATES, Constants::POS_STATES_MAX, Constants::START_POS_MODEL_INDEX, Constants::TOP
Instance Attribute Summary collapse
-
#dict_size ⇒ Object
readonly
Returns the value of attribute dict_size.
-
#lc ⇒ Object
readonly
Returns the value of attribute lc.
-
#lp ⇒ Object
readonly
Returns the value of attribute lp.
-
#pb ⇒ Object
readonly
Returns the value of attribute pb.
Instance Method Summary collapse
-
#encode_stream(input) ⇒ Array<String, Integer>, void
Encode a stream of data.
-
#initialize(output, options = {}) ⇒ Encoder
constructor
Initialize the encoder.
Constructor Details
#initialize(output, options = {}) ⇒ Encoder
Initialize the encoder
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/omnizip/algorithms/lzma/encoder.rb', line 56 def initialize(output, = {}) @output = output @dict_size = [:dict_size] || (1 << 16) # 64KB default @lc = [:lc] || 3 @lp = [:lp] || 0 @pb = [:pb] || 2 @write_size = .fetch(:write_size, true) @xz_compatible = .fetch(:xz_compatible, false) @sdk_compatible = .fetch(:sdk_compatible, !@xz_compatible) @raw_mode = .fetch(:raw_mode, false) validate_parameters # Factory pattern: create implementation based on mode @impl = if @xz_compatible # Use XzEncoder (XZ Utils LZMA) XzEncoderAdapter.new(output, ) else # Use SdkEncoder (7-Zip LZMA SDK compatible) - DEFAULT Implementations::SevenZip::LZMA::Encoder.new(output, ) end end |
Instance Attribute Details
#dict_size ⇒ Object (readonly)
Returns the value of attribute dict_size.
42 43 44 |
# File 'lib/omnizip/algorithms/lzma/encoder.rb', line 42 def dict_size @dict_size end |
#lc ⇒ Object (readonly)
Returns the value of attribute lc.
42 43 44 |
# File 'lib/omnizip/algorithms/lzma/encoder.rb', line 42 def lc @lc end |
#lp ⇒ Object (readonly)
Returns the value of attribute lp.
42 43 44 |
# File 'lib/omnizip/algorithms/lzma/encoder.rb', line 42 def lp @lp end |
#pb ⇒ Object (readonly)
Returns the value of attribute pb.
42 43 44 |
# File 'lib/omnizip/algorithms/lzma/encoder.rb', line 42 def pb @pb end |
Instance Method Details
#encode_stream(input) ⇒ Array<String, Integer>, void
Encode a stream of data
84 85 86 |
# File 'lib/omnizip/algorithms/lzma/encoder.rb', line 84 def encode_stream(input) @impl.encode_stream(input) end |