From 85e0f500b22ca38791af59bd96f29e255d39ed83 Mon Sep 17 00:00:00 2001 From: ddukbg Date: Sat, 2 Nov 2024 19:38:12 +0900 Subject: [PATCH] fix: Improve ZstdCompressor implementation Signed-off-by: ddukbg --- lib/fluent/plugin/out_s3.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/fluent/plugin/out_s3.rb b/lib/fluent/plugin/out_s3.rb index 9149a0b..92d5aa6 100644 --- a/lib/fluent/plugin/out_s3.rb +++ b/lib/fluent/plugin/out_s3.rb @@ -632,17 +632,26 @@ def compress(chunk, tmp) end class ZstdCompressor < Compressor + require 'zstd-ruby' + + DEFAULT_LEVEL = 3 + + def initialize(level = nil) + @level = level || DEFAULT_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) - tmp.write(compressed_data) + data = chunk.read + compressed = Zstd.compress(data, level: @level) + tmp.write(compressed) rescue => e log.warn "zstd compression failed: #{e.message}" raise e