File indexing completed on 2025-05-11 08:24:10
0001
0002
0003
0004
0005
0006
0007
0008 #define ZLIB_INTERNAL
0009 #include "zlib.h"
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 int ZEXPORT compress2(dest, destLen, source, sourceLen, level)
0023 Bytef *dest;
0024 uLongf *destLen;
0025 const Bytef *source;
0026 uLong sourceLen;
0027 int level;
0028 {
0029 z_stream stream;
0030 int err;
0031 const uInt max = (uInt)-1;
0032 uLong left;
0033
0034 left = *destLen;
0035 *destLen = 0;
0036
0037 stream.zalloc = (alloc_func)0;
0038 stream.zfree = (free_func)0;
0039 stream.opaque = (voidpf)0;
0040
0041 err = deflateInit(&stream, level);
0042 if (err != Z_OK) return err;
0043
0044 stream.next_out = dest;
0045 stream.avail_out = 0;
0046 stream.next_in = (z_const Bytef *)source;
0047 stream.avail_in = 0;
0048
0049 do {
0050 if (stream.avail_out == 0) {
0051 stream.avail_out = left > (uLong)max ? max : (uInt)left;
0052 left -= stream.avail_out;
0053 }
0054 if (stream.avail_in == 0) {
0055 stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen;
0056 sourceLen -= stream.avail_in;
0057 }
0058 err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
0059 } while (err == Z_OK);
0060
0061 *destLen = stream.total_out;
0062 deflateEnd(&stream);
0063 return err == Z_STREAM_END ? Z_OK : err;
0064 }
0065
0066
0067
0068 int ZEXPORT compress(dest, destLen, source, sourceLen)
0069 Bytef *dest;
0070 uLongf *destLen;
0071 const Bytef *source;
0072 uLong sourceLen;
0073 {
0074 return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
0075 }
0076
0077
0078
0079
0080
0081 uLong ZEXPORT compressBound(sourceLen)
0082 uLong sourceLen;
0083 {
0084 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
0085 (sourceLen >> 25) + 13;
0086 }