Skip to content

Latest commit

 

History

History
41 lines (28 loc) · 1.62 KB

README.md

File metadata and controls

41 lines (28 loc) · 1.62 KB

MimeTypes

This project uses a copy of /etc/media.types file from the media-types linux package.

Usage

Init

The static constructor tries to read the embedded ressource "mime.types.gz" of the executing assembly. You can also use ReadMimeTypesFrom(Stream,..) to replace all mime types.

    ReadMimeTypesFrom(Stream stream, bool disposeStream = false)

Stream can be either GZip compressed or raw.
One mime type per line followed by file suffixes seperated by any combination of ' ' or ',' or ';' or '\t'
'#' Marks a comment

Examples:

    image/jpg jpg jpeg
    video/jpg # Will be skipped since no suffix specified

GetMimeTypeExtensions

    IEnumerable<string> GetMimeTypeExtensions(string mimetype)

Returns an IEnumerable of all suffices for the specified mime type.

GetMimeTypes

    1. IEnumerable<string> GetMimeTypes(string fileName)
    2. IEnumerable<string> GetMimeTypes()
  1. Returns an IEnumerable containing all found mime types, or FallbackMimeType if non was found.
    fileName must contain '.' for example "test.png" or ".png" or "/test/test.png" for "image/png".
    Throws ArgumentNullException if fileName is null.
  2. Returns a distinct enumeration of all mime types

TryGetMimeType

    bool TryGetMimeType(string? fileName, out IEnumerable<string> mimeTypes)

True if the suffix is found. mimeTypes is a list of all found mime types.
fileName must contain '.' for example "test.png" or ".png" or "/test/test.png" for "image/png".

Example

    MimeTypes.MimeTypes.GetMimeType("test.png"); // returns { "image/png" }