Is is possible to prepend some “magic number” data to a core data persistent store?
I have an older application which uses a custom binary file format. Each file starts with a 5-byte magic number (let's say 0A 0B 0C 0D 0E
) and a 1-byte format version identifier; after which follows the actual data. Existing versions of the application do the following check when a user tries to open a file:
- If the first 5 bytes of the file don't match the magic number, the user gets a message like “The file is not in a format that this application can read. It may have the wrong file extension.”
- If the magic number matches, but the version identifier is higher than what the version of the application can read, the user gets a message like “The file was created with a newer version of this application. You need to upgrade to the new version.”
I would like to leverage core data for storage in a new version of the application, while still using the same file extension and retaining appropriate compatibility with older versions of the application: users that try to use an old version to open a file written with the new version should get the message that they should upgrade, rather than the other message. Is this possible? And how?