4 ms·
Out curiosity, what sort of mechanism do you think is best for the OS to figure out the file type? Metadata can be opaque and leads to applications being rigid
by mrbrowning 13y ago
Out curiosity, what sort of mechanism do you think is best for the OS to figure out the file type? Metadata can be opaque and leads to applications being rigid about what type of input they'll accept, and sniffing magic bytes can't possibly be sufficiently reliable. Relying on extensions is suboptimal in terms of polluting what should be a logically independent attribute of a file, the name, with information about its type, but practically it seems like a serviceable and flexible solution.
- yew 13y agoThe 'correct' way to determine the type of a file is indeed to look at metadata. This includes things like magic numbers and extensions, but shouldn't be limited to those things. Just looking at extensions can be misleading because not all files have extensions and some extensions correspond to multiple types of files. In general, no method will be perfect because no modern OS provides dedicated file typing (some older operating systems stored the file type as metadata, although even that breaks down at the boundary between your computer and the rest of the world). The imperfection is usually manageable, depending on the type of file (which is the real answer to your question - it depends on why you want to know). Applications that won't open what I tell them to because they disagree about the file type are just broken. (Having to rename files whenever I want to open them is annoying. Having to replace a good piece of software because it refuses to follow instructions is even more annoying.)