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

Graham Dumpleton grahamd at dscpl.com.au
Mon Mar 6 22:41:04 EST 2006


jarrod roberson wrote ..
> On 3/6/06, Graham Dumpleton <grahamd at dscpl.com.au> wrote:
> >
> > Can you please explain the .tell() issue and how it is a problem? If
> > you are packing it into an instance of StringIO rather than onto req,
> > then it will be able to find a .tell() function and others it needs.
> > Obviously, the issue with StringIO is that it must hold it all in
> > memory until everything is complete and only then can you send
> > data. Ie., can't be streamed as you go.
> >
> > Thus, please show examples of how you were using ZipFile and go
> > into more detail of why it doesn't work and what errors you get.
> >
> > Graham
> 
> 
> considering that our users will be able to have up to 10GB of quota,
> StringIO won't work for all our cases :-(
> I really need something that will write the Zip File to req.write() on
> the
> fly.
> 
> ZipFile's constructor takes a file like object and write() calls .tell()
> internally to find where the headers end, so it can backtrack and update
> them after the fact, no worky with a one way stream :-(
> 
> And since some of the files will be very large hundreds of megs if not
> gigs,
> in memory isn't going to cut it.

If it is using tell() merely to get how much data has been sent, could
you replace it with a reference to "req.bytes_sent"? If however it then
wants to do a seek() that is a bigger problem. Your use of the word
"backtrack" is worrying, as it suggests the file format can't be streamed
if it needs to rewind back to the start to update stuff in the header.

Graham


More information about the Mod_python mailing list