Module: Fluent::Plugin::Compressable

Included in:
EventStream, Buffer::Chunk::Decompressable
Defined in:
lib/fluent/plugin/compressable.rb

Instance Method Summary collapse

Instance Method Details

#compress(data, **kwargs) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/fluent/plugin/compressable.rb', line 23

def compress(data, **kwargs)
  output_io = kwargs[:output_io]
  io = output_io || StringIO.new
  Zlib::GzipWriter.wrap(io) do |gz|
    gz.write data
  end

  output_io || io.string
end

#decompress(compressed_data = nil, output_io: nil, input_io: nil) ⇒ Object

compressed_data is String like ‘compress(data1) + compress(data2) + … + compress(dataN)` www.ruby-forum.com/topic/971591#979503



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fluent/plugin/compressable.rb', line 35

def decompress(compressed_data = nil, output_io: nil, input_io: nil)
  case
  when input_io && output_io
    io_decompress(input_io, output_io)
  when input_io
    output_io = StringIO.new
    io = io_decompress(input_io, output_io)
    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)
  else
    string_decompress(compressed_data)
  end
end