writeResp method

  1. @override
Future<void> writeResp()
override

Implementation

@override
Future<void> writeResp() async {
  File file = File(dir);
  if (!(await file.exists())) {
    setStatus(404);
    headers.contentType = ContentType.text;
    write("File not found");
    return;
  }
  String? mimetype = MimeTypes.ofFile(file);
  if (mimetype != null) {
    List list = mimetype.split('/');
    headers.contentType = ContentType(list.first, list.last);
  } else {
    headers.contentType = ContentType.binary;
  }
  await addStream(file.openRead());
}