Boost logo

Boost :

From: Joe Mariadassou (JMariadassou_at_[hidden])
Date: 2001-02-15 20:35:31

> -----Original Message-----
> From: Murray, Peter C [mailto:Peter.Murray_at_[hidden]]
> Sent: Thursday, 15 February 2001 10:56 AM
> To: 'boost_at_[hidden]'
> Subject: [boost] Stream manipulators for compression, encryption, etc
> With regard to the disussions on compression, would a more
> elegant approach
> be to create some form of compressing stream manipulator? I
> admit that I am
> particularly weak on streams, so apologies if I am proposing something
> impossible...
> Conceptually, I'd like to do something like this:
> outfile << encrypt<DES> << compress<ZIP> << myClass;
> infile >> decrypt<DES> >> decompress<ZIP> >> myClass;
> What do people think of this approach, if its even possible?
> - Peter.

One solution would be like this
class Compress
///some defs
class CompressStream: public ostream
// some code

CompressStream operator<<(ostream&,Compress&);

However the catch would be after excecuting
the compress stream adapter would be destroyed.

So a better solution would be something like this:
class CompressBuf: public streambuf
    streambuf& buf;
   CompressBuf(streambuf& inbuf): buf(inbuf)
        // other init code
   //override overflow to compress the data before putting it into buf
which would be used as:

ofstream ofs("outfil");
CompressBuf obuf(*ofs.rdbuf());
ostream ostr(obuf);


Of course you can cascade streams like this:

ofstream ofs("outfil");
Base64Buf b64Buf(*ofs.rdbuf());
CompressBuf cbuf(b64Buf);
ostream ostr(cbuf);

This should compress Mydata and convert it base64 and put it to ofs;

Developing in VC++ I must caution:
puts only one character (0xa) which is not quite what I expected.


Boost list run by bdawes at, gregod at, cpdaniel at, john at