Sha256: a67864bb07f3eaea86ae0bb0ad7de43b4c3ecd7e33e5b5d2a3934dac1d860825

Contents?: true

Size: 1.23 KB

Versions: 51

Compression:

Stored size: 1.23 KB

Contents

module Fluent::Plugin
  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")
                 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

51 entries across 51 versions & 3 rubygems

Version Path
fluent-plugin-s3-1.8.1 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.8.0 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.7.2 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.7.1 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.7.0 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.6.1 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.6.0 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.5.1 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.5.0 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-file-inclusion-1.4.1 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.4.0 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.3.4 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.3.3 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.3.2 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.3.1 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.3.0 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.2.1 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.2.0 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.1.11 lib/fluent/plugin/s3_compressor_gzip_command.rb
fluent-plugin-s3-1.1.10 lib/fluent/plugin/s3_compressor_gzip_command.rb