def stream_decompress(iterator, mode='gzip'):
 if (mode not in ['gzip', 'deflate']):
  raise ValueError('stream_decompress mode must be gzip or deflate')
 zlib_mode = ((16 + zlib.MAX_WBITS) if (mode == 'gzip') else (- zlib.MAX_WBITS))
 dec = zlib.decompressobj(zlib_mode)
 try:
  for chunk in iterator:
   rv = dec.decompress(chunk)
   if rv:
    (yield rv)
 except zlib.error:
  (yield chunk)
  for chunk in iterator:
   (yield chunk)
 else:
  buf = dec.decompress(bytes())
  rv = (buf + dec.flush())
  if rv:
   (yield rv)

def stream_decompress ( iterator , mode = 'gzip' ) : if ( mode not in [ 'gzip' , 'deflate' ] ) : raise ValueError ( 'stream_decompress mode must be gzip or deflate' ) zlib_mode = ( ( 16 + zlib . MAX_WBITS ) if ( mode == 'gzip' ) else ( - zlib . MAX_WBITS ) ) dec = zlib . decompressobj ( zlib_mode ) try : for chunk in iterator : rv = dec . decompress ( chunk ) if rv : ( yield rv ) except zlib . error : ( yield chunk ) for chunk in iterator : ( yield chunk ) else : buf = dec . decompress ( bytes ( ) ) rv = ( buf + dec . flush ( ) ) if rv : ( yield rv )
stream decodes an iterator over compressed data .