1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use base64::{engine::general_purpose::STANDARD_NO_PAD, DecodeError, Engine};
#[inline]
pub(crate) fn encode(data: impl AsRef<[u8]>) -> String {
STANDARD_NO_PAD.encode(data)
}
#[inline]
pub(crate) fn decode(data: impl AsRef<[u8]>) -> Result<Vec<u8>, DecodeError> {
STANDARD_NO_PAD.decode(data)
}
#[cfg(feature = "connector-arrow")]
pub(crate) fn encode_data_url(data: impl AsRef<[u8]>) -> String {
let bytes = data.as_ref();
let mut data = String::with_capacity(bytes.len() * 3 / 4);
base64::engine::general_purpose::STANDARD.encode_string(&bytes, &mut data);
format!("data:text/plain;base64,{data}")
}