Python zlib 膨胀错误

发布于 2024-11-27 03:02:39 字数 1864 浏览 0 评论 0原文

我正在尝试使用 Python 和以下代码来膨胀 zlib 压缩文件:

import zlib

data = open("3B42.110531.21.6A.HDF.Z", 'rb').read()
inflated = zlib.decompress(data)
f = open('3B42.110531.21.6A.HDF', 'wb')
f.write(inflated)
f.close()

我已经使用不同的选项进行了多次尝试:

  • zlib.decompress (zlib.decompress( data,-15))
  • 跳过前两个字节 zlib.decompress(data[2:-4]) / zlib.decompress(data[2:] /.. )
  • 基本编码为64位。

无论如何,我一直失败并显示以下消息:

    Traceback (most recent call last):
  File "C:\opt\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
    exec codeObject in __main__.__dict__
  File "E:\Tesis\data\uncompress.py", line 6, in <module>
    inflated = zlib.decompress(data)
error: Error -3 while decompressing data: incorrect header check

唯一的区别是在 zlib.decompress 中使用负参数:无效的块类型。

import zlib

data = open("3B42.110531.21.6A.HDF.Z", 'rb').read()
inflated = zlib.decompress(data,-15)
f = open('3B42.110531.21.6A.HDF', 'wb')
f.write(inflated)
f.close()


Traceback (most recent call last):
  File "C:\opt\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
    exec codeObject in __main__.__dict__
  File "E:\Tesis\data\uncompress.py", line 6, in <module>
    inflated = zlib.decompress(data,-15)
error: Error -3 while decompressing data: invalid block type

我确信该文件没有损坏,我可以从 WinRAR 打开它。 (环境:Windows x64,Python 2.5,我猜该文件位于Unix机器中..下载了二进制文件)

我已经阅读了以下链接

I'm trying to inflate a zlib compressed file using Python with this code:

import zlib

data = open("3B42.110531.21.6A.HDF.Z", 'rb').read()
inflated = zlib.decompress(data)
f = open('3B42.110531.21.6A.HDF', 'wb')
f.write(inflated)
f.close()

I've already done several attempts with different options:

  • Adding a second parameter to zlib.decompress (zlib.decompress(data,-15))
  • Skipping the first two bytes zlib.decompress(data[2:-4]) / zlib.decompress(data[2:] /.. )
  • Basecoding to 64 bits.

Anyway, I keep failing with this message:

    Traceback (most recent call last):
  File "C:\opt\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
    exec codeObject in __main__.__dict__
  File "E:\Tesis\data\uncompress.py", line 6, in <module>
    inflated = zlib.decompress(data)
error: Error -3 while decompressing data: incorrect header check

The only difference is using a negative parameter in zlib.decompress: invalid block type.

import zlib

data = open("3B42.110531.21.6A.HDF.Z", 'rb').read()
inflated = zlib.decompress(data,-15)
f = open('3B42.110531.21.6A.HDF', 'wb')
f.write(inflated)
f.close()


Traceback (most recent call last):
  File "C:\opt\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
    exec codeObject in __main__.__dict__
  File "E:\Tesis\data\uncompress.py", line 6, in <module>
    inflated = zlib.decompress(data,-15)
error: Error -3 while decompressing data: invalid block type

I'm sure that the file is not corrupted, I can open it from WinRAR.
(environment: Windows x64, Python 2.5, I guess that the file is in a Unix machine..binary downloaded)

I've already read the following links

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝梦月影 2024-12-04 03:02:39

.Z 表示 LZC/< a href="http://linux.die.net/man/1/compress" rel="nofollow">压缩 文件。尽管名称相似,但这种压缩格式与 zlib 实现的 gzip 不同。

尝试使用命令行 compress 实用程序来解压缩文件(您的 gzip 程序也可能能够解压缩它)。

.Z indicates a LZC/compress file. Despite the name similarity, this compression format differs from gzip, which is what zlib implements.

Try using the command-line compress utility to uncompress the file (Your gzip program may also be able to decompress it).

迷雾森÷林ヴ 2024-12-04 03:02:39

文件扩展名“.Z”和您到目前为止尝试的尝试听起来像是您错误地使用了 zLib(但根据您发布的链接似乎是正确的)或者 zLib 流不在文件的开头。

您可以使用我的工具 Precomp 与文件来检测文件内 zLib 流的位置:

precomp -v -slow 3B42.110531.21.6A.HDF.Z

它应该输出类似这样的内容:

Possible zLib-Stream (slow mode) found at position 85, windowbits = 15
Can be decompressed to 9264 bytes

这将告诉您流的位置和要使用的 windowbits 参数(取反)。

它还会告诉您文件中是否有 zLib 流,因为 phihag 说,该文件可能是用与 deflate/zLib 不同的东西压缩的。请注意,在这种情况下,可能会出现一些误检测,因为 zLib 标头的大小只有 2 个字节,但可以通过解压缩到 <100 个字节来识别这些错误。

The file extension '.Z' and the attempts you tried so far sound like you either use zLib wrong (but it seems correct according to your posted links) or the zLib stream isn't right at the beginning of the file.

You can use my tool Precomp with the file to detect the position of zLib stream(s) inside the file:

precomp -v -slow 3B42.110531.21.6A.HDF.Z

It should output something like this:

Possible zLib-Stream (slow mode) found at position 85, windowbits = 15
Can be decompressed to 9264 bytes

This will tell you both the position of the stream and the windowbits parameter to use (negated).

It will also tell you if there are zLib streams inside the file at all because as phihag said, it's possible that the file is compressed with something different than deflate/zLib. Note that in this case, there'll probably be some misdetections as the zLib header is only 2 bytes in size, but those can be identified by decompressing to <100 bytes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文