ZipUtils

Function module for compression methods.

Methods
compress tar_bzip tar_bzip2 tar_gzip tar_j tar_z tgz untar_bzip untar_bzip2 untar_gzip untar_j untar_z unzip zip
Classes and Modules
Module ZipUtils::DryRun
Module ZipUtils::NoWrite
Module ZipUtils::Verbose
Constants
COMPRESS_FORMAT = { 'tar.gz' => 'tar_gzip', 'tgz' => 'tar_gzip', 'tar.bz2' => 'tar_bzip', 'zip' => 'zip', '.tar.gz' => 'tar_gzip', '.tgz' => 'tar_gzip', '.tar.bz2' => 'tar_bzip', '.zip' => 'zip'
Public Instance methods
compress(format_extension, folder, file=nil, options={})

Compress based on given extension. Supported extensions are:

# File lib/more/facets/ziputils.rb, line 56
  def compress(format_extension, folder, file=nil, options={})
    format = COMPRESS_FORMAT[format_extension.to_s]
    if format
      send(format, folder, file, options)
    else
      raise ArgumentError, "unknown compression format -- #{format_extension}"
    end
  end
tar_bzip(folder, file=nil, options={})

Alias for tar_bzip2

tar_bzip2(folder, file=nil, options={})

Tar Bzip2

This method is also aliased as tar_bzip tar_j
# File lib/more/facets/ziputils.rb, line 103
  def tar_bzip2(folder, file=nil, options={})
    # name of file to create
    file ||= File.basename(File.expand_path(folder)) + '.tar.bz2'
    cmd = "tar --bzip2 -cf #{file} #{folder}"
    # display equivalent commandline
    if options[:verbose] or options[:dryrun]
      puts cmd
    end
    # create tar.bzip2 file
    unless options[:noop] or options[:dryrun]
      system cmd
    end
    return File.expand_path(file)
  end
tar_gzip(folder, file=nil, options={})

Tar Gzip

This method is also aliased as tar_z
# File lib/more/facets/ziputils.rb, line 67
  def tar_gzip(folder, file=nil, options={})
    require 'zlib'
    # name of file to create
    file ||= File.basename(File.expand_path(folder)) + '.tar.gz'
    cmd = "tar --gzip -czf #{file} #{folder}"
    # display equivalent commandline
    if options[:verbose] or options[:dryrun]
      puts cmd
    end
    # create tar.gzip file
    unless options[:noop] or options[:dryrun]
      gzIO = Zlib::GzipWriter.new(File.open(file, 'wb'))
      Archive::Tar::Minitar.pack(folder, gzIO)
    end
    return File.expand_path(file)
  end
tar_j(folder, file=nil, options={})

Alias for tar_bzip2

tar_z(folder, file=nil, options={})

Alias for tar_gzip

tgz(folder, file=nil, options={})
# File lib/more/facets/ziputils.rb, line 87
  def tgz(folder, file=nil, options={})
    file ||= File.basename(File.expand_path(folder)) + '.tgz'
    tar_gzip(folder, file, options)
  end
untar_bzip(file, options={})

Alias for untar_bzip2

untar_bzip2(file, options={})

Untar Bzip2

This method is also aliased as untar_bzip untar_j
# File lib/more/facets/ziputils.rb, line 122
  def untar_bzip2(file, options={})
    cmd = "tar --bzip2 -xf #{file}"
    # display equivalent commandline
    if options[:verbose] or options[:dryrun]
      puts cmd
    end
    # untar/bzip2 file
    unless options[:noop] or options[:dryrun]
      system cmd
    end
  end
untar_gzip(file, options={})

Untar Gzip

This method is also aliased as untar_z
# File lib/more/facets/ziputils.rb, line 94
  def untar_gzip(file, options={})
    require 'zlib'
    # TODO Write internalized untar_gzip function.

  end
untar_j(file, options={})

Alias for untar_bzip2

untar_z(file, options={})

Alias for untar_gzip

unzip(file, options={})

Unzip

# File lib/more/facets/ziputils.rb, line 156
  def unzip(file, options={})
    cmd = "unzip #{file}"
    # display equivalent commandline
    if options[:verbose] or options[:dryrun]
      puts cmd
    end
    # unzip file
    unless options[:noop] or options[:dryrun]
      system cmd
    end
  end
zip(folder, file=nil, options={})

Zip

# File lib/more/facets/ziputils.rb, line 138
  def zip(folder, file=nil, options={})
    raise ArgumentError if folder == '.*'
    # name of file to create
    file ||= File.basename(File.expand_path(folder)) + '.zip'
    cmd = "zip -rqu #{file} #{folder}"
    # display equivalent commandline
    if options[:verbose] or options[:dryrun]
      puts cmd
    end
    # create zip file
    unless options[:noop] or options[:dryrun]
      system cmd
    end
    return File.expand_path(file)
  end