Class: Omnizip::Algorithms::LZMA::Decoder

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/algorithms/lzma/decoder.rb

Overview

LZMA Decoder - Factory for LZMA decompression implementations

This class provides a unified interface for LZMA decoding, delegating to the XZ Utils implementation for full compatibility.

The decoder reads a stream that consists of:

  • Property byte (lc, lp, pb parameters)
  • Dictionary size (4 bytes)
  • Uncompressed size (8 bytes)
  • Compressed data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, options = {}) ⇒ Decoder

Initialize the decoder

Parameters:

  • input (IO)

    Input stream of compressed data

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

    Decoding options

Options Hash (options):

  • :raw_mode (Boolean)

    Skip header parsing for raw LZMA (for LZMA2)

  • :dict_size (Integer)

    Dictionary size for raw mode



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/omnizip/algorithms/lzma/decoder.rb', line 45

def initialize(input, options = {})
  # Use XZ Utils LZMA decoder (full XZ Utils compatibility)
  @impl = XzUtilsDecoder.new(input, options)

  # Expose header info as attributes
  @lc = @impl.lc
  @lp = @impl.lp
  @pb = @impl.pb
  @dict_size = @impl.dict_size
  @uncompressed_size = @impl.uncompressed_size
end

Instance Attribute Details

#dict_sizeObject (readonly)

Returns the value of attribute dict_size.



37
38
39
# File 'lib/omnizip/algorithms/lzma/decoder.rb', line 37

def dict_size
  @dict_size
end

#lcObject (readonly)

Returns the value of attribute lc.



37
38
39
# File 'lib/omnizip/algorithms/lzma/decoder.rb', line 37

def lc
  @lc
end

#lpObject (readonly)

Returns the value of attribute lp.



37
38
39
# File 'lib/omnizip/algorithms/lzma/decoder.rb', line 37

def lp
  @lp
end

#pbObject (readonly)

Returns the value of attribute pb.



37
38
39
# File 'lib/omnizip/algorithms/lzma/decoder.rb', line 37

def pb
  @pb
end

#uncompressed_sizeObject (readonly)

Returns the value of attribute uncompressed_size.



37
38
39
# File 'lib/omnizip/algorithms/lzma/decoder.rb', line 37

def uncompressed_size
  @uncompressed_size
end

Instance Method Details

#decode_stream(output = nil, preserve_dict: false) ⇒ String, Integer

Decode a compressed stream

Parameters:

  • output (IO, nil) (defaults to: nil)

    Optional output stream (if nil, returns String)

  • preserve_dict (Boolean) (defaults to: false)

    Whether to preserve dictionary from previous decode

Returns:

  • (String, Integer)

    Decompressed data or bytes written



62
63
64
# File 'lib/omnizip/algorithms/lzma/decoder.rb', line 62

def decode_stream(output = nil, preserve_dict: false)
  @impl.decode_stream(output, preserve_dict: preserve_dict)
end

#finish_state_resetvoid

This method returns an undefined value.

Finish state reset - called AFTER setting new input

This method is used by LZMA2 decoder for multi-chunk streams.



119
120
121
# File 'lib/omnizip/algorithms/lzma/decoder.rb', line 119

def finish_state_reset
  @impl.finish_state_reset
end

#prepare_state_resetvoid

This method returns an undefined value.

Prepare state reset - called BEFORE setting new input

This method is used by LZMA2 decoder for multi-chunk streams.



99
100
101
# File 'lib/omnizip/algorithms/lzma/decoder.rb', line 99

def prepare_state_reset
  @impl.prepare_state_reset
end

#reset(new_lc: nil, new_lp: nil, new_pb: nil, preserve_dict: false) ⇒ void

This method returns an undefined value.

Reset the decoder state for reuse with new properties

This method is used by LZMA2 decoder for multi-chunk streams.

Parameters:

  • new_lc (Integer, nil) (defaults to: nil)

    New lc value (if nil, keeps current)

  • new_lp (Integer, nil) (defaults to: nil)

    New lp value (if nil, keeps current)

  • new_pb (Integer, nil) (defaults to: nil)

    New pb value (if nil, keeps current)

  • preserve_dict (Boolean) (defaults to: false)

    If true, preserve dictionary state (pos, dict_full)



75
76
77
78
79
80
81
82
83
# File 'lib/omnizip/algorithms/lzma/decoder.rb', line 75

def reset(new_lc: nil, new_lp: nil, new_pb: nil, preserve_dict: false)
  @impl.reset(new_lc: new_lc, new_lp: new_lp, new_pb: new_pb,
              preserve_dict: preserve_dict)

  # Update cached properties
  @lc = @impl.lc
  @lp = @impl.lp
  @pb = @impl.pb
end

#reset_state_machine_onlyvoid

This method returns an undefined value.

Reset state machine only - preserves rep distances

This method is used by LZMA2 decoder for multi-chunk streams where we want to reset the state machine but preserve rep distances from the previous chunk (control >= 0xA0 but < 0xC0).



110
111
112
# File 'lib/omnizip/algorithms/lzma/decoder.rb', line 110

def reset_state_machine_only
  @impl.reset_state_machine_only
end

#reset_state_onlyvoid

This method returns an undefined value.

Reset only state machine and rep distances, preserve probability models

This method is used by LZMA2 decoder for multi-chunk streams.



90
91
92
# File 'lib/omnizip/algorithms/lzma/decoder.rb', line 90

def reset_state_only
  @impl.reset_state_only
end

#set_input(new_input) ⇒ void

This method returns an undefined value.

Set new input stream for chunked decoding

This method is used by LZMA2 decoder for multi-chunk streams.

Parameters:

  • new_input (IO)

    New input stream



129
130
131
# File 'lib/omnizip/algorithms/lzma/decoder.rb', line 129

def set_input(new_input)
  @impl.set_input(new_input)
end

#set_uncompressed_size(size, allow_eopm: true) ⇒ void

This method returns an undefined value.

Set uncompressed size for chunked decoding

This method is used by LZMA2 decoder for multi-chunk streams.

Parameters:

  • size (Integer)

    Uncompressed size

  • allow_eopm (Boolean) (defaults to: true)

    Whether to allow end-of-stream marker



140
141
142
# File 'lib/omnizip/algorithms/lzma/decoder.rb', line 140

def set_uncompressed_size(size, allow_eopm: true)
  @impl.set_uncompressed_size(size, allow_eopm: allow_eopm)
end