Sorry for top posting (I don't know yet how to tell MS Outlook not to do so)
Anyway, All I wanted to say is although I'd thought the filtering stream was derived from regular iostreams, it appears that isn't the case, and that's why close isn't available as a member function. However, boost::iostreams provides a template function called close, so the statements 'close(out)' and 'close(in)' both compile.
I can't get it to link, though, as it complains about unresolved externals relating to libboost-zlib ….. this is with both MSVC++ 2010 and cygwin. There are no libraries related to zlib in either directory where I built the boost libraries. I don't (yet) know why.
Anyway, your problem of closing your streams ought to be resolved by resorting to the close template function.
Cheers
Ted
From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Anders Knudby
Sent: April-27-11 2:06 PM
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] Read/write with gzip
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
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users