Most file formats consist of two parts.
First part is the header which is responsible for identification of the file format -- it often contains some "magic number", version information, author data, etc and it should have a constant length (or its length should be stored somewhere near the beginning of the file).
The second part is responsible for keeping the data itself. The way you implement it depends only on you. This data storage part is often organised as a vector of chunks, where each chunk has its internal structure (chunk header and body which can differ depending on the chunk type). Each of the chunks holds some part of data and their meaning and behaviour depends on the type of data it represents.
Chunks are especially nice if you want your file format to be incremental -- then you can add a new chunk of data on the end of the file without the need to rewrite the already existing part. It is convenient to have a constant sized header in such a situation (so that you can be sure you won't have to rewrite the whole file just to replace one byte in the header).
Other types of file formats (like BMP for example) are a plain dump of held data -- in case of BMP it is the header containing picture size, then the colour lookup table for non-truecolour images and then a dump of pixell data (upside down and in BGR format, AFAIR).
Additional thing to remember is that often files contain data in some compressed format and it is important to choose the compression algorithm depending on the characteristics of data representation (for example mentioned qCompress can give much worse results than some other compression).
Bookmarks