#12945 closed Feature Requests (invalid)
boost::iostreams filtering streambufs only work with binary archive
Reported by: | Owned by: | Robert Ramey | |
---|---|---|---|
Milestone: | To Be Determined | Component: | serialization |
Version: | Boost 1.62.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Since there is no portable binary format, using the text archive and gzipping it seems convenient. However, using boost::iostream's filtering_streambuf only works with the binary archive, not the text archive, which is somewhat surprising.
#include <iostream> #include <sstream> #include <boost/archive/binary_oarchive.hpp> #include <boost/archive/text_oarchive.hpp> #include <boost/iostreams/filter/gzip.hpp> #include <boost/iostreams/filtering_streambuf.hpp> #include <boost/serialization/vector.hpp> int main() { const std::vector<int> v{0, 1, 2}; std::stringstream ss; { boost::iostreams::filtering_ostreambuf o; o.push(boost::iostreams::gzip_decompressor()); o.push(ss); // filtering_ostreambuf isn't accepted by text_oarchive's ctor, only by binary_oarchive // So this doesn't work boost::archive::text_oarchive oa(o); // But this does // boost::archive::binary_oarchive oa(o); oa << v; } std::cout << ss.str() << '\n'; return 0; }
Change History (3)
comment:1 by , 5 years ago
comment:2 by , 5 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
for text files use filtering_ostream rather than filtering_ostreambuf .
text files must use streams. binary files may use streams or streambuf
#include <iostream> #include <sstream> #include <boost/archive/binary_oarchive.hpp> #include <boost/archive/text_oarchive.hpp> #include <boost/iostreams/filter/gzip.hpp> #include <boost/iostreams/filtering_stream.hpp> #include <boost/serialization/vector.hpp> int main() { const std::vector<int> v{0, 1, 2}; std::stringstream ss; { boost::iostreams::filtering_ostream o; o.push(boost::iostreams::gzip_decompressor()); o.push(ss); // filtering_ostreambuf isn't accepted by text_oarchive's ctor, only by binary_oarchive // So this doesn't work boost::archive::text_oarchive oa(o); // But this does // boost::archive::binary_oarchive oa(o); oa << v; } std::cout << ss.str() << '\n'; return 0; }
comment:3 by , 5 years ago
Oh, I'm sorry! In my defense I'd like to add I had several people look at it and they didn't see it. I guess it's confusing text archives work with both while binary ones don't, but of course that's not a bug.
Thank you!
Indeed - it IS surprising.
And it's not toooooooo hard to fix. I'll look into it.