Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gernest/base32
base32 encoding/decoding for ziglang
https://github.com/gernest/base32
base32 base32hex zig ziglang
Last synced: about 2 months ago
JSON representation
base32 encoding/decoding for ziglang
- Host: GitHub
- URL: https://github.com/gernest/base32
- Owner: gernest
- License: mit
- Created: 2019-10-12T07:26:58.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-22T23:18:24.000Z (4 months ago)
- Last Synced: 2024-10-02T07:04:56.907Z (2 months ago)
- Topics: base32, base32hex, zig, ziglang
- Language: Zig
- Homepage:
- Size: 24.4 KB
- Stars: 11
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-zig - gernest/base32
- awesome-zig - base32🗒️base32 encoding/decoding for ziglang
README
# base32
This implements `base32` `encoding` and `decoding` for the zig programming language (ziglang)
# Installation
First fetch dependency by running:
```
zig fetch --save git+https://github.com/gernest/base32
```
Then update your `build.zig` file to load the module:
```
const base32 = b.dependency("base32", .{});
exe.root_module.addImport("base32", base32.module("base32"));
```# Usage
`example.zig`
```zig
const std = @import("std");
const base32 = @import("src/base32.zig");
const stdout = std.io.getStdOut().writer();pub fn main() !void {
try encodeString();
try stdout.print("\n\n", .{});
try decodeString();
}fn encodeString() !void {
const src = "any + old & data";
const size = comptime base32.std_encoding.encodeLen(src.len);
var buf: [size]u8 = undefined;
const out = base32.std_encoding.encode(&buf, src);
try stdout.print("ExampleEncodingToString:\nsource: \"{s}\"\noutput: {s}\n", .{src, out});
}fn decodeString() !void {
const src = "ONXW2ZJAMRQXIYJAO5UXI2BAAAQGC3TEEDX3XPY=";
const size = comptime base32.std_encoding.decodeLen(src.len);
var buf: [size]u8 = undefined;
const out = try base32.std_encoding.decode(&buf, src);
try stdout.print("ExampleDecodingString:\nsource: {s}\noutput: \"{s}\"\n", .{src, out});
}
``````
$ zig run example.zig
ExampleEncodingToString:
source: "any + old & data"
output: MFXHSIBLEBXWYZBAEYQGIYLUME======ExampleDecodingString:
source: ONXW2ZJAMRQXIYJAO5UXI2BAAAQGC3TEEDX3XPY=
output: "some data with and "```