mimetype.pl -- Determine mime-type for a file
Simple library to guess the mime-type from the extension of a file. As various applications need to do this type ofinferencing it seems worthwhile to place this functionality in an extensible library.
- file_mime_type(+FileName, -MimeType) is semidet
- True when MimeType is the mime-type to be used for sending FileName. The default rules can be overridden and extended using the hook mime:mime_extension/2.
- mime:mime_extension(+Ext, -MimeType) is semidet[multifile]
- Hook that is called by file_mime_type/2 before the default table is examined.
- file_content_type(+File:atom, -ContentType:atom) is det
- file_content_type(+File:atom, ?MediaType, -ContentType:atom) is det
- True if File should be served using
ContentType:
ContentType. It takes the following steps:- Determine the media type using file_mime_type/2, unless already specified using file_content_type/3.
- Determine it is a text file using text_mimetype/1
- Use the charset from the Prolog flag
default_charset
The behavior is controlled by several hooks and a flag.
- mime:mime_extension/2 defines the media type
- text_mimetype/1 defines the media type is text
- mime:charset/3 derives the charset for a file with a given media type, if the media type is text according to text_mimetype/1.
- If text_mimetype/1 succeeds and mime:charset/3 fails, the
flag
default_charset
defines the charset unless it is set to-
. The flag set by default toUTF-8
if the Prolog flagencoding
is set toutf8
.
- mime:charset(+File, +MediaType, -Charset) is semidet[multifile]
- Hook that determines the Charset for File that has media type MediaType. This hook allows overruling file_content_type/2.
Re-exported predicates
The following predicates are exported from this file while their implementation is defined in imported modules or non-module files loaded by this module.
- file_content_type(+File:atom, -ContentType:atom) is det
- file_content_type(+File:atom, ?MediaType, -ContentType:atom) is det
- True if File should be served using
ContentType:
ContentType. It takes the following steps:- Determine the media type using file_mime_type/2, unless already specified using file_content_type/3.
- Determine it is a text file using text_mimetype/1
- Use the charset from the Prolog flag
default_charset
The behavior is controlled by several hooks and a flag.
- mime:mime_extension/2 defines the media type
- text_mimetype/1 defines the media type is text
- mime:charset/3 derives the charset for a file with a given media type, if the media type is text according to text_mimetype/1.
- If text_mimetype/1 succeeds and mime:charset/3 fails, the
flag
default_charset
defines the charset unless it is set to-
. The flag set by default toUTF-8
if the Prolog flagencoding
is set toutf8
.