Boost logo

Boost Users :

Subject: Re: [Boost-users] Read/write with gzip
From: johann (jgoetz_at_[hidden])
Date: 2011-04-27 12:10:13

I have a feeling this a file descriptor problem. I noticed you didn't close
the FD you opened when writing so I put the write and read blocks in their
own scope (see below). This seems to work now. I'm not sure if you can write
and read from a gzip'd file at the same time, maybe someone else can address
this issue?

compiled with boost 1.45 (gcc)
> g++ test.cpp -otest -lboost_iostreams -lboost_filesystem -lboost_system
> ./test

/// BEGIN file: test.cpp
#include <iostream>

#include &lt;boost/iostreams/filtering_streambuf.hpp&gt;
#include &lt;boost/iostreams/filtering_stream.hpp&gt;
#include &lt;boost/iostreams/copy.hpp&gt;
#include &lt;boost/iostreams/filter/gzip.hpp&gt;
#include &lt;boost/iostreams/device/file_descriptor.hpp&gt;
#include &lt;boost/filesystem.hpp&gt;

using namespace std;
namespace io = boost::iostreams;

int main()
    char* memblock_out = (char*) "aaa";
        io::filtering_ostream out;
        out.write(memblock_out, size);
    cout << memblock_out << endl;

    char* memblock_in = new char [4];
        io::filtering_istream in;
        in.push(io::file_descriptor_source("outfile.tmp.gz"));, size);
    cout << memblock_in << endl;
/// EOF

View this message in context:
Sent from the Boost - Users mailing list archive at

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at