Module Magic

module Magic: sig .. end

Try to identify the type of file using some "magic number" tests.


type t 

Magic "cookies".

exception Failure of string

Raised by the functions of this library when they fail. The string is an explanation of why the failure happened.

type flag = 
| Symlink (*

If the file queried is a symlink, follow it.

*)
| Compress (*

If the file is compressed, unpack it and look at the contents.

*)
| Devices (*

If the file is a block or character special device, then open the device and try to look in its contents.

*)
| Mime (*

Return a mime string, instead of a textual description.

*)
| Continue (*

Return all matches, not just the first.

*)
| Check (*

Check the magic database for consistency and print warnings to stderr.

*)
| Preserve_atime (*

On systems that support utime(2) or utimes(2), attempt to preserve the access time of files analyzed.

*)
| Raw (*

Don't translate unprintable characters to a \ooo octal representation.

*)
val make : ?flags:flag list -> string list -> t

make ?flags filenames creates a magic cookie, loading the databases in filenames. If filenames = [], the default database is used.

flags : specifies how the other magic functions should behave (default: []).
val create : ?flags:flag list -> string list -> t
Deprecated. Synonym for Magic.make.
val close : t -> unit

close cookie frees the resources associated with the cookie c. You need not to close cookies as the resources will be freed by the garbage collector anyway.

val file : t -> string -> string

file cookie filename returns a textual description of the contents of the filename argument.

val buffer : t -> ?len:int -> string -> string

file cookie ?len buf returns a textual description of the contents of the filename argument.

val setflags : t -> flag list -> unit

setflags cookie flags specifies how the other magic functions should behave.

val load : t -> string list -> unit

load cookie filenames loads the the list of database files filenames, or [] for the default database file.

val compile : t -> string list -> unit

compile cookie filenames compiles the the list of database files filenames, or [] for the default database. The compiled files created are named from the basename(1) of each file argument with ".mgc" appended to it.

val check : t -> string list -> bool

check cookie filenames checks the validity of entries in the database files filenames, or [] for the default database.