Class: Omnizip::Algorithms::BZip2::Decoder

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

Overview

BZip2 Decoder

Reverses the full BZip2 compression pipeline:

  1. Read block headers
  2. Decode Huffman coding
  3. Reverse Run-Length Encoding (RLE)
  4. Reverse Move-to-Front Transform (MTF)
  5. Reverse Burrows-Wheeler Transform (BWT)
  6. Verify CRC32 checksum

Processes each block independently and concatenates results.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initialize decoder

Parameters:

  • input (IO)

    Input stream

  • options (Hash)

    Decoding options



44
45
46
47
48
49
50
# File 'lib/omnizip/algorithms/bzip2/decoder.rb', line 44

def initialize(input, _options = {})
  @input = input
  @bwt = Bwt.new
  @mtf = Mtf.new
  @rle = Rle.new
  @huffman = Huffman.new
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



38
39
40
# File 'lib/omnizip/algorithms/bzip2/decoder.rb', line 38

def input
  @input
end

Instance Method Details

#decode_streamString

Decode stream using BZip2 algorithm

Returns:

  • (String)

    Decoded data



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

def decode_stream
  result = []

  # Read and decode all blocks
  loop do
    block_data = decode_block
    break unless block_data

    result << block_data
  end

  result.join.b
end