mimedb

Types

ContentType = string
A string representing the MIME type, e.g., "text/html".
Mime = ref object
Represents a MIME type and its associated metadata.
MimeDatabaseStorage = ref object
MimeDBException = object of CatchableError
Exception type for MIME database errors.
MimeSource = enum
  mimeSourceNone = "none", mimeSourceApache = "apache", mimeSourceIana = "iana",
  mimeSourceNginx = "nginx"
The source of the MIME type information.

Vars

MimeDB: MimeDatabaseStorage
A global variable that holds the MIME database. It contains mappings of MIME types to their metadata and file extensions to MIME types.

Procs

proc getExtensions(mime: Option[Mime]): Option[seq[string]] {....raises: [],
    tags: [], forbids: [].}
Returns the file extensions associated with a given Mime type.
proc getMimeInfo(mimeType: string): Option[Mime] {....raises: [KeyError], tags: [],
    forbids: [].}
Returns the Mime information for a given MIME type, if it exists.
proc getMimeType(ext: string): Option[string] {....raises: [KeyError], tags: [],
    forbids: [].}
Returns the MIME type for a given file extension, if it exists.
proc getSource(mime: Option[Mime]): MimeSource {....raises: [], tags: [],
    forbids: [].}
Returns the source of the given Mime type.
proc hasExtension(mime: Option[Mime]; ext: string): bool {....raises: [], tags: [],
    forbids: [].}
Checks if the given Mime type has the specified file extension.
proc hasMimeType(mimeType: string): bool {....raises: [], tags: [], forbids: [].}
Checks if the MIME database has an entry for the given MIME type.
proc initMimeDatabase(data: sink string) {.
    ...raises: [MimeDBException, JsonError, ValueError], tags: [], forbids: [].}
Initializes the MIME database from a JSON string at runtime.
proc isCompressible(mime: Option[Mime]): bool {....raises: [], tags: [],
    forbids: [].}
Checks if the given MIME type is compressible.
proc isExtension(ext: string): bool {....raises: [], tags: [], forbids: [].}
Checks if the MIME database has an entry for the given file extension.

Macros

macro initDatabase()
Loads the MIME database from a JSON file at runtime. This macro reads the JSON file at compile-time. At runtime, is parsed and populates the MimeDatabase and MimeDatabaseExtensions tables.