finding mimetype of file

Edscott Wilson Garcia edscott at xfce.org
Sat Nov 19 02:34:37 CET 2005




On Sat, 19 Nov 2005, Jani Monoses wrote:

> Hello
>
> is there a recommended way of finding out the mimetype of a file when
> writing xfce apps? I see thunar has it's own lib, exo used xdgmime but
> dropped it probably since now thunar's is better, there are mime related
> functions in libxfcegui4 and xffm too. And then there's libmagic and
> again an xdgmime tree inside the gtk2 sources but which don't seem to be
> entirely exported.
>

Basically there are two methods. The first is by file extension. The 
second is by looking into the file for certain characteristics (someone 
had the bright idea of calling this method "magic" although there is 
nothing magic about it).

The first method is quite fast if you implement your own 
hash/database/cache or whatever for quick access.

The second method is slow, since you have to open and read data from the 
file to compare with available "magic" types.

Both file extensions and "magic" characteristics are available in the 
shared-mimetype package. Tailoring this to your particular needs may 
produce smaller/faster code.

regards,




More information about the Xfce4-dev mailing list