0
目前我正在写一个像这样的文件:从一个字节串荏苒在存储器中的文件
with open('derp.bin', 'wb') as f:
f.write(file_data)
但是有时候这个文件是非常大的,我需要压缩它,我想,以尽量减少数量写入磁盘并在内存中执行此操作。我知道我可以使用BytesIO
和ZipFile
从数据创建一个zip文件。这是我到目前为止有:
zipbuf = io.BytesIO(file_data)
z = zipfile.ZipFile(zipbuf, 'w')
z.close()
with open('derp.zip', 'wb') as f:
shutil.copyfileobj(zipbuf, f)
我怎样才能让这个当你解压缩zip文件有原derp.bin
内
在我的Python列表中的文件名需要反转:'z = zipfile.ZipFile('derp.zip','w')''和'z.writestr('derp.bin',file_data,8)'而不是写入的东西。 – dafnahaktana