pub fn read_file_to_string(path: &Path, max_size: Option<u64>) -> Result<String>Expand description
Reads a file’s entire contents into a String with ADR 0004 security checks.
Performs the following validations before reading:
- File existence: checks
fs::metadata()before opening - File size: rejects files exceeding
max_size(default 100 MB) - UTF-8 encoding: on UTF-8 failure, falls back to lossy conversion with a warning
§Arguments
path- Path to the file to readmax_size- Maximum allowed file size in bytes (defaults toMAX_MANIFEST_SIZE)
§Returns
Ok(String)- File contents as UTF-8 string (lossy if non-UTF-8 bytes found)Err- File doesn’t exist, is too large, or cannot be read
§Examples
use std::path::Path;
use provenant::parsers::utils::read_file_to_string;
let content = read_file_to_string(Path::new("path/to/file.txt"), None)?;