Probably the easiest way to frame this question is to show you the code I have:
def determine_format(self, story_data: BufferedReader):
story_data.seek(0)
# Read the first four bytes. This will be enough to get the format
# regardless of the actual type of story file.
data_format = story_data.read(4)
print(f"Data Format: {data_format} ({data_format.decode('latin-1')})")
if data_format.decode("latin-1") == "FORM":
# Change the stream position to the given byte offset, in this
# case, relative to SEEK_SET, which is considered to be the start
# of the stream. The goal here is to take the pointer beyond the
# chunk ID and the chunk length. That will take us to the chunk
# data itself.
story_data.seek(8)
# From the start of the chunk data, we can read the first four
# bytes to get the type identifier.
if story_data.read(4).decode("latin-1") == "IFRS":
self.format = FORMAT.BLORB
else:
self.format = FORMAT.UNKNOWN
if data_format.decode("latin-1") == "Glul":
self.format = FORMAT.GLULX
eprint(f"\nQuendor is unable to interpret Glulx files.")
if data_format[0] >= 1 and data_format[0] <= 8:
self.format = FORMAT.ZCODE
if self.format == FORMAT.UNKNOWN:
eprint(
f"\nQuendor could not determine the story file type.\n"
f"File being read was: {self.story_file_path()}"
)
So I distinguish between BLORB, GLULX, and ZCODE. The Glulx and Zcode parts are easy. So, actually, is the blorb part.
However, Quendor will not be initially supporting Glulx at all. But “blb” files or “glorb” files are recognized simply as blorbs, just as is the case with a “zblorb” file. So my above logic treats all three as a “Blorb” even though there is a distinction.
You can see how I’m looking in the byte stream to get the information I need to determine the format of the story file. Is there a more refined way I can make the above logic more sensitive in terms of determining if I’m dealing with with a Glulx-style blorb?
I realize I could just use the filename extension. Maybe it’s just that simple? Any file with a “gblorb” or “blb” extension is Glulx-based.