[mod_python] Re: streaming zipped data with publisher

Daniel Nogradi nogradi at gmail.com
Mon Jan 9 06:43:12 EST 2006


> > As Graham pointed out, I wasn't talking about zipping everything I
> > send to the clients, only zipping a file once in a while when users
> > request an archive of a bunch of files. And, more importantly, I don't
> > want to store the zip file, but create it upon request, send it, and
> > delete it.
> >
> > It seems this StringIO solution is best. Only I'm not sure how I
> > return the 'data' (in your example) since I'm using the publisher
> > handler. As far as I understand, perhaps I'm wrong here, the publisher
> > handler does all header stuff by itself, but in this case I need to
> > set content length, content type, etc, so how does this go with
> > publisher?
>
> I bet you can get away with the following:
>
> req.add_header('Content-Type', 'application/octet-stream')
> myzip = zipfile.ZipFile(req,"w")
> ##   ... build up zip
> myzip.close()
>
> (req is the request object from publisher)
>
> ZipFile will just output the data directly to the client now. Publisher
> will (hopefully) chunk-encode it.
>
> No temp files, and no memory hog (which StringIO might do...)
>
> An alternative to chunked encoding (but less 'nice' since the client
> cannot determine whether the transfer was aborted or not) is to add
> "Connection: Close" to the headers (effectively using HTTP/1.0 protocol).


Great, thanks, that was exactly what I was looking for.



More information about the Mod_python mailing list