Sha256: 4f290d3edd55b47459c104f1da6c9d0c03ba1b626e5097306ee77f63685e8464
Contents?: true
Size: 574 Bytes
Versions: 1
Compression:
Stored size: 574 Bytes
Contents
require 'zlib' # # A mutation of "open" that lets you read/write gzip files, as well as # regular files. (NOTE: gzip detection is purely based on filename.) # def zopen(filename, mode="r") file = open(filename, mode) if filename =~ /\.gz$/ case mode when "r" file = Zlib::GzipReader.new(file) when "w" file = Zlib::GzipWriter.new(file) else raise "Unknown mode: #{mode.inspect}. zopen only supports 'r' and 'w'." end end if block_given? result = yield(file) file.close result else file end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
epitools-0.1.4 | lib/epitools/zopen.rb |