Magicada

Website:

https://gitlab.com/stcarrez/ada-libmagic

Author:
  • Stephane.Carrez@gmail.com
Maintainer:
  • Stephane.Carrez@gmail.com
License:

Apache-2.0

Version:

1.0.1

Alire CI:

Dependencies: Dependents:

No dependents.

Badge:

Magic Number Recognition Library Ada binding

#magic #file #bindings

Small Ada binding library to the libmagic (3) library which is used by the implementation of the file (1) command.

To simplify and help in the use of the magic Ada library, the Magic.Manager package encapsulates the management of the libmagic library and provides high level simple operations to hide the details of interacting with the C library. The package defines the Magic_Manager tagged record that takes care of the C library interaction and cleaning of the libmagic library once the manager is no longer required. To use it, declare the instance and initialize it with the Initialize procedure:

 with Magic.Manager;
 ...
    Mgr : Magic.Manager.Magic_Manager;
    ...
       Mgr.Initialize (Magic.MAGIC_MIME, Magic.DEFAULT_PATH);

The first parameter defines a set of flags represented by the Magic.Flags type to control various options of the libmagic library. The second parameter indicates the default path to the magic file (see magic (5)). Once configured, the Identify functions can be used to identify a content. For the first form, a path of the file is given:

 Mime : constant String := Mgr.Identify ("file.ads");

With the second form, a Stream_Element_Array with the content to identify is given to the function.

Example