Module: Fluent::Plugin::Compressable
- Defined in:
- lib/fluent/plugin/compressable.rb
Instance Method Summary collapse
- #compress(data, type: :gzip, **kwargs) ⇒ Object
-
#decompress(compressed_data = nil, output_io: nil, input_io: nil, type: :gzip) ⇒ Object
compressed_data is String like ‘compress(data1) + compress(data2) + …
Instance Method Details
#compress(data, type: :gzip, **kwargs) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fluent/plugin/compressable.rb', line 24 def compress(data, type: :gzip, **kwargs) output_io = kwargs[:output_io] io = output_io || StringIO.new if type == :gzip writer = Zlib::GzipWriter.new(io) elsif type == :zstd writer = Zstd::StreamWriter.new(io) else raise ArgumentError, "Unknown compression type: #{type}" end writer.write(data) writer.finish output_io || io.string end |
#decompress(compressed_data = nil, output_io: nil, input_io: nil, type: :gzip) ⇒ Object
compressed_data is String like ‘compress(data1) + compress(data2) + … + compress(dataN)` www.ruby-forum.com/topic/971591#979503
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fluent/plugin/compressable.rb', line 41 def decompress(compressed_data = nil, output_io: nil, input_io: nil, type: :gzip) case when input_io && output_io io_decompress(input_io, output_io, type) when input_io output_io = StringIO.new io = io_decompress(input_io, output_io, type) io.string when compressed_data.nil? || compressed_data.empty? # check compressed_data(String) is 0 length compressed_data when output_io # execute after checking compressed_data is empty or not io = StringIO.new(compressed_data) io_decompress(io, output_io, type) else string_decompress(compressed_data, type) end end |