Sha256: 87c180a2b2ffbb89711dee875d09145ad2c07066b3a05713379d6e73c6a77707

Contents?: true

Size: 1.23 KB

Versions: 6

Compression:

Stored size: 1.23 KB

Contents

module Fluent
  class S3Output
    class GzipCommandCompressor < Compressor
      S3Output.register_compressor('gzip_command', self)

      config_param :command_parameter, :string, :default => ''

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

      def ext
        'gz'.freeze
      end

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

      def compress(chunk, tmp)
        chunk_is_file = @buffer_type == 'file'
        path = if chunk_is_file
                 chunk.path
               else
                 w = Tempfile.new("chunk-gzip-tmp", @tmp_dir)
                 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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fluent-plugin-s3-0.8.8 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-0.8.7 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-0.8.6 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-0.8.5 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-0.8.4 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-0.8.3 lib/fluent/plugin/s3_compressor_gzip_command.rb