uxum 0.9.4

Opinionated backend service framework based on axum
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use std::{io, path::Path};

use tokio::{fs, io::AsyncReadExt};

/// Read whole file into new buffer.
///
/// # Errors
///
/// Returns `Err` if there was an I/O error while opening or reading the file.
pub(crate) async fn read_file(path: impl AsRef<Path>) -> Result<Vec<u8>, io::Error> {
    let mut file = fs::OpenOptions::new().read(true).open(path).await?;
    let meta = file.metadata().await?;
    let mut buf = Vec::with_capacity(meta.len() as usize);
    file.read_to_end(&mut buf).await?;
    Ok(buf)
}