Class: Fluent::Plugin::S3Output::GzipCommandCompressor

Inherits:
Compressor
  • Object
show all
Defined in:
lib/fluent/plugin/s3_compressor_gzip_command.rb

Instance Attribute Summary

Attributes inherited from Compressor

#buffer_type, #log

Instance Method Summary collapse

Methods inherited from Compressor

#initialize

Constructor Details

This class inherits a constructor from Fluent::Plugin::S3Output::Compressor

Instance Method Details

#compress(chunk, tmp) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fluent/plugin/s3_compressor_gzip_command.rb', line 21

def compress(chunk, tmp)
  if @buffer_compressed_type == :gzip
    chunk.write_to(tmp, compressed: @buffer_compressed_type)
    return
  end

  chunk_is_file = @buffer_type == 'file'
  path = if chunk_is_file
           chunk.path
         else
           w = Tempfile.new("chunk-gzip-tmp")
           w.binmode
           chunk.write_to(w)
           w.close
           w.path
         end

  res = system "gzip #{@command_parameter} -c #{path} > #{tmp.path}"
  unless res
    log.warn "failed to execute gzip command. Fallback to GzipWriter. status = #{$?}"
    begin
      tmp.truncate(0)
      gw = Zlib::GzipWriter.new(tmp)
      chunk.write_to(gw)
      gw.close
    ensure
      gw.close rescue nil
    end
  end
ensure
  unless chunk_is_file
    w.close(true) rescue nil
  end
end

#configure(conf) ⇒ Object



8
9
10
11
# File 'lib/fluent/plugin/s3_compressor_gzip_command.rb', line 8

def configure(conf)
  super
  check_command('gzip')
end

#content_typeObject



17
18
19
# File 'lib/fluent/plugin/s3_compressor_gzip_command.rb', line 17

def content_type
  'application/x-gzip'.freeze
end

#extObject



13
14
15
# File 'lib/fluent/plugin/s3_compressor_gzip_command.rb', line 13

def ext
  'gz'.freeze
end