def format_size(bytes):
    """
    Format a file size in a human-readable way.
    :param bytes: Number of bytes
    :type bytes: int
    :return: string
    """

    if bytes > 1000000:
        return '%.1fMB' % (bytes / 1000000.0)

    if bytes > 10 * 1000:
        return '%ikB' % (bytes / 1000)

    if bytes > 1000:
        return '%.1fkB' % (bytes / 1000.0)

    return '%ibytes' % bytes