A collection of code samples and walkthroughs for performing common tasks in Zig.
All the zig files in this repository are interactive and can be executed by zig run <path-to-zig-file>
.
This guide follows zig master branch.
Inspired from Bun Guides.
- Create a file
- Read a file
- Delete a file
- Copy a file
- Check if a file exists
- Append data incrementally to a file
- Write to stdout
- Start a simple HTTP server
- Send an HTTP request using fetch
- Fetch JSON from an API url and parse it
- Download a file from url
- Send a POST request
- Read input from stdin
- Listen for Ctrl + C
- Spawn a child process
- Parse command line arguments
- Read environment variables
- Generate SHA256 hash of a data
- Generate MD5 hash of a data
- Incrementally compute hash of a data
- Generate cryptographically secure random data
Run using
zig test <path-to-zig-file>
.
- Call function from a dynamic library
- Sleep for a fixed number of nanoseconds
- Encode and decode base64 string
- Compress and decompress data
- Parse a semver version string
- Generate random data
All code in this repository is licensed under The Unlicense which allows you to use any part of the code anywhere without restrictions.