How to determine MIME file type by content?

Is there a way to determine the MIME type of a file by its content? Maybe with some kind of Haskell library?

+5
source share
1 answer

Haskell bindings to libmagic may be the solution to your problem. Here is an example.

import Magic
import System.Environment (getArgs)

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

All Articles