Detect encoding from file extension. Some file extensions strongly suggest a particular encoding. # Arguments `extension` - The file extension (without the leading dot) # Returns `Some(Encoding::Binary)` for known binary extensions, `None` otherwise. # Examples ```rust use atomic_core::change::Encoding; assert_eq!(Encoding::from_extension("png"), Some(Encoding::Binary)); assert_eq!(Encodin
(extension: &str)
| 249 | /// assert_eq!(Encoding::from_extension("rs"), None); // Could be any text encoding |
| 250 | /// ``` |
| 251 | pub fn from_extension(extension: &str) -> Option<Self> { |
| 252 | let lower = extension.to_lowercase(); |
| 253 | match lower.as_str() { |
| 254 | // Images |
| 255 | "png" | "jpg" | "jpeg" | "gif" | "bmp" | "ico" | "webp" | "svg" | "tiff" | "tif" => { |
| 256 | Some(Encoding::Binary) |
| 257 | } |
| 258 | // Audio/Video |
| 259 | "mp3" | "mp4" | "wav" | "ogg" | "flac" | "avi" | "mkv" | "mov" | "webm" => { |
| 260 | Some(Encoding::Binary) |
| 261 | } |
| 262 | // Archives |
| 263 | "zip" | "tar" | "gz" | "bz2" | "xz" | "7z" | "rar" => Some(Encoding::Binary), |
| 264 | // Executables |
| 265 | "exe" | "dll" | "so" | "dylib" | "o" | "a" => Some(Encoding::Binary), |
| 266 | // Documents |
| 267 | "pdf" | "doc" | "docx" | "xls" | "xlsx" | "ppt" | "pptx" => Some(Encoding::Binary), |
| 268 | // Fonts |
| 269 | "ttf" | "otf" | "woff" | "woff2" | "eot" => Some(Encoding::Binary), |
| 270 | // Other binary |
| 271 | "bin" | "dat" | "db" | "sqlite" | "sqlite3" => Some(Encoding::Binary), |
| 272 | // Unknown - let content detection decide |
| 273 | _ => None, |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | /// Skip BOM bytes in content if present. |
| 278 | /// |