use std::path::{Path, PathBuf};
use std::sync::Arc;
use base64::prelude::{Engine as _, BASE64_STANDARD};
#[derive(Debug)]
pub struct SubplotDataFile {
name: Arc<Path>,
data: Arc<[u8]>,
}
impl Clone for SubplotDataFile {
fn clone(&self) -> Self {
Self {
name: Arc::clone(&self.name),
data: Arc::clone(&self.data),
}
}
}
impl Default for SubplotDataFile {
fn default() -> Self {
Self {
name: PathBuf::from("").into(),
data: Vec::new().into(),
}
}
}
impl SubplotDataFile {
pub fn new(name: &str, data: &str) -> Self {
let name = BASE64_STANDARD
.decode(name)
.expect("Subplot generated bad base64?");
let name = String::from_utf8_lossy(&name);
let name: PathBuf = name.as_ref().into();
let name = name.into();
let data = BASE64_STANDARD
.decode(data)
.expect("Subplot generated bad base64?")
.into();
Self { name, data }
}
pub fn name(&self) -> &Path {
&self.name
}
pub fn data(&self) -> &[u8] {
&self.data
}
}