canDecodeFileName function

bool canDecodeFileName(
  1. String fileName, {
  2. List<ModelDecoder> decoders = const <ModelDecoder>[],
})

Whether a file called fileName is one decodeModelBytes would read on its name alone — a built-in suffix, or one of decoders claiming it.

By name, with no bytes, because the callers are the ones that have not read the file yet or should not trust what it starts with: a drop target deciding whether to try at all, and a converter walking a directory. A decoder that recognises its format only by magic answers false here, which is the honest answer to a question asked without the bytes.

Implementation

bool canDecodeFileName(
  String fileName, {
  List<ModelDecoder> decoders = const <ModelDecoder>[],
}) {
  if (recognizedModelFormat(fileName) != null) return true;
  final name = fileName.toLowerCase();
  final nothing = Uint8List(0);
  return decoders.any((ModelDecoder decoder) => decoder.handles(name, nothing));
}