class ZipUtil

Public Class Methods

compress(*sources, destination) click to toggle source
# File lib/jenkins_util/zip_util.rb, line 19
def self.compress(*sources, destination)
  Zip::File.open(destination, ::Zip::File::CREATE) do |zip_archive|
    sources.each do |source|
      write_path_to_archive(zip_archive, source)
    end
  end
end
uncompress(source, destination) click to toggle source
# File lib/jenkins_util/zip_util.rb, line 27
def self.uncompress(source, destination)
  Zip::File.open(source) do |zip_file|
    zip_file.each do |entry|
      path = File.join(destination, entry.name)
      LoggerUtil.log.debug("Extracting #{path}")
      entry.extract(File.join(destination, entry.name))
    end
  end
end

Private Class Methods

write_directory_to_archive(zip_archive, disk_path) click to toggle source
# File lib/jenkins_util/zip_util.rb, line 52
def self.write_directory_to_archive(zip_archive, disk_path)
  zip_archive.mkdir disk_path
  entries = Dir.entries(disk_path) - %w(. ..)

  entries.each do |entry|
    write_path_to_archive(zip_archive, File.join(disk_path, entry))
  end
end
write_file_to_archive(zip_archive, disk_path) click to toggle source
# File lib/jenkins_util/zip_util.rb, line 61
def self.write_file_to_archive(zip_archive, disk_path)
  zip_archive.get_output_stream(disk_path) do |output_stream|
    output_stream.write(File.open(disk_path, 'rb').read)
  end
end
write_path_to_archive(zip_archive, disk_path) click to toggle source
# File lib/jenkins_util/zip_util.rb, line 37
def self.write_path_to_archive(zip_archive, disk_path)
  unless File.exist?(disk_path)
    LoggerUtil.log.error("Path does not exist: #{disk_path}")
    exit(-1)
  end

  LoggerUtil.log.debug("Archiving #{disk_path}")

  if File.directory?(disk_path)
    write_directory_to_archive(zip_archive, disk_path)
  else
    write_file_to_archive(zip_archive, disk_path)
  end
end