[英]How to create an in-memory zip file with directories without touching the disk?
在python Web应用程序中,我将一些东西打包成zip文件。 我想在内存中完全执行此操作,而不需要触摸磁盘。 只要我创建一个平面目录结构,使用ZipFile.writestr就可以了,但是如何在zip中创建目录?
我正在使用python2.4。
什么'theomega'在我的原始帖子的评论中说,在文件名中添加'/'就可以了。 谢谢!
from zipfile import ZipFile
from StringIO import StringIO
inMemoryOutputFile = StringIO()
zipFile = ZipFile(inMemoryOutputFile, 'w')
zipFile.writestr('OEBPS/content.xhtml', 'hello world')
zipFile.close()
inMemoryOutputFile.seek(0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.