Zig Requires Chilkat v11.2.0+
Zig
Base62 Encoding and Decoding
Demonstrates base62 encoding and decoding.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();
// Base62 encode.
bd.appendString("hello world", "utf-8") catch {};
const base62_encoded = try bd.getEncoded(alloc, "base62");
std.debug.print("hello world --> {s}\n", .{base62_encoded});
// Output:
// hello world --> AAwf93rvy4aWQVw
// Base62 decode
const sb = try chilkat.StringBuilder.init();
defer sb.deinit();
sb.decodeAndAppend("AAwf93rvy4aWQVw", "base62", "utf-8") catch {};
std.debug.print("decoded: {s}\n", .{try sb.getAsString(alloc)});
// Output:
// decoded: hello world
}