问题: 假设我在zip中写20个小pdf文件,那么zip大小约为400 MB,而那20个文件的总大小仅为4 MB。打开创建的zip文件后,只有20个文件,但是当我对该zip文件执行恢复操作时,我存档的文件会有很多pdf副本,我不知道为什么。当我在本地进行所有操作时,文件存储在s3中,并且zip也创建在s3中。以下是我正在使用的代码片段
with process_obj.archive_file.storage.open(process_obj.archive_file.name, 'wb') as archive_file:
# Create a zip archive
with zipfile.ZipFile(archive_file, mode='w', compression=zipfile.ZIP_DEFATED) as zip_file:
# Write excel file in zip
process_obj.excel_file.save(download_excel_util.get_excel_filename(), temp_workbook)
zip_file.writestr(
download_excel_util.get_excel_filename(),
process_obj.excel_file.read()
)
process_obj.added_file_count += 1
process_obj.save()
for file in files:
zip_file.writestr(u'{}{}'.format(u'Profiles/', u'{}.pdf'.format(resume.get_file_name())), file.read())
# Update `added_file_count` in process object
process_obj.added_file_count += 1
process_obj.save()