3 ms·
> Magic numbers aren't for parsing files, they're for identifying file formats. Unpopular corollary: thinking those are two separate actions is a terribly bad
by ajross 2y ago
> Magic numbers aren't for parsing files, they're for identifying file formats.
Unpopular corollary: thinking those are two separate actions is a terribly bad design smell. What are you going to do with that file you "identified" if not read it to get something out of it, or hand it to something that will.
If your file manager wants to turn that path into a thumbnail, you have already gone beyond anything the magic number can have helped you with.
Again, needless pedantry. Put a random number in the front and be done with it. Anything else needs a parser anyway.
- kergonath 2y agoSpeaking of needless pedantry, why do you start with this? > Unpopular corollary: To me at least it comes across as condescending and unnecessarily edgy or contrarian for the sake of it. I am perfectly able to gauge whether a comment is popular or not.
- IshKebab 2y ago> What are you going to do with that file you "identified" if not read it to get something out of it Anything where there's a decision based on the file format but not its contents. This happens all the time. * Telling the user what file type it is. * Choosing a parser to load a file with. * Restricting file types on upload forms. * Identifying files for linters. * Associating files with programs. Ok some of those use file extensions because it's a lot easier and text based formats often don't have a magic number, but it's still a valid use case.