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.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
inapplication/epub+zip
.no setter - 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
- 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
- mp3 → const MediaType
- mp4 → const MediaType
- mpeg → const MediaType
- ncx → 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
- readiumAudiobook → const MediaType
- readiumAudiobookManifest → const MediaType
- readiumWebpub → const MediaType
- readiumWebpubManifest → const MediaType
- smil → const MediaType
-
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.
- svg → const MediaType
- text → const MediaType
- tiff → const MediaType
- ttf → const MediaType
- w3cWpubManifest → const MediaType
- wav → const MediaType
- webmAudio → const MediaType
- webmVideo → const MediaType
- webp → const MediaType
- woff → const MediaType
- woff2 → const MediaType
- xhtml → const MediaType
- xml → const MediaType
- zab → const MediaType
- zip → const MediaType