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.
Properties
- charset → String?
-
Encoding as declared in the
charset
parameter, if there's any.read-only - fileExtension → String?
-
final
- hashCode → int
-
The hash code for this object.
read-onlyoverride
- isAudio → bool
-
Returns whether this media type is of an audio clip.
read-only
- isBitmap → bool
-
Returns whether this media type is of a bitmap image, so excluding vectorial formats.
read-only
- isHtml → bool
-
Returns whether this media type is of an HTML document.
read-only
- isJson → bool
-
Returns whether this media type is structured as a JSON file.
read-only
- isOpds → bool
-
Returns whether this media type is of an OPDS feed.
read-only
- isPublication → bool
-
Returns whether this media type is of a publication file.
read-only
- isRwpm → bool
-
Returns whether this media type is of a Readium Web Publication Manifest.
read-only
- isVideo → bool
-
Returns whether this media type is of a video clip.
read-only
- isZip → bool
-
Returns whether this media type is structured as a ZIP archive.
read-only
- 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.
read-onlyinherited
- structuredSyntaxSuffix → String?
-
Structured syntax suffix, e.g.
+zip
inapplication/epub+zip
.read-only - subtype → String
-
The subtype component, e.g.
epub+zip
inapplication/epub+zip
.final - type → String
-
The type component, e.g.
application
inapplication/epub+zip
.final
Methods
-
canonicalMediaType(
) → Future< MediaType> - Returns the canonical version of this media type, if it is known.
-
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
-
filterByFileExtension(
String? fileExtension) → MediaType? -
of(
{List< String> mediaTypes = const [], List<String> fileExtensions = const [], List<Sniffer> sniffers = MediaType.sniffers}) → Future<MediaType?> - Resolves a format from file extension and media type hints, without checking the actual content.
-
ofBytes(
Future< ByteData> bytes(), {List<String> mediaTypes = const [], List<String> fileExtensions = const [], List<Sniffer> sniffers = MediaType.sniffers}) → Future<MediaType?> - Resolves a format from bytes, e.g. from an HTTP response.
-
ofBytesWithSingleHint(
Future< ByteData> bytes(), {String? mediaType, String? fileExtension, List<Sniffer> sniffers = MediaType.sniffers}) → Future<MediaType?> - Resolves a format from bytes, e.g. from an HTTP response.
-
ofFile(
FileSystemEntity file, {List< String> mediaTypes = const [], List<String> fileExtensions = const [], List<Sniffer> sniffers = MediaType.sniffers}) → Future<MediaType?> - Resolves a format from a local file path.
-
ofFilePath(
String path, {List< String> mediaTypes = const [], List<String> fileExtensions = const [], List<Sniffer> sniffers = MediaType.sniffers}) → Future<MediaType?> - Resolves a format from a local file path.
-
ofFilePathWithSingleHint(
String path, {String? mediaType, String? fileExtension, List< Sniffer> sniffers = MediaType.sniffers}) → Future<MediaType?> - Resolves a format from a local file path.
-
ofFileWithSingleHint(
FileSystemEntity file, {String? mediaType, String? fileExtension, List< Sniffer> sniffers = MediaType.sniffers}) → Future<MediaType?> - Resolves a format from a local file path.
-
ofSingleHint(
{String? mediaType, String? fileExtension, List< Sniffer> sniffers = MediaType.sniffers}) → Future<MediaType?> - Resolves a format from a single file extension and media type hint, without checking the actual content.
-
ofUri(
Uri uri, {List< String> mediaTypes = const [], List<String> fileExtensions = const [], List<Sniffer> sniffers = MediaType.sniffers}) → Future<MediaType?> -
Resolves a format from a content URI and a
ContentResolver
. Accepts the following URI schemes: content, android.resource, file. -
ofUriWithSingleHint(
Uri uri, {String? mediaType, String? fileExtension, List< Sniffer> sniffers = MediaType.sniffers}) → Future<MediaType?> -
Resolves a format from a content URI and a
ContentResolver
. Accepts the following URI schemes: content, android.resource, file. -
parse(
String string, {String? name, String? fileExtension}) → MediaType? - Creates a MediaType from its string representation.
Constants
- aac → const MediaType
-
MediaType._(type: "audio", subtype: "aac", fileExtension: "aac")
- acsm → const MediaType
-
MediaType._(type: "application", subtype: "vnd.adobe.adept+xml", name: "Adobe Content Server Message", fileExtension: "acsm")
- aiff → const MediaType
-
MediaType._(type: "audio", subtype: "aiff", fileExtension: "aiff")
- avi → const MediaType
-
MediaType._(type: "video", subtype: "x-msvideo", fileExtension: "avi")
- binary → const MediaType
-
MediaType._(type: "application", subtype: "octet-stream")
- bmp → const MediaType
-
MediaType._(type: "image", subtype: "bmp", fileExtension: "bmp")
- cbz → const MediaType
-
MediaType._(type: "application", subtype: "vnd.comicbook+zip", name: "Comic Book Archive", fileExtension: "cbz")
- css → const MediaType
-
MediaType._(type: "text", subtype: "css", fileExtension: "css")
- divina → const MediaType
-
MediaType._(type: "application", subtype: "divina+zip", name: "Digital Visual Narratives", fileExtension: "divina")
- divinaManifest → const MediaType
-
MediaType._(type: "application", subtype: "divina+json", name: "Digital Visual Narratives", fileExtension: "json")
- doc → const MediaType
-
MediaType._(type: "application", subtype: "msword", fileExtension: "doc")
- docx → const MediaType
-
MediaType._(type: "application", subtype: "vnd.openxmlformats-officedocument.wordprocessingml.document", fileExtension: "docx")
- epub → const MediaType
-
MediaType._(type: "application", subtype: "epub+zip", name: "EPUB", fileExtension: "epub")
- gif → const MediaType
-
MediaType._(type: "image", subtype: "gif", fileExtension: "gif")
- gz → const MediaType
-
MediaType._(type: "application", subtype: "gzip", fileExtension: "gz")
- html → const MediaType
-
MediaType._(type: "text", subtype: "html", fileExtension: "html")
- javascript → const MediaType
-
MediaType._(type: "text", subtype: "javascript", fileExtension: "js")
- jpeg → const MediaType
-
MediaType._(type: "image", subtype: "jpeg", fileExtension: "jpeg")
- json → const MediaType
-
MediaType._(type: "application", subtype: "json")
- lcpLicenseDocument → const MediaType
-
MediaType._(type: "application", subtype: "vnd.readium.lcp.license.v1.0+json", name: "LCP License", fileExtension: "lcpl")
- lcpProtectedAudiobook → const MediaType
-
MediaType._(type: "application", subtype: "audiobook+lcp", name: "LCP Protected Audiobook", fileExtension: "lcpa")
- lcpProtectedPdf → const MediaType
-
MediaType._(type: "application", subtype: "pdf+lcp", name: "LCP Protected PDF", fileExtension: "lcpdf")
- lcpStatusDocument → const MediaType
-
MediaType._(type: "application", subtype: "vnd.readium.license.status.v1.0+json")
- lpf → const MediaType
-
MediaType._(type: "application", subtype: "lpf+zip", fileExtension: "lpf")
- mp3 → const MediaType
-
MediaType._(type: "audio", subtype: "mpeg", fileExtension: "mp3")
- mp4 → const MediaType
-
MediaType._(type: "video", subtype: "mp4", fileExtension: "mp4")
- mpeg → const MediaType
-
MediaType._(type: "video", subtype: "mpeg", fileExtension: "mpeg")
- ncx → const MediaType
-
MediaType._(type: "application", subtype: "x-dtbncx+xml", fileExtension: "ncx")
- ogg → const MediaType
-
MediaType._(type: "audio", subtype: "ogg", fileExtension: "oga")
- ogv → const MediaType
-
MediaType._(type: "video", subtype: "ogg", fileExtension: "ogv")
- opds1 → const MediaType
-
MediaType._(type: "application", subtype: "atom+xml", parameters: {"profile" : "opds-catalog"})
- opds1Entry → const MediaType
-
MediaType._(type: "application", subtype: "atom+xml", parameters: {"type" : "entry", "profile" : "opds-catalog"})
- opds2 → const MediaType
-
MediaType._(type: "application", subtype: "opds+json")
- opds2Publication → const MediaType
-
MediaType._(type: "application", subtype: "opds-publication+json")
- opdsAuthentication → const MediaType
-
MediaType._(type: "application", subtype: "opds-authentication+json")
- opus → const MediaType
-
MediaType._(type: "audio", subtype: "opus", fileExtension: "opus")
- otf → const MediaType
-
MediaType._(type: "font", subtype: "otf", fileExtension: "otf")
- pdf → const MediaType
-
MediaType._(type: "application", subtype: "pdf", name: "PDF", fileExtension: "pdf")
- png → const MediaType
-
MediaType._(type: "image", subtype: "png", fileExtension: "png")
- readiumAudiobook → const MediaType
-
MediaType._(type: "application", subtype: "audiobook+zip", name: "Readium Audiobook", fileExtension: "audiobook")
- readiumAudiobookManifest → const MediaType
-
MediaType._(type: "application", subtype: "audiobook+json", name: "Readium Audiobook", fileExtension: "json")
- readiumWebpub → const MediaType
-
MediaType._(type: "application", subtype: "webpub+zip", name: "Readium Web Publication", fileExtension: "webpub")
- readiumWebpubManifest → const MediaType
-
MediaType._(type: "application", subtype: "webpub+json", name: "Readium Web Publication", fileExtension: "json")
- smil → const MediaType
-
MediaType._(type: "application", subtype: "smil+xml", fileExtension: "smil")
-
sniffers
→ const List<
Sniffer> -
The default sniffers provided by Readium 2 to resolve a MediaType.
You can register additional sniffers globally by modifying this list.
The sniffers order is important, because some formats are subsets of other formats.
Sniffers.all
- svg → const MediaType
-
MediaType._(type: "image", subtype: "svg+xml", fileExtension: "svg")
- text → const MediaType
-
MediaType._(type: "text", subtype: "plain", fileExtension: "txt")
- tiff → const MediaType
-
MediaType._(type: "image", subtype: "tiff", fileExtension: "tiff")
- ttf → const MediaType
-
MediaType._(type: "font", subtype: "ttf", fileExtension: "ttf")
- w3cWpubManifest → const MediaType
-
MediaType._(type: "application", subtype: "x.readium.w3c.wpub+json", name: "Web Publication", fileExtension: "json")
- wav → const MediaType
-
MediaType._(type: "audio", subtype: "wav", fileExtension: "wav")
- webmAudio → const MediaType
-
MediaType._(type: "audio", subtype: "webm", fileExtension: "webm")
- webmVideo → const MediaType
-
MediaType._(type: "video", subtype: "webm", fileExtension: "webm")
- webp → const MediaType
-
MediaType._(type: "image", subtype: "webp", fileExtension: "webp")
- woff → const MediaType
-
MediaType._(type: "font", subtype: "woff", fileExtension: "woff")
- woff2 → const MediaType
-
MediaType._(type: "font", subtype: "woff2", fileExtension: "woff2")
- xhtml → const MediaType
-
MediaType._(type: "application", subtype: "xhtml+xml", fileExtension: "xhtml")
- xml → const MediaType
-
MediaType._(type: "application", subtype: "xml", fileExtension: "xml")
- zab → const MediaType
-
MediaType._(type: "application", subtype: "x.readium.zab+zip", name: "Zipped Audio Book", fileExtension: "zab")
- zip → const MediaType
-
MediaType._(type: "application", subtype: "zip", fileExtension: "zip")