python - 如何使用 python zipfile 库检查 zip 文件是否拆分为多个存档?

标签 python python-2.7 zip filesplitting python-zipfile

根据zip文件标准:http://www.pkware.com/documents/casestudies/APPNOTE.TXT它还支持将 zip 文件拆分为多个文件:

      Spanned/Split archives created using PKZIP for Windows
      (V2.50 or greater), PKZIP Command Line (V2.50 or greater),
      or PKZIP Explorer will include a special spanning 
      signature as the first 4 bytes of the first segment of
      the archive.  This signature (0x08074b50) will be 
      followed immediately by the local header signature for
      the first file in the archive.  

      A special spanning marker may also appear in spanned/split 
      archives if the spanning or splitting process starts but 
      only requires one segment.  In this case the 0x08074b50 
      signature will be replaced with the temporary spanning 
      marker signature of 0x30304b50.  Split archives can
      only be uncompressed by other versions of PKZIP that
      know how to create a split archive.

      The signature value 0x08074b50 is also used by some
      ZIP implementations as a marker for the Data Descriptor 
      record.  Conflict in this alternate assignment can be
      avoided by ensuring the position of the signature
      within the ZIP file to determine the use for which it
      is intended.  

知道如何检查该签名或其他方式来检查 zip 是否拆分为多个文件吗?

最佳答案

他们在标准中讨论的特定签名,即 PK\007\008 根本不由 zipfile 处理,通过 grep 库源代码可以看出(我得到了与 Python 3.2 的结果相同):

# grep PK /usr/lib/python2.7/zipfile.py 

stringEndArchive = "PK\005\006"
stringCentralDir = "PK\001\002"
stringFileHeader = "PK\003\004"
stringEndArchive64Locator = "PK\x06\x07"
stringEndArchive64 = "PK\x06\x06"

所以我怀疑您是否可以使用该库来实现此目的。不妨尝试通过扩展库自己找到该签名。

关于python - 如何使用 python zipfile 库检查 zip 文件是否拆分为多个存档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12039237/

相关文章:

javascript - 使用 jQuery 在 Jinja2 循环内提供 onclick 事件

python - 使用 openpyxl 对列进行排序

python - 使用索引作为键从数据框创建字典

python - 在python中合并两个不同长度的列表

go - 为什么 calibre 无法读取重新创建的 .epub 文件上的元数据?

c++ - Python 的 zip() 等价于 C 或 C++

Python2.7 - 安装Python3后解释器语法错误

循环遍历大型 numpy 整数数组时 Python 内存溢出,一次性转换

python - 使用列表输出而不是元组进行压缩

python - 是否可以从列表中随机*删除*一定百分比/数量的项目,然后将它们*附加*到另一个列表?