-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Improve ZSTD compression implementation - Remove unnecessary lin…
…e ending and encoding handling - Fix compression logic using chunk.write_to method - Properly implement ZstdCompressor in separate file The previous implementation mistakenly included explicit line ending and encoding handling during troubleshooting. This has been removed as the proper implementation using chunk.write_to handles the data correctly without such manipulation. Signed-off-by: ddukbg <[email protected]> Signed-off-by: ddukbg <[email protected]>
- Loading branch information
Showing
2 changed files
with
37 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'zstd-ruby' | ||
|
||
module Fluent::Plugin | ||
class S3Output | ||
class ZstdCompressor < Compressor | ||
S3Output.register_compressor('zstd', self) | ||
|
||
config_section :compress, param_name: :compress_config, init: true, multi: false do | ||
desc "Compression level for zstd (1-22)" | ||
config_param :level, :integer, default: 3 | ||
end | ||
|
||
def ext | ||
'zst'.freeze | ||
end | ||
|
||
def content_type | ||
'application/x-zst'.freeze | ||
end | ||
|
||
def compress(chunk, tmp) | ||
w = StringIO.new | ||
chunk.write_to(w) | ||
w.rewind | ||
compressed = Zstd.compress(w.read, level: @compress_config.level) | ||
tmp.binmode | ||
tmp.rewind | ||
tmp.write(compressed) | ||
tmp.rewind | ||
rescue => e | ||
log.warn "zstd compression failed: #{e.message}" | ||
raise | ||
end | ||
end | ||
end | ||
end |