MimeType.fromString constructor

MimeType.fromString(
  1. String value
)

Create MimeType from string of type/subtype;parameter=value

Implementation

factory MimeType.fromString(String value) {
  var separatorIndex = value.indexOf('/');
  var type = value.substring(0, separatorIndex);
  var subtype = value.substring(separatorIndex + 1);
  var hasParam = subtype.indexOf(';');
  Map<String, String>? parameters;
  if (hasParam > 0) {
    var param = subtype.substring(hasParam + 1).trim().split('=');
    subtype = subtype.substring(0, hasParam);
    parameters = {
      param[0]: param[1],
    };
  }
  return MimeType(type, subtype, parameters);
}