Sha256: 9f67487d3ff0bc77d1e18eec71cddc40c4d9d330ce8ace4d558209e5d447e17d
Contents?: true
Size: 1.48 KB
Versions: 207
Compression:
Stored size: 1.48 KB
Contents
module Sprout class ZipUtil #:nodoc: # Pack up an archive from a directory on disk def self.pack(input, archive, excludes) Zip::ZipFile.open(archive, Zip::ZipFile::CREATE) do |zip| add_file_to_zip(zip, input, excludes) end end # Unpack an archive to a directory on disk def self.unpack(archive, destination) Zip::ZipFile.open(archive) do |zip| unpack_file(zip, destination) end end def self.unpack_file(zip, destination, path='') if(zip.file.file?(path)) File.open(File.join(destination, path), 'w') do |dest| zip.file.open(path) do |src| dest.write src.read end end else Dir.mkdir(File.join(destination, path)) zip.dir.foreach(path) do |dir| unpack_file(zip, destination, File.join(path, dir)) end end end def self.add_file_to_zip(zip, path, excludes) if(File.directory?(path)) zip.dir.mkdir(path) Dir.open(path).each do |child| if(!excluded?(child, excludes)) add_file_to_zip(zip, File.join(path, child), excludes) end end else File.open(path) do |src| zip.file.open(path, 'w') do |dest| dest.write src.read end end end end def self.excluded?(str, excludes) excludes.each do |exc| if(str == exc) return true end end return false end end end
Version data entries
207 entries across 207 versions & 1 rubygems