Class: Fluent::Plugin::S3Input::GzipCommandExtractor

Inherits:
Extractor
  • Object
show all
Defined in:
lib/fluent/plugin/s3_extractor_gzip_command.rb

Instance Attribute Summary

Attributes inherited from Extractor

#log

Instance Method Summary collapse

Methods inherited from Extractor

#initialize

Constructor Details

This class inherits a constructor from Fluent::Plugin::S3Input::Extractor

Instance Method Details

#configure(conf) ⇒ Object



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

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

#content_typeObject



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

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

#extObject



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

def ext
  'gz'.freeze
end

#extract(io) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fluent/plugin/s3_extractor_gzip_command.rb', line 21

def extract(io)
  path = if io.respond_to?(:path)
           io.path
         else
           temp = Tempfile.new("gzip-temp")
           temp.write(io.read)
           temp.close
           temp.path
         end

  stdout, succeeded = Open3.capture2("gzip #{@command_parameter} #{path}")
  if succeeded
    stdout
  else
    log.warn "failed to execute gzip command. Fallback to GzipReader. status = #{succeeded}"
    begin
      io.rewind
      Zlib::GzipReader.wrap(io) do |gz|
        gz.read
      end
    end
  end
end