#include <va_util.h>


va_string *va_resolve_file_url(const va_string *path)🔗

Converts a file URL to an absolute path.

File URLs can be either path names or URLs with a “file://” or “res://” scheme.

Resource URLs are used as system-independent identifiers for files inside components such as apps and tool libraries. A resource URL starts with a “res://” scheme and is followed by a component’s ID, including the major version number, for example “res://com.example.component/1/file.txt”. A resource URL will be converted to an absolute path.

If path starts with “file://”, the function returns the rest of path.

If path does not start with a URL scheme, a clone of path will be returned.

The caller is responsible for releasing the returned pointer.

If the URL cannot be resolved, this function returns NULL. Note that the file may not exist even if its path was successfully resolved.

// Refer to a file in an installed component.
va_string* path = va_resolve_file_url("res://com.example.component/1/data.dat");
int len = va_string_utf8_length(path);
char* fileName = (char*)malloc(len);
va_string_to_utf8(path, fileName, len);
FILE* fp = fopen(fileName, "r");
// Check and use fp ...