Module: IPFS::IO::Tar
- Defined in:
- lib/ipfs-api/io.rb
Overview
:nodoc:
Class Method Summary collapse
Class Method Details
.extract(stream, destination) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ipfs-api/io.rb', line 27 def extract stream, destination Gem::Package::TarReader.new(stream) do |tar| path = nil tar.each do |entry| if entry.full_name == '././@LongLink' path = File.join(destination, entry.read.strip) next end path ||= File.join(destination, entry.full_name) if entry.directory? if File.exist?(path) and not File.directory?(path) raise IOError.new("Not a directory: #{path}") end FileUtils.mkdir_p path, :mode => entry.header.mode, :verbose => false elsif entry.file? if File.exist?(path) and not File.file?(path) raise IOError.new("Not a file: #{path}") end File.open path, "wb" do |fd| while (chunk = entry.read(1024)) fd.write chunk end end FileUtils.chmod entry.header.mode, path, :verbose => false end path = nil end end true end |