isTextMimeType function
Checks if a file is considered a text file based on its MIME type.
path: The path to the file.headerBytes: Optional header bytes for more accurate MIME type detection.
Returns true if the file's MIME type is recognized as text, false otherwise.
doTextMimeInit(); // initializes
print(isTextMimeType('a.txt')); // true
print(isTextMimeType('a.pdf')); // false
print(isTextMimeType('a.yml')); // false
// add a custom text mimetype, yml|yaml is a config language.
doTextMimeAdd('yml', 'text/yaml');
print(isTextMimeType('a.yml')); // true
Implementation
bool isTextMimeType(String path, {List<int>? headerBytes}) {
final mime = _textMimeResolver.lookup(path, headerBytes: headerBytes) ?? '';
return mime.isNotEmpty;
}