def sizeof_fmt(size, binary=True, separator=' ', suffix='B', digits=2):
    """
    takes a *size* (in bytes) and convert it in a human readable format.

    :param size: size in bytes
    :param digits: amount of decimals for any number
    :param binary: `True` for binary (:math:`2^x`) or `False` for decimal (:math:`10^x`) conversion; default: True
    :param separator: separator between number and unit; default: u' '
    :param suffix: B, Byte, byte etc.; default: u'B'
    :return:

    It converts into kilobytes, megabytes, gigabytes, terabytes and so on until the value is readable.
    Then it returns this value with the corresponding unit as a string.

    By setting *binary*, you can choose between *binary* and *decimal* conversion.
    The unit will be set accordingly to *XiB* for binary or *XB* for decimal.

    Examples:

    >>> sizeof_fmt(499999699990)
    u'465.7 GiB'
    >>> sizeof_fmt(499999699990, binary=False)
    u'500.0 GB'
    >>> sizeof_fmt(499999699990, separator='')
    u'465.7GiB'
    >>> sizeof_fmt(499999699990, binary=False, suffix='Byte')
    u'500.0 GByte'
    """
    factor = 1024.0 if binary else 1000.0
    unit = ''
    for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
        if abs(size) < factor:
            s = '{s:3.{d}f}{sep:s}{unit:s}{suf:s}'
            # @formatter:off
            return s.format(
                d=digits,
                s=size,
                sep=separator,
                unit=unit if binary and len(unit) > 1 else unit[:-1],
                suf=suffix)
            # @formatter:on
        size /= factor
    return '{:.1f}{:s}{:s}{:s}'.format(size, separator, 'Yi' if binary and len(unit) > 1 else 'Y', suffix)