import six


def bytes_fmt(num, suffix='B'):
    """
    Turn a number of bytes into a more friendly representation, e.g. 2.5MiB.

    :param num: The number of bytes to convert.
    :param suffix: The unit suffix (defaults to 'B').
    :return: The human-readable equivalent of the input size.
    :raises ValueError: If num is not an integer.
    """
    if not isinstance(num, six.integer_types):
        raise ValueError('Byte count must be an integral type')

    num = abs(num)
    for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
        if num < 1024.0:
            return '{0:.1f} {1}{2}'.format(num, unit, suffix)
        num /= 1024.0
    return '{0:.1f} {1}{2}'.format(num, 'Yi', suffix)