Sample code for 30+ languages & platforms
Lua

Append Encoded Binary Data to StringBuilder

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

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local bd = chilkat.BinData.new()

local success = bd:load_file("qa_data/jpg/starfish.jpg")
if not success then
    print("Failed to load file.")
    return
end

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

print(sb:get_as_string())

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