use crate::io;
use alloc::vec::Vec;
pub const MAX_CONFIG_FILE_SIZE: usize = 100 * 1024 * 1024;
pub trait ConfigRead {
fn read(&self, path: &str) -> io::Result<Vec<u8>>;
}
#[cfg(feature = "std")]
pub struct StdConfigRead;
#[cfg(feature = "std")]
impl ConfigRead for StdConfigRead {
fn read(&self, path: &str) -> io::Result<Vec<u8>> {
let file = std::fs::File::open(path)?;
let len = file.metadata()?.len();
if len > MAX_CONFIG_FILE_SIZE as u64 {
return Err(io::ErrorKind::FileTooLarge.into());
}
let mut buf = Vec::with_capacity(len as usize);
std::io::Read::read_to_end(&mut &file, &mut buf)?;
Ok(buf)
}
}