[−][src]Function tree_magic::from_filepath_node
pub fn from_filepath_node(
parentnode: NodeIndex,
filepath: &Path
) -> Option<String>
Gets the type of a file from a filepath, starting at a certain node in the type graph.
Returns MIME as string wrapped in Some if a type matches, or
None if the file is not found or cannot be opened.
Retreive the node from the TYPE.hash
FnvHashMap, using the MIME as the key.
Panics
Will panic if the given node is not found in the graph.
As the graph is immutable, this should not happen if the node index comes from
TYPE.hash
.
Examples
/// In this example, we know we have a ZIP, but we want to see if it's something /// like an Office document that subclasses a ZIP. If it is not, like this example, /// it will return None. use std::path::Path; // Get path to a ZIP file let path: &Path = Path::new("tests/application/zip"); // Get the graph node for ZIP let zipnode = tree_magic::TYPE.hash.get("application/zip").unwrap(); // Find the MIME type of the ZIP, starting from ZIP. let result = tree_magic::from_filepath_node(*zipnode, path); assert_eq!(result, None);