【问题标题】:How to change the header of the zip archive (PK to PIRAKA)?如何更改 zip 存档的标题(PK 到 PIRAKA)?
【发布时间】:2019-04-10 13:12:41
【问题描述】:

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

【问题讨论】:

标签: python zip archive zipfile ziparchive


【解决方案1】:

只需在二进制模式下更改 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ё ...

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2021-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
  • 2022-01-04
  • 2010-09-15
  • 2011-06-15
相关资源
最近更新 更多