/* Returns the actual number of bytes extracted. If any errors occur, such as a corrupted compressed stream, an error is printed an the platform's exit() function is called.  */
int gunzip_partial(struct gunzip_state *state, void *dst, int dstlen)
/* Returns the actual number of bytes extracted. If any errors occur, such as a corrupted compressed stream, an error is printed an the platform's exit() function is called.  */
int gunzip_partial(struct gunzip_state *state, void *dst, int dstlen)
{
	int len;
	if (state->s.workspace) {
		int r;
		state->s.next_out = dst;
		state->s.avail_out = dstlen;
		r = zlib_inflate(&state->s, Z_FULL_FLUSH);
		if (r != Z_OK && r != Z_STREAM_END)
			fatal("inflate returned %d msg: %s\n\r", r, state->s.msg);
		len = state->s.next_out - (unsigned char *)dst;
	} else {
		len = min(state->s.avail_in, (unsigned)dstlen);
		memcpy(dst, state->s.next_in, len);
		state->s.next_in += len;
		state->s.avail_in -= len;
	}
	return len;
}