MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / is_binary

Function is_binary

crates/opencode-tool/src/read.rs:459–477  ·  view source on GitHub ↗
(content: &[u8])

Source from the content-addressed store, hash-verified

457}
458
459fn is_binary(content: &[u8]) -> bool {
460 if content.is_empty() {
461 return false;
462 }
463
464 let check_len = std::cmp::min(4096, content.len());
465 let bytes = &content[..check_len];
466
467 if bytes.contains(&0) {
468 return true;
469 }
470
471 let non_printable = bytes
472 .iter()
473 .filter(|&&b| b < 9 || (b > 13 && b < 32))
474 .count();
475
476 non_printable as f32 / check_len as f32 > 0.3
477}
478
479struct InstructionPrompt {
480 filepath: String,

Callers 1

executeMethod · 0.85

Calls 4

is_emptyMethod · 0.80
containsMethod · 0.80
countMethod · 0.80
filterMethod · 0.45

Tested by

no test coverage detected