On 03/07/11 00:09, Nick Sabalausky wrote: > "Jonathan M Davis" <jmdavisp...@gmx.com> wrote in message > news:mailman.2280.1299459971.4748.digitalmar...@puremagic.com... >> >> This reminds me. I should look into mime types one of these days to see >> what the >> appropriate way (if any) would be to put support for them in Phobos. It >> would be >> nice to not have to go by extension for the few programs that I have which >> have >> to worry about file type. >> > > I'm no unix expert, but my understanding is that mime types in the > filesystem don't even exist at all, and that what it *really* does is use > some complex black-box-ish algorithm that takes into account the first few > bytes of the file, the extention, the exec flag, and god-knows-what-else to > determine what type of file it is. Contrary to how people keep making it > sound, mime type is *not* the determining factor (and cannot possibly be), > but rather nothing more than the way the *result* of all that analysis is > represented. > >
One could likely get a good grip of the "black box" by studying the source of the common "file" utility. It can be surprisingly detailed in some cases, such as the following real example: $ file debug.log debug.log: UTF-8 Unicode English text, with very long lines It does generate mime types as well: $ file -bi debug.log text/plain; charset=utf-8 -- Chris N-S