コード例 #1
0
ファイル: zlibutil.c プロジェクト: cielavenir/7razf
int slz_deflate(
	unsigned char *dest,
	unsigned long *destLen,
	const unsigned char *source,
	unsigned long sourceLen,
	int level
){
	if(!slz_initialized){
		slz_prepare_dist_table();
		slz_initialized=true;
	}
	struct slz_stream strm;
	slz_init(&strm, level, SLZ_FMT_DEFLATE);
	*destLen=slz_encode(&strm,dest,source,sourceLen,0);
	*destLen+=slz_finish(&strm,dest+*destLen);
	return Z_OK;
}
コード例 #2
0
ファイル: compression.c プロジェクト: spinpunch/haproxy-1.8
/* Compresses the data accumulated using add_data(), and optionally sends the
 * format-specific trailer if <finish> is non-null. <out> is expected to have a
 * large enough free non-wrapping space as verified by http_comp_buffer_init().
 * The number of bytes emitted is reported.
 */
static int rfc195x_flush_or_finish(struct comp_ctx *comp_ctx, struct buffer *out, int finish)
{
	struct slz_stream *strm = &comp_ctx->strm;
	const char *in_ptr;
	int in_len;
	int out_len;

	in_ptr = comp_ctx->direct_ptr;
	in_len = comp_ctx->direct_len;

	if (comp_ctx->queued) {
		in_ptr = comp_ctx->queued->p;
		in_len = comp_ctx->queued->i;
	}

	out_len = out->i;

	if (in_ptr)
		out->i += slz_encode(strm, bi_end(out), in_ptr, in_len, !finish);

	if (finish)
		out->i += slz_finish(strm, bi_end(out));

	out_len = out->i - out_len;

	/* very important, we must wipe the data we've just flushed */
	comp_ctx->direct_len = 0;
	comp_ctx->direct_ptr = NULL;
	comp_ctx->queued     = NULL;

	/* Verify compression rate limiting and CPU usage */
	if ((global.comp_rate_lim > 0 && (read_freq_ctr(&global.comp_bps_out) > global.comp_rate_lim)) ||    /* rate */
	   (idle_pct < compress_min_idle)) {                                                                 /* idle */
		if (comp_ctx->cur_lvl > 0)
			strm->level = --comp_ctx->cur_lvl;
	}
	else if (comp_ctx->cur_lvl < global.tune.comp_maxlevel && comp_ctx->cur_lvl < 1) {
		strm->level = ++comp_ctx->cur_lvl;
	}

	/* and that's all */
	return out_len;
}