Class: Omnizip::Algorithms::PPMd7::Decoder

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

Overview

PPMd7 Decoder using range coding

Decodes a stream that was compressed with PPMd7 encoder. Maintains synchronized model state with the encoder.

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):

  • :model_order (Integer)

    Maximum context order

  • :mem_size (Integer)

    Memory size for model



39
40
41
42
43
44
45
46
# File 'lib/omnizip/algorithms/ppmd7/decoder.rb', line 39

def initialize(input, options = {})
  @input = input
  @model = Model.new(
    options[:model_order] || Model::DEFAULT_ORDER,
    options[:mem_size] || Model::DEFAULT_MEM_SIZE,
  )
  @range_decoder = LZMA::RangeDecoder.new(input)
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



31
32
33
# File 'lib/omnizip/algorithms/ppmd7/decoder.rb', line 31

def model
  @model
end

Instance Method Details

#decode_streamString

Decode a stream back to original bytes

Reads compressed data, decodes using PPMd7 model, and returns the original data.

Returns:

  • (String)

    Decoded data



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/omnizip/algorithms/ppmd7/decoder.rb', line 54

def decode_stream
  result = String.new(encoding: Encoding::BINARY)

  # Simplified decoding - in practice would need proper
  # stream termination handling
  100.times do
    symbol = decode_symbol
    break if symbol.nil?

    result << symbol.chr
  end

  result
end