Jump to content
  • Advertisement
Sign in to follow this  
Komal Shashank

What exactly is a file header?

This topic is 1260 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

Hi... I'm new to GameDev.net. This is my first post. Can someone please tell me: What is a file header? Why is it used? And what would I need to do to write a file header to a file or read a file header from a file in binary using fstream?

 
Searching for this on Google turns up results for header files (.h). Nothing for file header. Please help. Thank you.

Share this post


Link to post
Share on other sites
Advertisement

OK... So if I wanted to write in C++, say a vector of integers (std::vector<int>), in binary format, I just ofstream their binary representation as bytes into the file? Also, how would I separate the file's data from it's header while writing so that when reading it will be distinguished respectively and treated as such (header as header and data as data)?

Edited by WDRKKS

Share this post


Link to post
Share on other sites

A file header is part of the file, it's not really separate from it. It's just a number of bytes that's defined (in the file's format description) as having some specific meaning.

 

So you don't do anything special to read or write it, it's just some more data.

 

For your own file format, you could define a struct that holds a value to identify the file as something that you know (some pre-defined 32bit integer value, for example) and then some useful information (count of the items you've written, for example).

Share this post


Link to post
Share on other sites

Nice! That's a very detailed article. Thanks for the link. And thank you guys for helping out. It really answered a lot of questions I had. I really appreciate it. I upvoted all your posts. Cheers! smile.png

Share this post


Link to post
Share on other sites

Thank you, frob! That is a very detailed and informative explanation. I do have one question though... All the different types of data that you mention that can be stored in the header, can all this be declared inside a struct and written normally at the start of the file just like the payload data? Please clarify. Thanks.

Edited by WDRKKS

Share this post


Link to post
Share on other sites

Thank you, frob! That is a very detailed and informative explanation. I do have one question though... All the different types of data that you mention that can be stored in the header, can all this be declared inside a struct and written normally at the start of the file just like the payload data? Please clarify. Thanks.

 

That's pretty much how that would work, yeah. Fill out your header struct in your code and just write it to the beginning of your file. At read time you just read in this struct again from the beginning of the file and you're good to go

Share this post


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

  • 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!