processDataCompressed(const instanceConf_t *const inst,
	struct conn_wrkr_s *connWrkr, const char* buf, size_t len)
{
	DEFiRet;

	if (!connWrkr->parseState.bzInitDone) {
		/* allocate deflate state */
		connWrkr->parseState.zstrm.zalloc = Z_NULL;
		connWrkr->parseState.zstrm.zfree = Z_NULL;
		connWrkr->parseState.zstrm.opaque = Z_NULL;
		int rc = inflateInit2(&connWrkr->parseState.zstrm, (MAX_WBITS | 16));
		if (rc != Z_OK) {
			dbgprintf("imhttp: error %d returned from zlib/inflateInit()\n", rc);
			ABORT_FINALIZE(RS_RET_ZLIB_ERR);
		}
		connWrkr->parseState.bzInitDone = 1;
	}

	connWrkr->parseState.zstrm.next_in = (Bytef*) buf;
	connWrkr->parseState.zstrm.avail_in = len;
	/* run inflate() on buffer until everything has been uncompressed */
	int outtotal = 0;
	do {
		int zRet = 0;
		int outavail = 0;
		dbgprintf("imhttp: in inflate() loop, avail_in %d, total_in %ld\n",
				connWrkr->parseState.zstrm.avail_in, connWrkr->parseState.zstrm.total_in);

		connWrkr->parseState.zstrm.avail_out = sizeof(connWrkr->zipBuf);
		connWrkr->parseState.zstrm.next_out = connWrkr->zipBuf;
		zRet = inflate(&connWrkr->parseState.zstrm, Z_SYNC_FLUSH);
		dbgprintf("imhttp: inflate(), ret: %d, avail_out: %d\n", zRet, connWrkr->parseState.zstrm.avail_out);
		outavail = sizeof(connWrkr->zipBuf) - connWrkr->parseState.zstrm.avail_out;
		if (outavail != 0) {
			outtotal += outavail;
			CHKiRet(processDataUncompressed(inst, connWrkr, (const char*)connWrkr->zipBuf, outavail));
		}
	} while (connWrkr->parseState.zstrm.avail_out == 0);

	dbgprintf("imhttp: processDataCompressed complete, sizes: in %lld, out %llu\n", (long long) len,
		(long long unsigned) outtotal);

finalize_it:
	RETiRet;
}
processDataCompressed(const instanceConf_t *const inst,
	struct conn_wrkr_s *connWrkr, const char* buf, size_t len)
{
	DEFiRet;

	if (!connWrkr->parseState.bzInitDone) {
		 
		connWrkr->parseState.zstrm.zalloc = Z_NULL;
		connWrkr->parseState.zstrm.zfree = Z_NULL;
		connWrkr->parseState.zstrm.opaque = Z_NULL;
		int rc = inflateInit2(&connWrkr->parseState.zstrm, (MAX_WBITS | 16));
		if (rc != Z_OK) {
			dbgprintf("imhttp: error %d returned from zlib/inflateInit()\n", rc);
			ABORT_FINALIZE(RS_RET_ZLIB_ERR);
		}
		connWrkr->parseState.bzInitDone = 1;
	}

	connWrkr->parseState.zstrm.next_in = (Bytef*) buf;
	connWrkr->parseState.zstrm.avail_in = len;
	 
	int outtotal = 0;
	do {
		int zRet = 0;
		int outavail = 0;
		dbgprintf("imhttp: in inflate() loop, avail_in %d, total_in %ld\n",
				connWrkr->parseState.zstrm.avail_in, connWrkr->parseState.zstrm.total_in);

		connWrkr->parseState.zstrm.avail_out = sizeof(connWrkr->zipBuf);
		connWrkr->parseState.zstrm.next_out = connWrkr->zipBuf;
		zRet = inflate(&connWrkr->parseState.zstrm, Z_SYNC_FLUSH);
		dbgprintf("imhttp: inflate(), ret: %d, avail_out: %d\n", zRet, connWrkr->parseState.zstrm.avail_out);
		outavail = sizeof(connWrkr->zipBuf) - connWrkr->parseState.zstrm.avail_out;
		if (outavail != 0) {
			outtotal += outavail;
			CHKiRet(processDataUncompressed(inst, connWrkr, (const char*)connWrkr->zipBuf, outavail));
		}
	} while (connWrkr->parseState.zstrm.avail_out == 0);

	dbgprintf("imhttp: processDataCompressed complete, sizes: in %lld, out %llu\n", (long long) len,
		(long long unsigned) outtotal);

finalize_it:
	RETiRet;
}