From 45523d1292454f4f5e3c18c54352f3ff2a7ec3d8 Mon Sep 17 00:00:00 2001 From: Kalle Carlbark Date: Wed, 30 Aug 2023 22:42:01 +0200 Subject: [PATCH] docs: Add README While here, clean up and s/zb64/b64/g --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ build.zig | 2 +- build.zig.zon | 2 +- src/main.zig | 4 ++-- 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..ae55174 --- /dev/null +++ b/README.md @@ -0,0 +1,56 @@ +# b64 + +Is a tool I created to +* Quickly encode and decode base64 +* Learn a bit of Zig + + +## Usage +``` +Usage: b64 [-e] [-d] + + -h, --help + Display this help and exit. + + -d, --decode + Decode base64 to string. + + -e, --encode + Encode string to base64. + + -v, --version + Display version. + + + String to encode or decode. +``` +### Encoding + +```shell +$ b64 -e "encode this string to base64" +ZW5jb2RlIHRoaXMgc3RyaW5nIHRvIGJhc2U2NA== + +# From stdin +$ echo -n "encode this string to base64" | b64 -e +ZW5jb2RlIHRoaXMgc3RyaW5nIHRvIGJhc2U2NA== +$ +``` + +### Decoding +```shell +$ b64 -d ZW5jb2RlIHRoaXMgc3RyaW5nIHRvIGJhc2U2NA== +encode this string to base64 + +# From stdin +$ echo -n "ZW5jb2RlIHRoaXMgc3RyaW5nIHRvIGJhc2U2NA==" | b64 -d +encode this string to base64 +$ +``` + +## Build + +```shell +$ git clone https://git.kcbark.net/zig/b64.git && cd b64 +$ zig build -Doptimize=ReleaseFast +$ cp zig-out/bin/b64 ~/.local/bin +``` \ No newline at end of file diff --git a/build.zig b/build.zig index 889b0e3..4e620df 100644 --- a/build.zig +++ b/build.zig @@ -21,7 +21,7 @@ pub fn build(b: *std.Build) void { var opt = b.addOptions(); opt.addOption([]const u8, "version", "0.0.1"); const exe = b.addExecutable(.{ - .name = "zb64", + .name = "b64", // In this case the main source file is merely a path, however, in more // complicated build scripts, this could be a generated file. .root_source_file = .{ .path = "src/main.zig" }, diff --git a/build.zig.zon b/build.zig.zon index ccb5847..d2ffede 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,5 +1,5 @@ .{ - .name = "zb64", + .name = "b64", .version = "0.0.1", .dependencies = .{ .clap = .{ diff --git a/src/main.zig b/src/main.zig index a517227..b41cb52 100644 --- a/src/main.zig +++ b/src/main.zig @@ -109,11 +109,11 @@ pub fn main() !void { } fn usage() void { - std.debug.print("Usage: zb64 [-e] [-d] \n\n", .{}); + std.debug.print("Usage: b64 [-e] [-d] \n\n", .{}); } fn version() void { - std.debug.print("zb64 - {s}\n", .{build_info.version}); + std.debug.print("b64 - {s}\n", .{build_info.version}); } fn read_from_stream(allocator: std.mem.Allocator, stream: std.fs.File) !std.ArrayList(u8) {