I have defined a boost Device called ZipFileDevice, that takes in an archive path, and a path to a file within that archive.
The Device defines read, write, seek, a costructor that takes the two paths, and a destructor.
I am opening the zip file in the constructor of ZipFileDevice, and closing it in the destructor.
This is how I am using the Device:
boost::iostreams::stream_buffer<ZipFileDevice> kBuff("path/to/archive", "path/to/file");
std::iostream kStream(&kBuff);
kStream.read(...);
My problem is that the ZipFileDevice is copied twice when creating the stream_buffer, and the copies are destroyed, closing the zip file. When I read from the stream, the file has been closed.
How do I correctly handle opening and closing a Device?