pub fn read_file_bounded(
path: impl AsRef<Path>,
max_bytes: usize,
) -> Result<Vec<u8>, Error>Expand description
Reads a regular file containing at most max_bytes bytes.
Symlinks to regular files are accepted. Directories, pipes, and devices are rejected before opening them. On Unix, nonblocking opening also prevents a replacement FIFO from blocking. The opened file is checked again, and reads are bounded even if it grows after the metadata check. No allocation is based on the file’s reported length.
§Errors
Returns an I/O error if the path cannot be read, is not a regular file, or exceeds the limit.