"Steven Schveighoffer" <[email protected]> wrote in message news:[email protected]... > On Thu, 16 Sep 2010 01:16:20 -0400, Nick Sabalausky <[email protected]> wrote: >> >> 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 :) >
Yea, I know, but I was thinking more about text formats (and the rare binary formats that don't have that). A lot of text-based formats out there don't use shebang syntax. And a lot of them are just small variations on each other (at least from a type-detection standpoint). >> 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. > Yea, that makes sence. Never knew that before though, I just assumed it was just extensions and shebang syntax.
