R
Robert Klemme
Hi,
does anybody else think this (or something similar) would be a useful
extension to zlib?
file zliba.rb:
require 'zlib'
# Conveniently process a number of files that may
# be a mixture of gzip compressed and uncompressed
# files.
ARGFZ = Class.new do
include Enumerable
def each(&b)
::ARGV.each do |arg|
if arg == "-"
$stdin.each(&b)
else
io = ::Zlib::GzipReader.open(arg) rescue ::File.open(arg)
begin
io.each(&b)
ensure
io.close
end
end
end
self
end
# addional methods for gets etc. could be added
# but seeking is too hard to be possible
end.new
Example usage, file catz.rb:
#!/bin/env ruby
require 'zliba' # this would be 'zlib' once this is integrated
ARGFZ.each do |line|
puts line
end
Then on shell prompt:
catz.rb foo foo.gz
Will print all lines from foo and then from foo.gz.
Kind regards
robert
does anybody else think this (or something similar) would be a useful
extension to zlib?
file zliba.rb:
require 'zlib'
# Conveniently process a number of files that may
# be a mixture of gzip compressed and uncompressed
# files.
ARGFZ = Class.new do
include Enumerable
def each(&b)
::ARGV.each do |arg|
if arg == "-"
$stdin.each(&b)
else
io = ::Zlib::GzipReader.open(arg) rescue ::File.open(arg)
begin
io.each(&b)
ensure
io.close
end
end
end
self
end
# addional methods for gets etc. could be added
# but seeking is too hard to be possible
end.new
Example usage, file catz.rb:
#!/bin/env ruby
require 'zliba' # this would be 'zlib' once this is integrated
ARGFZ.each do |line|
puts line
end
Then on shell prompt:
catz.rb foo foo.gz
Will print all lines from foo and then from foo.gz.
Kind regards
robert