backuppc_clone.misc.sizeof_fmt()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nop 2
dl 0
loc 15
rs 10
c 0
b 0
f 0
1
def sizeof_fmt(num: int, suffix: str = 'B') -> str:
2
    """
3
    Returns the size in bytes in human-readable format.
4
5
    @param int num: The number of bytes.
6
    @param str suffix: The suffix.
7
8
    :rtype: str
9
    """
10
    for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
11
        if abs(num) < 1024.0:
12
            return '%3.1f%s%s' % (num, unit, suffix)
13
        num /= 1024.0
14
15
    return '%.1f%s%s' % (num, 'Yi', suffix)
16