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::DryRunModule 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
[ + ]
# 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
Alias for tar_bzip2
Tar Bzip2
[ + ]
# 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
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
Alias for tar_bzip2
Alias for tar_gzip
[ + ]
# 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
Alias for untar_bzip2
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
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
Alias for untar_bzip2
Alias for untar_gzip
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
[ + ]
# 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