Class: Omnizip::Algorithms::PPMd7::Decoder
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::PPMd7::Decoder
- 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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#decode_stream ⇒ String
Decode a stream back to original bytes.
-
#initialize(input, options = {}) ⇒ Decoder
constructor
Initialize the decoder.
Constructor Details
#initialize(input, options = {}) ⇒ Decoder
Initialize the decoder
39 40 41 42 43 44 45 46 |
# File 'lib/omnizip/algorithms/ppmd7/decoder.rb', line 39 def initialize(input, = {}) @input = input @model = Model.new( [:model_order] || Model::DEFAULT_ORDER, [:mem_size] || Model::DEFAULT_MEM_SIZE, ) @range_decoder = LZMA::RangeDecoder.new(input) end |
Instance Attribute Details
#model ⇒ Object (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_stream ⇒ String
Decode a stream back to original bytes
Reads compressed data, decodes using PPMd7 model, and returns the original 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 |