MCPcopy Create free account
hub / github.com/GraphiteEditor/Graphite / read

Function read

tools/third-party-licenses/src/cef.rs:67–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65}
66
67fn read() -> Result<String, Error> {
68 let cef_path = PathBuf::from(env!("CEF_PATH"));
69 let cef_credits = std::fs::read_dir(&cef_path)
70 .map_err(|e| Error::Io(e, format!("Failed to read CEF_PATH directory {}", cef_path.display())))?
71 .filter_map(|entry| entry.ok())
72 .find(|entry| {
73 let name = entry.file_name();
74 name.eq_ignore_ascii_case("credits.html") || name.eq_ignore_ascii_case("credits.html.xz")
75 })
76 .map(|entry| entry.path())
77 .ok_or_else(|| Error::CefCreditsNotFound(cef_path.clone()))?;
78
79 let decompress_xz = cef_credits.extension().map(|ext| ext.eq_ignore_ascii_case("xz")).unwrap_or(false);
80
81 if decompress_xz {
82 let file = fs::File::open(&cef_credits).map_err(|e| Error::Io(e, format!("Failed to open CEF credits file {}", cef_credits.display())))?;
83 let mut reader = XzReader::new(file, false);
84 let mut html = String::new();
85 reader
86 .read_to_string(&mut html)
87 .map_err(|e| Error::Io(e, format!("Failed to decompress CEF credits file {}", cef_credits.display())))?;
88 Ok(html)
89 } else {
90 fs::read_to_string(&cef_credits).map_err(|e| Error::Io(e, format!("Failed to read CEF credits file {}", cef_credits.display())))
91 }
92}

Callers 4

runFunction · 0.70
licensesMethod · 0.70
hashMethod · 0.70
readMethod · 0.50

Calls 3

extensionMethod · 0.80
pathMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected