[Twisted-Python] Event-driven version of gzip module?

Donovan Baarda abo at minkirri.apana.org.au
Tue Dec 17 16:59:52 EST 2002

On Wed, 2002-12-18 at 02:48, l.m.orchard wrote:
> Still getting my head around Twisted, so hopefully I make sense in 
> asking this:
> Does there happen to be an event-driven version of the gzip module for 
> Twisted?  That is, instead of expecting a file object to actively read 
> and seek at will, it accepts chunks of data from a stream and hits a 
> callback with decompressed chunks as they're available.  (Would this 
> involve a deferred?)  I was trying to do something with just zlib, but 
> I forgot that that doesn't do anything to handle the header of a gzip 
> stream like the gzip module itself does.

the Python zlib module can compress/uncompress gzip data a block at a
time; perfect for what you want.

I'm not sure you need the gzip header stuff for http decompression, but
it you do, just have a look at the gzip.py source... the gzip module is
written in python and uses the zlib module. You might find once you look
at the gzip module implementation that it can actualy do what you want
anyway (it seems to support block at a time read/write, and provided you
use a stringIO file type should not block).

More information about the Twisted-Python mailing list