Boost logo

Boost Users :

Subject: [Boost-users] [iostreams] Inconsistent state of stream
From: Nicola (nvitacolonna_at_[hidden])
Date: 2010-04-29 13:00:51


Hi,
can someone tell me if the behaviour of the enclosed example is a bug?
In my test, the last two assertions fail, but I don't understand why
(Boost 1.42.0).

Thanks,
Nicola

#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <cassert>
#include <fstream>
#include <sstream>

struct bz2istream :
public boost::iostreams::filtering_stream<boost::iostreams::input>
{
public:
   bz2istream(std::string const& path) :
      pBz2file(path.c_str(), std::ios_base::in | std::ios_base::binary)
   {
      push(boost::iostreams::bzip2_decompressor());
      push(pBz2file);
   }
private:
   std::ifstream pBz2file;
};

int main() {
   bz2istream bzippedfile("foo.bz2");
   std::ostringstream os;
   boost::iostreams::copy(bzippedfile, os);
   
   assert(!(bzippedfile.rdstate() & std::ios_base::goodbit)); // Ok
   assert(bzippedfile.rdstate() & std::ios_base::eofbit); // Fails
   assert(!(bzippedfile.good())); // Fails
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net