std::istream* stream_; boost::iostreams::filtering_streambuf<boost::iostreams::input>* filtering_streambuf_; ... stream_ = new std::istream(memoryBuffer_); if (stream_) { filtering_streambuf_ = new boost::iostreams::filtering_streambuf<boost::iostreams::input>(); if (filtering_streambuf_) { filtering_streambuf_->push(boost::iostreams::gzip_decompressor()); filtering_streambuf_->push(*stream_); archive_ = new eos::portable_iarchive(*filtering_streambuf_); } }
using zip when reading data from archives, and filtering_streambuf has a method like
std::streamsize std::streambuf::in_avail() Get number of characters available to read
so I check the end of the archive as
bool IArchiveContainer::eof() const { if (filtering_streambuf_) { return filtering_streambuf_->in_avail() == 0; } return false; }
It does not help to know how many objects are left in the archive last, but it helps to determine their end. (I use eof test only in a unit test to serialize / deserialize my classes / structures - to make sure that I read everything I write)
Yuri Levitsky
source share