MediaType.fromSubtype constructor

MediaType.fromSubtype(
  1. MediaSubtype subtype
)

Creates a media type from the specified subtype.

Implementation

factory MediaType.fromSubtype(MediaSubtype subtype) {
  for (final key in _subtypesByMimeType.keys) {
    final sub = _subtypesByMimeType[key];
    if (sub == subtype) {
      final splitPos = key.indexOf('/');
      if (splitPos != -1) {
        final topText = key.substring(0, splitPos);
        final top = _topLevelByMimeName[topText] ?? MediaToptype.other;

        return MediaType(key, top, subtype);
      }
      break;
    }
  }
  print('Error: unable to resolve media subtype $subtype');

  return MediaType('example/example', MediaToptype.other, subtype);
}