def _gzipped(stream):
    """Return True if stream is a gzip file."""

    initial_pos = stream.tell()
    gzip_magic = b"\x1f\x8b"
    file_magic = stream.read(2)
    stream.seek(initial_pos)  # rewind back 2 bytes

    return file_magic == gzip_magic