Add code snippet to README.md

This commit is contained in:
2025-11-17 13:01:30 +01:00
parent bc0a95a9a5
commit 04a706dad9
+28
View File
@@ -7,6 +7,34 @@ You can use ToastyFS to store your files reliably over multiple machines knowing
🎵 Now let's get toasty 🎵
ToastyFS works by running nodes on multiple machines. Clients using the ToastyFS C library can then send file operations to the cluster. Here's a quick example:
```c
#include <ToastyFS.h>
int main(void)
{
ToastyString addr = TOASTY_STR("127.0.0.1");
int port = 8080;
ToastyString file = TOASTY_STR("/my_file.txt");
// Connect to cluster
ToastyFS *toasty = toasty_connect(addr, port);
// Create and write to a file
toasty_create_file(toasty, file, 4096);
toasty_write(toasty, file, 0, "Hello!", 6);
// Read it back
char buf[6];
toasty_read(toasty, file, 0, buf, 6);
// Done!
toasty_disconnect(toasty);
return 0;
}
```
## Features
- Cross-platform (runs on Windows and Linux)