MIME

public struct MIME
extension MIME: CustomStringConvertible

A media type (also known as a Multipurpose Internet Mail Extensions or MIME type) is a standard that indicates the nature and format of a document, file, or assortment of bytes. It is defined and standardized in IETF’s RFC 6838.

  • A default type which is application.

    Declaration

    Swift

    public static let type: String
  • A default subtype which is octet-stream.

    Declaration

    Swift

    public static let subtype: String
  • A type such as text, application, etc.

    Declaration

    Swift

    public let type: String
  • A subtype such as html, css, etc.

    Declaration

    Swift

    public let subtype: String
  • ext

    A file extension matching a type/subtype value such as swift, js, etc.

    Declaration

    Swift

    public let ext: String?
  • Initializes a new instance with a type, subtype, and file extension as a hint since MIME types can have multiple file extensions. For example, a MIME type of application/java-archive can have jar, ear, and war file extensions. It falls back to application/octet-stream if the type, subtype or file extension is invalid.

    Declaration

    Swift

    public init(type: String = type, subtype: String = subtype, ext: String? = nil)

    Parameters

    type

    A type such as text, application, etc. Defaults to application.

    subtype

    A subtype such as html, css, etc. Defaults to octet-stream.

    ext

    A file extension matching a type/subtype value such as swift, js, etc. Defaults to nil.

  • Initializes a new instance with the combination of type/subtype and a file extension as a hint since MIME types can have multiple file extensions. For example, a MIME type of application/java-archive can have jar, ear, and war file extensions. It falls back to application/octet-stream if the combination of type/subtype and file extension is invalid.

    Declaration

    Swift

    public init(_ mime: String, ext: String? = nil)

    Parameters

    mime

    A type/subtype value.

    ext

    A file extension matching a type/subtype value. Defaults to nil.

  • Initializes a new instance with a file extension. It falls back to application/octet-stream if the file extension is invalid.

    Declaration

    Swift

    public init(ext: String)

    Parameters

    ext

    A file extension.

  • Initializes a new instance with a file path. It falls back to application/octet-stream if the file path is invalid.

    Declaration

    Swift

    public init(path: String)

    Parameters

    path

    A file path.

  • Initializes a new instance with a file URL. It falls back to application/octet-stream if the file URL is invalid.

    Declaration

    Swift

    public init(url: URL)

    Parameters

    url

    A file URL.

  • Guesses a MIME type from data.

    Declaration

    Swift

    public static func guess(from data: Data) -> MIME

    Parameters

    data

    A value with Data type.

    Return Value

    A guessed MIME or .init("application/octet-stream") if it can’t guess.

  • Guesses a MIME type from bytes.

    Declaration

    Swift

    public static func guess(from bytes: [UInt8]) -> MIME

    Parameters

    bytes

    A value in bytes.

    Return Value

    A guessed MIME type or .init("application/octet-stream") if it can’t guess.

  • See CustomStringConvertible.

    Declaration

    Swift

    public var description: String { get }