I wonder how this can best be handled without reading excessive file content to memory and possibly having to fudge things with a pointer into that memory at some point?
I can't remember how well the traditional (pre-streams) "file of" types handled (tagged or untagged) variant records.
MarkMLl
I would simply read the whole file into memory, I don't know that much about the raw image format, but I guess its something like 32 bit per pixel so in 4k this would be 300 megs. Thats easiely managable. Especially if you want to do work on that image that must be done anyway.
That said, depending on when the model dispatching is done, you can simply just read enough memory for the header and read it into the variant record:
size := GetFormatHeaderSize(Model);
MyStream.ReadBuffer(commonHeader, size);
Regarding the file of, this would just read the size of the union, meaning if the vendor stuff has different length, you might read to much, so you need to seek back that amount. That said, for such purposes reading bytewise is probably the better idea