MIME-Detect reviews


RSS | Module Info | Add a review of MIME-Detect

MIME-Detect (0.08)

MIME::Detect offers two ways to get the MIME type. One is "mime_types", which gets the mime type from the file itself, similar to File::MMagic or File::Type. The other is "mime_types_from_name", which looks at the extension part of the file name, like ".txt" or ".png". Both of these functions return a list of mime types in case more than one pattern matches.

MIME::Detect uses a very large XML file from freedesktop.org for the matching patterns.

In the tests I tried, MIME::Detect performed fairly well, although the "mime_types" method couldn't detect some formats. The failures included executable files, files containing old encodings, and the old Microsoft BMP image format.

MIME::Detect was last updated in 2016 and seems to work well on most file types, so it seems this can be recommended for modern people.

Unfortunately though, it is by far the slowest of all the modules I tried. Loading and using this single module actually takes much more time than loading and checking the types of the files with all the other modules, "File::MMagic", "File::MMagic::XS", "Media::Type::Simple", "MIME::Types", "File::LibMagic", and "File::MimeInfo", combined.

Here is the time of my test with all the lines related to MIME::Detect commented out, but with all of the other above modules:

real 0m0.495s
user 0m0.440s
sys 0m0.056s

Here is the time after MIME::Detect is uncommented:

real 0m1.918s
user 0m1.768s
sys 0m0.150s

A bit slow! I have not profiled to find out what causes this slowness, but it's probably because the module parses a two megabyte XML file each time it is started.

It would make sense to preprocess the huge XML file, and distribute the preprocessed version, rather than parse the huge XML file each time the module is used. The bulk of the XML file is actually comments describing what the mime types are in various languages.

Regarding the documentation, the list of all the other modules for detecting mime types in the module's SEE ALSO is useful.

For a full comparison including source code and results on various files, see www.lemoda.net/perl/find-type-of-file/