1use std::error::Error;
2use std::rc::Rc;
3use std::result::Result;
4
5use base64::{encode, encode_config, URL_SAFE};
6
7use crate::build::Val;
8use crate::convert::traits::Importer;
9
10pub struct Base64Importer {
11 pub url_safe: bool,
12}
13
14impl Importer for Base64Importer {
15 fn import(&self, bytes: &[u8]) -> Result<Rc<Val>, Box<dyn Error>> {
16 let bslice = bytes.into();
17 return if self.url_safe {
18 Ok(Rc::new(Val::Str(encode(bslice))))
19 } else {
20 Ok(Rc::new(Val::Str(encode_config(bslice, URL_SAFE))))
21 };
22 }
23}