creating compressed tarfiles
Jeff Bauer
jbauer at rubic.com
Tue Aug 22 18:26:57 EDT 2000
Tw wrote:
> 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?
>
> I need examples.
>
> It must run on both windows and Linux, so preferrably no
> os.system-stuff.
I responded directly to Tw, but for the record I use
Jim Fulton's tar.py. IIRC, it's not documented in the
Zope distribution, but it's pretty easy to use. Download
Zope from http://www.zope.org.
An example of building a test.tgz archive from files
listed on the command line:
if __name__ == '__main__':
files = sys.argv[1:]
archive = tgzarchive('test')
for filename in files:
f = open(filename, 'rb')
archive.add(filename, f.read())
archive.finish()
outfile = open('test.tgz', 'wb')
outfile.write(str(archive))
outfile.close()
Jeff Bauer
Rubicon Research
More information about the Python-list
mailing list