streamFile method

Future streamFile(
  1. File file
)

Streams a file to this response.

HEAD responses will not actually write data.

Implementation

Future streamFile(File file) async {
  if (!isOpen) {
    throw closed();
  }
  var mimeType = app!.mimeTypeResolver.lookup(file.path);
  contentLength = await file.length();
  contentType = mimeType == null
      ? MediaType('application', 'octet-stream')
      : MediaType.parse(mimeType);

  if (correspondingRequest!.method != 'HEAD') {
    return addStream(file.openRead().cast<List<int>>()).then((_) => close());
  }
}