def sizeof_fmt(num, suffix='B', longsuffix=True, usespace=True, base=1024):
    """ Returns a string representation of the size ``num``.

    - Examples:
    >>> sizeof_fmt(1020)
    '1020 B'
    >>> sizeof_fmt(1024)
    '1 KiB'
    >>> sizeof_fmt(12011993)
    '11.5 MiB'
    >>> sizeof_fmt(123456789)
    '117.7 MiB'
    >>> sizeof_fmt(123456789911)
    '115 GiB'

    Options include:

    - No space before unit:
    >>> sizeof_fmt(123456789911, usespace=False)
    '115GiB'

    - French style, with short suffix, the "O" suffix for "octets", and a base 1000:
    >>> sizeof_fmt(123456789911, longsuffix=False, suffix='O', base=1000)
    '123.5 GO'

    - Reference: https://stackoverflow.com/a/1094933/5889533
    """
    num = float(num)  # force typecast
    base = float(base)

    suffixes = ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']
    if longsuffix:
        suffixes = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi']

    for unit in suffixes[:-1]:
        if abs(num) < base:
            return "{num:3.1f}{space}{unit}{suffix}".format(
                num=num,
                space=' ' if usespace else '',
                unit=unit,
                suffix=suffix,
            ).replace(".0", "")
        num /= base
    return "{num:.1f}{space}{unit}{suffix}".format(
        num=num,
        space=' ' if usespace else '',
        unit=suffixes[-1],
        suffix=suffix,
    ).replace(".0", "")