*** DocumentRef.cc.old Fri Jan 29 15:52:26 1999 --- DocumentRef.cc Fri Jan 29 23:01:44 1999 *************** *** 18,30 **** #ifdef HAVE_LIBZ #include - #endif extern Configuration config; ! // Static member variable so we get only a single copy ! // Used to buffer the zlib compression ! static unsigned char DocumentRef::c_buffer[60000]; //***************************************************************************** // DocumentRef::DocumentRef() --- 18,129 ---- #ifdef HAVE_LIBZ #include extern Configuration config; ! //unsigned char DocumentRef::c_buffer[32000]; ! // ! // Compress Function ! // ! int DocumentRef::Compress(String &s) { ! static int cf=config.Value("compression_level",0); ! if (cf) { ! // ! // Now compress s into c_s ! // ! unsigned char c_buffer[16384]; ! String c_s; ! z_stream c_stream; /* compression stream */ ! c_stream.zalloc=(alloc_func)0; ! c_stream.zfree=(free_func)0; ! c_stream.opaque=(voidpf)0; ! // Get compression factor, default to best ! if (cf<-1) cf=-1; else if (cf>9) cf=9; ! int err=deflateInit(&c_stream,cf); ! if (err!=Z_OK) return 0; ! int len=s.length(); ! c_stream.next_in=(Bytef*)(char *)s; ! c_stream.avail_in=len; ! while (err==Z_OK && c_stream.total_in!=(uLong)len) { ! c_stream.next_out=c_buffer; ! c_stream.avail_out=sizeof(c_buffer); ! err=deflate(&c_stream,Z_NO_FLUSH); ! c_s.append((char *)c_buffer,c_stream.next_out-c_buffer); ! } ! // Finish the stream ! for (;;) { ! c_stream.next_out=c_buffer; ! c_stream.avail_out=sizeof(c_buffer); ! err=deflate(&c_stream,Z_FINISH); ! c_s.append((char *)c_buffer,c_stream.next_out-c_buffer); ! if (err==Z_STREAM_END) break; ! //CHECK_ERR(err, "deflate"); ! } ! err=deflateEnd(&c_stream); ! s=c_s; ! } ! return 1; ! } ! ! // ! // Decompress routine returns 0 if decompressed 1 if compressed ! // ! int DocumentRef::Decompress(String &s) { ! static int cf=config.Value("compression_level",0); ! if (cf) { ! String c_s; ! // Decompress stream ! unsigned char c_buffer[16384]; ! z_stream d_stream; ! d_stream.zalloc=(alloc_func)0; ! d_stream.zfree=(free_func)0; ! d_stream.opaque=(voidpf)0; ! ! int len=s.length(); ! d_stream.next_in=(Bytef*)(char *)s; ! d_stream.avail_in=len; ! ! int err=inflateInit(&d_stream); ! if (err!=Z_OK) return 1; ! ! while (err==Z_OK && d_stream.total_in9) cf=9; - int err=deflateInit(&c_stream,cf); - if (err!=Z_OK) return; - int len=s.length(); - c_stream.next_in=(Bytef*)(char *)s; - c_stream.avail_in=len; - while (err==Z_OK && c_stream.total_in!=(uLong)len) { - c_stream.next_out=c_buffer; - c_stream.avail_out=sizeof(c_buffer); - err=deflate(&c_stream,Z_NO_FLUSH); - c_s.append((char *)c_buffer,c_stream.next_out-c_buffer); - } - // Finish the stream - for (;;) { - c_stream.next_out=c_buffer; - c_stream.avail_out=sizeof(c_buffer); - err=deflate(&c_stream,Z_FINISH); - c_s.append((char *)c_buffer,c_stream.next_out-c_buffer); - if (err==Z_STREAM_END) break; - //CHECK_ERR(err, "deflate"); - } - err = deflateEnd(&c_stream); - s=c_s; - } - #endif } --- 347,352 ---- *************** void DocumentRef::Serialize(String &s) *** 288,333 **** void DocumentRef::Deserialize(String &stream) { Clear(); - #ifdef HAVE_LIBZ - char *s; - char *end; - String c_s; - static int cf=config.Value("compression_level",0); - if (cf) { - // Decompress stream - z_stream d_stream; /* decompression stream */ - - d_stream.zalloc = (alloc_func)0; - d_stream.zfree = (free_func)0; - d_stream.opaque = (voidpf)0; - - d_stream.next_in = (Bytef*)(char *)stream; - d_stream.avail_in = 0; - - int err = inflateInit(&d_stream); - if (err!=Z_OK) return; - - int len=stream.length(); - d_stream.avail_in=len; - while (err==Z_OK && d_stream.total_in