Rewinding streams in C++
I'm making a simple image library that supports loading different kinds of image file formats from std::istreams. I need to be able to determine the image file format before starting to decode it. For example I need to know if the file is a JPEG file, before I initialize libjpeg to decode the image.
In order to do this I need to read several bytes from the stream, then somehow go back to the beginning of the stream to read the data for the lowlevel image library. I cannot use peek() since it reads only one byte. For the same reason unget() is out of the question. I cannot use seekg() because I might be reading the image from a stream that doesn't support seeks.
Can I somehow encapsulate the stream into another to allow seeking back to the beginning after reading a handful of bytes, or should I device some kind of clunky buffering scheme of my own?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement