@classmethod
def from_filename(cls, filename):
    """Read the struct from a file given its path."""
    if str(filename).endswith('.mat'):
        with open(str(filename), 'rb') as f:
            return cls.from_binary(f)
    with open(str(filename)) as f:
        string = f.read()
    return cls.from_string(string)
