Module: ZipUtils
- Defined in:
- lib/more/facets/ziputils.rb
Overview
Function module for compression methods.
Note: This used to be extensions to FileUtils.
Defined Under Namespace
Modules: DryRun, NoWrite, Verbose
Constant Summary collapse
- 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' }
Class Method Summary collapse
-
.compress(format_extension, folder, file = nil, options = {}) ⇒ Object
Compress based on given extension.
-
.tar_bzip2(folder, file = nil, options = {}) ⇒ Object
(also: tar_bzip, tar_j)
Tar Bzip2.
-
.tar_gzip(folder, file = nil, options = {}) ⇒ Object
(also: tar_z)
Tar Gzip.
-
.untar_bzip2(file, options = {}) ⇒ Object
(also: untar_bzip, untar_j)
Untar Bzip2.
-
.untar_gzip(file, options = {}) ⇒ Object
(also: untar_z)
Untar Gzip.
-
.unzip(file, options = {}) ⇒ Object
Unzip.
-
.zip(folder, file = nil, options = {}) ⇒ Object
Zip.
Class Method Details
.compress(format_extension, folder, file = nil, options = {}) ⇒ Object
Compress based on given extension. Supported extensions are:
-
tar.gz
-
tgz
-
tar.bz2
-
zip
64 65 66 67 68 69 70 71 |
# File 'lib/more/facets/ziputils.rb', line 64 def compress(format_extension, folder, file=nil, ={}) format = COMPRESS_FORMAT[format_extension.to_s] if format send(format, folder, file, ) else raise ArgumentError, "unknown compression format -- #{format_extension}" end end |
.tar_bzip2(folder, file = nil, options = {}) ⇒ Object Also known as: tar_bzip, tar_j
Tar Bzip2
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/more/facets/ziputils.rb', line 104 def tar_bzip2(folder, file=nil, ={}) # name of file to create file ||= File.basename(File.(folder)) + '.tar.bz2' cmd = "tar --bzip2 -cf #{file} #{folder}" # display equivalent commandline if [:verbose] or [:dryrun] puts cmd end # create tar.bzip2 file unless [:noop] or [:dryrun] system cmd end return File.(file) end |
.tar_gzip(folder, file = nil, options = {}) ⇒ Object Also known as: tar_z
Tar Gzip
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/more/facets/ziputils.rb', line 75 def tar_gzip(folder, file=nil, ={}) require 'zlib' # name of file to create file ||= File.basename(File.(folder)) + '.tar.gz' cmd = "tar --gzip -czf #{file} #{folder}" # display equivalent commandline if [:verbose] or [:dryrun] puts cmd end # create tar.gzip file unless [:noop] or [:dryrun] gzIO = Zlib::GzipWriter.new(File.open(file, 'wb')) Archive::Tar::Minitar.pack(folder, gzIO) end return File.(file) end |
.untar_bzip2(file, options = {}) ⇒ Object Also known as: untar_bzip, untar_j
Untar Bzip2
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/more/facets/ziputils.rb', line 123 def untar_bzip2(file, ={}) cmd = "tar --bzip2 -xf #{file}" # display equivalent commandline if [:verbose] or [:dryrun] puts cmd end # untar/bzip2 file unless [:noop] or [:dryrun] system cmd end end |
.untar_gzip(file, options = {}) ⇒ Object Also known as: untar_z
Untar Gzip
95 96 97 98 99 |
# File 'lib/more/facets/ziputils.rb', line 95 def untar_gzip(file, ={}) require 'zlib' # TODO Write internalized untar_gzip function. end |
.unzip(file, options = {}) ⇒ Object
Unzip
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/more/facets/ziputils.rb', line 157 def unzip(file, ={}) cmd = "unzip #{file}" # display equivalent commandline if [:verbose] or [:dryrun] puts cmd end # unzip file unless [:noop] or [:dryrun] system cmd end end |
.zip(folder, file = nil, options = {}) ⇒ Object
Zip
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/more/facets/ziputils.rb', line 139 def zip(folder, file=nil, ={}) raise ArgumentError if folder == '.*' # name of file to create file ||= File.basename(File.(folder)) + '.zip' cmd = "zip -rqu #{file} #{folder}" # display equivalent commandline if [:verbose] or [:dryrun] puts cmd end # create zip file unless [:noop] or [:dryrun] system cmd end return File.(file) end |