We've been having some discussion on IRC over the current mimetype detection...

There are several issues with the current call:
- it assumes a local file, so implementations try to read xattrs,
- it returns "text/html" on failure instead of NULL, which have some side 
effects.

In several places I would need some similar calls but for urls or data buffers 
but I can't use the existing call correctly.
For example, with gopher some item types don't have a specific mime type so it 
must be probed either by extension or by sniffing the incoming data. But using 
fetch_filetype() which returns text/html by default makes it try to display 
binary files...

BeOS had a mime sniffer for 15 years, and other "sane" OS have one too.
XDG seems to have something specified as well:
http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec

There seems to be an attempt at normalizing some mime sniffing as part of HTML5 
also:
http://code.google.com/p/mimesniff/
http://tools.ietf.org/html/draft-abarth-mime-sniff-03

What I'd propose is to have something like:

[const?] char *fetch_mime_localfile(const char *path);
[const?] char *fetch_mime_by_ext(const char *filename);
[const?] char *fetch_mime_by_data(const void *data, size_t size);

The last 2, the new ones, are easily implemented in BeOS for ex. with the 
BMimeType:GuessMimeType() variants:
http://cvincent.pagesperso-orange.fr/bebook/Release 
Notes/StorageKit.html#GuessMimeType()

François.

Reply via email to