Skip to main content

read_file_with_eol

Function read_file_with_eol 

Source
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 non-UTF-8 head or a too-small file 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();