1
# $Id: gzip_consumer.py 271 2004-10-09 10:50:59Z fredrik $
4
# Copyright (c) 2001-2004 by Fredrik Lundh. All rights reserved.
8
# Consumer wrapper for GZIP streams.
12
def __init__(self, consumer):
13
self.__consumer = consumer
17
def __getattr__(self, key):
18
return getattr(self.__consumer, key)
21
if self.__decoder is None:
22
# check if we have a full gzip header
23
data = self.__data + data
28
x = ord(data[i]) + 256*ord(data[i+1])
30
if flag & 8: # filename
34
if flag & 16: # comment
41
raise IndexError("not enough data")
42
if data[:3] != "\x1f\x8b\x08":
43
raise IOError("invalid gzip data")
47
return # need more data
50
self.__decoder = zlib.decompressobj(-zlib.MAX_WBITS)
51
data = self.__decoder.decompress(data)
53
self.__consumer.feed(data)
57
data = self.__decoder.flush()
59
self.__consumer.feed(data)
60
self.__consumer.close()