测试 ZIP 文件不需要 zip64 支持

huangapple go评论79阅读模式
英文:

Test that a ZIP doesn't require zip64 support

问题

我想测试一些Python代码,用于创建动态选择zip32或zip64的zip文件,并且我想要断言在某些情况下它确实创建了有效的zip32文件,可以在不支持zip64的情况下打开它。

如何在Python中检查文件是否确实可以被不支持zip64的东西打开。Python的zipfile模块中的"allowZip64"选项似乎只用于写入,而不是阅读 https://docs.python.org/3/library/zipfile.html

(我宁愿不查看文件的字节 - 我想要一个更集成的样式测试,使用现有的库/软件来处理文件)

英文:

I'm looking to test some Python code makes zip files that dynamically chooses zip32 or zip64, and I would like to assert that in certain cases it really does create valid zip32 files by opening it in something that does not support zip64.

How can I check that a file really is openable by something that doesn't support zip64 in Python. The "allowZip64" option in Python's zipfile module seems to only be for writing, rather than reading https://docs.python.org/3/library/zipfile.html

(I would prefer to not peek at the bytes of the file - I would like a more integration style test that uses existing library/software to process the file)

答案1

得分: 1

可能只需获取经典的PKZIP 2.04g可执行文件的旧副本。它应该仍然可以运行。

或者,您可以安装一个在zipfile中引入Zip64支持之前的Python版本2.5之前的版本

英文:

Maybe just get an old copy of the classic PKZIP 2.04g executable. It should still run.

Or you can install a version of Python before 2.5, which is when Zip64 support in zipfile was introduced.

答案2

得分: 0

我不确定这是否算作作弊,但就在几分钟前,Python库stream-unzip通过传递allow_zip64=False来支持 禁用 zip64 支持。

https://github.com/uktrade/stream-unzip/pull/46

从其文档中修改的示例:

from stream_unzip import stream_unzip
import httpx

def zipped_chunks():
    with httpx.stream('GET', 'https://www.example.com/my.zip') as r:
        yield from r.iter_bytes(chunk_size=65536)

# 如果尝试打开Zip64文件,则会引发UnsupportedZip64Error
for name, size, chunks in stream_unzip(zipped_chunks(), allow_zip64=False):
    for chunk in chunks:
        pass
英文:

I'm not sure if this is somehow cheating, but as of a few minutes ago, the Python library stream-unzip supports disabling zip64 support by passing it allow_zip64=False

https://github.com/uktrade/stream-unzip/pull/46

Modifying an example from its docs:

from stream_unzip import stream_unzip
import httpx

def zipped_chunks():
    with httpx.stream('GET', 'https://www.example.com/my.zip') as r:
        yield from r.iter_bytes(chunk_size=65536)

# Will raise UnsupportedZip64Error if trying to open a Zip64 file
for name, size, chunks in stream_unzip(zipped_chunks(), allow_zip64=False):
    for chunk in chunks:
        pass

huangapple
  • 本文由 发表于 2023年5月28日 19:58:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76351373.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定