MCPcopy Create free account
hub / github.com/FastLED/FastLED / resolve_host

Function resolve_host

src/fl/asset/asset.cpp.hpp:74–110  ·  view source on GitHub ↗

Host/stub resolution: try the raw file on disk, then the sibling `.lnk`. Rules: - If ` / ` exists, return `file:// `. We use the plain path as the URL body since `fl::url` accepts arbitrary strings; the test harness and host consumers treat the returned url's string() as a filesystem path. - Otherwise if ` / .lnk` exists, return the URL from the `.lnk`

Source from the content-addressed store, hash-verified

72/// `.lnk` file (same fallback as WASM).
73/// - Otherwise return invalid url().
74inline fl::url resolve_host(fl::string_view path) FL_NOEXCEPT {
75 // Try raw file on disk.
76 fl::string pathStr(path.data(), path.size());
77 {
78 fl::ifstream probe(pathStr.c_str(), fl::ios::in | fl::ios::binary);
79 if (probe.is_open()) {
80 probe.close();
81 // Return the path as-is (a relative/absolute filesystem path).
82 // fl::url accepts any string; callers on host treat .string() as
83 // a local path. This matches the existing AudioUrl test pattern
84 // that stores a raw URL string in the url field.
85 return fl::url(pathStr);
86 }
87 }
88
89 // Fallback: try <path>.lnk alongside.
90 fl::string lnkPath = pathStr;
91 lnkPath += ".lnk";
92 fl::ifstream lnk(lnkPath.c_str(), fl::ios::in | fl::ios::binary);
93 if (!lnk.is_open()) {
94 return fl::url();
95 }
96 // Read entire file. .lnk files are expected to be tiny (URL + a few
97 // metadata lines); cap the read at 8 KiB to avoid pathological inputs.
98 constexpr fl::size kMaxLnkBytes = 8 * 1024;
99 fl::size sz = lnk.size();
100 if (sz > kMaxLnkBytes) {
101 sz = kMaxLnkBytes;
102 }
103 fl::string content;
104 content.resize(sz);
105 if (sz > 0) {
106 lnk.read(&content[0], sz);
107 }
108 lnk.close();
109 return parse_lnk(fl::string_view(content.data(), content.size()));
110}
111#endif
112
113} // namespace asset_detail

Callers 1

resolve_assetFunction · 0.85

Calls 10

urlClass · 0.85
parse_lnkFunction · 0.85
string_viewClass · 0.50
dataMethod · 0.45
sizeMethod · 0.45
c_strMethod · 0.45
is_openMethod · 0.45
closeMethod · 0.45
resizeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected