Class: Fluent::GCS::GZipCommandObjectCreator

Inherits:
ObjectCreator show all
Defined in:
lib/fluent/plugin/gcs/object_creator.rb

Instance Method Summary collapse

Methods inherited from ObjectCreator

#create

Constructor Details

#initialize(transcoding:, command_parameter:, log:) ⇒ GZipCommandObjectCreator

Returns a new instance of GZipCommandObjectCreator.



77
78
79
80
81
82
# File 'lib/fluent/plugin/gcs/object_creator.rb', line 77

def initialize(transcoding:, command_parameter:, log:)
  @transcoding = transcoding
  @command_parameter = command_parameter || ""
  @log = log
  check_gzip_command
end

Instance Method Details

#content_encodingObject



88
89
90
# File 'lib/fluent/plugin/gcs/object_creator.rb', line 88

def content_encoding
  @transcoding ? "gzip" : nil
end

#content_typeObject



84
85
86
# File 'lib/fluent/plugin/gcs/object_creator.rb', line 84

def content_type
  @transcoding ? "text/plain" : "application/gzip"
end

#file_extensionObject



92
93
94
# File 'lib/fluent/plugin/gcs/object_creator.rb', line 92

def file_extension
  "gz"
end

#write(chunk, io) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/fluent/plugin/gcs/object_creator.rb', line 96

def write(chunk, io)
  cmd = ["gzip", *@command_parameter.shellsplit, "-c"]
  status = Open3.pipeline_w(cmd, out: io.path) do |stdin, wait_thrs|
    chunk.write_to(stdin)
    stdin.close
    wait_thrs.last.value
  end

  unless status.success?
    @log&.warn("failed to execute gzip command. Fallback to GzipWriter. status = #{status}")
    io.truncate(0)
    io.rewind
    fallback_to_gzip_writer(chunk, io)
  end
end