Skip to content

Commit

Permalink
Shell out to zcat to decompress s3 file stream
Browse files Browse the repository at this point in the history
  • Loading branch information
eherot committed Feb 6, 2024
1 parent 164d757 commit 18023d6
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/logstash/inputs/s3/stream_downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,30 @@ def self.fetcher(remote_file, logger)

class CompressedStreamDownloader < StreamDownloader
def fetch
original_file = super
compressed_file_io_object = super
@logger.debug("Decompressing gzip file", :remote_object_key => @remote_object.key)
Zlib::GzipReader.new(original_file)
decompress_io_object(compressed_file_io_object)
end

private

def decompress_io_object(io_object)
# Shelling out is necessary here until logstash-oss is using JRuby 9.4 which includes
# the Zlib::GzipReader.zcat method
output = ''
IO.popen('zcat', 'r+') do |zcat|
writer_thread = Thread.new do
while chunk = io_object.read(65536)
zcat.write(chunk)
end
zcat.close_write
end

output = zcat.read
writer_thread.join
end

output
end
end
end;end;end

0 comments on commit 18023d6

Please sign in to comment.