wand

Retrieve 'Magic' Attributes from Files and Directories

'MIME' types are shorthand descriptors for
file contents and can be determined from "magic"
bytes in file headers, file contents or intuited
from file extensions. Tools are provided to
perform curated "magic" tests as well as mapping
'MIME' types from a database of over 1,500
extension mappings.

wand : Retrieve 'Magic' Attributes from Files and Directories

The libmagic library must be installed on *nix/macOS and available to use this.

apt-get install libmagic-dev on Ubuntu/Debian-ish systems

brew install libmagic on macOS

yum install file-devel on RHEL/CentOS/Fedora

While the package was developed using the 5.28 version of libmagic it has been configured to work with older versions. Note that some fields in the resultant data frame might not be available with older library versions. When using the function magic_wand_file() it checks for which version of libmagic is installed on your system and provides a suitable magic.mgc file for it.

The package also works on Windows but it's a bit of a hack because, well, Windows. The Windows version makes two system2() calls and relies on Rtools being installed and file.exe being available on the Windows PATH, so it's sub-optimal at best. Help to get it working in C would be greatly appreciated. Windows folk can go here to find out more info on Rtools.

The following functions are implemented:

incant : returns the "magic" metadata of the files in the input vector (as a data frame)

magic_wand_file : provides a full path to the package-provided magic file