[Lazarus] Function to get the mimetype from a file extension

Henry Vermaak henry.vermaak at gmail.com
Wed May 9 17:01:52 CEST 2012


On 09/05/12 15:47, Graeme Geldenhuys wrote:
> I know Linux (at least Gnome) uses magic numbers (first 2-4 bytes of a
> file) to detect the real file type without looking at the file
> extension. These magic numbers information is stored somewhere in
> linux (can't remember where now), and it includes the magic number and
> mime type mapping. I'll see if I can find the file I am talking about.
> But as with everything Linux, this is probably highly distro specific
> etc.

/usr/share/misc/magic.mgc (which on my system is a symlink to somewhere
else).  It's a big file: 1.8MB.

Linking to libmagic will get you most the functionality of the `file`
command, afaik.

Henry




More information about the Lazarus mailing list