getContentType function

ContentType? getContentType(
  1. String? path, {
  2. List<int>? headerBytes,
  3. bool? isExtension,
  4. bool autoUtf8 = true,
})

Returns ContentType of the specified path, or null if not fund.

For example,

getContentType("home.js");
getContentType("alpha/home.js");
getContentType("js");
getContentType("alpha/home.js?foo");
  //returns parseContentType("text/javascript; charset=utf-8")''
  • isExtension whether path is an extension, e.g., "js". If not specified (i.e., null), extension is assumed if it doesn't contain '.' nor '/'/
  • autoUtf8 whether to append "; charset=utf-8" when detecing a text mime type.

Implementation

ContentType? getContentType(String? path,
    {List<int>? headerBytes, bool? isExtension, bool autoUtf8 = true}) {
  var mime = getMimeType(path, headerBytes: headerBytes,
      isExtension: isExtension, autoUtf8: autoUtf8);
  if (mime != null) return parseContentType(mime);
}