| Copyright | Copyright (C) 2005 John Goerzen |
|---|---|
| License | BSD-3-Clause |
| Maintainer | Philippe <philippedev101\@gmail.com> |
| Stability | provisional |
| Portability | portable |
| Safe Haskell | None |
| Language | Haskell2010 |
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
- magicFile :: Magic -> FilePath -> IO String
- magicStdin :: Magic -> IO String
- magicDescriptor :: Magic -> Fd -> IO String
- magicString :: Magic -> String -> IO String
- magicCString :: Magic -> CStringLen -> IO String
- magicByteString :: Magic -> ByteString -> IO String
- magicSetFlags :: Magic -> [MagicFlag] -> IO ()
- magicGetFlags :: Magic -> IO [MagicFlag]
- magicGetParam :: Magic -> MagicParam -> IO Int
- magicSetParam :: Magic -> MagicParam -> Int -> IO ()
- magicCompile :: Magic -> Maybe String -> IO ()
- magicCheck :: Magic -> Maybe FilePath -> IO Bool
- magicGetPath :: IO FilePath
- magicVersion :: IO Int
- magicErrno :: Magic -> IO Int
Guessing the type
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
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
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