Conditions | 4 |
Total Lines | 9 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import os |
||
13 | def humanize_bytes(bytes, precision=2): |
||
14 | """Return a humanized string representation of a number of bytes.""" |
||
15 | abbrevs = ((1 << 50, 'PB'), (1 << 40, 'TB'), (1 << 30, 'GB'), (1 << 20, 'MB'), (1 << 10, 'kB'), (1, 'bytes')) |
||
16 | if bytes == 1: |
||
17 | return '1 byte' |
||
18 | for factor, suffix in abbrevs: |
||
19 | if bytes >= factor: |
||
20 | break |
||
21 | return '%.*f %s' % (precision, bytes / factor, suffix) |
||
22 | |||
27 |