最重要的问题是 减压目的长度初始化设置大小,应该大于数据大小,否则uncompress会失败。
char acSource[100], acDest[100], acSourD[100];
int nSoucelen = 0, nDestLen, nSouceDLen1 =100 ;
memset(acSource, 0, 100);
memset(acDest, 0, 100);
memset(acSourD, 0, 100);
strcpy(acSource, "daddbddddcdesddddddddddddddddddddddddddddddddddddddddddddddddddddddddsdes");
nSoucelen = 73;
compress((unsigned char *)acDest, (unsigned long *)&nDestLen, (const unsigned char *)acSource, nSoucelen);
uncompress((unsigned char *)acSourD, (unsigned long *)&nSouceDLen1,(const unsigned char *)acDest, nDestLen);
ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
/*
compressBound() returns an upper bound on the compressed size after
compress() or compress2() on sourceLen bytes. It would be used before
a compress() or compress2() call to allocate the destination buffer.
*/
ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
/*
Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be large enough to hold the
entire uncompressed data. (The size of the uncompressed data must have
been saved previously by the compressor and transmitted to the decompressor
by some mechanism outside the scope of this compression library.)
Upon exit, destLen is the actual size of the compressed buffer.
This function can be used to decompress a whole file at once if the
input file is mmap'ed.
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.
*/