Zig
Zig
UU Encoding and Decoding
See more Encryption Examples
Demonstrates how to UU encode and decode.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const crypt = try chilkat.Crypt2.init();
defer crypt.deinit();
const s1 = "This string is to be UU encoded";
crypt.setUuMode("666");
crypt.setUuFilename("something.txt");
// UU encode:
const s2 = try crypt.encodeString(alloc, s1, "ansi", "uu");
// Note: Call crypt.Encode instead of crypt.EncodeString
// to UU encode binary bytes (i.e. non-text binary data).
std.debug.print("{s}\n", .{s2});
// UU decode:
const crypt2 = try chilkat.Crypt2.init();
defer crypt2.deinit();
const s3 = try crypt2.decodeString(alloc, s2, "ansi", "uu");
// Note: Likewise, call crypt.Decode to decode non-text binary data.
std.debug.print("{s}\n", .{s3});
// Show the file permissions mode and filename found
// in the UU encoded data:
std.debug.print("UuMode = {s}\n", .{try crypt2.getUuMode(alloc)});
std.debug.print("UuFilename = {s}\n", .{try crypt2.getUuFilename(alloc)});
}