Qore Magic Module
0.0.2
|
This is a module for recognizing the type of data contained in a computer file using so called magic numbers. It is a wrapper around libmagic
C library (covered by the standard Berkeley Software Distribution copyright).
This module is released under the LGPL 2.1 and is tagged as such in the module's header (meaning it can be loaded unconditionally regardless of how the Qore library was initialized).
This module provides the following class:
The Single Unix Specification (SUS) specifies that a series of tests are performed on the file specified on the command line:
Magic position-sensitive tests are normally implemented by matching various locations within the file against a textual database of magic numbers. This differs from other simpler methods such as file extensions and schemes like MIME.
In most implementations, the file command uses a database to drive the probing of the lead bytes. That database is implemented in file called magic
, whose location is usually in /etc/magic
, /usr/share/file/magic
or a similar location.
To use the module in a Qore script, use the %requires
directive as in the following example:
The above command would result in the following output when executed on a standard UNIX or UNIX-like system:
"inode/symlink; charset=binary"