lib/io_streams/gzip/reader.rb in iostreams-0.20.3 vs lib/io_streams/gzip/reader.rb in iostreams-1.0.0.beta
- old
+ new
@@ -1,20 +1,13 @@
module IOStreams
module Gzip
- class Reader
- # Read from a gzip file or stream, decompressing the contents as it is read
- 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
+ class Reader < IOStreams::Reader
+ # Read from a gzip stream, decompressing the contents as it is read
+ def self.stream(input_stream, original_file_name: nil, &block)
+ io = ::Zlib::GzipReader.new(input_stream)
+ block.call(io)
+ ensure
+ io&.close
end
-
end
end
end