pub fn read_file_with_eol(path: &Path) -> Result<Option<Vec<u8>>>Expand description
Reads a file, normalising all CR-only and CRLF line endings to LF, and ensures
the buffer ends with exactly one \n. Returns None for files ≤ 3 bytes or
files that appear to be non-UTF-8.
§Errors
Returns any std::io::Error surfaced by File::open (the
path is missing, lacks read permission, is a directory, …) or by
the subsequent reads from the open file handle. A clean short read
during the probe (UnexpectedEof) yields Ok(None); any other
read_exact error kind propagates as Err. A non-UTF-8 head, a
too-small file, or a UTF-16 BE/LE BOM is reported via Ok(None),
not an error.
§Examples
use std::path::Path;
use big_code_analysis::read_file_with_eol;
let path = Path::new("Cargo.toml");
read_file_with_eol(&path).unwrap();