lib/rbbt/util/tar.rb in rbbt-util-5.17.3 vs lib/rbbt/util/tar.rb in rbbt-util-5.17.4

- old
+ new

@@ -74,34 +74,42 @@ StringIO.new gz.string end # un-gzips the given IO, returning the # decompressed version as a StringIO - def ungzip(tarfile) + def self.ungzip(tarfile) z = Zlib::GzipReader.new(tarfile) unzipped = StringIO.new(z.read) z.close unzipped end + def self._untar_cmd(io, destination) + FileUtils.mkdir_p destination unless File.exists? destination + CMD.cmd("tar xvf - -C '#{destination}'", :in => io) + nil + end + # untars the given IO into the specified # directory - def untar(io, destination) - Gem::Package::TarReader.new io do |tar| - tar.each do |tarfile| - destination_file = File.join destination, tarfile.full_name + def self.untar(io, destination) + return _untar_cmd(io, destination) - if tarfile.directory? - FileUtils.mkdir_p destination_file - else - destination_directory = File.dirname(destination_file) - FileUtils.mkdir_p destination_directory unless File.directory?(destination_directory) - File.open destination_file, "wb" do |f| - f.print tarfile.read - end - end - end - end + #Gem::Package::TarReader.new io do |tar| + # tar.each do |tarfile| + # destination_file = File.join destination, tarfile.full_name + + # if tarfile.directory? + # FileUtils.mkdir_p destination_file + # else + # destination_directory = File.dirname(destination_file) + # FileUtils.mkdir_p destination_directory unless File.directory?(destination_directory) + # File.open destination_file, "wb" do |f| + # f.print tarfile.read + # end + # end + # end + #end end end ### Usage Example: ###