def humanize_filesize(num):
    """
    Convert a file size to human-readable form.
    eg:  in = 2048, out = ('2', 'KB')
    """
    if num < 1024.0:
        return ('%3.0f' % num, 'B')
    for x in ['B', 'KB', 'MB', 'GB', 'TB']:
        if num < 1024.0:
            return ('%3.1f' % num, x)
        num /= 1024.0