resolveFilePath static method

String resolveFilePath(
  1. String path
)

The file of path, as AngelHttp.secure reads its paths:

  • an absolute path, as C:\certs\server.pem on Windows or /etc/certs/server.pem, as it is;
  • a file: URI, as file:///etc/certs/server.pem, as its path;
  • a relative path, of either separator on Windows, of the directory of Platform.script if it is a file, as of dart run, and else of the current directory.

The path was resolved as a URI of the script, where a Windows path is not one: C:\certs\server.pem was of a scheme c, which failed.

Implementation

static String resolveFilePath(String path) {
  if (path.startsWith('file:')) return Uri.parse(path).toFilePath();
  if (p.isAbsolute(path)) return path;
  var script = Platform.script;
  if (script.isScheme('file')) {
    return p.normalize(p.join(p.dirname(script.toFilePath()), path));
  }
  return p.absolute(path);
}