MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / is_binary_content

Function is_binary_content

atomic-core/src/record/detect.rs:767–785  ·  view source on GitHub ↗

Check if content is binary. # Arguments `content` - The content to check # Returns `true` if the content appears to be binary.

(content: &[u8])

Source from the content-addressed store, hash-verified

765///
766/// `true` if the content appears to be binary.
767pub fn is_binary_content(content: &[u8]) -> bool {
768 // Quick check: null bytes indicate binary
769 if content.contains(&0) {
770 return true;
771 }
772
773 // Check for high ratio of non-printable characters
774 let non_printable = content
775 .iter()
776 .filter(|&&b| b < 0x20 && b != b'\n' && b != b'\r' && b != b'\t')
777 .count();
778
779 // If more than 30% non-printable, consider binary
780 if !content.is_empty() && non_printable * 100 / content.len() > 30 {
781 return true;
782 }
783
784 false
785}
786
787// TESTS
788

Callers

nothing calls this directly

Calls 5

containsMethod · 0.45
countMethod · 0.45
iterMethod · 0.45
is_emptyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected