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

Magic.Operations

Description

Querying the type of files and in-memory data, and other operations on a magic handle. The handle must first be created with magicOpen and populated with magicLoadDefault or magicLoad (see Magic.Init).

Written by John Goerzen.

Synopsis

Guessing the type

magicFile :: Magic -> FilePath -> IO String Source #

Identify the file at the given path. The result is in the form selected by the handle's flags (a textual description, a MIME type, an encoding, and so on; see MagicFlag). Raises an IOError if the file cannot be examined.

magicStdin :: Magic -> IO String Source #

Identify the data available on standard input, as magicFile does for a named file. Raises an IOError if the data cannot be examined.

magicDescriptor :: Magic -> Fd -> IO String Source #

Identify the data behind an open file descriptor, as magicFile does for a named file. Useful for sockets, pipes, or files you have already opened. Raises an IOError if the descriptor cannot be examined.

Since: 1.1.2

magicString :: Magic -> String -> IO String Source #

Identify the contents of the given String. Note that the string is processed strictly, not lazily.

This is convenient for textual data. For binary data prefer magicCString (or write it to a file and use magicFile): marshalling through String goes via the current locale encoding, which can corrupt non-textual bytes. Raises an IOError if the data cannot be examined.

magicCString :: Magic -> CStringLen -> IO String Source #

Identify the contents of a C string buffer (a pointer and a length). This is the lower-level primitive behind magicString, and the right choice for raw binary data since it does no encoding conversion. Raises an IOError if the data cannot be examined.

magicByteString :: Magic -> ByteString -> IO String Source #

Identify the contents of a strict ByteString. Unlike magicString this does no encoding conversion, so it is the right choice for binary data. Raises an IOError if the data cannot be examined.

Since: 1.1.2

Flags

magicSetFlags :: Magic -> [MagicFlag] -> IO () Source #

Change the flags (see MagicFlag) on an existing handle, for example to switch between textual descriptions and MIME types. Raises an IOError on failure.

magicGetFlags :: Magic -> IO [MagicFlag] Source #

Read the flags currently set on the handle (see magicSetFlags). Composite masks are returned decomposed into their individual flags. Raises an IOError if the running libmagic does not support querying flags.

Since: 1.1.2

Tunable parameters

magicGetParam :: Magic -> MagicParam -> IO Int Source #

Read a tunable parameter (see MagicParam).

Since: 1.1.2

magicSetParam :: Magic -> MagicParam -> Int -> IO () Source #

Set a tunable parameter (see MagicParam), for example to cap the number of bytes scanned in untrusted input. Raises an IOError on failure.

Since: 1.1.2

Magic databases

magicCompile Source #

Arguments

:: Magic

Object to use

-> Maybe String

Colon separated list of databases, or Nothing for default

-> IO () 

Compile the given colon-separated magic database file(s) into the binary .mgc form. Each compiled file is named after its source with .mgc appended. Pass Nothing to compile the default database. Raises an IOError on failure.

magicCheck :: Magic -> Maybe FilePath -> IO Bool Source #

Check the validity of the given magic database file(s) without compiling them, as file -c does. Pass Nothing for the default database. Returns True if the database is valid.

Since: 1.1.2

magicGetPath :: IO FilePath Source #

The path of the default magic database, honouring the MAGIC environment variable.

Since: 1.1.2

Library information

magicVersion :: IO Int Source #

The version of the libmagic library in use, encoded as a single integer (for example 545 for version 5.45).

Since: 1.1.2

magicErrno :: Magic -> IO Int Source #

The errno recorded by the last failing operation on the handle, or 0 if the last failure was not caused by a system error.

Since: 1.1.2