def format_size(size):
    """Return file size as string from byte size."""
    for unit in ('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'):
        if size < 2048:
            return '%.f %s' % (size, unit)
        size /= 1024.0
