| 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 -> OsPath -> IO Text
- magicStdin :: Magic -> IO Text
- magicDescriptor :: Magic -> Fd -> IO Text
- magicCString :: Magic -> CStringLen -> IO Text
- magicByteString :: Magic -> ByteString -> IO Text
- magicSetFlags :: Magic -> MagicFlags -> IO ()
- magicGetFlags :: Magic -> IO MagicFlags
- magicGetParam :: Magic -> MagicParam -> IO Int
- magicSetParam :: Magic -> MagicParam -> Int -> IO ()
- magicCompile :: Magic -> [OsPath] -> IO ()
- magicCheck :: Magic -> [OsPath] -> IO Bool
- magicLoadBuffers :: Magic -> [ByteString] -> IO ()
- magicGetPath :: IO [OsPath]
- magicVersion :: IO Int
- magicErrno :: Magic -> IO Int
Guessing the type
magicFile :: Magic -> OsPath -> IO Text 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 MagicFlags). Raises a MagicException if the file cannot be
examined.
magicStdin :: Magic -> IO Text Source #
Identify the data available on standard input, as magicFile does for a
named file. Raises a MagicException if the data cannot be
examined.
magicDescriptor :: Magic -> Fd -> IO Text 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
a MagicException if the descriptor cannot be examined.
Since: 1.1.2
magicCString :: Magic -> CStringLen -> IO Text Source #
Identify the contents of a C string buffer (a pointer and a length). The
lowest-level in-memory primitive; for ordinary use prefer magicByteString.
Raises a MagicException if the data cannot be examined.
magicByteString :: Magic -> ByteString -> IO Text Source #
Identify the contents of a strict ByteString. Does no encoding
conversion, so it is the right way to examine in-memory data. Raises a
MagicException if the data cannot be examined.
Since: 1.1.2
Flags
magicSetFlags :: Magic -> MagicFlags -> IO () Source #
Change the flags (see MagicFlags) on an existing handle, for example to
switch between textual descriptions and MIME types. Raises a MagicException on
failure.
magicGetFlags :: Magic -> IO MagicFlags Source #
Read the flags currently set on the handle (see magicSetFlags). Test the
result with hasFlag. Raises a MagicException 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 a MagicException on failure.
Since: 1.1.2
Magic databases
magicCompile :: Magic -> [OsPath] -> IO () Source #
Compile the given magic database file(s) into the binary .mgc form. Each
compiled file is named after its source with .mgc appended. Pass the empty
list to compile the default database. Raises a MagicException on failure.
(libmagic joins the list with the platform search-path separator, so a path that itself contains that separator cannot be represented.)
magicCheck :: Magic -> [OsPath] -> IO Bool Source #
Check the validity of the given magic database file(s) without compiling
them, as file -c does. Pass the empty list for the default database. Returns
True if the database is valid. (libmagic joins the list with the platform
search-path separator, so a path that itself contains that separator cannot be
represented.)
Since: 1.1.2
magicLoadBuffers :: Magic -> [ByteString] -> IO () Source #
Load magic from one or more in-memory compiled databases (the .mgc binary
form produced by magicCompile), rather than from files. This lets a program
embed its magic database.
libmagic keeps (does not copy) the supplied buffers for the lifetime of the
handle, so the handle retains references to the given ByteStrings to keep
their memory alive until it is closed. Raises a MagicException on failure.
Since: 2.0.0
magicGetPath :: IO [OsPath] Source #
The default magic database search path, honouring the MAGIC environment
variable, as a list of paths.
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