A high-performance, fully asynchronous, compressed file server built on Zig's new std.Io interface.
- std.Io: Functions are runtime-agnostic. See Available Backends.
- Compression: Uses
std.compress.flateto compress files before sending them over the network. - Graceful Shutdown: Safely handles
SIGINT(Ctrl+C). - Safe Cancellation: Protects file-transfer regions to ensure clients never receive half-written data during a shutdown.
- Caching: Caches compressed files using a
StringHashMapandIo.RwLock. - Cache Invalidation: On Linux targets, an inotify-based worker ensures that the cached data stays fresh.
- Zig 0.16.
- The target OS must support
sigaction().
This project supports multiple Io backends via the Zig build system. You can select the backend using the -Dio= flag.
zio(Default): Uses the zio runtime. Highly optimized stackful coroutines.std: Uses Zig's built-instd.Io.Threadedruntime.single_threaded: A purely synchronous, blocking fallback without a concurrent scheduler.
# Run with the default zio backend
zig build run
# Run with Zig's standard threaded Io
zig build -Dio=std run
# Run in single-threaded blocking mode (limited to one client at a time)
zig build -Dio=single_threaded runTo verify that the server responds with correct data, you can use nc and gzip.
- Start the server in one terminal:
zig build run. - In a second terminal, you can act as a client:
This should output the contents of this README file.
echo -ne 'README.md\0\0' | nc localhost 3000 | gzip -d
To test the server's concurrency and observe it in action, you can use the included benchmark program to spam the server with requests.
- Start the server in one terminal:
zig build -Doptimize=ReleaseFast run. - In a second terminal, execute the benchmark:
zig build -Doptimize=ReleaseFast benchmark - To test cancelation and error handling while the stress test is hammering the server, return to the first terminal and press Ctrl+C.