Module: IMW::Archives::Targz

Includes:
Base, CompressedFiles::Base
Defined in:
lib/imw/archives/targz.rb

Instance Method Summary collapse

Methods included from Base

#append, #contents, #extract, #is_archive?

Methods included from CompressedFiles::Base

#decompress, #decompress!, #decompressed_path, #is_compressed?, #is_compressible?

Instance Method Details

#archive_settingsObject



26
27
28
29
30
31
32
33
# File 'lib/imw/archives/targz.rb', line 26

def archive_settings
  @archive_settings ||= {
    :program               => :tar,        
    :list                  => "-tzf",
    :create                => '-cf',            
    :extract               => "-xzf"
  }
end

#compression_settingsObject



11
12
13
14
15
16
17
18
# File 'lib/imw/archives/targz.rb', line 11

def compression_settings
  @compression_settings ||= {
    :program               => :gzip,
    :decompression_program => :gunzip,
    :decompress            => '',
    :extension             => 'gz'
  }
end

#create(*input_paths) ⇒ Object

Overrides default behvaior of IMW::Files::Archive#create to compress files after creating them.



37
38
39
40
41
42
# File 'lib/imw/archives/targz.rb', line 37

def create *input_paths
  IMW.system(archive_settings[:program], archive_settings[:create].split, path_between_archive_and_compression, *input_paths.flatten)
  tar = IMW.open(path_between_archive_and_compression)
  tar.compression_settings = compression_settings
  tar.compress!
end

#decompressed_basenameObject



44
45
46
47
48
49
50
# File 'lib/imw/archives/targz.rb', line 44

def decompressed_basename
  case extname
  when '.tar.gz' then basename[0..-4]              # .tar.gz => .tar
  when '.tgz'    then basename.gsub(/tgz$/, 'tar') # .tgz    => .tar
  else                basename[0..-(extname.size + 1)]
  end
end

#extnameObject

It’s both an archive and a compressed file!



62
63
64
65
66
67
68
# File 'lib/imw/archives/targz.rb', line 62

def extname
  case path
  when /\.tar\.gz$/ then '.tar.gz'
  when /\.tgz$/     then '.tgz'
  else              File.extname(path)
  end
end