def HumanizeBytes(totalBytes, precision=1, suffix=None):
    """
    Convert a number of bytes into the appropriate pretty kiB, MiB, etc.

    Args:
        totalBytes: the number to convert
        precision:  how many decimal numbers of precision to preserve
        suffix:     use this suffix (kiB, MiB, etc.) instead of automatically determining it

    Returns:
        The prettified string version of the input
    """
    if (totalBytes == None):
        return "0 B"

    converted = float(totalBytes)
    suffix_index = 0
    suffix_list = ['B', 'kiB', 'MiB', 'GiB', 'TiB']

    while (abs(converted) >= 1000):
        converted /= 1024.0
        suffix_index += 1
        if suffix_list[suffix_index] == suffix:
            break

    return "{0:.{1}f} {2}".format(converted, precision, suffix_list[suffix_index])