Class: Paperclip::Processors::Gzip

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Gzip.



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

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

Instance Method Details

#makeObject



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

def make
  level       = @gzip_options[:level]
  strategy    = @gzip_options[:strategy]

  dst = create_tempfile
  Zlib::GzipWriter.open(dst, level, strategy) do |gz|
    while chunk = @file.read(16 * 1024) do
      gz.write chunk
    end
  end
  @file.rewind
  dst.open

  dst
end