Example #1
0
int ey_zlib_stream_pack(ey_zlib_t z, char *i_buf, size_t i_len, ey_zlib_callback cb, void *arg)
{
	if(!z || !cb || !i_buf || !i_len)
	{
		zlib_debug(debug_zlib_basic, "bad parameter in ey_zlib_stream_pack\n");
		return -1;
	}
	
	ey_zlib_private_t *zp = (ey_zlib_private_t*)z;
	ey_zlib_format_t format = zp->format;
	zp->err_msg = NULL;
	if(format == EY_ZLIB_FORMAT_DEFLATE_PACK)
	{
		if(do_deflate(zp, i_buf, i_len, cb, arg))
		{
			zlib_debug(debug_zlib_basic, "find error in deflate: %s\n", zp->err_msg?zp->err_msg:"unkown error");
			return -1;
		}
		zlib_debug(debug_zlib_basic, "deflate %d bytes successfully\n", i_len);
	}
	else if(format == EY_ZLIB_FORMAT_GZIP_PACK)
	{
		if(do_gzip(zp, i_buf, i_len, cb, arg))
		{
			zlib_debug(debug_zlib_basic, "find error in gzip: %s\n", zp->err_msg?zp->err_msg:"unkown error");
			return -1;
		}
		zlib_debug(debug_zlib_basic, "gzip %d bytes successfully\n", i_len);
	}
	else
	{
		assert(0);
	}
	return 0;
}
Example #2
0
File: scs.c Project: babongo/libscs
static int optional_deflate (scs_t *ctx, const uint8_t *state, size_t state_sz)
{
    scs_atoms_t *ats = &ctx->atoms;
    scs_keyset_t *ks = &ctx->cur_keyset;

    /* Assume we have already passed through reset_atoms(). */
    assert(ats->data_sz == sizeof ats->data);

    if (!ks->comp)
    {
        ats->data_sz = state_sz;
        memcpy(ats->data, (uint8_t *) state, ats->data_sz);
        return 0;
    }

    return do_deflate(ctx, state, state_sz);
}