sinf 0.1.0

Library for obtaining in-depth system information at both the hardware and software levels
Documentation
use std::fs::File;
use std::io::{self, Read};
use std::path::Path;

#[cfg(feature = "system")]
pub(crate) fn get_all_data_from_file(file: &mut File, size: usize) -> io::Result<Vec<u8>> {
    use std::io::Seek;

    let mut buf = Vec::with_capacity(size);
    file.rewind()?;
    file.read_to_end(&mut buf)?;
    Ok(buf)
}

/// Reads the whole content of `file` from its start into `buf`, replacing its previous content.
#[cfg(feature = "system")]
pub(crate) fn read_file_into(file: &mut File, buf: &mut Vec<u8>) -> io::Result<()> {
    use std::io::Seek;

    buf.clear();
    file.rewind()?;
    file.read_to_end(buf)?;
    Ok(())
}

/// Reads the whole content of the file at `file_path` into `buf`, replacing its previous content.
#[cfg(feature = "system")]
pub(crate) fn read_path_into<P: AsRef<Path>>(file_path: P, buf: &mut Vec<u8>) -> io::Result<()> {
    let mut file = File::open(file_path.as_ref())?;
    buf.clear();
    file.read_to_end(buf)?;
    Ok(())
}

#[cfg(any(feature = "disk", feature = "system"))]
pub(crate) fn get_all_utf8_data<P: AsRef<Path>>(file_path: P, size: usize) -> io::Result<String> {
    let mut file = File::open(file_path.as_ref())?;
    let mut buf = String::with_capacity(size);
    file.read_to_string(&mut buf)?;
    Ok(buf)
}