Beispiel #1
0
def decode_gzip(data):
    """Return the gzip-decompressed bytes.

    :raises: :exc:`~ichnaea.exceptions.GZIPDecodeError`
    """
    try:
        return gzip.decompress(data)
    except (IOError, OSError, EOFError, struct.error, zlib.error) as exc:
        raise GZIPDecodeError(repr(exc))
Beispiel #2
0
def decode_gzip(data, encoding='utf-8'):
    """Decode the bytes data and return a Unicode string.

    :raises: :exc:`~ichnaea.exceptions.GZIPDecodeError`
    """
    try:
        with GzipFile(None, mode='rb', fileobj=BytesIO(data)) as gzip_file:
            out = gzip_file.read()
        if encoding:
            return out.decode(encoding)
        return out
    except (IOError, OSError, EOFError, struct.error, zlib.error) as exc:
        raise GZIPDecodeError(repr(exc))