Overview
Features
Download
Documentation
Community
Add-Ons & Services

Deflate a stringstream, or ostringstream

Please post support and help requests here.

Deflate a stringstream, or ostringstream

Postby cosu2004 » 30 Oct 2012, 13:11

Hello,

Big question guys, is giving me a big headache...How can I deflate a string? I want to send it over a StreamSocket to another computer but I want to compress it. I tried this bit of code and I get an error when copying the deflater stream to another stream. And how can I get the size of the compressed stream???

Another idea is to create an ostream from a string (which I don't know how to do it) and then get the compressed version

Help! :(

Code: Select all
        ostringstream str;
        istringstream outstr(XMLString);
   DeflatingStreamBuf deflater(outstr, Poco::DeflatingStreamBuf::STREAM_ZLIB, -1);
   deflater<<XMLString;
   deflater.close();
   StreamCopier::copyStream(str, deflater);
   
   cout <<"Compressed size: "<<outstr.str().size();
cosu2004
 
Posts: 14
Joined: 05 Jul 2012, 10:50

Re: Deflate a stringstream, or ostringstream

Postby rakesh » 30 Oct 2012, 16:21

You are closing the deflater stream before the copy.
rakesh
 
Posts: 78
Joined: 13 Apr 2011, 17:43
Location: Chicago

Re: Deflate a stringstream, or ostringstream

Postby cosu2004 » 01 Nov 2012, 00:59

I manage to fix it....
Code: Select all
   ostringstream OutStream; // the stream that will contain the deflated message
   istringstream InStream(XMLString);
   DeflatingOutputStream compressor(OutStream, Poco::DeflatingStreamBuf::STREAM_GZIP, thconf.globalParse._thAppconf->SOCS.ThreadMsgCompressLevel);
   //deflater<<XMLString;
   StreamCopier::copyStream(InStream, compressor);
   compressor.close();
cosu2004
 
Posts: 14
Joined: 05 Jul 2012, 10:50


Return to Support

Who is online

Users browsing this forum: No registered users and 6 guests

cron