umya_spreadsheet/helper/
binary.rs1use crate::structs::MediaObject;
2use base64::{engine::general_purpose::STANDARD, Engine as _};
3use std::fs;
4use std::fs::File;
5use std::io::BufReader;
6use std::io::Cursor;
7use std::io::Read;
8
9#[inline]
10pub fn get_binary_data(path: &str) -> Vec<u8> {
11 let path = std::path::Path::new(path);
12 let mut buf = Vec::new();
13
14 let file = File::open(path).unwrap();
15 BufReader::new(file).read_to_end(&mut buf).unwrap();
16 return buf;
17}
18
19#[inline]
20pub fn make_media_object(path: &str) -> MediaObject {
21 let name = path.split("/").last().unwrap();
22 let mut obj = MediaObject::default();
23 obj.set_image_data(get_binary_data(path));
24 obj.set_image_name(name);
25 obj.set_image_title(name.split(".").next().unwrap_or(""));
26 obj
27}