Class: Inspec::Archive::TarArchiveGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/archive/tar.rb

Instance Method Summary collapse

Instance Method Details

#archive(base_dir, files, archive) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/inspec/archive/tar.rb', line 5

def archive(base_dir, files, archive)
  File.open(archive, "wb") do |file|
    Zlib::GzipWriter.wrap(file) do |gz|
      Gem::Package::TarWriter.new(gz) do |tar|
        files.each do |input_filename|
          path = Pathname.new(base_dir).join(input_filename)
          stat = File.stat(path)
          if path.directory?
            tar.mkdir(input_filename, stat.mode)
          else
            tar.add_file_simple(input_filename, stat.mode, stat.size) do |io|
              io.write(File.binread(path))
            end
          end
        end
      end
    end
  end
end