Class: Omnizip::Algorithms::PPMd7::Encoder

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

Overview

PPMd7 Encoder using range coding

Encodes a stream of bytes using the PPMd7 prediction model combined with range encoding for arithmetic coding.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initialize the encoder

Parameters:

  • output (IO)

    Output stream for compressed data

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

    Encoding 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/encoder.rb', line 39

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

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end

Instance Method Details

#encode_stream(input) ⇒ void

This method returns an undefined value.

Encode a stream of bytes

Reads from input, compresses using PPMd7 model, and writes to output stream.

Parameters:

  • input (IO)

    Input stream to compress



55
56
57
58
59
60
61
62
# File 'lib/omnizip/algorithms/ppmd7/encoder.rb', line 55

def encode_stream(input)
  while (byte = input.getbyte)
    encode_symbol(byte)
  end

  # Flush encoder
  @range_encoder.flush
end