Skip to content

infinity.mimeType

Provides functionality for matching MIME-Types to file extensions and vice versa. The MIME-Types have to be configured inside the [MimeTypes] section of the ini file of the used infinity executable (infinity.ini, or infinity.service.ini for the service executable) in the format .extension=mime/type (refer to infinity.default.ini for a set of default mappings). The mappings are loaded when the runtime starts. Extensions and MIME types are matched case-insensitively (since 3.11; before, ini entries containing upper-case letters never matched). Note: the default mappings contain no entry for .json (unknown extensions return application/octet-stream); add .json=application/json to the ini file if needed.

Module: infinity.mimeType

infinity.loadModule('infinity.mimeType');

let mimeType = infinity.mimeType.getMimeType('.jpg');
console.debug(mimeType);
//image/jpeg


let extension = infinity.mimeType.getExtension('text/javascript');
console.debug(extension);
//.js

Functions

getExtension()

Returns the matching file extension (including the leading dot) for the given MIME-Type. Returns '*' if the MIME-Type is not configured. If several extensions are configured for the same MIME-Type, the last configured extension is returned.

Signature:

getExtension( mimeType: string ): string

Parameters:

  • mimeType: string

    The MIME-Type to be matched to a file extension.

Return type: string

Example:

infinity.loadModule('infinity.mimeType');

let extension = infinity.mimeType.getExtension('text/javascript');
console.debug(extension);
//.js

getMimeType()

Returns the matching MIME-Type for the given file extension. Returns 'application/octet-stream' if the extension is not configured.

Signature:

getMimeType( extension: string ): string

Parameters:

  • extension: string

    The file extension (including the leading dot, e.g. '.jpg') to be matched to a MIME-Type.

Return type: string

Example:

infinity.loadModule('infinity.mimeType');

let mimeType = infinity.mimeType.getMimeType('.jpg');
console.debug(mimeType);
//image/jpeg