Class: Zopfli::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/zopfli/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, iterations) ⇒ Options

Returns a new instance of Options.



8
9
10
# File 'lib/zopfli/options.rb', line 8

def initialize(type, iterations)
  @type, @iterations = type, iterations
end

Instance Attribute Details

#iterationsObject (readonly)

Returns the value of attribute iterations.



6
7
8
# File 'lib/zopfli/options.rb', line 6

def iterations
  @iterations
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/zopfli/options.rb', line 6

def type
  @type
end

Instance Method Details

#compress_pointerObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/zopfli/options.rb', line 12

def compress_pointer
  options_pointer = FFI::MemoryPointer.new :char, C::ZopfliConfig.size, false
  options_struct = C::ZopfliConfig.new options_pointer
  # set format
  options_struct[:type] = case type
    when :deflate then 1
    when :gzip then 2
    else 0
  end
  # set numiterations
  options_struct[:numiterations] = iterations.to_i if iterations.to_i > 0

  options_pointer
end