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