Skip to main content

inspect_file

Function inspect_file 

Source
pub fn inspect_file(path: &Path) -> Result<FileInfo, Error>
Expand description

Inspects a regular file without interpreting its bytes as text.

Returns its raw byte length, line count, and full-file BLAKE3 fingerprint. Lines end at LF, which belongs to the line; a nonempty unterminated suffix also counts as a line. A trailing LF adds no extra line. Empty files have zero bytes and lines. CR is ordinary content, and invalid UTF-8 is accepted.

Each call reopens the path. Keep the file unchanged throughout inspection and any subsequent comparison; restart after editing or replacing it. See the file stability requirements.

§Errors

Returns Error::Io if metadata lookup, opening, or reading fails, Error::NotRegularFile for a non-regular input, or Error::FileTooLarge if a byte or line count cannot fit in u64.

§Examples

use paircomp_core::inspect_file;
use std::path::Path;

let info = inspect_file(Path::new("local-copy.txt"))?;
println!("{} lines, {} bytes", info.line_count, info.byte_len);
// Display the full digest for manual comparison with the other system.
print!("Fingerprint: ");
for byte in info.fingerprint.as_bytes() {
    print!("{byte:02x}");
}
println!();