如何更改zip存档的标题(PK到PIRAKA)?

问题描述 投票:0回答:1

如何更改zip存档的标题(PK到PIRAKA)?我在python中更改了zipfile模块。我需要创建一个带有标题PIRAKA而不是PK的zip存档(存档结果创建)。问题是你无法在'r'模式下打开文件.Pirfile

python zip archive zipfile ziparchive
1个回答
0
投票

只需以二进制模式更改ZIP文件内容:

with open('file.zip', 'rb') as f:
    data = f.read().replace(b'PK', b'PIRAKA')

with open('result.zip', 'wb') as f:
    f.write(data)

输入ZIP文件头:

PK    ™QЉNLщFCё ...

输出ZIP文件头:

PIRAKA    ™QЉNLщFCё ...
© www.soinside.com 2019 - 2024. All rights reserved.