magic

  1. magic
  2. Description
  3. API
  4. Author
  5. License

Description

Bindings to the magic file recognition library.

Two modules are included, (magic) and (magic libmagic):

The following documentation applies to the (magic) module.

The source for this egg is available here.

API

One procedure is provided, identify, that tries to do what you mean.

Whenever libmagic returns an error, an exception of type (exn magic) is raised.

Note that the magic module loads libmagic's magic numbers database as soon as it's loaded. If you're not OK with this, use the low-level module.

[procedure] (identify [object [flags]]) => string

identify returns a textual description of the file indicated by object, or the contents of (current-input-port) if no object is specified.

If object is given, it may be any of the following object types, with identify returning a description of:

If flags is given, it must be a symbol or list of symbols indicating the type of description to return. These correspond to the MAGIC_* constants in libmagic.h, and can be any combination of the following (though not all combinations make sense):

For example:

(identify "/usr/include/magic.h") ; => "C source, ASCII text"
(identify "/usr/include/magic.h" 'mime) ; => "text/x-c; charset=us-ascii"
(identify "/usr/include/magic.h" '(preserve-atime no-text)) ; => "data"

An unrecognized flag will raise an exception of type (exn magic).

Author

Evan Hanson

License

3-Clause BSD