Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411916 Posts in 69431 Topics- by 58477 Members - Latest Member: KriegsHetzer

June 10, 2024, 02:11:18 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Variable length file headers?
Pages: [1]
Print
Author Topic: Variable length file headers?  (Read 919 times)
ACardboardRobot
Guest
« on: July 01, 2010, 04:10:05 PM »

nope
« Last Edit: December 10, 2016, 06:58:16 PM by acardboardrobot » Logged
LemonScented
Level 7
**



View Profile
« Reply #1 on: July 01, 2010, 04:45:01 PM »

I'm not sure I understand the question... Any file format is possible so long as it can be expressed as binary data. All you have to do is make sure that the program that reads the data can interpret it correctly.

File headers are typically of a standard size because they tend to contain a known finite amount of information, but that doesn't have to be the case. You could make the file header (and any other sections of the file you want) look something like the chunks in a RIFF file format (http://en.wikipedia.org/wiki/Resource_Interchange_File_Format)), where the size of the chunk (in this case, the file header itself) is specified as some known offset from the start of the chunk. Specifying the size of a chunk at the start is useful to code that has to read file formats, so it can know how much memory to allocate for certain things up front, and it saves the need for "footers" at the end of the chunk (bytes 13-16 in your example).

Incidentally, is it intentional that you use 5 bytes to store the height of your image?

The best way I've found when creating binary data formats is just to jump in and start defining one or more structs (I'm assuming you're working in C/C++ here - if not, whatever is the equivalent of a struct in your language of choice) which lays out the data for your header and whatever other chunks you might want to use. It's pretty easy then to write something that can fill out the information in the structs and save them to file, and to write something else that can read the data back out of the file into the structs so they can be used.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic