Function broot::content_search::get_mmap
source · Examples found in repository?
src/content_search/mod.rs (line 41)
35 36 37 38 39 40 41 42 43 44 45 46
pub fn get_mmap_if_suitable<P: AsRef<Path>>(hay_path: P, max_size: usize) -> io::Result<Option<Mmap>> {
if let Some(ext) = hay_path.as_ref().extension().and_then(|s| s.to_str()) {
if extensions::is_known_binary(ext) {
return Ok(None);
}
}
let hay = get_mmap(&hay_path)?;
if hay.len() > max_size || magic_numbers::is_known_binary(&hay) {
return Ok(None);
}
Ok(Some(hay))
}
More examples
src/content_search/needle.rs (line 216)
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
pub fn get_match<P: AsRef<Path>>(
&self,
hay_path: P,
desired_len: usize,
) -> Option<ContentMatch> {
let hay = match get_mmap(hay_path) {
Ok(hay) => hay,
_ => { return None; }
};
match self.search_mmap(&hay) {
ContentSearchResult::Found { pos } => {
Some(ContentMatch::build(&hay, pos, self.as_str(), desired_len))
}
_ => None,
}
}