解压

源自zlib官网代码

int uncompress(char *buf, int size, char *newbuf, int newsize)
{
    int ret;
    z_stream strm;

    /* allocate inflate state */
    strm.zalloc = Z_NULL;
    strm.zfree = Z_NULL;
    strm.opaque = Z_NULL;
    strm.avail_in = 0;
    strm.next_in = Z_NULL;
    ret = inflateInit(&strm);
    if (ret != Z_OK)
        return ret;

    /* decompress until deflate stream ends or end of file */
	strm.avail_in = size;
	strm.next_in = (Bytef *)buf;

	/* run inflate() on input until output buffer not full */
	strm.avail_out = newsize;
	strm.next_out = (Bytef *)newbuf;
	ret = inflate(&strm, Z_NO_FLUSH);
	if(ret == Z_STREAM_ERROR)  /* state not clobbered */
		return ret;
	switch (ret) {
		case Z_NEED_DICT:
			ret = Z_DATA_ERROR;     /* and fall through */
		case Z_DATA_ERROR:
		case Z_MEM_ERROR:
			(void)inflateEnd(&strm);
			return ret;
	}

	/* done when inflate() says it's done */

    /* clean up and return */
    (void)inflateEnd(&strm);
    return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;

}