The problem with unofficial, de facto standards, like magic.mime? What happened late last month, when the Unix file(1) command development team, led by Christos Zoulas, released version 4.24, a minor revision that changes the entire magic format and no longer generates a magic.mime file.
Many programs rely on the magic format in order to identify a file’s MIME type (for example, returning “video/quicktime” for a QuickTime movie or “image/jpeg” for a JPEG image). With MIME detection being merged into magic.mgc, a compiled file, programs that rely on this functionality must be modified in order to use the latest changes.
According to Christos the new format yields more accurate results:
[N]ow mime detection is more precise as it depends on the full magic specification of each magic type, not just a single magic/offset.
And indeed, in testing this appears to be the case, e.g., MP4 videos are detected more often than they were in 4.23. But to use these latest changes, many developers must make system-level calls directly to the file command until extensions are updated.
The PHP extension Fileinfo, for example, is a thin wrapper around the library version of file (libmagic), but yet does not understand the new format. In PHP, calling the Unix file(1) command on a fast machine via
exec() is about 16 times slower than using Fileinfo (0.128 seconds versus 0.008).
Of course, there is a standard specification, but neither file(1) nor Fileinfo use it, unfortunately.