Sha256: f988b4bb023ac6f135261d543c1f620de3804b6522f46af183c29e25b95921fa

Contents?: true

Size: 974 Bytes

Versions: 1

Compression:

Stored size: 974 Bytes

Contents

module Ratch

  #
  module ZlibUtils

    #
    def self.included(base)
      require 'zlib'
    end

    def self.extended(base)
      included(base)
    end

    # Create a gzip file.
    def gzip(file, tofile=nil, options={})
      noop, verbose = *util_options(options)

      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

    # Unpack a gzip file.
    def ungzip(file, options={})
      noop, verbose = *util_options(options)

      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

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ratch-1.2.0 lib/ratch/utils/zlib.rb