[][src]Function tree_magic_fork::from_filepath

pub fn from_filepath(filepath: &Path) -> Option<String>

Gets the type of a file from a filepath.

Does not look at file name or extension, just the contents. Returns MIME as string wrapped in Some if a type matches, or None if the file is not found or cannot be opened.

Examples

use std::path::Path;

// Get path to a GIF file
let path: &Path = Path::new("tests/image/gif");

// Find the MIME type of the GIF
let result = tree_magic::from_filepath(path);
assert_eq!(result, Some("image/gif"));