1
# $Id: gzip_consumer.py 271 2004-10-09 10:50:59Z fredrik $
4
# Copyright (c) 2001-2004 by Fredrik Lundh. All rights reserved.
7
from __future__ import absolute_import
10
# Consumer wrapper for GZIP streams.
14
def __init__(self, consumer):
15
self.__consumer = consumer
19
def __getattr__(self, key):
20
return getattr(self.__consumer, key)
23
if self.__decoder is None:
24
# check if we have a full gzip header
25
data = self.__data + data
30
x = ord(data[i]) + 256*ord(data[i+1])
32
if flag & 8: # filename
36
if flag & 16: # comment
43
raise IndexError("not enough data")
44
if data[:3] != "\x1f\x8b\x08":
45
raise IOError("invalid gzip data")
49
return # need more data
52
self.__decoder = zlib.decompressobj(-zlib.MAX_WBITS)
53
data = self.__decoder.decompress(data)
55
self.__consumer.feed(data)
59
data = self.__decoder.flush()
61
self.__consumer.feed(data)
62
self.__consumer.close()