magic
CopyrightCopyright (C) 2005 John Goerzen
LicenseBSD-3-Clause
MaintainerPhilippe <philippedev101\@gmail.com>
Stabilityprovisional
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Magic

Description

Haskell bindings to the C libmagic library, which identifies the type of a file by inspecting its contents rather than its name. It can report a textual description, a MIME type, or a character-set encoding.

This top-level module re-exports the whole interface: the types in Magic.Types, the initialization functions in Magic.Init, and the querying functions in Magic.Operations.

A typical session creates a handle, loads the system magic database, then queries files or in-memory data. The flags passed to magicOpen (see MagicFlag) choose what kind of answer comes back:

import Magic

main :: IO ()
main = do
  magic <- magicOpen [MagicMimeType]   -- ask for MIME types
  magicLoadDefault magic               -- load the system database
  mime <- magicFile magic "/etc/passwd"
  putStrLn mime                        -- e.g. "text/plain"

Handles are closed and their memory freed automatically when they are garbage-collected (see Magic); there is no explicit close. On failure the operations in this library raise an IOError.

Originally written by John Goerzen.

Synopsis

Basic Types

Initialization

module Magic.Init

Operation