From c4062c3d4d073f01a75257c96bedfdae62209471 Mon Sep 17 00:00:00 2001 From: ddukbg Date: Sat, 2 Nov 2024 18:56:16 +0900 Subject: [PATCH] feat: Add compression level configuration to ZstdCompressor Signed-off-by: ddukbg --- lib/fluent/plugin/out_s3.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/fluent/plugin/out_s3.rb b/lib/fluent/plugin/out_s3.rb index 9149a0b..66da620 100644 --- a/lib/fluent/plugin/out_s3.rb +++ b/lib/fluent/plugin/out_s3.rb @@ -632,17 +632,25 @@ def compress(chunk, tmp) end class ZstdCompressor < Compressor + 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) + data = chunk.read + compressed_data = Zstd.compress(data, level: @level) tmp.write(compressed_data) + tmp.close rescue => e log.warn "zstd compression failed: #{e.message}" raise e