Class: Omnizip::Algorithms::Deflate64

Inherits:
Omnizip::Algorithm show all
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

#filter, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Omnizip::Algorithm

inherited, #initialize, #with_filter

Constructor Details

This class inherits a constructor from Omnizip::Algorithm

Class Method Details

.compression_methodInteger

Get compression method ID for ZIP format

Returns:

  • (Integer)

    Method 9



107
108
109
# File 'lib/omnizip/algorithms/deflate64.rb', line 107

def self.compression_method
  9
end

.dictionary_sizeInteger

Get dictionary size

Returns:

  • (Integer)

    64KB



100
101
102
# File 'lib/omnizip/algorithms/deflate64.rb', line 100

def self.dictionary_size
  DICTIONARY_SIZE
end

.metadataObject

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

Returns:

  • (Boolean)

    Always true for Deflate64



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

Parameters:

  • input (IO)

    Input stream

  • output (IO)

    Output stream

  • options (Hash) (defaults to: {})

    Compression options

Options Hash (options):

  • :level (Integer)

    Compression level (1-9)



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, options = {})
  level = options[: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

Parameters:

  • input (IO)

    Input stream

  • output (IO)

    Output stream

  • options (Hash)

    Decompression options



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, _options = {})
  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