MIME Magic

Jorge Godoy jgodoy at gmail.com
Sat Mar 17 19:30:45 EDT 2007


"Samuel" <knipknap at gmail.com> writes:

> Hi,
>
> How can I determine the type of a file from "magic bytes", similar to
> what the "file" command on unix does? I found
>
> http://docs.python.org/lib/module-mimetypes.html
>
> but this only seems to use the filename (extension) for finding the
> type. Any hints?

I'd start by taking a look at "file"'s code. :-)

The thing is being able to identify the signatures of several different types
of files.  Here's some help for you:
http://www.garykessler.net/library/file_sigs.html

And here's an example of an authoritative source for that table:
http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html 



-- 
Jorge Godoy      <jgodoy at gmail.com>



More information about the Python-list mailing list