Sha256: cfad97b8258859a6c07f5bade1cc7f8007c649eb05c7b620085d2269bf35d5dc
Contents?: true
Size: 1.79 KB
Versions: 3
Compression:
Stored size: 1.79 KB
Contents
module Pione module Util module Zip class << self # Create a zip archive of the location. # # @param src [DataLocation] # the source directory location # @param archive [DataLocation] # the archive location def compress(src, archive) # src should be a directory raise ArgumentError.new(src) unless src.directory? # make local path _src = src.local _archive = Location[Temppath.create] # compress ::Zip::File.open(_archive.path.to_s, ::Zip::File::CREATE) do |zip| _src.rel_entries(rec: true).each do |relpath| relpath = relpath.to_s location = _src + relpath if location.directory? zip.mkdir(relpath) else entry = zip.add(relpath, location.path.to_s) entry.time = ::Zip::DOSTime.at(location.mtime) entry.extra.delete("UniversalTime") end end end # upload archive _archive.move(archive) end # Expand the archive into the destination directory. # # @param archive [DataLocation] # the archive location # @param dest [DataLocation] # the destination directory location def uncompress(archive, dest) _archive = archive.local ::Zip::File.open(_archive.path.to_s) do |zip| zip.each do |entry| if entry.directory? (dest + entry.name).mkdir else tmp = Temppath.create entry.extract(tmp) Location[tmp].move(dest + entry.name) end end end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
pione-0.3.2 | lib/pione/util/zip.rb |
pione-0.3.1 | lib/pione/util/zip.rb |
pione-0.3.0 | lib/pione/util/zip.rb |