Compress zlib

来源:百度文库 编辑:神马文学网 时间:2024/04/28 20:07:11
Ezlib.lib
Estlib.lib
#include
#include
#include
#include
{
int err;
z_stream c_stream; /* compression stream */
Byte * compr;
uLong comprLen = 20*sizeof(int);
compr    = (Byte*)calloc((uInt)comprLen, 1);
const char hello[] = "hello, hello!";
uLong len = (uLong)strlen(hello)+1;
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
c_stream.next_in  = (Bytef*)hello;
c_stream.next_out = compr;
while (c_stream.total_in != len && c_stream.total_out < comprLen)
{
c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
err = deflate(&c_stream, Z_NO_FLUSH);
}    /* Finish the stream, still forcing small buffers: */
deflateEnd(&c_stream);
free(compr);
}