Sample code for 30+ languages & platforms
Zig

Base64 Encode a File

_LANGUAGE_ to Base64 encode the contents of a file.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // Get the contents of a file into a base64 encoded string:
    const fac = try chilkat.FileAccess.init();
    defer fac.deinit();
    const str_base64 = fac.readBinaryToEncoded(alloc, "c:/data/something.pdf", "base64") catch {
        std.debug.print("{s}\n", .{try fac.getLastErrorText(alloc)});
        return;
    };

    // Now write the string to a file:
    fac.writeEntireTextFile("c:/data/something_pdf_base64.txt", str_base64, "us-ascii", false) catch {
        std.debug.print("{s}\n", .{try fac.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Success!\n", .{});
}