gpt4 book ai didi

python - 使用 PyLZMA 解压

转载 作者:太空宇宙 更新时间:2023-11-04 01:34:36 30 4
gpt4 key购买 nike

我使用这个脚本压缩我的文件

import pylzma, struct
i = open(path+fileName,'rb')
o = open(path+zipName+'.zip','wb')
data = i.read()
c = pylzma.compressfile(data, eos=1)
result = c.read(5)
result += struct.pack('<Q', len(data))
o.write(result + c.read())
i.close()
o.close()

我使用此方法,如 PyLZMA documentation 中所示因为它允许 7zip 或 lzma.exe 读取我的文件。使用 7zip 解压缩效果很好,但当我使用 PyLZMA 时它不起作用。我用这个:

i = open(path+name+'.zip', 'rb')
o = open(path+name, 'wb')
data = i.read()
u = pylzma.decompress(data)
o.write(u)

它在 pylzma.decompress 上停止,我收到以下错误:

TypeError: Error while decompressing: 1

最佳答案

如果我正在阅读 documentation正确(我在安装 PyLZMA 时遇到问题,所以我无法验证),compress() 输出 decompress() 可以处理的字符串。

但是,为了使压缩后的字符串与其他实用程序兼容,有必要在前 5 个字节和压缩数据的其余部分之间插入 8 个字节的长度。

因此,如果您想使用 PyLZMA 解压缩数据,我怀疑您需要手动删除该 8 字节长度字段(最快的方法可能是打开输入文件,读取 5 个字节,跳过 8,然后读取文件的其余部分)。

关于python - 使用 PyLZMA 解压,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11005301/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com