Class: Omnizip::Algorithms::BZip2
- Inherits:
-
Omnizip::Algorithm
- Object
- Omnizip::Algorithm
- Omnizip::Algorithms::BZip2
- Defined in:
- lib/omnizip/algorithms/bzip2.rb,
lib/omnizip/algorithms/bzip2/bwt.rb,
lib/omnizip/algorithms/bzip2/mtf.rb,
lib/omnizip/algorithms/bzip2/rle.rb,
lib/omnizip/algorithms/bzip2/decoder.rb,
lib/omnizip/algorithms/bzip2/encoder.rb,
lib/omnizip/algorithms/bzip2/huffman.rb
Overview
BZip2 block-sorting compression algorithm
BZip2 combines several compression techniques in a pipeline:
- Burrows-Wheeler Transform (BWT) - block-sorting transformation
- Move-to-Front Transform (MTF) - exploits locality
- Run-Length Encoding (RLE) - compresses repeated bytes
- Huffman Coding - variable-length entropy encoding
This algorithm is particularly effective for:
- Text files with repetitive patterns
- Data with high local similarity
- Files where block-sorting improves compressibility
Block size affects both compression ratio and memory usage. Larger blocks (up to 900KB) generally provide better compression but require more memory.
Defined Under Namespace
Classes: Bwt, Decoder, Encoder, Huffman, Mtf, Rle
Instance Attribute Summary
Attributes inherited from Omnizip::Algorithm
Class Method Summary collapse
-
.metadata ⇒ AlgorithmMetadata
Get algorithm metadata.
Instance Method Summary collapse
-
#compress(input_stream, output_stream, options = nil) ⇒ void
Compress data using BZip2 algorithm.
-
#decompress(input_stream, output_stream, _options = nil) ⇒ void
Decompress BZip2-compressed data.
Methods inherited from Omnizip::Algorithm
inherited, #initialize, #with_filter
Constructor Details
This class inherits a constructor from Omnizip::Algorithm
Class Method Details
.metadata ⇒ AlgorithmMetadata
Get algorithm metadata
56 57 58 59 60 61 62 63 |
# File 'lib/omnizip/algorithms/bzip2.rb', line 56 def self. Models::AlgorithmMetadata.new.tap do || .name = "bzip2" .description = "BZip2 block-sorting compression using " \ "BWT, MTF, RLE, and Huffman coding" .version = "1.0.0" end end |
Instance Method Details
#compress(input_stream, output_stream, options = nil) ⇒ void
This method returns an undefined value.
Compress data using BZip2 algorithm
71 72 73 74 75 76 |
# File 'lib/omnizip/algorithms/bzip2.rb', line 71 def compress(input_stream, output_stream, = nil) input_data = input_stream.read encoder = Encoder.new(output_stream, ()) encoder.encode_stream(input_data) end |
#decompress(input_stream, output_stream, _options = nil) ⇒ void
This method returns an undefined value.
Decompress BZip2-compressed data
84 85 86 87 88 89 90 91 |
# File 'lib/omnizip/algorithms/bzip2.rb', line 84 def decompress(input_stream, output_stream, = nil) if output_stream.respond_to?(:set_encoding) output_stream.set_encoding(Encoding::BINARY) end decoder = Decoder.new(input_stream) decompressed = decoder.decode_stream output_stream.write(decompressed) end |