在这里,我尝试使用zipstream新的python模块创建一个zip生成器。 https://pypi.org/project/zipstream-new/
有一件事我不知道,如何防止过多的内存使用。以下是我至今所拥有的:
''
def zip_generator():
import zipstream
z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_STORED, allowZip64=True)
for path in path_list:
z.write(asset_path, arcname=asset_details.get("file_name"))
for chunk in z:
yield chunk
response.set_header('Content-Disposition','attachment; filename={}'.format(zip_filename))
response.set_header('Content-Type', 'application/zip')
return zip_generator()
''
如有其他选择,请提出建议
目前没有回答
相关问题 更多 >
编程相关推荐