7 COMP_METHOD *COMP_zlib(void );
11 static COMP_METHOD zlib_method={
25 static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
26 unsigned int olen, unsigned char *in, unsigned int ilen);
27 static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
28 unsigned int olen, unsigned char *in, unsigned int ilen);
30 static int zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
33 static COMP_METHOD zlib_method={
43 static int zlib_compress_block(ctx,out,olen,in,ilen)
58 i=compress(&(out[1]),&l,in,(unsigned long)ilen);
70 memcpy(&(out[1]),in,ilen);
73 fprintf(stderr,"compress(%4d)->%4d %s\n",ilen,(int)l,(clear)?"clear":"zlib");
77 static int zlib_expand_block(ctx,out,olen,in,ilen)
90 i=zz_uncompress(out,&l,&(in[1]),(unsigned long)ilen-1);
96 memcpy(out,&(in[1]),ilen-1);
99 fprintf(stderr,"expand (%4d)->%4d %s\n",ilen,(int)l,in[0]?"zlib":"clear");
103 static int zz_uncompress (dest, destLen, source, sourceLen)
112 stream.next_in = (Bytef*)source;
113 stream.avail_in = (uInt)sourceLen;
114 /* Check for source > 64K on 16-bit machine: */
115 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
117 stream.next_out = dest;
118 stream.avail_out = (uInt)*destLen;
119 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
121 stream.zalloc = (alloc_func)0;
122 stream.zfree = (free_func)0;
124 err = inflateInit(&stream);
125 if (err != Z_OK) return err;
127 err = inflate(&stream, Z_FINISH);
128 if (err != Z_STREAM_END) {
132 *destLen = stream.total_out;
134 err = inflateEnd(&stream);
140 COMP_METHOD *COMP_zlib()
142 return(&zlib_method);