[Tutor] using tarfile on strings or filelike objects

Luke Paireepinart rabidpoobear at gmail.com
Fri Mar 2 17:43:52 CET 2007


Barton David wrote:
> 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.
What did you try? What was the error message?

>  
> 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.
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   



More information about the Tutor mailing list