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

Function detect_encoding

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

Detect the encoding of content. # Arguments `content` - The content to analyze # Returns The detected encoding.

(content: &[u8])

Source from the content-addressed store, hash-verified

742///
743/// The detected encoding.
744pub fn detect_encoding(content: &[u8]) -> Encoding {
745 // Check for UTF-8 validity
746 if std::str::from_utf8(content).is_ok() {
747 // Check for null bytes (binary indicator even in valid UTF-8)
748 if content.contains(&0) {
749 Encoding::Binary
750 } else {
751 Encoding::Utf8
752 }
753 } else {
754 Encoding::Binary
755 }
756}
757
758/// Check if content is binary.
759///

Calls 1

containsMethod · 0.45