Applications can detect the MIME type of a file as follows:
The following sections provide further information on file content sniffers and the MIME type registry.
File content sniffers are specified in the file /etc/gnome-vfs-mime-magic. The following is an example of a file content sniffer:
The syntax for file content sniffers is as follows:
Table 5-1 describes the fields in a file content sniffer.
Field | Description |
---|---|
offset_start | Specifies the number of characters to ignore in the file before searching for a text pattern. |
pattern_type | Specifies the type of pattern to search for. The string pattern type is the only pattern type that is supported at the time of publication of this guide. |
pattern | Specifies the pattern to search for. |
pattern_mask |
Specifies a pattern mask, in hexadecimal format. For more information on pattern masks, see the next section. This field is optional. This field is not present in the example. |
type | Specifies the MIME type to associate with files that match this entry. |
A pattern mask identifies bits in the pattern to ignore when searching for a pattern in a file. The following is an example of a file content sniffer with a pattern mask:
The pattern and mask in the example are as follows:
Pattern | B | M | x | x | x | x | \000 | \000 |
Mask | ff | ff | 00 | 00 | 00 | 00 | ff | ff |
The pattern and mask specify a file with the following characteristics:
The file content sniffer specifies that the MIME type of files that match the pattern and mask is image/bmp.
The MIME type registry is located in /usr/share/mime-info. The MIME type registry contains the following files:
File | File Extension |
---|---|
MIME information file | .mime |
MIME keys file | .keys |
The following sections describe MIME information files and MIME keys files.
MIME information files associate MIME types with one or both of the following:
When an application searches for the MIME type of a file, the application checks the filename against the MIME information files. If a match for the filename is found, the MIME type associated with the extension or pattern is the MIME type of the file.
In MIME information files, the filename pattern to search for is written as a regular expression.
The format of MIME type entries in MIME information files is as follows:
You can specify a priority value for the file extension and the regular expression. You can use the priority value to differentiate composite filenames. For example, you can assign a priority of 1 to the .gz extension, and assign a higher priority of 2 to the .tar.gz extension. In this case, the file abc.tar.gz takes the MIME type for .tar.gz.
You must indent the ext field and the regex field with a tab character (\t).
The following MIME type entries are samples from the gnome-vfs.mime MIME information file:
The file manager reads the MIME information files alphabetically. The alphabetical order determines the order in which MIME types are assigned to file extensions or regular expressions. For example, if the same file extension is assigned to different MIME types in the files abc.mime and def.mime, the MIME type in abc.mime is used.
MIME keys file provide information about a MIME type that is used in the user interface. For example, the MIME keys file provides a description of a MIME type, and specifies an icon to represent files of that MIME type.
The following is a sample from a MIME keys file:
You must indent the keys in a MIME keys file with a tab character (\t).
Table 5-2 describes the most important keys in MIME keys files. Typically, the description key and the category key are localized.
Key | Description |
---|---|
can_be_executable | Specifies whether files of this MIME type can be executed. |
description | Describes the MIME type. This description can be displayed in the file manager and other applications. |
icon_filename |
Specifies the filename of an icon to represent the MIME type. Does not specify the path to the filename, or the file extension. This icon can be displayed in the file manager and other applications. |
default_action_type | Specifies the category of action to take when a file of this MIME type is opened by the user. Enter application for this MIME type for most applications. |
short_list_application_ids
_for_novice_user_level
|
Specifies the application to use when a file of this MIME type is opened by a user. Specify one or more applications, in order of priority. The applications must also be registered in the application registry. |
category | Specifies a category for the MIME type. The value of this key determines the location of the MIME type in the File Types and Programs preference tool. |