Rust
Rust
Base64 Encode a File
_LANGUAGE_ to Base64 encode the contents of a file.Chilkat Rust Downloads
// Get the contents of a file into a base64 encoded string:
let fac = chilkat::FileAccess::new();
let Ok(str_base64) = fac.read_binary_to_encoded("c:/data/something.pdf", "base64") else {
println!("{}", fac.last_error_text());
return;
};
// Now write the string to a file:
if fac.write_entire_text_file("c:/data/something_pdf_base64.txt", &str_base64, "us-ascii", false).is_err() {
println!("{}", fac.last_error_text());
return;
}
println!("Success!");