def format_filesize(size):
    """Formats the file size into a human readable format."""
    for suffix in ('bytes', 'KB', 'MB', 'GB', 'TB'):
        if size < 1024.0:
            if suffix in ('GB', 'TB'):
                return '{0:3.2f} {1}'.format(size, suffix)
            else:
                return '{0:3.1f} {1}'.format(size, suffix)
        size /= 1024.0
