libmagic
binding for lua.
see man libmagic
for more details.
NOTE: this module is tested with libmagic v5.41.
- libmagic: https://github.com/file/file
you should be installed libmagic-dev
or equivalent package before install this module.
luarocks install libmagic
local libmagic = require('libmagic')
local m = libmagic.open( libmagic.MIME_TYPE, libmagic.NO_CHECK_COMPRESS )
assert(m:load()) -- load the default database
print(m:file('README.md')) -- output "text/plain"
libmagic
module has the following constants.
- libmagic.VERSION
- libmagic.NONE
- libmagic.DEBUG
- libmagic.SYMLINK
- libmagic.COMPRESS
- libmagic.DEVICES
- libmagic.MIME_TYPE
- libmagic.CONTINUE
- libmagic.CHECK
- libmagic.PRESERVE_ATIME
- libmagic.RAW
- libmagic.ERROR
- libmagic.MIME_ENCODING
- libmagic.MIME
- libmagic.APPLE
- libmagic.EXTENSION
- libmagic.COMPRESS_TRANSP
- libmagic.NODESC
- libmagic.NO_CHECK_COMPRESS
- libmagic.NO_CHECK_TAR
- libmagic.NO_CHECK_SOFT
- libmagic.NO_CHECK_APPTYPE
- libmagic.NO_CHECK_ELF
- libmagic.NO_CHECK_TEXT
- libmagic.NO_CHECK_CDF
- libmagic.NO_CHECK_TOKENS
- libmagic.NO_CHECK_ENCODING
- libmagic.NO_CHECK_JSON
- libmagic.NO_CHECK_ASCII
- libmagic.NO_CHECK_FORTRAN
- libmagic.NO_CHECK_TROFF
local libmagic = require('libmagic')
local m = libmagic.open(libmagic.MIME_TYPE)
helper function to get a textual description of the contents of the file.
Parameters
arg:string|integer|file*
: pathname or file descriptor or file handle of the file.arg:string
: equivalent tom:file( pathname )
.arg:integer
: equivalent tom:descriptor( fd )
.arg:file*
: equivalent tom:filehandle( fh )
.
Returns
str:string
: a textual description.err:string
: error string.
returns a textual description of the contents of the file.
Parameters
pathname:string
: pathname of the file.
Returns
str:string
: a textual description.err:string
: error string.
returns a textual description of the contents of the file descriptor.
Parameters
fd:integer
: file descriptor.
Returns
str:string
: a textual description.err:string
: error string.
returns a textual description of the contents of the filehandle.
Parameters
fh:filehandle
: lua filehandle.
Returns
str:string
: a textual description.err:string
: error string.
returns a textual description of the contents of the buffer.
Parameters
buf:string
: buffer string.
Returns
str:string
: a textual description.err:string
: error string.
returns a textual explanation of the last error.
Returns
err:string
: error string.
set flags.
Returns
ok:boolean
:true
on success.
loads the database files from the colon separated list of database files.
Parameters
pathnames:string
: the colon separated list of database files.
Returns
ok:boolean
:true
on success.err:string
: error string.
compile the colon separated list of database files.
Parameters
pathnames:string
: the colon separated list of database files.
Returns
ok:boolean
:true
on success.err:string
: error string.
check the validity of entries in the colon separated database files.
Parameters
pathnames:string
: the colon separated list of database files.
Returns
ok:boolean
:true
on success.err:string
: error string.
dumps all magic entries in a human readable format
Returns
ok:boolean
:true
on success.err:string
: error string.
returns the last operating system error number.
Returns
errno:integer
: system error number (errno
).