I need to detect whether a particular file is binary file saved by boost::serialization. Looking at a few files, I saw they have those 16 bytes at the beginning:
0000000 0016 0000 0000 0000 6573 6972 6c61 7a69 | ........serializ
0000010 7461 6f69 3a6e 613a 6372 6968 6576 0009 | ation::archive..
Is that a reliable sequence to detect such an archive?
Reliable? Probably yes, as long as you keep using the same implementation of boost::serialization. Possibly also across updates of the library. But the reference documentation doesn’t mention any support for file magic, so officially, the effect of checking the file header is undefined, and might silently break in future versions. If you need to be robust, it is better to attempt to deserialize and catch whatever is thrown on failure. So, for a quick file browser that prints informative icons, sure, go ahead and use the header detection. In a enterprise system for archiving backups, not so much.