Boost logo

Boost Users :

From: CPPer (coolcute_at_[hidden])
Date: 2007-04-20 09:32:02


Hi!
Is there anyone know how to use boost::iostreams to de/compress data from
memory ?

>From file the code bellow works well:

#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>

namespace io = boost::iostreams;

int main()
{
        using namespace std;

        ifstream file("hello.gz", ios_base::in | ios_base::binary);
        io::filtering_streambuf<io::input> in;
        in.push(io::gzip_decompressor());
        in.push(file);
        io::copy(in, cout);
}

But if I changed ifstream into istringstream like this:
#include <fstream>
#include <sstream>
#include <boost/iostreams/filtering_stream.hpp>
//#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>

namespace io = boost::iostreams;

int main()
{
        using namespace std;

        ifstream file("hello.gz", ios_base::in | ios_base::binary);
        io::filtering_istream in;
        in.push(io::gzip_decompressor());
        in.push(file);

        //std::ostringstream ostr;

        //io::copy (in, ostr);

        //std::string stir = ostr.str ();
        std::string stir;

        in >> stir;

        //ofstream ofs("output.gz", ios_base::out | ios_base::binary);
        ostringstream ostr;
        io::filtering_ostream out;
        out.push (io::gzip_compressor());
        out.push (ostr);

        out << stir;

        stir= out.str();
}

the std::string stir always NULL when I want to get the data after compress.

Sorry for my bad English..
I am a Chinese.


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