Skip to content

Instantly share code, notes, and snippets.

@Armiixteryx
Created September 12, 2020 19:21
Show Gist options
  • Save Armiixteryx/a0aed5e423928de5b03d7fe14c70d9cd to your computer and use it in GitHub Desktop.
Save Armiixteryx/a0aed5e423928de5b03d7fe14c70d9cd to your computer and use it in GitHub Desktop.
base64_file
#[derive(Debug)]
pub struct Base64File {
filename: String,
content: String,
content_type: String,
size: usize,
}
impl Base64File {
pub fn from_bytes(filename: String, bytes: Vec<u8>, content_type: String, size: usize) -> Base64File {
Self {
filename,
content: base64::encode(bytes),
content_type,
size
}
}
pub fn print(&self) -> &str {
self.content.as_str()
}
}
#[cfg(test)]
mod tests {
#[test]
fn convert_text() {
use crate::Base64File;
let bytes = String::from("Hello World!").into_bytes();
let len = bytes.len();
let result = Base64File::from_bytes("Hello".into(), bytes, "application/pdf".into(), len);
assert_eq!("SGVsbG8gV29ybGQh", result.print());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment