MediaType class

Represents a document format, identified by a unique RFC 6838 media type.

MediaType handles:

  • components parsing – eg. type, subtype and parameters,
  • media types comparison.

Comparing media types is more complicated than it looks, since they can contain parameters, such as charset=utf-8. We can't ignore them because some formats use parameters in their media type, for example application/atom+xml;profile=opds-catalog for an OPDS 1 catalog.

Specification: https://tools.ietf.org/html/rfc6838

@param string String representation for this media type. @param name A human readable name identifying the media type, which may be presented to the user. @param fileExtension The default file extension to use for this media type.

Annotations

Constructors

MediaType({required String type, required String subtype, String? name, String? fileExtension, Map<String, String> parameters = const {}})
const

Properties

charset String?
Encoding as declared in the charset parameter, if there's any.
no setter
fileExtension String?
final
hashCode int
The hash code for this object.
no setteroverride
isAudio bool
Returns whether this media type is of an audio clip.
no setter
isBitmap bool
Returns whether this media type is of a bitmap image, so excluding vectorial formats.
no setter
isHtml bool
Returns whether this media type is of an HTML document.
no setter
isJson bool
Returns whether this media type is structured as a JSON file.
no setter
isOpds bool
Returns whether this media type is of an OPDS feed.
no setter
isPublication bool
Returns whether this media type is of a publication file.
no setter
isRwpm bool
Returns whether this media type is of a Readium Web Publication Manifest.
no setter
isVideo bool
Returns whether this media type is of a video clip.
no setter
isZip bool
Returns whether this media type is structured as a ZIP archive.
no setter
name String?
final
parameters Map<String, String>
The parameters in the media type, such as charset=utf-8.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
structuredSyntaxSuffix String?
Structured syntax suffix, e.g. +zip in application/epub+zip.
no setter
subtype String
The subtype component, e.g. epub+zip in application/epub+zip.
final
type String
The type component, e.g. application in application/epub+zip.
final

Methods

contains(MediaType? other) bool
Returns whether the given other media type is included in this media type.
containsFromName(String? other) bool
Returns whether the given other media type is included in this media type.
matches(MediaType? other) bool
Returns whether this media type and other are the same, ignoring parameters that are not in both media types.
matchesAny(Iterable<MediaType> others) bool
Returns whether this media type matches any of the others media types.
matchesAnyFromName(Iterable<String> others) bool
Returns whether this media type matches any of the others media types.
matchesFromName(String? other) bool
Returns whether this media type and other are the same, ignoring parameters that are not in both media types.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
The string representation of this media type.
override

Operators

operator ==(Object other) bool
Returns whether two media types are equal, checking the type, subtype and parameters. Parameters order is ignored.
override

Static Methods

addSupportedType(MediaType mediaType) → void
filterByFileExtension(String? fileExtension) MediaType?
parse(String string, {String? name, String? fileExtension}) MediaType?
Creates a MediaType from its string representation.

Constants

aac → const MediaType
acsm → const MediaType
aiff → const MediaType
avi → const MediaType
binary → const MediaType
bmp → const MediaType
cbz → const MediaType
css → const MediaType
divina → const MediaType
divinaManifest → const MediaType
doc → const MediaType
docx → const MediaType
epub → const MediaType
gif → const MediaType
gz → const MediaType
html → const MediaType
javascript → const MediaType
jpeg → const MediaType
json → const MediaType
lcpLicenseDocument → const MediaType
lcpProtectedAudiobook → const MediaType
lcpProtectedPdf → const MediaType
lcpStatusDocument → const MediaType
lpf → const MediaType
mkv → const MediaType
mov → const MediaType
mp3 → const MediaType
mp4 → const MediaType
mp4a → const MediaType
mpeg → const MediaType
mpg → const MediaType
ncx → const MediaType
oga → const MediaType
ogg → const MediaType
ogv → const MediaType
opds1 → const MediaType
opds1Entry → const MediaType
opds2 → const MediaType
opds2Publication → const MediaType
opdsAuthentication → const MediaType
opus → const MediaType
otf → const MediaType
pdf → const MediaType
png → const MediaType
ppt → const MediaType
pptx → const MediaType
readiumAudiobook → const MediaType
readiumAudiobookManifest → const MediaType
readiumNarration → const MediaType
Readium Sync Narration JSON — the newer per-item media overlay format used by the Readium web/ts-toolkit (application/vnd.readium.narration+json).
readiumWebpub → const MediaType
readiumWebpubManifest → const MediaType
smil → const MediaType
svg → const MediaType
syncMediaNarration → const MediaType
syncMediaNarrationManifest → const MediaType
text → const MediaType
tiff → const MediaType
ttf → const MediaType
v3g2 → const MediaType
v3gp → const MediaType
w3cWpubManifest → const MediaType
wav → const MediaType
waveform → const MediaType
webmAudio → const MediaType
webmVideo → const MediaType
webp → const MediaType
woff → const MediaType
woff2 → const MediaType
xaiff → const MediaType
xaiffc → const MediaType
xhtml → const MediaType
xls → const MediaType
xlsx → const MediaType
xml → const MediaType
xmpegurl → const MediaType
zab → const MediaType
zip → const MediaType