Class: Omnizip::Algorithms::BZip2::Encoder
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::BZip2::Encoder
- Defined in:
- lib/omnizip/algorithms/bzip2/encoder.rb
Overview
BZip2 Encoder
Orchestrates the full BZip2 compression pipeline:
- Block splitting (configurable block size)
- Burrows-Wheeler Transform (BWT)
- Move-to-Front Transform (MTF)
- Run-Length Encoding (RLE)
- Huffman Coding
- CRC32 checksum calculation
Each block is compressed independently for better parallelization potential and error recovery.
Constant Summary collapse
- MIN_BLOCK_SIZE =
Block size constants (in bytes)
100_000- MAX_BLOCK_SIZE =
100KB
900_000- DEFAULT_BLOCK_SIZE =
900KB
900_000
Instance Attribute Summary collapse
-
#block_size ⇒ Object
readonly
Returns the value of attribute block_size.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#encode_stream(input) ⇒ void
Encode stream using BZip2 algorithm.
-
#initialize(output, options = {}) ⇒ Encoder
constructor
Initialize encoder.
Constructor Details
#initialize(output, options = {}) ⇒ Encoder
Initialize encoder
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/omnizip/algorithms/bzip2/encoder.rb', line 51 def initialize(output, = {}) @output = output @block_size = validate_block_size( [:block_size] || DEFAULT_BLOCK_SIZE, ) @bwt = Bwt.new @mtf = Mtf.new @rle = Rle.new @huffman = Huffman.new end |
Instance Attribute Details
#block_size ⇒ Object (readonly)
Returns the value of attribute block_size.
39 40 41 |
# File 'lib/omnizip/algorithms/bzip2/encoder.rb', line 39 def block_size @block_size end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
39 40 41 |
# File 'lib/omnizip/algorithms/bzip2/encoder.rb', line 39 def output @output end |
Instance Method Details
#encode_stream(input) ⇒ void
This method returns an undefined value.
Encode stream using BZip2 algorithm
66 67 68 69 70 71 72 |
# File 'lib/omnizip/algorithms/bzip2/encoder.rb', line 66 def encode_stream(input) return if input.empty? # Split into blocks and encode each blocks = split_into_blocks(input) blocks.each { |block| encode_block(block) } end |