MCPcopy Create free account
hub / github.com/douglance/devsql / is_binary

Function is_binary

crates/devsql/src/providers/mod.rs:107–116  ·  view source on GitHub ↗

Check if a file appears to be binary by reading the first 8 KB and looking for null bytes.

(path: &Path)

Source from the content-addressed store, hash-verified

105/// Check if a file appears to be binary by reading the first 8 KB and looking
106/// for null bytes.
107pub fn is_binary(path: &Path) -> bool {
108 let Ok(mut file) = fs::File::open(path) else {
109 return true; // can't read → treat as binary
110 };
111 let mut buf = [0u8; 8192];
112 let Ok(n) = file.read(&mut buf) else {
113 return true;
114 };
115 buf[..n].contains(&0)
116}
117
118/// Map a file extension to a human-readable language name.
119pub fn detect_language(ext: &str) -> &'static str {

Callers 1

walk_source_filesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected