My file is a binary file with a text header. The header consists of multiple records all 128 bytes long. Each record has a 32 byte key followed by a 96 byte value. It looks something like this:
FILE_TYPE TIME_HISTORY_FILE
CREATION_DATE JANUARY 27, 2021
SAMPLE_PERIOD 0.001
NUMBER_OF_SAMPLES 4
NUMBER_OF_CHANNELS 2
CHANNEL_1_NAME X
CHANNEL_1_UNITS m
CHANNEL_2_NAME Y
CHANNEL_2_UNITS mm
END_OF_HEADER
The length of the header changes to allow different numbers of channels.
Following the header is the time history data.
x0,y0,x1,y1,x2,y2,x3,y3
Each time history value is 4 bytes long. The length of the time history data is NUMBER_OF_SAMPLES * NUMBER_OF_CHANNELS.
I cannot change the file organization. There are several legacy applications that work with this file format.
In other languages the API for this file type is:
open(filename) : Opens file and reads header
get(key) : Returns value associated with this header key
set(key, value) : Set value associated with this header key
read(count, buffer) : Read count time history values into buffer
save(filename) : Opens file for writing. Writes header to file.
write(count, buffer) : Write count time history values stored in buffer
close() : Close the file
I would like to look at ways that others have solved similar problems. I am currently studying the gzip library.