如何为部分zlib文件充气 [英] How to inflate a partial zlib file

查看:71
本文介绍了如何为部分zlib文件充气的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用zlib的deflate()函数压缩的文件的前两个连续3/3。最后的1/3输了。未压缩的原始文件为600KB。

I have the first contiguous 2/3rds of a file that was compressed with zlib's deflate() function. The last 1/3 was lost in transmission. The original uncompressed file was 600KB.

发送方多次调用Defate,同时将原始文件切成2KB的块大小,并在Z_FINISH传递Z_NO_FLUSH直到文件结尾通过了。最终的完整压缩文件已传输,但按所述方式部分丢失。

Deflate was called multiple times by the transmitter while chopping the original file into chunk sizes of 2KB and passing Z_NO_FLUSH until the end of file when Z_FINISH was passed. The resulting complete compressed file was transmitted, but partially lost as described.

是否可以恢复部分原始文件?如果是这样,对如何做有什么建议?

Is it possible to recover part of the original file? If so, any suggestions on how?

我同时使用ZLIB的纯C实现和/或ZLIB的Python 2.7实现。

I'm using both the plain C implementation of ZLIB, and/or the Python 2.7 implementation of ZLIB.

推荐答案

尽管我不了解python,但还是设法使它起作用:

Though I don't know python, I managed to get this to work:

#!/usr/bin/python
import sys
import zlib
f = open(sys.argv[1], "rb")
g = open(sys.argv[2], "wb")
z = zlib.decompressobj()
while True:
    buf = z.unconsumed_tail
    if buf == "":
        buf = f.read(8192)
        if buf == "":
            break
    got = z.decompress(buf)
    if got == "":
        break
    g.write(got)

提取部分zlib文件中所有可用的文件。

That should extract all that's available from your partial zlib file.

这篇关于如何为部分zlib文件充气的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆