{ } qjs-modules

magic

Source: quickjs-magic.c — module export: Magic

Bindings to libmagic (the file(1) library) for content-type detection. The instance is also callable.

Constructor

new Magic([flags])   // length 1

Methods

MethodArgsDescription
descriptor(fd)1Identifies the content read from a file descriptor.
file(path)1Identifies the content of a file by path.
buffer(data)1Identifies the content of an in-memory buffer.
getflags()0Returns the active flags.
setflags(flags)1Sets the active flags (Magic.MIME, etc.).
check(path)1Checks the validity of a magic database.
compile(path)1Compiles a magic database.
list(path)1Lists entries in a magic database.
load([path])0Loads a magic database.
getparam(param)2Reads a libmagic parameter (Magic.PARAM_*).
setparam(param, value)2Sets a libmagic parameter.

Properties (read-only)

PropertyDescription
errorLast error string.
errnoLast error number.
versionlibmagic version.

Static constants

Flags: NONE, DEBUG, SYMLINK, COMPRESS, DEVICES, MIME_TYPE, CONTINUE, CHECK, PRESERVE_ATIME, RAW, ERROR, MIME_ENCODING, MIME, APPLE, EXTENSION, COMPRESS_TRANSP, NODESC, and the NO_CHECK_* family.

Parameters: PARAM_INDIR_MAX, PARAM_NAME_MAX, PARAM_ELF_PHNUM_MAX, PARAM_ELF_SHNUM_MAX, PARAM_ELF_NOTES_MAX, PARAM_REGEX_MAX, PARAM_BYTES_MAX. Also VERSION and DEFAULT_DB.