Class: Threatinator::Decoders::Gzip

Inherits:
Threatinator::Decoder show all
Defined in:
lib/threatinator/decoders/gzip.rb

Instance Attribute Summary

Attributes inherited from Threatinator::Decoder

#encoding

Instance Method Summary collapse

Methods inherited from Threatinator::Decoder

#initialize

Constructor Details

This class inherits a constructor from Threatinator::Decoder

Instance Method Details

#decode(io) ⇒ Object

Decompresses the io using Gzip.

Parameters:

  • io (IO)

    The IO to decode



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/threatinator/decoders/gzip.rb', line 12

def decode(io)
  zio = Zlib::GzipReader.new(io, encoding: "binary")
  tempfile = Tempfile.new("threatinator", encoding: "binary")
  while chunk = zio.read(10240)
    tempfile.write(chunk)
  end
  
  zio.close
  io.close unless io.closed?
  tempfile.rewind
  tempfile.set_encoding(self.encoding)
  tempfile
rescue Zlib::GzipFile::Error => e
  raise Threatinator::Exceptions::DecoderError.new
end