Sha256: 582365434176919940eda783653efb33df1bdd87edad4791afde65ca5c895248
Contents?: true
Size: 1.25 KB
Versions: 15
Compression:
Stored size: 1.25 KB
Contents
require 'zip' module TerraformDevKit class ZipFileGenerator def initialize(input_dir, output_file) @input_dir = input_dir @output_file = output_file end def write entries = Dir.entries(@input_dir) entries.delete('.') entries.delete('..') Zip::File.open(@output_file, Zip::File::CREATE) do |zipfile| write_entries(entries, '', zipfile) end end private def write_entries(entries, path, zipfile) entries.each do |e| zip_file_path = path == '' ? e : File.join(path, e) disk_file_path = File.join(@input_dir, zip_file_path) if File.directory?(disk_file_path) write_directory(disk_file_path, zip_file_path, zipfile) else write_file(disk_file_path, zip_file_path, zipfile) end end end def write_directory(disk_file_path, zip_file_path, zipfile) zipfile.mkdir(zip_file_path) subdir = Dir.entries(disk_file_path) subdir.delete('.') subdir.delete('..') write_entries(subdir, zip_file_path, zipfile) end def write_file(disk_file_path, zip_file_path, zipfile) zipfile.get_output_stream(zip_file_path) do |f| f.puts(File.open(disk_file_path, 'rb').read) end end end end
Version data entries
15 entries across 15 versions & 1 rubygems