MODULE HAS BEEN RENAMED TO https://github.com/mah0x211/lua-libmagic
libmagic
binding for lua.
see man libmagic
for more details.
- libmagic: https://github.com/file/file
luarocks install mah0x211/magic
local magic = require('magic')
local m = magic.open( magic.MIME_TYPE, magic.NO_CHECK_COMPRESS )
assert(m:load()) -- load the default database
print(m:file('README.md')) -- output "text/plain"
magic
module has the following constants.
- magic.VERSION
- magic.NONE
- magic.DEBUG
- magic.SYMLINK
- magic.COMPRESS
- magic.DEVICES
- magic.MIME_TYPE
- magic.CONTINUE
- magic.CHECK
- magic.PRESERVE_ATIME
- magic.RAW
- magic.ERROR
- magic.MIME_ENCODING
- magic.MIME
- magic.APPLE
- magic.EXTENSION
- magic.COMPRESS_TRANSP
- magic.NODESC
- magic.NO_CHECK_COMPRESS
- magic.NO_CHECK_TAR
- magic.NO_CHECK_SOFT
- magic.NO_CHECK_APPTYPE
- magic.NO_CHECK_ELF
- magic.NO_CHECK_TEXT
- magic.NO_CHECK_CDF
- magic.NO_CHECK_TOKENS
- magic.NO_CHECK_ENCODING
- magic.NO_CHECK_JSON
- magic.NO_CHECK_ASCII
- magic.NO_CHECK_FORTRAN
- magic.NO_CHECK_TROFF
local magic = require('magic')
local m = magic.open(magic.MIME_TYPE)
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
).