Search code examples
haskellmime

How to determine the file MIME type by content?


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


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