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



449
450
451
# File 'lib/fluent/plugin/in_s3.rb', line 449

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

#extObject



445
446
447
# File 'lib/fluent/plugin/in_s3.rb', line 445

def ext
  'gz'.freeze
end

#extract(io) ⇒ Object



456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
# File 'lib/fluent/plugin/in_s3.rb', line 456

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