Class: Fluent::Plugin::S3Input::GzipExtractor

Inherits:
Extractor
  • Object
show all
Defined in:
lib/fluent/plugin/in_s3.rb

Constant Summary

Constants inherited from Extractor

Extractor::BYTES_TO_READ

Instance Attribute Summary

Attributes inherited from Extractor

#log

Instance Method Summary collapse

Methods inherited from Extractor

#configure, #initialize

Constructor Details

This class inherits a constructor from Fluent::Plugin::S3Input::Extractor

Instance Method Details

#content_typeObject



496
497
498
# File 'lib/fluent/plugin/in_s3.rb', line 496

def content_type
  'application/x-gzip'.freeze
end

#extObject



492
493
494
# File 'lib/fluent/plugin/in_s3.rb', line 492

def ext
  'gz'.freeze
end

#extract(io) ⇒ Object



503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
# File 'lib/fluent/plugin/in_s3.rb', line 503

def extract(io)
  out = ''
  loop do
    unused = nil
    Zlib::GzipReader.wrap(io) do |gz|
      while (chunk = gz.read(BYTES_TO_READ))
        out << chunk
        if out.bytesize > @decompression_size_limit
          raise SizeLimitError, "Extracted data exceeds limit of #{@decompression_size_limit} bytes"
        end
      end
      unused = gz.unused
      gz.finish
    end
    io.pos -= unused ? unused.length : 0
    break if io.eof?
  end
  out
ensure
  io.close unless io.closed?
end