Sample code for 30+ languages & platforms
Rust

Append Encoded Binary Data to StringBuilder

Demonstrates how to append encoded binary data to the contenets of a StringBuilder.

Chilkat Rust Downloads

Rust

let bd = chilkat::BinData::new();

if bd.load_file("qa_data/jpg/starfish.jpg").is_err() {
    println!("Failed to load file.");
    return;
}

// For example, let's say we want construct simple JSON containing the base64 representation of the above JPG file.
let sb = chilkat::StringBuilder::new();
let _ = sb.append("{ \"jpg\": \"");
// GetEncodedSb appends the enocded representation of the binary data to the StringBuiler passed in the 2nd arg.
let _ = bd.get_encoded_sb("base64", &sb);
let _ = sb.append("\" }");

println!("{}", sb.get_as_string().unwrap_or_default());

// Output looks like this:
//  { "jpg": "/9j/4AAQSkZJRgABAg...rcQ+vo//2Q==" }