module Akabei::ArchiveUtils
Constants
- BUFSIZ
Public Instance Methods
archive_all(src, dest, comp, format)
click to toggle source
# File lib/akabei/archive_utils.rb, line 39 def archive_all(src, dest, comp, format) Archive::Writer.open_filename(dest.to_s, comp, format) do |archive| list_tree_paths(src).sort.each do |path| archive.new_entry do |entry| entry.pathname = path.relative_path_from(src).to_s is_dir = path.directory? if is_dir entry.pathname += '/' end entry.copy_stat(path.to_s) archive.write_header(entry) unless is_dir path.open do |f| archive.write_data do f.read(BUFSIZ) end end end end end end end
each_entry(path, &block)
click to toggle source
# File lib/akabei/archive_utils.rb, line 7 def each_entry(path, &block) Archive.read_open_filename(path.to_s) do |archive| while entry = archive.next_header block.call(entry, archive) end end end
extract_all(src, dest)
click to toggle source
# File lib/akabei/archive_utils.rb, line 25 def extract_all(src, dest) each_entry(src) do |entry, archive| path = dest.join(entry.pathname) path.parent.mkpath if entry.regular? path.open('wb') do |f| archive.read_data do |buf| f.write(buf) end end end end end
list_paths(path)
click to toggle source
# File lib/akabei/archive_utils.rb, line 15 def list_paths(path) paths = [] each_entry(path) do |entry| paths << entry.pathname end paths end
list_tree_paths(dir)
click to toggle source
# File lib/akabei/archive_utils.rb, line 62 def list_tree_paths(dir) paths = [] q = dir.each_child.to_a until q.empty? path = q.shift paths << path if path.directory? q += path.each_child.to_a end end paths end