亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 5874 | 回復: 5
打印 上一主題 下一主題

如何用zipfile往zip壓縮包中寫入壓縮包的說明信息? [復制鏈接]

論壇徽章:
1
2015亞冠之西悉尼流浪者
日期:2015-05-28 16:30:37
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2014-05-22 11:41 |只看該作者 |倒序瀏覽
對于一個已經生成的 "test.zip" 壓縮包,  在shell命令行下
  1. echo "comment"|zip -z test.zip
復制代碼
可以往zip壓縮包中寫入"comment"說明信息.

想用python實現(xiàn)這個簡單的功能
  1. import zipfile

  2. zf = zipfile.ZipFile('test.zip', 'a')
  3. zf.comment = 'comment'
  4. zf.close()
復制代碼
ok, 這樣沒有問題!
但是當我第二次在寫入新的說明信息時, 遇到了些問題!

shell終端下:
  1. echo "test" |zip -z test.zip
復制代碼
python代碼
  1. import zipfile

  2. zf = zipfile.ZipFile('test.zip', 'a')
  3. zf.comment = 'test'
  4. zf.close()
復制代碼
這次, 由于第二次寫入的注釋信息比第一次短, 造成兩種方式生成的 'test.zip'壓縮包大小, md5值均發(fā)生的變化.

經過多次測試, 當多次寫入注釋, 且后面寫入的注釋信息比上一次短時, 用python zipfile實現(xiàn)的方式會與用shell  zip -z方式 生成的壓縮包的 大小, md5值發(fā)生變化!

請問, 是我往zip壓縮包里寫入注釋的方法不對么? 這樣的差異問題該如何解決呢?

論壇徽章:
11
技術圖書徽章
日期:2014-03-01 14:44:34天蝎座
日期:2014-05-21 22:11:59金牛座
日期:2014-05-30 17:06:14
2 [報告]
發(fā)表于 2014-05-22 12:58 |只看該作者
zip內容不一樣,md5變化是正常的,md5變化影響了誰,改誰的代碼。

論壇徽章:
1
2015亞冠之西悉尼流浪者
日期:2015-05-28 16:30:37
3 [報告]
發(fā)表于 2014-05-22 14:29 |只看該作者
  1. root@Debian:~# echo "short"|zip -z test.zip
  2. enter new zip file comment (end with .):
  3. root@Debian:~# md5sum test.zip
  4. 48da9079a2c19f9755203e148731dae9  test.zip
  5. root@Debian:~# echo "longlong"|zip -z test.zip
  6. current zip file comment is:
  7. short
  8. enter new zip file comment (end with .):
  9. root@Debian:~# md5sum test.zip
  10. 3618846524ae0ce51fbc53e4b32aa35b  test.zip
  11. root@Debian:~# echo "short"|zip -z test.zip
  12. current zip file comment is:
  13. longlong
  14. enter new zip file comment (end with .):
  15. root@Debian:~# md5sum test.zip
  16. 48da9079a2c19f9755203e148731dae9  test.zip
  17. root@Debian:~# echo "longlong"|zip -z test.zip
  18. current zip file comment is:
  19. short
  20. enter new zip file comment (end with .):
  21. root@Debian:~# md5sum test.zip
  22. 3618846524ae0ce51fbc53e4b32aa35b  test.zip
復制代碼
第一次和第三次操作后, test.zip md5一致; 第二次和第四次操作后, test.zip md5一致;
現(xiàn)在用python zipfile 這樣處理后, 沒辦法做到這樣!
所以我想問問, 該如何使用python zipfile往 "zip"壓縮包里添加注釋信息?
回復 2# timespace


   

論壇徽章:
7
榮譽版主
日期:2011-11-23 16:44:17子鼠
日期:2014-07-24 15:38:07獅子座
日期:2014-07-24 11:00:54巨蟹座
日期:2014-07-21 19:03:10雙子座
日期:2014-05-22 12:00:09卯兔
日期:2014-05-08 19:43:17卯兔
日期:2014-08-22 13:39:09
4 [報告]
發(fā)表于 2014-05-22 14:33 |只看該作者
提交bug給zipfile

論壇徽章:
11
技術圖書徽章
日期:2014-03-01 14:44:34天蝎座
日期:2014-05-21 22:11:59金牛座
日期:2014-05-30 17:06:14
5 [報告]
發(fā)表于 2014-05-22 15:35 |只看該作者
明白樓主意思了。這個從API用法上是無法解釋的,即使是解決辦法也看不出來。。。
The ZIP file format is a common archive and compression standard. This module provides tools to create, read, write, append, and list a ZIP file. Any advanced use of this module will require an understanding of the format, as defined in PKZIP Application Note.


本質原因需要從zipfile實現(xiàn)和PKZIP算法入手。但應該不用這么糾結吧,如果你很依賴md5的變化與否,就用python調用shell的zip吧。

論壇徽章:
1
2015亞冠之西悉尼流浪者
日期:2015-05-28 16:30:37
6 [報告]
發(fā)表于 2014-05-22 17:20 |只看該作者
哦, 謝謝兄臺的解答了, 小弟還以為是我用的不對呢!
回復 5# timespace


   
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP