File I/O using Zig master branch - was hard to find examples

I was struggling to find working File I/O examples for Zig master, so I decided to keep updating my personal file encryption/decryption tool as a way to learn the new API.

The tool uses ChaCha20Poly1305 AEAD, which meant dealing with binary headers, struct padding, chunked processing, and all the edge cases that come with real-world file handling. It turned out to be a great learning project because it hit most of the gotchas you’ll encounter.

I’ve written up the main lessons I learned and the code is on GitHub with tests. Hope it helps.
Thanks for reading this!

AEAD encryption File IO examples using Zig master branch

16 Likes

Welcome to the forum the code is really elegant and minimal, and it works really great :slight_smile:

2 Likes

Thanks! I’m just trying to speed up the learning curve and (hopefully) provide some useful, practical examples for people in the same situation. :wink:

2 Likes

Hi and welcome to the Ziggit!
Just by quick read thru, your code looks nice and clean.

One thing i would personally change is how you handle command line arguments.
Its nothing big, but i recommend to look at StaticStringMap, its really nice for this kind of of argument parsing with its initComptime.
(you can for example map the arguments to an enum and then switch on it)

Robert :grin:

1 Like

Yes, thanks for your feedback, I read that on another thread about the Zlist showcase. I’ll definitely take a closer look, as the current approach feels a bit too verbose for my taste.

1 Like

Yeah I hope to see more of it :slight_smile: