file method

Future<void> file(
  1. String path, {
  2. String? mimeType,
})

Implementation

Future<void> file(String path, {String? mimeType}) async {
  final bytes = File(path).readAsBytesSync();
  final mime = mimeType ?? lookupMimeType(path);

  if (mime == null) {
    return internalServerError(message: "mime-type can't resolved.");
  }

  headers
    ..contentLength = bytes.length
    ..set('content-type', mime);

  add(bytes);

  await close();
}