1 ! Copyright (C) 2014 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: destructors io.backend kernel magic.ffi ;
10 : check-magic-error ( magic num -- )
11 -1 = [ magic_error throw ] [ drop ] if ;
13 : magic-file ( path flags -- result )
15 magic_open &magic_close
16 [ dup f magic_load check-magic-error ]
17 [ swap normalize-path magic_file ] bi
22 : guess-file ( path -- file-type )
23 MAGIC_NONE magic-file ;
25 : guess-mime-type ( path -- mime-type )
26 MAGIC_MIME_TYPE magic-file ;
28 : guess-mime-encoding ( path -- encoding )
29 MAGIC_MIME_ENCODING magic-file ;