[iostreams] buffer flushing problem

Hi all,
I have encountered some strange behavior while using the Boost
iostreams zlib compression filter.
The problem is tricky to reproduce -- I have posted a tarball that
includes an example program (pasted below) together with a 72k binary
file that will be read in and compressed:
http://proteowizard.sourceforge.net/temp/zlib_error.tgz
If you're curious, the 72k data array comes from an array of doubles,
which were intensities from a single scan on a mass spectrometer. The
problem occurs on platforms darwin, gcc, msvc.
In general, the functions run_filter_1 and run_filter_2 produce
identical output. However, when the input is the binary array read in
from the 72k file, run_filter_1 appears not to flush some buffer
properly. This may be due to my ignorance of how to force the buffers
to flush, though it's not clear to me that this should be necessary
with the use of boost::iostreams::copy().
Thank you in advance for any help!
Darren
#include "boost/iostreams/filtering_streambuf.hpp"
#include "boost/iostreams/filtering_stream.hpp"
#include "boost/iostreams/copy.hpp"
#include "boost/iostreams/filter/zlib.hpp"
#include "boost/iostreams/device/array.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
using namespace std;
using namespace boost::iostreams;
template <typename filter_type>
string run_filter_1(const string& buffer)
{
ostringstream result(ios::binary);
array_source source(&buffer[0], buffer.size());
filtering_streambuf<input> in;
in.push(filter_type());
in.push(source);
boost::iostreams::copy(in, result); // not flushing properly in
all cases?
return result.str();
}
template <typename filter_type>
string run_filter_2(const string& buffer)
{
ostringstream result(ios::binary);
filtering_ostream fos;
fos.push(filter_type());
fos.push(result);
fos.write(&buffer[0], buffer.size());
fos.pop();
fos.pop(); // force flush buffer
return result.str();
}
int main()
{
// fill buffer with something trivial
string buffer(72000, '\0');
for (size_t i=0; i
participants (1)
-
Darren Kessner