use crate::HttpResponse;
use http_body_util::BodyExt;
use std::path::Path;
use tokio::io::AsyncReadExt;
pub(crate) async fn read_file_bytes(response: &mut HttpResponse) -> Vec<u8> {
let mut buffer = vec![];
while let Some(next) = response.body_mut().frame().await {
let frame = next.unwrap();
if let Some(chunk) = frame.data_ref() {
buffer.extend_from_slice(chunk);
}
}
if buffer.starts_with(&[0xEF, 0xBB, 0xBF]) {
buffer.drain(0..3); }
buffer
}
pub(crate) async fn read_file(path: impl AsRef<Path>) -> Vec<u8> {
let mut file = tokio::fs::File::open(path).await.unwrap();
let mut bytes = vec![];
file.read_to_end(&mut bytes).await.unwrap();
if bytes.starts_with(&[0xEF, 0xBB, 0xBF]) {
bytes.drain(0..3); }
bytes
}