Well, it's been a total failure

Steven Schveighoffer schveiguy at yahoo.com
Thu Sep 16 05:29:08 PDT 2010


On Thu, 16 Sep 2010 01:16:20 -0400, Nick Sabalausky <a at a.a> wrote:

> "Jonathan M Davis" <jmdavisProg at gmx.com> wrote in message
> news:mailman.227.1284590189.858.digitalmars-d at puremagic.com...
>> On Wednesday, September 15, 2010 12:48:32 Nick Sabalausky wrote:
>>> "Jonathan M Davis" <jmdavisProg at gmx.com> wrote in message
>>> news:mailman.225.1284568096.858.digitalmars-d at puremagic.com...
>>>
>>> > If you're on a non-Windows system, the mime-type becomes far more
>>> > important than
>>> > the extension. Most programs in Linux (and I believe MacOS X as well)
>>> > don't care
>>> > about the extension. They just look at the mime type. Extensions  
>>> become
>>> > almost
>>> > entirely a thing for the user. So, whether your file is useable  
>>> becomes
>>> > more of
>>> > an issue of known mime type than known extension. Still, you don't
>>> > generally
>>> > want to just be making up extensions.
>>>
>>> I didn't think unix file systems had a concept of mime type.
>>
>> They don't have a concept of file extension either. Mime types has to do
>> with the
>> contents of the file and file extensions has to do with the name of the
>> file. It's
>> programs which interpret those, not the file system. Typically, on
>> Windows, the
>> extension is used by the OS to determine which program to use to open a
>> file. In
>> unix, it's the mime type that's used to determine that.
>>
>> The one bit of overlap there is the fact that Windows treats the exe
>> extension
>> essentially the way that unix treats the executable file attribute.
>>
>> Now, I wouldn't advise ditching file extensions in unix, since it not  
>> only
>> can
>> help the human using them but there are occasionally programs which  
>> check
>> the
>> extension rather the mime type (so, ultimately, you may end up using  
>> both
>> the
>> extension and the mime type), but it's primarily the mime type which is
>> used,
>> and it's definitely the mime type which is used to determine which  
>> program
>> to use
>> to open a file in the desktop environments.
>>
>
> Yea, but my question was more "how in the hell would it know the mime  
> type
> of a file in the first place?" It's obviously not stored in the filename,
> and 99.9% is the time it's not stored in the file's data either.

Most binary file formats are designed to be detectable using a "magic  
number" that's found at the front of the file.  This magic number allows  
programs to easily determine the file type.

So yeah, it is stored in the file's data :)

> Since then, someone mentioned it typically analyses the content of the  
> file
> and infers the mime type based on that. That's news to me. It would seem
> limited and error-prone though, so I have a hard time believing it  
> doesn't
> suppliment that content-analysis with extension-checking in many cases.

I think it's a combination of many things.  Try the Linux 'file' command  
to see how it detects all different types of files.

-Steve


More information about the Digitalmars-d mailing list