885: def pack_file(entry, outputter)
886: outputter = outputter.tar if outputter.kind_of?(Archive::Tar::Minitar::Output)
887:
888: stats = {}
889:
890: if entry.kind_of?(Hash)
891: name = entry[:name]
892:
893: entry.each { |kk, vv| stats[kk] = vv unless vv.nil? }
894: else
895: name = entry
896: end
897:
898: name = name.sub(%r{\./}, '')
899: stat = File.stat(name)
900: stats[:mode] ||= stat.mode
901: stats[:mtime] ||= stat.mtime
902: stats[:size] = stat.size
903:
904: if RUBY_PLATFORM =~ /win32/
905: stats[:uid] = nil
906: stats[:gid] = nil
907: else
908: stats[:uid] ||= stat.uid
909: stats[:gid] ||= stat.gid
910: end
911:
912: case
913: when File.file?(name)
914: outputter.add_file_simple(name, stats) do |os|
915: stats[:current] = 0
916: yield :file_start, name, stats if block_given?
917: File.open(name, "rb") do |ff|
918: until ff.eof?
919: stats[:currinc] = os.write(ff.read(4096))
920: stats[:current] += stats[:currinc]
921: yield :file_progress, name, stats if block_given?
922: end
923: end
924: yield :file_done, name, stats if block_given?
925: end
926: when dir?(name)
927: yield :dir, name, stats if block_given?
928: outputter.mkdir(name, stats)
929: else
930: raise "Don't yet know how to pack this type of file."
931: end
932: end