wrapping stdlib fstream with boost filtering streams

Hi, I have a homebrewed matlab file library for which I am considering using the boost filtering streams for zlib compression. In Matlab(tm) files, variables may be compressed individually, meaning there will be compressed blocks inside the file surrounded by umcompressed data. Thus I would like to have (de)compressors which I can plug in at the start of the block and take back out when I am done. I went and applied the boost filtering streams but I have some problems, so before I go into hardcore debugging I would like to ask if I am using the lib right (because the docs are a bit sparse at the relevant spots). This is how I start up the stream(s): File::File(std::string path, std::ios_base::openmode mode) : _fstream(path.c_str(), mode | std::ios_base::binary) { if (!_fstream.is_open()) throw_error("could not open matfile " << path); _istream.set_auto_close(false); _ostream.set_auto_close(false); _istream.push(_fstream); _ostream.push(_fstream); } and these are the methods for starting/stopping the compressed blocks for reading/writing: void File::startunzipping(std::streampos len) { stopunzipping(); _unzend = _fstream.tellg() + len; _unzcount = 0; _istream.pop(); _istream.push(boost::iostreams::zlib_decompressor()); _istream.push(_fstream); _unzipping = true; } void File::stopunzipping() { if (_unzipping==false) return; _istream.pop(); _istream.pop(); _istream.push(_fstream); _unzipping = false; _fstream.seekg(_unzend); } void File::startzipping() { stopzipping(); write_type_and_size(TypeAndSize(Types::Compressed,0),false); _zstart = _fstream.tellp(); _zcount = 0; _ostream.pop(); _ostream.push(boost::iostreams::zlib_compressor()); _ostream.push(_fstream); _zipping = true; } void File::stopzipping() { if (_zipping==false) return; _ostream.flush(); _ostream.pop(); _ostream.pop(); _ostream.push(_fstream); _zipping = false; _zend = _fstream.tellp(); } Two open questions that come to mind: 1) does the compressor flush the zlib compression buffer when I flush/ pop it? 2) is fstream a bidirectional stream (my guess due to separate seekg/ seekp methods) or a seekable stream (one read/write head)? Because I currently require the former. btw: the above code runs without exceptions, but when I read back variables I have just written they are garbled.

Daniel Oberhoff wrote:
Two open questions that come to mind:
1) does the compressor flush the zlib compression buffer when I flush/ pop it?
As I understand it, pop() and reset() both flush and close the current device and then destroy it.
2) is fstream a bidirectional stream (my guess due to separate seekg/ seekp methods) or a seekable stream (one read/write head)? Because I currently require the former.
btw: the above code runs without exceptions, but when I read back variables I have just written they are garbled.
You should read the thread of messages at... there may be some relevant info here: http://thread.gmane.org/gmane.comp.lib.boost.user/13824 Especially the replies by Jonathan Turkanis
participants (2)
-
Daniel Oberhoff
-
egoots