🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #5393

Re: Compress/uncompress a Buffer

#5393
From: Andrue Cope [TeamB]
Date: Fri, 19 Aug 2005 15:54
54 lines
2610 bytes
The following might work. Unfortunately for no obvious reason I can see
I'm unable to create a running application based around it:

std::vector<BYTE> compress( AnsiString const & TheString )
{
  std::vector<BYTE> result( 2*TheString.Length() ); // Allow for an
overhead

  DWORD len=result.size();

  compress( &( result[ 0 ] ),
            &len,
            reinterpret_cast<BYTE *>( TheString.c_str() ),
            TheString.Length());

  result.resize( len );

  return result;
}

AnsiString decompressData( std::vector<BYTE> TheBuffer )
{
  std::vector<BYTE> result( 1024 ); 
  // Should be enough but you need to do something about this

  DWORD len=result.size();

  uncompress( &( result[ 0 ] ),
              &len,
              &( TheBuffer[ 0 ] ),
              TheBuffer.size() );

  return AnsiString( reinterpret_cast<char *>( &( result[ 0 ] ) ),
                     len );
}

void test()
{
  AnsiString fred="This is a compression test";

  std::vector<BYTE> compressedData=compress( fred );

  ShowMessage( decompressData( compressedData ) );
        return 0;
}

For some /bizarre/ reason as soon as the linker has to include the zlib
functions the application won't run. It just hits some freaky
breakpoint and stops. I'll see if I can find out why but I don't know.
We have other applications using this library without a problem :-/
-- 
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
Technical Details
Message-ID: <43060098$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!mpls-transit-01.news.qwest.net!38.119.100.82.MISMATCH!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <4304a1d6@newsgroups.borland.com> <4304a3dd@newsgroups.borland.com> <4304c079@newsgroups.borland.com> <4305934f$1@newsgroups.borland.com> <4305ccc9@newsgroups.borland.com> <4305d471$1@newsgroups.borland.com> <4305f25b@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
From: "Andrue Cope [TeamB]" <no.spam@not.a.valid.address>
Subject: Re: Compress/uncompress a Buffer
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4304a1d6@newsgroups.borland.com> <4304a3dd@newsgroups.borland.com> <4304c079@newsgroups.borland.com> <4305934f$1@newsgroups.borland.com> <4305ccc9@newsgroups.borland.com> <4305d471$1@newsgroups.borland.com> <4305f25b@newsgroups.borland.com>
Date: Fri, 19 Aug 2005 16:54:15 +0100
User-Agent: XanaNews/1.17.5.9
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
NNTP-Posting-Host: 217.207.223.34
Message-ID: <43060098$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1124466840 217.207.223.34 (19 Aug 2005 08:54:00 -0700)
Lines: 54
X-Authenticated-User: acope
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!mpls-transit-01.news.qwest.net!38.119.100.82.MISMATCH!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail