ajlittoz has asked for the wisdom of the Perl Monks concerning the following question:
Hi wise monks,
I'd like to use File::MMagic to discriminate between different file types. What I basically need is text, image and "others", i.e. the first part of the MIME type from the start to the / separator. Unfortunately, File::MMagic returns invariably application/octet-stream for image file.
The first argument I gave to File::MMagic is my system "magic" file but File::MMagic result is different from system command file.
I know file is using a compiled version of the system "magic" file and I suppose both formats are equivalent (i.e. they contain the same magic numbers).
I am also sure File::MMagic method new has correctly taken note of the argument because of a bug (see File::MMagic bug?).
This behaviour has already been reported in a different context (see Comparing different MIME type checking modules). I'm not asking here for the "best" MIME type, but only for a coarse indication of the kind of data in a file. My grief is that application/octet-stream is way too coarse and that I could get a finer approximation allowed by the system "magic" file.
It looks to me File::MMagic reverts to its internal table when methods checktype_* are invoked.
1. How can I assert File::MMagic is really using the designated magic file?
2. What is a simple reliable way of classifying files as text, image and "others"?
Note: I don't want to use `file thefile_to_test` as it involves process forking, pipe connection, etc. which would negatively impact performance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File::MMagic returns application/octet-stream for most files
by Your Mother (Archbishop) on Jan 23, 2016 at 17:31 UTC | |
by ajlittoz (Novice) on Jan 23, 2016 at 20:43 UTC |