I am using boost::iostreams filtering_stream to implement my custom archive format. This format should support various compression algorithm so that each file could be compressed by using a different method.
To that end I keep a global stream for reading (or writing) and add or remove filters as required. However it is unclear whether adding and removing filters on the fly is actually possible.
In essence, I am trying to do something like this:
void ArchiveFile::readFromStream( std::istream& inputStream, unsigned filters )
{
// create the filtered stream
boost::iostreams::filtering_istream in;
if ( filters & FILTERS_BZIP )
{
in.push( boost::iostreams::bzip2_decompressor() );
}
// add the source stream
in.push( inputStream );
// read file content
in.read( &mFileContent[0], mFileSize );
}
I am calling readFromStream for each file, using the same inputStream. However I keep getting gibberish this way even when not using any filter. When I directly use inputStream the file is read ok.
What am I doing wrong?