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 -
A file extension matching a
type/subtypevalue such asswift,js, etc.Declaration
Swift
public let ext: String? -
Initializes a new instance with a type, subtype, and file extension as a hint since
MIMEtypes can have multiple file extensions. For example, aMIMEtype ofapplication/java-archivecan havejar,ear, andwarfile extensions. It falls back toapplication/octet-streamif the type, subtype or file extension is invalid.Parameters
typeA type such as
text,application, etc. Defaults toapplication.subtypeA subtype such as
html,css, etc. Defaults tooctet-stream.extA file extension matching a
type/subtypevalue such asswift,js, etc. Defaults tonil. -
Initializes a new instance with the combination of
type/subtypeand a file extension as a hint sinceMIMEtypes can have multiple file extensions. For example, aMIMEtype ofapplication/java-archivecan havejar,ear, andwarfile extensions. It falls back toapplication/octet-streamif the combination oftype/subtypeand file extension is invalid.Declaration
Swift
public init(_ mime: String, ext: String? = nil)Parameters
mimeA
type/subtypevalue.extA file extension matching a
type/subtypevalue. Defaults tonil. -
Initializes a new instance with a file extension. It falls back to
application/octet-streamif the file extension is invalid.Declaration
Swift
public init(ext: String)Parameters
extA file extension.
-
Initializes a new instance with a file path. It falls back to
application/octet-streamif the file path is invalid.Declaration
Swift
public init(path: String)Parameters
pathA file path.
-
Initializes a new instance with a file URL. It falls back to
application/octet-streamif the file URL is invalid.Declaration
Swift
public init(url: URL)Parameters
urlA file URL.
-
Guesses a
MIMEtype from data.Declaration
Swift
public static func guess(from data: Data) -> MIMEParameters
dataA value with
Datatype.Return Value
A guessed
MIMEor.init("application/octet-stream")if it can’t guess. -
Guesses a
MIMEtype from bytes.Declaration
Swift
public static func guess(from bytes: [UInt8]) -> MIMEParameters
bytesA value in bytes.
Return Value
A guessed
MIMEtype or.init("application/octet-stream")if it can’t guess. -
See
CustomStringConvertible.Declaration
Swift
public var description: String { get }
View on GitHub
Install in Dash
MIME Structure Reference