Sample code for 30+ languages & platforms
PowerShell

Append Encoded Binary Data to StringBuilder

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

Chilkat PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

$bd = New-Object Chilkat.BinData

$success = $bd.LoadFile("qa_data/jpg/starfish.jpg")
if ($success -eq $false) {
    $("Failed to load file.")
    exit
}

# For example, let's say we want construct simple JSON containing the base64 representation of the above JPG file.
$sb = New-Object Chilkat.StringBuilder
$sb.Append("{ `"jpg`": `"")
# GetEncodedSb appends the enocded representation of the binary data to the StringBuiler passed in the 2nd arg.
$bd.GetEncodedSb("base64",$sb)
$sb.Append("`" }")

$($sb.GetAsString())

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