[Iostreams] Zlib compression sometimes creates corrupt data on OSX

Hello,
I’m having the following problem with my program: If I save data on OSX
using a boost::iostreams::filtering_ostream with a
boost::iostreams::zlib_compressor() the resulting file is sometimes
corrupted.
The following example code reproduces the problem:
#include <fstream>
#include <iostream>
#include <vector>
#include

On 10/2/2013 11:07 AM, Michael Jung wrote:
Hello,
I’m having the following problem with my program: If I save data on OSX using a boost::iostreams::filtering_ostream with a boost::iostreams::zlib_compressor() the resulting file is sometimes corrupted.
The following example code reproduces the problem:
#include <fstream> #include <iostream> #include <vector> #include
#include int main(int argc, char** argv) { if (argc != 2) return 1; std::ifstream file(argv[1]);
Maybe add: , std::ios_base::binary
if (file) { file.seekg(0, std::ios::end); std::streampos length = file.tellg(); file.seekg(0, std::ios::beg);
std::vector<char> buffer1(length); std::vector<char> buffer2(length);
file.read(&buffer1[0], length);
{ std::ofstream ofs("test.dat", std::ios_base::binary); boost::iostreams::filtering_ostream fos; fos.push(boost::iostreams::zlib_compressor()); fos.push(ofs);
fos.write(&buffer1[0], length); } { std::ifstream ifs("test.dat", std::ios_base::binary); boost::iostreams::filtering_istream fis; fis.push(boost::iostreams::zlib_decompressor()); fis.push(ifs);
fis.read(&buffer2[0], length); }
std::cout << (buffer1 == buffer2 ? "equal" : "not equal") << std::endl; } }
otherwise search the mailing list for a thread from back in July 2013: "[iostreams] How can I use the Stream Insertion operator (<<) with a filtering_streambuf?" Jeff
participants (2)
-
Jeff Flinn
-
Michael Jung