def decode(cls, data, charset=None, mimetype=None): try: with gzip.GzipFile(fileobj=io.BytesIO(data)) as fd: return fd.read() # data = zlib.decompress(data, 16 + zlib.MAX_WBITS) except (zlib.error, IOError, EOFError): raise DecodeError(_(u'Invalid gzip data.')) return Codec.decode(data, charset)
def encode(cls, data, charset=None, mimetype=None): try: out = io.BytesIO() with gzip.GzipFile(fileobj=out, mode="w") as fd: fd.write(Codec.encode(data, charset)) return out.getvalue() # return zlib.compress(Codec.encode(data, charset), cls.compression_level) except zlib.error: raise EncodeError(_(u'Invalid gzip data.'))
def decode(cls, data, charset=None, mimetype=None): try: data = zlib.decompress(data, 16 + zlib.MAX_WBITS) except zlib.error: raise DecodeError(_(u'Invalid gzip data.')) return Codec.decode(data, charset)
def encode(cls, data, charset=None, mimetype=None): try: return zlib.compress(Codec.encode(data, charset), 16 + zlib.MAX_WBITS) except zlib.error: raise EncodeError(_(u'Invalid gzip data.'))
def decode(cls, data, charset=None, mimetype=None): try: data = zlib.decompress(data) except zlib.error: raise DecodeError(_(u'Invalid zlib/deflate data.')) return Codec.decode(data, charset)
def encode(cls, data, charset=None, mimetype=None): try: return zlib.compress(Codec.encode(data, charset)) except zlib.error: raise EncodeError(_(u'Invalid zlib/deflate data.'))