00001
00002
00003
00004
00005
00006
00007
00008 #include "zlib.h"
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
00022 Bytef *dest;
00023 uLongf *destLen;
00024 const Bytef *source;
00025 uLong sourceLen;
00026 int level;
00027 {
00028 z_stream stream;
00029 int err;
00030
00031 stream.next_in = (Bytef*)source;
00032 stream.avail_in = (uInt)sourceLen;
00033 #ifdef MAXSEG_64K
00034
00035 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
00036 #endif
00037 stream.next_out = dest;
00038 stream.avail_out = (uInt)*destLen;
00039 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
00040
00041 stream.zalloc = (alloc_func)0;
00042 stream.zfree = (free_func)0;
00043 stream.opaque = (voidpf)0;
00044
00045 err = deflateInit(&stream, level);
00046 if (err != Z_OK) return err;
00047
00048 err = deflate(&stream, Z_FINISH);
00049 if (err != Z_STREAM_END) {
00050 deflateEnd(&stream);
00051 return err == Z_OK ? Z_BUF_ERROR : err;
00052 }
00053 *destLen = stream.total_out;
00054
00055 err = deflateEnd(&stream);
00056 return err;
00057 }
00058
00059
00060
00061 int ZEXPORT compress (dest, destLen, source, sourceLen)
00062 Bytef *dest;
00063 uLongf *destLen;
00064 const Bytef *source;
00065 uLong sourceLen;
00066 {
00067 return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
00068 }