- 论坛徽章:
- 1
|
对于一个已经生成的 "test.zip" 压缩包, 在shell命令行下- echo "comment"|zip -z test.zip
复制代码 可以往zip压缩包中写入"comment"说明信息.
想用python实现这个简单的功能- import zipfile
- zf = zipfile.ZipFile('test.zip', 'a')
- zf.comment = 'comment'
- zf.close()
复制代码 ok, 这样没有问题!
但是当我第二次在写入新的说明信息时, 遇到了些问题!
shell终端下:- echo "test" |zip -z test.zip
复制代码 python代码- import zipfile
- zf = zipfile.ZipFile('test.zip', 'a')
- zf.comment = 'test'
- zf.close()
复制代码 这次, 由于第二次写入的注释信息比第一次短, 造成两种方式生成的 'test.zip'压缩包大小, md5值均发生的变化.
经过多次测试, 当多次写入注释, 且后面写入的注释信息比上一次短时, 用python zipfile实现的方式会与用shell zip -z方式 生成的压缩包的 大小, md5值发生变化!
请问, 是我往zip压缩包里写入注释的方法不对么? 这样的差异问题该如何解决呢? |
|