Module: ZipTarGz

Defined in:
lib/build/zip_tar_gz.rb

Class Method Summary collapse

Class Method Details

.pack_tar_gz(tar_gz_file, base_dir, entries) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/build/zip_tar_gz.rb', line 23

def self.pack_tar_gz(tar_gz_file, base_dir, entries)
  write_tar_gz(tar_gz_file) do |tar|
    list_files(base_dir, entries).each do |file|
      path = File.join(base_dir, file)
      stat = File.stat(path)

      tar.add_file_simple(file, stat.mode, stat.size) do |tar_file|
        open(path, 'rb') do |file|
          copy(file, tar_file)
        end
      end
    end
  end
end

.pack_zip(zip_file, base_dir, entries) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/build/zip_tar_gz.rb', line 8

def self.pack_zip(zip_file, base_dir, entries)
  require 'zip'
  Zip::File.open(zip_file, Zip::File::CREATE) do |zip|
    list_files(base_dir, entries).each do |file|
      path = File.join(base_dir, file)

      zip.get_output_stream(file) do |zip_file|
        open(path, 'rb') do |file|
          copy(file, zip_file)
        end
      end
    end
  end
end

.unpack_tar_gz(tar_gz_file, base_dir) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/build/zip_tar_gz.rb', line 38

def self.unpack_tar_gz(tar_gz_file, base_dir)
  read_tar_gz(tar_gz_file) do |entry|
    path = File.join(base_dir, entry.full_name)

    FileUtils.rm_rf(path)

    FileUtils.mkdir_p(File.dirname(path))

    if entry.file?
      open(path, 'wb', entry.header.mode) do |out|
        copy(entry, out)
      end
    end
  end
end