Skip to content

Commit 18023d6

Browse files
committed
Shell out to zcat to decompress s3 file stream
1 parent 164d757 commit 18023d6

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lib/logstash/inputs/s3/stream_downloader.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,30 @@ def self.fetcher(remote_file, logger)
2828

2929
class CompressedStreamDownloader < StreamDownloader
3030
def fetch
31-
original_file = super
31+
compressed_file_io_object = super
3232
@logger.debug("Decompressing gzip file", :remote_object_key => @remote_object.key)
33-
Zlib::GzipReader.new(original_file)
33+
decompress_io_object(compressed_file_io_object)
34+
end
35+
36+
private
37+
38+
def decompress_io_object(io_object)
39+
# Shelling out is necessary here until logstash-oss is using JRuby 9.4 which includes
40+
# the Zlib::GzipReader.zcat method
41+
output = ''
42+
IO.popen('zcat', 'r+') do |zcat|
43+
writer_thread = Thread.new do
44+
while chunk = io_object.read(65536)
45+
zcat.write(chunk)
46+
end
47+
zcat.close_write
48+
end
49+
50+
output = zcat.read
51+
writer_thread.join
52+
end
53+
54+
output
3455
end
3556
end
3657
end;end;end

0 commit comments

Comments
 (0)