MIME Magic

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Samuel

    #1

    MIME Magic

    Hi,

    How can I determine the type of a file from "magic bytes", similar to
    what the "file" command on unix does? I found

    Source code: Lib/mimetypes.py The mimetypes module converts between a filename or URL and the MIME type associated with the filename extension. Conversions are provided from filename to MIME type a...


    but this only seems to use the filename (extension) for finding the
    type. Any hints?

    -Samuel

  • Jorge Godoy

    #2
    Re: MIME Magic

    "Samuel" <knipknap@gmail .comwrites:
    Hi,
    >
    How can I determine the type of a file from "magic bytes", similar to
    what the "file" command on unix does? I found
    >
    Source code: Lib/mimetypes.py The mimetypes module converts between a filename or URL and the MIME type associated with the filename extension. Conversions are provided from filename to MIME type a...

    >
    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:


    And here's an example of an authoritative source for that table:




    --
    Jorge Godoy <jgodoy@gmail.c om>

    Comment

    • Samuel

      #3
      Re: MIME Magic

      On Mar 18, 12:30 am, Jorge Godoy <jgo...@gmail.c omwrote:
      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...Structure.html
      Actually, I am looking for an existing solution because I do not want
      to write it from scratch... I hope I am not out of options.

      -Samuel

      Comment

      • aspineux

        #4
        Re: MIME Magic

        On 18 mar, 00:54, "Samuel" <knipk...@gmail .comwrote:
        On Mar 18, 12:30 am, Jorge Godoy <jgo...@gmail.c omwrote:
        >
        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...Structure.html
        >
        Actually, I am looking for an existing solution because I do not want
        to write it from scratch... I hope I am not out of options.
        >
        -Samuel

        python-magic : Python binding for the magic library

        This Python library can be use to query /etc/magic information for a
        given file in Python.


        Comment

        Working...