Class: IOStreams::Gzip::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/io_streams/gzip/reader.rb

Class Method Summary collapse

Class Method Details

.open(file_name_or_io, **args, &block) ⇒ Object

Read from a gzip file or stream, decompressing the contents as it is read



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/io_streams/gzip/reader.rb', line 5

def self.open(file_name_or_io, **args, &block)
  unless IOStreams.reader_stream?(file_name_or_io)
    ::Zlib::GzipReader.open(file_name_or_io, &block)
  else
    begin
      io = ::Zlib::GzipReader.new(file_name_or_io)
      block.call(io)
    ensure
      io.close if io && (io.respond_to?(:closed?) && !io.closed?)
    end
  end
end