lib/io_streams/gzip/writer.rb in iostreams-0.20.3 vs lib/io_streams/gzip/writer.rb in iostreams-1.0.0.beta
- old
+ new
@@ -1,21 +1,13 @@
module IOStreams
module Gzip
- class Writer
- # Write to a file / stream, compressing with GZip
- def self.open(file_name_or_io, **args, &block)
- unless IOStreams.writer_stream?(file_name_or_io)
- IOStreams::File::Path.mkpath(file_name_or_io)
- Zlib::GzipWriter.open(file_name_or_io, &block)
- else
- begin
- io = Zlib::GzipWriter.new(file_name_or_io)
- block.call(io)
- ensure
- io.close if io && (io.respond_to?(:closed?) && !io.closed?)
- end
- end
+ class Writer < IOStreams::Writer
+ # Write to a stream, compressing with GZip
+ def self.stream(input_stream, original_file_name: nil, &block)
+ io = ::Zlib::GzipWriter.new(input_stream)
+ block.call(io)
+ ensure
+ io&.close
end
-
end
end
end