Detect the encoding of content. Analyzes content to determine if it's valid UTF-8 text or binary data. # Arguments `content` - The content to analyze # Returns `Encoding::Utf8` for valid text, `Encoding::Binary` otherwise. # Algorithm Content is considered binary if: 1. It contains null bytes (0x00) 2. It's not valid UTF-8 # Example ```rust use atomic_core::record::workflow::compare::dete
(content: &[u8])
| 237 | /// assert_eq!(detect_encoding(&[0x00, 0x01, 0x02]), Encoding::Binary); |
| 238 | /// ``` |
| 239 | pub fn detect_encoding(content: &[u8]) -> Encoding { |
| 240 | // Check for null bytes (strong indicator of binary) |
| 241 | if content.contains(&0) { |
| 242 | return Encoding::Binary; |
| 243 | } |
| 244 | |
| 245 | // Check for valid UTF-8 |
| 246 | if std::str::from_utf8(content).is_ok() { |
| 247 | Encoding::Utf8 |
| 248 | } else { |
| 249 | Encoding::Binary |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | /// Check if content is binary. |
| 254 | /// |