faqts : Computers : Programming : Languages : Python : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 8 people (75%) answered Yes
Recently 4 of 6 people (67%) answered Yes

Entry

How can I create compressed tarfiles, ie. lots of files inside a compressed file, using either the tarlib.py or tar.py ( found in Zope and gzip and/or zlib?

Aug 24th, 2000 20:46
unknown unknown, Martin von Loewis


Without trying, it appears that Zope's tar.py already handles
compressed files.
Let names contain a list of all files to add, I'd say the following
might work:
archive = tar.tgzarchive("foo")
for n in names:
  data = open(n).read()
  archive.add(n, data)
archive.finish()
open("foo.tgz").write(archive)
It appears as if this would keep the compressed file in memory,
though; there is apparently no streaming tar library.