import uuid


def split(input_file, chunk_size):
    """ 分割大文件为小文件，并且将小文件数据排序

    :param input_file: 输入文件
    :param chunk_size: 块大小
    :return: 小文件列表
    """
    temp_files = []
    chunk = []
    with open(input_file, 'r') as f:
        while True:
            line = f.readline()
            # 如果已结束或内存已满，则输出到临时文件
            if not line or len(chunk) >= chunk_size:
                if chunk:
                    chunk.sort()
                    temp_file = uuid.uuid4().hex
                    with open(temp_file, 'w') as temp_fd:
                        for num in chunk:
                            temp_fd.write(str(num)+'\n')
                    temp_files.append(temp_file)
                    del chunk
                    chunk = []
                if not line:
                    break
            num = int(line.strip())
            chunk.append(num)
    return temp_files