READMEmd[edit on web]

MAGICFFI Build Status

MAGICFFI is a CFFI interface to libmagic(3), the file type determination library using ``magic’’ numbers.

Download

To check out the git repository, run:

$ git clone git://github.com/guicho271828/magicffi.git

Installation

MAGICFFI depends on the following lisp libraries:

  • CFFI
  • CL-PPCRE (used by the internal flags generator)

The following system packages are also required:

  • libmagic-dev
  • libc6-dev
  • gcc

You have to install them on your system before loading magicffi.

Tutorial

> (asdf:load-system :magicffi)
> (use-package :magicffi)
> (with-open-magic (magic '(:mime-type :symlink))
    (magic-file magic #P"magicffi.asd"))
"text/plain"

Documentation

All external symbols of the package MAGICFFI are listed in package.lisp. Check out their docstrings for help.

Magic Flags

You can use either constants or keyword list as magic flags. I.e.,

(magic-open (logxor +magic-mime-type+ +magic-symlink+))

is equivalent to

(magic-open '(:mime-type :symlink))

The constant name and keyword name of a flag are based on its C name. See the following table for the pattern:

C name Lisp constant Lisp keyword
MAGIC_NONE +MAGIC-NONE+ :NONE

All constant names are exported.

Credit

  • Desmond O. Chang (original author)
  • Peter Hillerström
  • Pocket7878
  • Masataro Asai

tests

README[edit on web]

The testfiles come from the original libmagic source code. The file libmagic-COPYING is the license file of libmagic.

magicffiasd[edit on web]

defmethod
perform

(documentation missing)

src

packagelisp[edit on web]

defpackage
magicffi

(documentation missing)

src

grovelprocessed-grovel-file[edit on web]

defconstant
+magic-none+

(documentation missing)

defconstant
+magic-debug+

Turn on debugging

defconstant
+magic-symlink++magic-compress+
magicffi

(documentation missing)

defconstant
+magic-devices+

Look at the contents of devices

defconstant
+magic-mime-type+

Return the MIME type

defconstant
+magic-mime-encoding+

Return the MIME encoding

defconstant
+magic-mime+

A shorthand for MAGIC_MIME_TYPE | MAGIC_MIME_ENCODING

defconstant
+magic-continue+

Return all matches

defconstant
+magic-check+

Print warnings to stderr

defconstant
+magic-preserve-atime+

Restore access time on exit

defconstant
+magic-raw+

(documentation missing)

defconstant
+magic-error+

Handle ENOENT etc as real errors

defconstant
+magic-apple+

Return the Apple creator/type

defconstant
+magic-no-check-apptype+

Don't check application type

defconstant
+magic-no-check-cdf+

Don't check for cdf files

defconstant
+magic-no-check-compress+

Don't check for compressed files

defconstant
+magic-no-check-elf+

Don't check for elf details

defconstant
+magic-no-check-encoding++magic-no-check-soft+
magicffi

(documentation missing)

defconstant
+magic-no-check-tar+

Don't check for tar files

defconstant
+magic-no-check-text+

Don't check for text files

defconstant
+magic-no-check-tokens+

(documentation missing)

defconstant
+magic-no-check-ascii+

Defined for backwards compatibility (renamed): same as MAGIC_NO_CHECK_TEXT

defconstant
+magic-no-check-fortran++magic-no-check-troff+
magicffi

Defined for backwards compatibility; do nothing

src

typeslisp[edit on web]

define-condition
magic-error

Consists of errors that are related to MAGICFFI. Use the function MAGIC-ERROR to signal it. The error number and error string are accessed by the functions MAGIC-ERROR-ERRNO and MAGIC-ERROR-ERROR.

defclass
magic

(documentation missing)

defun
magicp
object

Returns 'true' if object is of type MAGIC; otherwise, returns 'false'. It is unaffected by whether object, if it is a magic, is open or closed.

defun
open-magic-p
magic

Returns 'true' if MAGIC is open; otherwise, returns 'false'.

apilisp[edit on web]

defun
magic-error
magic

Signals an error of type MAGIC-ERROR.

defun
magic-open
flags

Creates a magic cookie and returns it. An error of type SIMPLE-ERROR is signaled on failure. FLAGS specifies how the other magic functions should behave. See README for the flags usage.

defun
magic-close
magic

Closes the magic database and deallocates any resources used. It is permissible to close an already closed magic, and has no effect. Returns 'true' if an open magic cookie has been closed, or 'false' if the magic cookie is already closed.

defun
magic-file
magic pathspec

Returns a textual description of the contents of the PATHSPEC argument. PATHSPEC is a pathname designator. An error of type MAGIC-ERROR is signaled on failure.

defun
magic-buffer
magic string

Returns a textual description of the contents of the STRING argument. An error of type MAGIC-ERROR is signaled on failure.

defun
magic-setflags
magic flags

Sets the magic flags. Signals an error of type SIMPLE-ERROR on systems that don't support utime(2), or utimes(2) when :PRESERVE-ATIME is set; otherwise, returns 'true'.

defvar
*magic-database*

Default magic database files. It can be NIL(default), or a designator for a non-empty list of pathname designators. NIL means the default database files defined by libmagic.

defun
magic-check
magic &optional pathname-list

Checks the validity of database files. PATHNAME-LIST is NIL(default), which means use MAGIC-DATABASE, or a designator for a non-empty list of pathname designators. Returns 'true' on success and signals an error of type MAGIC-ERROR on failure.

defun
magic-compile
magic &optional pathname-list

Compiles database files. PATHNAME-LIST is NIL(default), which means use MAGIC-DATABASE, or a designator for a non-empty list of pathname designators. Returns 'true' on success and signals an error of type MAGIC-ERROR on failure. The compiled files created are named from the basename(1) of each file argument with `.mgc' appended to it.

defun
magic-load
magic &optional pathname-list

Loads database files. PATHNAME-LIST is NIL(default), which means use MAGIC-DATABASE, or a designator for a non-empty list of pathname designators. Returns 'true' on success and signals an error of type MAGIC-ERROR on failure.

defmacro
with-open-magic
(magic &optional (flags ''(none)) (magicfiles nil)) &body body

Opens the magic cookie MAGIC, executes BODY and close MAGIC.

FLAGS: A list of keywords (see types), defaulted to (:none).

MAGICFILES: NIL, or a list of pathname designators for the database files. Defaulted to NIL, which uses the default database available in the system. This covers the most usage.

shortcutslisp[edit on web]

Returns a description, as in unix file command

Return the MIME type

Return the MIME encoding

Return the MIME type

Return the Apple creator/type

Return a /-separated list of extensions. This is NOT about the file name extensions (such as .png).