Module: Ratch::TarUtils

Defined in:
lib/ratch/utils/tar.rb

Overview

Utility methods for working with tarballs archives. – TODO: Add compress support ? TODO: Add bzip support ? ++

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



20
21
22
# File 'lib/ratch/utils/tar.rb', line 20

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

.included(base) ⇒ Object

When included include GZipUtils too.



13
14
15
16
17
# File 'lib/ratch/utils/tar.rb', line 13

def self.included(base)
  #require 'zlib'
  include ZLibUtils
  require 'archive/tar/minitar'
end

Instance Method Details

#tar(folder, file = nil, options = {}) ⇒ Object

Tar



25
26
27
28
29
30
31
32
33
34
35
36
37
# 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 = {}) ⇒ Object Also known as: tar_z

Tar Gzip



55
56
57
58
59
60
61
62
63
64
65
66
67
# 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

#untar(file, options = {}) ⇒ Object

Untar



40
41
42
43
44
45
46
47
48
49
50
51
52
# 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 = {}) ⇒ Object Also known as: untar_z

Untar Gzip

FIXME: Write unified untar_gzip function.



74
75
76
# File 'lib/ratch/utils/tar.rb', line 74

def untar_gzip(file, options={})
  untar(ungzip(file, options), options)
end