c语言 - 无法提取根据 IETF RFC 1951 压缩的数据:"DEFLATE Compressed Data Format Specification version 1.3"



我想以deflate压缩格式(如RFC 1951中指定的deflate压缩格式(解压缩数据。我在Github中提到了此示例:https://gist.github.com/gaurav1981/9f8d9bbb7542b2222f575df

并修改了它只是为了解压缩我的数据:

    char dData[MAX_LENGTH];
    char cData[MAX_LENGTH]; 
    for(i=0; i < (size-4); i++)
    {
        cData[i] = *(data + i);
    }
    //cData[i] = '';
    printf("Compressed size is: %lun", strlen(cData));
    z_stream infstream;
    infstream.zalloc = Z_NULL;
    infstream.zfree = Z_NULL;
    infstream.opaque = Z_NULL;
    // setup "b" as the input and "c" as the compressed output
    //infstream.avail_in = (uInt)((char*)defstream.next_out - b); // size of input
    //infstream.avail_in = (uInt)((char*)defstream.next_out - cData);
    infstream.avail_in = (uInt)(size - 4);
    infstream.next_in = (Bytef *)cData; // input char array
    infstream.avail_out = (uInt)sizeof(dData); // size of output
    infstream.next_out = (Bytef *)dData; // output char array
    // the actual DE-compression work.
    inflateInit(&infstream);
    inflate(&infstream, Z_NO_FLUSH);
    inflateEnd(&infstream);
    printf("Uncompressed size is: %lun", strlen(dData));
    size = strlen(dData);

我的未压缩尺寸是0。所以有人可以告诉我的代码怎么了?

我什至将数据写入文件中,并将其保存为.gz和.zip,但是当我尝试提取它时出现了错误(我正在运行Ubuntu 14.04(

并且有人可以很好地分析我的数据并提取它。我的数据:

6374 492d 2d29 4ece c849 cc4b
294a 4cc9 cc57 f02e cd29 292d 6292 7780
30f2 1293 338a 3293 334a 52f3 98c4 0b9c
4a93 33b2 8b32 4b32 b399 d405 4212 d353
8b4b 320b 0a00 

而不是inflate(),您需要调用inflateInit2(),第二个参数为-15,以解压缩原始数据。

您的数据以 0开头,因此strlen将返回0,以使您的打印为未压缩数据的长度

最新更新