Class: Omnizip::Implementations::Base::LZMA2EncoderBase Abstract

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

Overview

This class is abstract.

Subclasses must implement #encode

Abstract base class for LZMA2 encoders.

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

LZMA2 is an improved version of LZMA that supports:

  • Uncompressed chunks for incompressible data
  • Dictionary/state resets for better compression
  • Simpler chunk format

Subclasses must implement the #encode method.

Constant Summary collapse

UNCOMPRESSED_MAX =

Maximum uncompressed size per LZMA2 chunk (2MB)

1 << 21
COMPRESSED_MAX =

Maximum compressed size per LZMA2 chunk (64KB)

1 << 16

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ LZMA2EncoderBase

Initialize the LZMA2 encoder.

Parameters:

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

    Encoding options

Options Hash (options):

  • :dict_size (Integer)

    Dictionary size (default: 8MB)

  • :lc (Integer)

    Literal context bits (default: 3)

  • :lp (Integer)

    Literal position bits (default: 0)

  • :pb (Integer)

    Position bits (default: 2)

  • :standalone (Boolean)

    Write property byte at start (default: true)



55
56
57
58
59
60
61
62
63
# File 'lib/omnizip/implementations/base/lzma2_encoder_base.rb', line 55

def initialize(options = {})
  @dict_size = options.fetch(:dict_size, 8 * 1024 * 1024)
  @lc = options.fetch(:lc, 3)
  @lp = options.fetch(:lp, 0)
  @pb = options.fetch(:pb, 2)
  @standalone = options.fetch(:standalone, true)

  validate_parameters!
end

Instance Attribute Details

#dict_sizeObject (readonly)

Returns the value of attribute dict_size.



40
41
42
# File 'lib/omnizip/implementations/base/lzma2_encoder_base.rb', line 40

def dict_size
  @dict_size
end

#lcObject (readonly)

Returns the value of attribute lc.



40
41
42
# File 'lib/omnizip/implementations/base/lzma2_encoder_base.rb', line 40

def lc
  @lc
end

#lpObject (readonly)

Returns the value of attribute lp.



40
41
42
# File 'lib/omnizip/implementations/base/lzma2_encoder_base.rb', line 40

def lp
  @lp
end

#pbObject (readonly)

Returns the value of attribute pb.



40
41
42
# File 'lib/omnizip/implementations/base/lzma2_encoder_base.rb', line 40

def pb
  @pb
end

Instance Method Details

#encode(data) ⇒ String

Encode data using LZMA2.

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

Returns:

  • (String)

    Compressed data

Raises:

  • (NotImplementedError)

    Always raised in base class



73
74
75
76
# File 'lib/omnizip/implementations/base/lzma2_encoder_base.rb', line 73

def encode(data)
  raise NotImplementedError,
        "#{self.class} must implement #encode"
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



85
86
87
88
# File 'lib/omnizip/implementations/base/lzma2_encoder_base.rb', line 85

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

#standalone?Boolean

Check if standalone mode is enabled.

Returns:

  • (Boolean)

    true if property byte should be written



93
94
95
# File 'lib/omnizip/implementations/base/lzma2_encoder_base.rb', line 93

def standalone?
  @standalone
end