tar.addfile(tarinfo=info)
info = tarfile.TarInfo(name='dir/foo')
info.size = len(string.buf)
info.mtime = time.time()
tar.addfile(tarinfo=info, fileobj=string)
tar.close()
How can I programmatically create a tar archive of nested directories and files solely from Python strings and without temporary files?