1 /** 2 * MIME type detector interface. 3 * Implementers should be capable of detecting MIME type name by various properties including file name, file data and namespace uri. 4 * 5 * Authors: 6 * $(LINK2 https://github.com/FreeSlave, Roman Chistokhodov) 7 * License: 8 * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0). 9 * Copyright: 10 * Roman Chistokhodov, 2016 11 */ 12 13 module mime.detector; 14 15 /** 16 * Interface for classes that detect mime type name from file name or data. 17 * 18 * This interface is designed to know nothing about $(D mime.type.MimeType), it deals only with mime type names. 19 * Implemented classes are not expected to be 'smart' (i.e. they should not do anything besides what required). See notes for member functions. 20 */ 21 interface IMimeDetector 22 { 23 /** 24 * The preferable mime type for fileName. 25 * Returns: The name of preferable mime type for given fileName or null if could not find any match. 26 * Note: 27 * Implementer is NOT expected to get the file data or state (e.g. read or stat it). 28 */ 29 const(char)[] mimeTypeForFileName(const(char)[] fileName); 30 31 /** 32 * The list of the most preferred mime types for fileName. 33 * If its length is greater than 1 it means there are many mime type with same priority matching this fileName. 34 * Returns: Array of names of the most preferred mime types for given fileName. 35 * Note: 36 * Implementer should prefer to return arrays with unique names. 37 * Implementer is NOT expected to get the file data or state (e.g. read or stat it). 38 */ 39 const(char[])[] mimeTypesForFileName(const(char)[] fileName); 40 41 /** 42 * The preferable mime type for data. 43 * Returns: The name of preferable mime type for given data or null if could not find any match. 44 * Note: 45 * Implementer is NOT expected to check if data is textual or not in order to provide text/plain or application/octet-stream fallback. 46 * Implementer is NOT expected to clarify mime type by namespace uri itself if it was detected that data is xml. 47 */ 48 const(char)[] mimeTypeForData(const(void)[] data); 49 50 /** 51 * The list of the most preferred mime types for data. 52 * If its length is greater than 1 it means there are many mime type with same priority matching this data. 53 * Returns: The array of the names of the most preferred mime types for given data. 54 * Note: 55 * Implementer should prefer to return arrays with unique names. 56 * Implementer is NOT expected to check if data is textual or not in order to provide text/plain or application/octet-stream fallback. 57 * Implementer is NOT expected to clarify mime type by namespace uri itself if it was detected that data is xml. 58 */ 59 const(char[])[] mimeTypesForData(const(void)[] data); 60 61 /** 62 * Returns: MIME type name for namespaceUri or null if not found (or feature is not implemented). 63 */ 64 const(char)[] mimeTypeForNamespaceURI(const(char)[] namespaceURI); 65 66 67 /** 68 * Get real name of mime type by alias. 69 * Returns: Resolved mime type name or null if not found (or feature not implemented). 70 * Note: 71 * Implementer is not required to return aliasName itself if it's real name of mime type. 72 */ 73 const(char)[] resolveAlias(const(char)[] aliasName); 74 75 /** 76 * Check if mimeType is subclass of parent. 77 * Returns: true if mimeType is subclass of parent. False otherwise. 78 * Note: 79 * Implementer is not required to treat mimeType as subclass of itself. 80 */ 81 bool isSubclassOf(const(char)[] mimeType, const(char)[] parent); 82 }