diff --git a/lib/fluent/plugin/out_s3.rb b/lib/fluent/plugin/out_s3.rb index 9149a0b..2c4e06a 100644 --- a/lib/fluent/plugin/out_s3.rb +++ b/lib/fluent/plugin/out_s3.rb @@ -632,16 +632,24 @@ def compress(chunk, tmp) end class ZstdCompressor < Compressor + def initialize(level = 3) + @level = level + end + def ext 'zst'.freeze end - + def content_type 'application/x-zst'.freeze end - + def compress(chunk, tmp) - compressed_data = Zstd.compress(chunk.read, level: @level) + uncompressed_data = '' + chunk.open do |io| + uncompressed_data = io.read + end + compressed_data = Zstd.compress(uncompressed_data, level: @level) tmp.write(compressed_data) rescue => e log.warn "zstd compression failed: #{e.message}"