def nicesize(nbytes: int, space: str = "") -> str:
    """
    Uses IEC 1998 units, such as KiB (1024).
        nbytes: Number of bytes
        space: Separator between digits and units

        Returns:
            Formatted string
    """
    data = {
        "PiB": 1024 ** 5,
        "TiB": 1024 ** 4,
        "GiB": 1024 ** 3,
        "MiB": 1024 ** 2,
        "KiB": 1024 ** 1,
    }
    for suffix, scale in data.items():
        if nbytes >= scale:
            break
    else:
        scale, suffix = 1, "B"
    return str(nbytes // scale) + space + suffix