Class: Omnizip::Implementations::Base::LZMAEncoderBase Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/implementations/base/lzma_encoder_base.rb

Overview

This class is abstract.

Subclasses must implement #encode_stream

Abstract base class for LZMA encoders.

This class defines the common interface and shared functionality for all LZMA encoder implementations (XZ Utils, 7-Zip SDK, etc.).

Subclasses must implement the #encode_stream method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, options = {}) ⇒ LZMAEncoderBase

Initialize the LZMA encoder.

Parameters:

  • output (IO)

    Output stream for compressed data

  • options (Hash) (defaults to: {})

    Encoding options

Options Hash (options):

  • :lc (Integer)

    Literal context bits (0-8, default: 3)

  • :lp (Integer)

    Literal position bits (0-4, default: 0)

  • :pb (Integer)

    Position bits (0-4, default: 2)

  • :dict_size (Integer)

    Dictionary size (default: 64KB)

Raises:

  • (ArgumentError)

    If parameters are invalid



46
47
48
49
50
51
52
53
54
# File 'lib/omnizip/implementations/base/lzma_encoder_base.rb', line 46

def initialize(output, options = {})
  @output = output
  @lc = options.fetch(:lc, 3)
  @lp = options.fetch(:lp, 0)
  @pb = options.fetch(:pb, 2)
  @dict_size = options.fetch(:dict_size, 1 << 16) # 64KB default

  validate_parameters!
end

Instance Attribute Details

#dict_sizeObject (readonly)

Returns the value of attribute dict_size.



35
36
37
# File 'lib/omnizip/implementations/base/lzma_encoder_base.rb', line 35

def dict_size
  @dict_size
end

#lcObject (readonly)

Returns the value of attribute lc.



35
36
37
# File 'lib/omnizip/implementations/base/lzma_encoder_base.rb', line 35

def lc
  @lc
end

#lpObject (readonly)

Returns the value of attribute lp.



35
36
37
# File 'lib/omnizip/implementations/base/lzma_encoder_base.rb', line 35

def lp
  @lp
end

#outputObject (readonly)

Returns the value of attribute output.



35
36
37
# File 'lib/omnizip/implementations/base/lzma_encoder_base.rb', line 35

def output
  @output
end

#pbObject (readonly)

Returns the value of attribute pb.



35
36
37
# File 'lib/omnizip/implementations/base/lzma_encoder_base.rb', line 35

def pb
  @pb
end

Instance Method Details

#encode_stream(data) ⇒ void

This method returns an undefined value.

Encode a stream of data.

Subclasses must implement this method to provide the specific encoding logic for their implementation (XZ Utils, 7-Zip, etc.).

Parameters:

  • data (String)

    Input data to compress

Raises:

  • (NotImplementedError)

    Always raised in base class



64
65
66
67
# File 'lib/omnizip/implementations/base/lzma_encoder_base.rb', line 64

def encode_stream(data)
  raise NotImplementedError,
        "#{self.class} must implement #encode_stream"
end

#implementation_nameSymbol

Get the implementation identifier.

Subclasses must implement this to return a symbol identifying their implementation (e.g., :xz_utils, :seven_zip).

Returns:

  • (Symbol)

    Implementation identifier

Raises:

  • (NotImplementedError)

    Always raised in base class



76
77
78
79
# File 'lib/omnizip/implementations/base/lzma_encoder_base.rb', line 76

def implementation_name
  raise NotImplementedError,
        "#{self.class} must implement #implementation_name"
end