Module: Ratch::ZlibUtils
- Defined in:
- lib/ratch/utils/zlib.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#gzip(file, tofile = nil, options = {}) ⇒ Object
Create a gzip file.
-
#ungzip(file, options = {}) ⇒ Object
Unpack a gzip file.
Class Method Details
.extended(base) ⇒ Object
11 12 13 |
# File 'lib/ratch/utils/zlib.rb', line 11 def self.extended(base) included(base) end |
.included(base) ⇒ Object
7 8 9 |
# File 'lib/ratch/utils/zlib.rb', line 7 def self.included(base) require 'zlib' end |
Instance Method Details
#gzip(file, tofile = nil, options = {}) ⇒ Object
Create a gzip file.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ratch/utils/zlib.rb', line 16 def gzip(file, tofile=nil, ={}) noop, verbose = *() tofile ||= File.basename(file) + '.gz' puts "gzip #{file}" if verbose file = localize(file) tofile = localize(tofile) Zlib::GzipWriter.open(tofile) do |gz| gz.write(File.read(file)) end unless noop return tofile end |
#ungzip(file, options = {}) ⇒ Object
Unpack a gzip file.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ratch/utils/zlib.rb', line 34 def ungzip(file, ={}) noop, verbose = *() fname = File.basename(file).chomp(File.extname(file)) puts "ungzip #{file}" if verbose fname = localize(fname) file = localize(file) Zlib::GzipReader.open(file) do |gz| File.open(fname, 'wb'){ |f| f << gz.read } end unless noop return fname end |