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/subtype
value 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
MIME
types can have multiple file extensions. For example, aMIME
type ofapplication/java-archive
can havejar
,ear
, andwar
file extensions. It falls back toapplication/octet-stream
if the type, subtype or file extension is invalid.Parameters
type
A type such as
text
,application
, etc. Defaults toapplication
.subtype
A subtype such as
html
,css
, etc. Defaults tooctet-stream
.ext
A file extension matching a
type/subtype
value such asswift
,js
, etc. Defaults tonil
. -
Initializes a new instance with the combination of
type/subtype
and a file extension as a hint sinceMIME
types can have multiple file extensions. For example, aMIME
type ofapplication/java-archive
can havejar
,ear
, andwar
file extensions. It falls back toapplication/octet-stream
if the combination oftype/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 tonil
. -
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 }