Here is the C function that does the job using zlib:
int gzip_inflate(char *compr, int comprLen, char *uncompr, int uncomprLen) { int err; z_stream d_stream; d_stream.zalloc = (alloc_func)0; d_stream.zfree = (free_func)0; d_stream.opaque = (voidpf)0; d_stream.next_in = (unsigned char *)compr; d_stream.avail_in = comprLen; d_stream.next_out = (unsigned char *)uncompr; d_stream.avail_out = uncomprLen; err = inflateInit2(&d_stream, 16+MAX_WBITS); if (err != Z_OK) return err; while (err != Z_STREAM_END) err = inflate(&d_stream, Z_NO_FLUSH); err = inflateEnd(&d_stream); return err; }
An uncompressed string is returned in uncompr. This is a C line with zero completion, so you can do puts (uncompr). The function above only works if the output is text. I tested it and it works.
source share