Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

DarkSaint

using file stream to open in memory buffer

This topic is 5276 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 using zlib/unzip to read my game files from a zip file. what I want to do is open a text file with the unzip function, uncompress it and then move it into a buffer and then use a file stream .open function. Does anyone know if it''s possible to open a buffer instead of an actual on-disk file with a fstream?

Share this post


Link to post
Share on other sites
Advertisement
That just seems slightly unecessary. You''ve already got the buffer in memory...why not just read directly out of it?

Share this post


Link to post
Share on other sites
I didn''t want to use the unzip read funcitons to read the file. Could I just use the extraction operator to read the data I need from the buffer like so?

buffer >> data1 >> data2 >> data3...etc

Share this post


Link to post
Share on other sites
What he meant was that if you already decompress the file to a buffer, why not just read directly from the buffer? It appears as though you want to wrap this decompressed buffer into a file stream, which would be pointless.

It''s possible to use streams though. You''d put your buffer into a basic_streambuf using the sputn function, then construct a new basic_istream which your stream buffer. Then you could use extraction operators on the stream.

You could also wrap it into a basic_stringstream if you so choose. That would probably be easier.

Share this post


Link to post
Share on other sites
thanks for the info. Could you tell me what functions are used to create a basic_stringstream or where I can get info on how to use the stream functions?

Share this post


Link to post
Share on other sites
You''ll either want an istream with a custom stream buffer (you''ll have to write that yourself), that asks zlib for mor data on underflow. Or, for simple extraction of data currently in the buffer (assuming all the data is already there), use an istringstream.


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!