summaryrefslogtreecommitdiff
path: root/subplotlib/src/utils.rs
blob: 25a936052a950c1c4c0d924a7f2b3823be9b42d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//! Utility functions used by subplotlib or the generated test functions

use base64::prelude::{Engine as _, BASE64_STANDARD};

/// Decode a base64 string.
///
/// If the result is not a valid utf8 string then it is lossily coerced.
///
/// ```
/// # use subplotlib::prelude::*;
///
/// assert_eq!(base64_decode("aGVsbG8="), "hello");
/// ```
///
/// # Panics
///
/// Will panic if it's not valid base64 leading to a string.
pub fn base64_decode(input: &str) -> String {
    let dec = BASE64_STANDARD.decode(input).expect("bad base64");
    String::from_utf8_lossy(&dec).to_string()
}