使用zlib解压缩gzip流

时间:2016-01-21 22:05:55

标签: c zip gzip zlib

我的gzip流看起来像这样。 我用google搜索标题31,-117,8应该是一个gzip文件。

{31, -117, 8, 0, 0, 0, 0, 0, 0, 0, -29, 22, 98, -27, 96, 80, 120, -63, -34, -59, -104, -58, -63, 44, -108, 96, 92, 99, 100, 104, 102, 104, 105, 102, 97, 110, 82, -109, -100, -97, -85, -105, -107, -105, -103, -110, -102, -101, -81, -105, 88, 80, 80, -100, -97, 83, 90, -110, -103, -97, 7, 19, -85, 49, -84, 113, -12, -53, -15, -9, 8, -12, 79, 75, 115, 77, 116, -11, 44, 72, 118, 76, -12, -15, 12, 44, -9, 118, -85, 40, -48, 118, 13, -56, -86, 74, -52, 115, 45, -73, -75, -83, 49, 52, 49, 53, 54, 50, 52, 50, 51, 52, 53, 53, 48, -111, 98, -32, 1, 0, -106, 39, -125, -109, 114, 0, 0, 0};

我认为这应该是一个gzip文件吗?

然后我使用zlib解压缩此文件

    do {
    do {
        s->strm.avail_in = s->size;
        s->strm.next_in = s->buf;
        s->strm.next_in = (Bytef *)tmp;

        s->strm.avail_out = ZCHUNK;
        s->strm.next_out = s->zbuf;

        ret = inflate(&s->strm, Z_SYNC_FLUSH);
        //    ret = inflateInit2(&s->strm, 16+MAX_WBITS);

        if (ret == Z_STREAM_ERROR) {
            printf("ret error");
        }

        if (ret == Z_MEM_ERROR) {
            printf("ret mem error");
        }

        if (ret == Z_DATA_ERROR) {
            printf("ret data error\n");
        }

        if (ret == Z_NEED_DICT) {
            printf("ret dict error");
        }

        if (ret != 0){
            (void)inflateEnd(&s->strm);
            printf("ret  = %d\n", ret);
            return 10;
        }

        have = ZCHUNK - s->strm.avail_out;
    } while (s->strm.avail_out == 0);
} while (ret != Z_STREAM_END);
inflateEnd(&s->strm);
return s->size;

我总是得到一个Z_DATA_ERROR。我做错了什么?????

1 个答案:

答案 0 :(得分:0)

数据是完全有效的gzip流。您尚未展示整个计划,因此我们无法提供帮助。