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
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
107 108 109 |
# File 'lib/omnizip/algorithms/deflate64.rb', line 107 def self.compression_method 9 end |
.dictionary_size ⇒ Integer
Get dictionary size
100 101 102 |
# File 'lib/omnizip/algorithms/deflate64.rb', line 100 def self.dictionary_size DICTIONARY_SIZE end |
.metadata ⇒ Object
Algorithm metadata
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/omnizip/algorithms/deflate64.rb', line 30 def self. { name: "Deflate64", type: :compression, streaming_supported: true, dictionary_size: DICTIONARY_SIZE, compression_method: 9, description: "Enhanced Deflate with 64KB window", } end |
.streaming_supported? ⇒ Boolean
Check if streaming is supported
93 94 95 |
# File 'lib/omnizip/algorithms/deflate64.rb', line 93 def self.streaming_supported? true end |
Instance Method Details
#compress(input, output, options = {}) ⇒ Object
Compress input stream to output stream
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/omnizip/algorithms/deflate64.rb', line 47 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
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/omnizip/algorithms/deflate64.rb', line 71 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) if output.respond_to?(:set_encoding) output.binmode if output.respond_to?(: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 |