rew_brew/lib.rs
1use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64};
2use anyhow::Result;
3
4/// Encodes the provided string content into Base64 format.
5///
6/// # Arguments
7/// * `content` - The string to encode.
8///
9/// # Returns
10/// * A Base64 encoded string.
11pub fn encode_brew_file(content: &str) -> String {
12 BASE64.encode(content.as_bytes())
13}
14
15/// Decodes a Base64 encoded string back into its original form.
16///
17/// # Arguments
18/// * `encoded` - The Base64 encoded string to decode.
19///
20/// # Returns
21/// * A `Result` containing the decoded string or an error message.
22pub fn decode_brew_file(encoded: &str) -> Result<String> {
23 let decoded = BASE64
24 .decode(encoded.trim())
25 .map_err(|e| anyhow::anyhow!("Failed to decode brew file: {}", e))?;
26
27 String::from_utf8(decoded)
28 .map_err(|e| anyhow::anyhow!("Failed to convert decoded bytes to string: {}", e))
29}