How to determine the file MIME type by content?

haskell, mime

Solution

Haskell bindings to libmagic might be a solution to your problem. Here's an example.

import Magic
import System.Environment (getArgs)

main =  do
  magic <- magicOpen [MagicMime]
  (file:_) <- getArgs
  magicLoadDefault magic
  mime <- magicFile magic file
  putStrLn mime

Problem

Is there some way to determine the MIME type of a file by it's content ? Maybe with some Haskell library ?

Original source