Class: Paperclip::Processors::Deflater

Inherits:
DeflaterBase
  • Object
show all
Defined in:
lib/paperclip/processors/deflater.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}, attachment = nil) ⇒ Deflater

Returns a new instance of Deflater.



6
7
8
9
# File 'lib/paperclip/processors/deflater.rb', line 6

def initialize(file, options = {}, attachment = nil)
  super
  @deflate_options = @options[:deflate_options] || {}
end

Instance Method Details

#makeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/paperclip/processors/deflater.rb', line 11

def make
  level       = @deflate_options[:level]
  window_bits = @deflate_options[:window_bits]
  memlevel    = @deflate_options[:memlevel]
  strategy    = @deflate_options[:strategy]

  dst = create_tempfile
  begin
    zd = Zlib::Deflate.new(level, window_bits, memlevel, strategy)
    dst.write zd.deflate(@file.read)
  ensure
    zd.close
  end
  @file.rewind
  dst.flush
  dst.rewind

  dst
end