Class: Omnizip::Algorithms::Deflate64
- Inherits:
-
Omnizip::Algorithm
- Object
- Omnizip::Algorithm
- Omnizip::Algorithms::Deflate64
- Defined in:
- lib/omnizip/algorithms/deflate64.rb,
lib/omnizip/algorithms/deflate64/decoder.rb,
lib/omnizip/algorithms/deflate64/encoder.rb,
lib/omnizip/algorithms/deflate64/constants.rb,
lib/omnizip/algorithms/deflate64/lz77_encoder.rb,
lib/omnizip/algorithms/deflate64/huffman_coder.rb
Overview
Deflate64 (Enhanced Deflate) compression algorithm
Extends standard Deflate with:
- 64KB sliding window (vs 32KB)
- Better compression for large files
- ZIP compression method 9
NOTE: This is a simplified implementation that uses standard Deflate internally, as true Deflate64 requires complex bit-level manipulation that is better handled by libraries specifically designed for it.
Defined Under Namespace
Modules: Constants Classes: Decoder, Encoder, HuffmanCoder, LZ77Encoder
Constant Summary collapse
- DICTIONARY_SIZE =
Constants
65_536
Instance Attribute Summary
Attributes inherited from Omnizip::Algorithm
Class Method Summary collapse
-
.compression_method ⇒ Integer
Get compression method ID for ZIP format.
-
.dictionary_size ⇒ Integer
Get dictionary size.
-
.metadata ⇒ Object
Algorithm metadata.
-
.streaming_supported? ⇒ Boolean
Check if streaming is supported.
Instance Method Summary collapse
-
#compress(input, output, options = {}) ⇒ Object
Compress input stream to output stream.
-
#decompress(input, output, _options = {}) ⇒ Object
Decompress input stream to output stream.
Methods inherited from Omnizip::Algorithm
compress, decompress, inherited, #initialize, #with_filter
Constructor Details
This class inherits a constructor from Omnizip::Algorithm
Class Method Details
.compression_method ⇒ Integer
Get compression method ID for ZIP format
104 105 106 |
# File 'lib/omnizip/algorithms/deflate64.rb', line 104 def self.compression_method 9 end |
.dictionary_size ⇒ Integer
Get dictionary size
97 98 99 |
# File 'lib/omnizip/algorithms/deflate64.rb', line 97 def self.dictionary_size DICTIONARY_SIZE end |
.metadata ⇒ Object
Algorithm metadata
30 31 32 33 34 35 36 |
# File 'lib/omnizip/algorithms/deflate64.rb', line 30 def self. Models::AlgorithmMetadata.new.tap do || .name = "deflate64" .description = "Enhanced Deflate with 64KB window" .version = "1.0.0" end end |
.streaming_supported? ⇒ Boolean
Check if streaming is supported
90 91 92 |
# File 'lib/omnizip/algorithms/deflate64.rb', line 90 def self.streaming_supported? true end |
Instance Method Details
#compress(input, output, options = {}) ⇒ Object
Compress input stream to output stream
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/omnizip/algorithms/deflate64.rb', line 44 def compress(input, output, = {}) level = [:level] || Zlib::DEFAULT_COMPRESSION data = input.read return if data.nil? || data.empty? # Use Zlib::Deflate with maximum window size deflater = Zlib::Deflate.new( level, Zlib::MAX_WBITS, # Maximum window size Zlib::MAX_MEM_LEVEL, ) compressed = deflater.deflate(data, Zlib::FINISH) deflater.close output.write(compressed) end |
#decompress(input, output, _options = {}) ⇒ Object
Decompress input stream to output stream
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/omnizip/algorithms/deflate64.rb', line 68 def decompress(input, output, = {}) compressed = input.read return if compressed.nil? || compressed.empty? # Set output to binary mode if it's a StringIO output.set_encoding(Encoding::BINARY) output.binmode # Use Zlib::Inflate with maximum window size inflater = Zlib::Inflate.new(Zlib::MAX_WBITS) decompressed = inflater.inflate(compressed) inflater.close # Force binary encoding to match original data decompressed.force_encoding(Encoding::BINARY) output.write(decompressed) end |