Sha256: 15c1613c45ac191d8ce49191b071da6930375702b3d4bb5cf5861fdb19edd76a

Contents?: true

Size: 1.25 KB

Versions: 18

Compression:

Stored size: 1.25 KB

Contents

module Fluent
  class AzureStorageGen2Output
    class GzipCommandCompressor < Compressor
      AzureStorageGen2Output.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

18 entries across 18 versions & 1 rubygems

Version Path
fluent-plugin-azurestorage-gen2-0.3.9 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.3.8 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.3.7 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.3.5 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.3.4 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.3.3 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.3.2 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.3.1 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.3.0 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.2.10 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.2.9 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.2.8 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.2.7 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.2.6 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.2.5 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.2.4 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.2.3 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb
fluent-plugin-azurestorage-gen2-0.2.2 lib/fluent/plugin/azurestorage_gen2_compressor_gzip_command.rb