使用方法:
包含zlib.h
连接时指明libz.so路径
compress,compress2为一次将所有串传入的压缩方法
int compress (Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen);
按照默认级别6压缩字符串
source,输入字符串,要求以‘\0'结尾,sourceLen = strlen(source)
dest 输出字符串,预先分配的空间,在source很短,只有几个byte时,长度需要比source长12个字节
一般情况,可以比较短。一般的压缩率是2~5。
返回值
compress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer.
zlib.h:
#define Z_OK 0
#define Z_STREAM_END 1
#define Z_NEED_DICT 2
#define Z_ERRNO (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR (-3)
#define Z_MEM_ERROR (-4)
#define Z_BUF_ERROR (-5)
#define Z_VERSION_ERROR (-6)
int compress2(Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen,
int level);
增加压缩级别参数level (1,...,9)
int uncompress (Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen);
统一解压缩函数,注意传出串的长度
返回值:
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
其他的使用方法见解压缩后的文件example.c
缓冲区设定方法:
1。修改zlib.h的默认值
2。编译时指定
-DMAX_WBITS=15 -DMAX_MEM_LEVEL=8(默认值)
DMAX_WBITS,窗口宽度,15似乎是最大的了,再高会出错.目前这个值是最好的.
DMAX_MEM_LEVEL 最大是8,小的话对性能有负面影响
分步压缩方法:
将串逐段传入,依次压缩,
第一个例子便是.
阅读(3562) | 评论(1) | 转发(0) |