[Tutor] using tarfile on strings or filelike objects

Barton David David.Barton at nottingham.ac.uk
Fri Mar 2 12:25:54 CET 2007


I like that I can access the contents of a zip archive that's stored in
memory (rather than on disk) by packing the archive contents into a
StringIO or cStringIO object and feeding that to ZipFile...
 
i.e. 
 
filelike=cStringIO.StringIO(archive_as_string)
zf=zipfile.ZipFile(filelike)
content=zf.read(archive_member_name)
zf.close()
filelike.close()
 
but I can't get the same thing to work with TarFile. Is there any way to
do this? (Other than first saving the archive data to disk and then
passing the path to TarFile.open?) The tarfile module documentation
talks about an optional fileobj flag but this doesn't seem to work.
 
cheers
Dave

This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070302/f0672317/attachment.htm 


More information about the Tutor mailing list