On Wed, Apr 27, 2011 at 12:27 PM, Ted Byers <r.ted.byers@gmail.com> wrote:


On Tue, Apr 26, 2011 at 8:54 PM, Anders Knudby <knudby@gmail.com> wrote:
Hello, I previously managed to write data to a gzipped file using the following code structure (it's an example of course, the "memblock" is actually filled with real data and the real filename is specified elsewhere).

#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/filesystem.hpp>

namespace io = boost::iostreams;
int size = 1000;
char* memblock = new char [size];

io::filtering_ostream out; out.push(io::gzip_compressor()); out.push(io::file_descriptor_sink("c:/outfile.gz"));
out.write (memblock, size);

Is there a reason not to invoke the stream's member function 'close' at this point?  You are, after all, reopening the same file later in your program.

Cheers

Ted

 
Thanks for the help. The problem of writing the file and then trying to read it later in the same process is an artefact of my example, in reality I have one program to write the files, and another to read them again. But the reason I'm not specifically closing the filtering_stream is that I don't know how! I thought I could treat it as a normal iostream (e.g. using read, write etc.), but the normal closing of an iostream - in.close() - doesn't compile. Instead it gives me the following error: "error C2039: 'close' : is not a member of 'boost::iostreams::filtering_stream<Mode>". I have found a mention somewhere that I need to make the filtering_stream 'closeable', but I haven't found out how to do that. Any help would be appreciated, I do like to close my streams...

In the meantime, I have somehow managed to get my code to work. I'm not sure how, but it is definitely related to the closing or not of the filtering_stream. If someone has a simple example of how to create and then close/destroy a filtering_streambuf that would be great. I can't find a single example in the Boost documentation, but maybe I'm just not looking in the right place or sufficiently code-literate.

Anders