Article View: borland.public.cppbuilder.nativeapi
Article #5386Re: Compress/uncompress a Buffer
From: sam
Date: Fri, 19 Aug 2005 12:13
Date: Fri, 19 Aug 2005 12:13
56 lines
2660 bytes
2660 bytes
Andrue, I have found these 2 ZLIB's functions for compress/uncompress a
buffer:
The COMPRESSSTRING works without error, but the UNCOMPRESSSTRING generates
error Z_BUF_ERROR.
What is wrong ?
bool COMPRESSSTRING( AnsiString &sString)
{
ULONG ulBuffLen;
char *szBuff=NULL;
ulBuffLen = sString.Length() + pMaxBuffer;
szBuff = new char[ulBuffLen+1];
szBuff[ulBuffLen]='\0';
memset(szBuff,'\0',ulBuffLen);
ULONG ulRet = compress( szBuff, &ulBuffLen, sString.c_str() ,
sString.Length());
if(Z_OK == ulRet){
// Now the pointer of the original string will point to the
compressed string.
AnsiString sResultStr(szBuff,ulBuffLen);
sString = sResultStr;
delete[] szBuff; return true;
}
else{
ShowMessage("Error Compression"); delete[] szBuff; return
false;
}
}
//------------------------------------------------------------------------------
bool UNCOMPRESSSTRING(AnsiString &sString)
{
ULONG ulBuffLen;
char *szBuff=NULL;
ulBuffLen = sString.Length() + pMaxBuffer+12;
szBuff = new char[ulBuffLen+1];
szBuff[ulBuffLen]='\0';
memset(szBuff,'\0',ulBuffLen);
ULONG ulRet = uncompress(szBuff, &ulBuffLen, sString.c_str(),
sString.Length());
if(Z_OK == ulRet){
AnsiString sResultStr(szBuff,ulBuffLen);
sString = sResultStr;
delete[] szBuff; return true;
}
else{
ShowMessage("Error uncompress: <" + IntToStr((int)ulRet) + ">");
delete[] szBuff; return false;
}
}
Technical Details
Message-ID:
<4305ccc9@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed.hal-mli.net!feeder1.hal-mli.net!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.spamkiller.net!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<4304a1d6@newsgroups.borland.com> <4304a3dd@newsgroups.borland.com> <4304c079@newsgroups.borland.com> <4305934f$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,68b90959c01bbcf3 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "sam" <s33@hotmail.com> From: "sam" <s33@hotmail.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4304a1d6@newsgroups.borland.com> <4304a3dd@newsgroups.borland.com> <4304c079@newsgroups.borland.com> <4305934f$1@newsgroups.borland.com> Subject: Re: Compress/uncompress a Buffer Date: Fri, 19 Aug 2005 14:13:01 +0200 Lines: 58 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 83.195.12.122 Message-ID: <4305ccc9@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1124453577 83.195.12.122 (19 Aug 2005 05:12:57 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed.hal-mli.net!feeder1.hal-mli.net!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.spamkiller.net!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mail