-
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.
Merge pull request #1 from ddukbg/feature/zst-compression
feat: Add Zstd compression support for S3 plugin Signed-off-by: ddukbg <[email protected]>
- Loading branch information
Showing
4 changed files
with
64 additions
and
1 deletion.
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
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,37 @@ | ||
require 'zstd-ruby' | ||
|
||
module Fluent::Plugin | ||
class S3Output | ||
class ZstdCompressor < Compressor | ||
S3Output.register_compressor('zstd', self) | ||
|
||
config_param :level, :integer, default: 3, desc: "Compression level for zstd (1-22)" | ||
|
||
def initialize(opts = {}) | ||
super() | ||
@buffer_type = opts[:buffer_type] | ||
@log = opts[:log] | ||
end | ||
|
||
def ext | ||
'zst'.freeze | ||
end | ||
|
||
def content_type | ||
'application/x-zstd'.freeze | ||
end | ||
|
||
def compress(chunk, tmp) | ||
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}" | ||
raise e | ||
end | ||
end | ||
end | ||
end |
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