module Ratch::TarUtils

Utility methods for working with tarballs archives.

Public Class Methods

extended(base) click to toggle source
# File lib/ratch/utils/tar.rb, line 20
def self.extended(base)
  included(base)
end
included(base) click to toggle source

When included include GZipUtils too.

# File lib/ratch/utils/tar.rb, line 13
def self.included(base)
  #require 'zlib'
  include ZLibUtils
  require 'archive/tar/minitar'
end

Public Instance Methods

tar(folder, file=nil, options={}) click to toggle source

Tar

# File lib/ratch/utils/tar.rb, line 25
def tar(folder, file=nil, options={})
  noop, verbose = *util_options(options)
  file ||= File.basename(File.expand_path(folder)) + '.tar'
  cmd = "tar -cf #{file} #{folder}"
  puts cmd if verbose
  unless noop
    locally do
      gzIO = File.open(file, 'wb')
      Archive::Tar::Minitar.pack(folder, gzIO)
    end
  end
  path(file)
end
tar_gzip(folder, file=nil, options={}) click to toggle source

Tar Gzip

# File lib/ratch/utils/tar.rb, line 55
def tar_gzip(folder, file=nil, options={})
  noop, verbose = *util_options(options)
  file ||= File.basename(File.expand_path(folder)) + '.tar.gz' # '.tgz' which ?
  cmd = "tar --gzip -czf #{file} #{folder}"
  puts cmd if verbose
  unless noop
    locally do #folder, file = localize(folder), localize(file)
      gzIO = Zlib::GzipWriter.new(File.open(file, 'wb'))
      Archive::Tar::Minitar.pack(folder, gzIO)
    end
  end
  path(file)
end
Also aliased as: tar_z
tar_z(folder, file=nil, options={})
Alias for: tar_gzip
untar(file, options={}) click to toggle source

Untar

# File lib/ratch/utils/tar.rb, line 40
def untar(file, options={})
  noop, verbose = *util_options(options)
  #file ||= File.basename(File.expand_path(folder)) + '.tar'
  cmd = "untar #{file}"
  puts cmd if verbose
  unless noop
    locally do
      gzIO = File.open(file, 'wb')
      Archive::Tar::Minitar.unpack(gzIO)
    end
  end
  path(file)
end
untar_gzip(file, options={}) click to toggle source

Untar Gzip

FIXME: Write unified untar_gzip function.

# File lib/ratch/utils/tar.rb, line 74
def untar_gzip(file, options={})
  untar(ungzip(file, options), options)
end
Also aliased as: untar_z
untar_z(file, options={})
Alias for: untar_gzip