Zig
Zig
Get Contents of File as Base64
See more Encryption Examples
Demonstrates how to read the contents of a file and convert to a base64 string.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const bd = try chilkat.BinData.init();
defer bd.deinit();
bd.loadFile("qa_data/jpg/starfish.jpg") catch {
std.debug.print("Failed to load file.\n", .{});
return;
};
std.debug.print("{s}\n", .{try bd.getEncoded(alloc, "base64")});
// If you want mult-line base64:
std.debug.print("--\n", .{});
std.debug.print("{s}\n", .{try bd.getEncoded(alloc, "base64_mime")});
// If you want hex..
std.debug.print("--\n", .{});
std.debug.print("{s}\n", .{try bd.getEncoded(alloc, "hex")});
// etc..
}