[mod_python] I need to create a Zip file on the fly and write it to the stream without any temp files or in memory file creation?

Mike Looijmans nlv11281 at natlab.research.philips.com
Tue Mar 7 01:25:16 EST 2006


Use TarFile (python 2.3 or higher) instead of zip.

Most "winzip" alike programs can handle TAR files just fine, so your 
users won't notice the difference. TAR files are designed to be 
streamable (Tape ARchive) and the python interface won't need tell(). 
You can stream anything that supports read() to a TAR  stream.

TAR does not support compression, but it is common to (g)zip the tar 
stream, which yields a streamable compressed result (and still delivers 
a tar file on the other side if you use a content-encoding of x-gzip)

Mike Looijmans
Philips Natlab / Topic Automation


jarrod roberson wrote:
> just to stop the responses now mod_deflate is NOT what I need. I need 
> the end user to get a pop up that allows them to down load the contents 
> of a directory as one big zip file.
> 
> I have a servlet in Java that does just this using the ZipOutputStream 
> and it works great! You can download giant directorys with very very 
> little load on the server since I am doing a ZERO level compression.
> 
> The reason I am looking at a mod_python solution is the way we have 
> mod_dav set up right now it takes over the namespace that we need to do 
> redirects from and can't get Apache to redirect the URL to the Java 
> Servlet, and we have a big time crunch and can't re-archtiect the entire 
> directory layout to try and fix it right now.
> 
> I saw a post recommending to use ZipFile, ZipFile won't work, it needs 
> .tell(). It updates all the zip headers after the fact.
> I found something called zipstream.py, but alas, it does the same thing!
> 
> Before I go and write a ZipOutputStream wrapper around the request 
> object, I wanted to see if any of you know of anythign out there that 
> does this.
> 
> Thanks again, and remember mod_deflate is NOT going to work.



More information about the Mod_python mailing list