Advertisement Jump to content
Sign in to follow this  

Rewinding streams in C++

This topic is 4958 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!