Files
fx/test/io/streams.c

27 lines
627 B
C
Raw Normal View History

2026-03-16 10:35:43 +00:00
#include <fx/core/stream.h>
#include <fx/io/file.h>
#include <fx/io/path.h>
2025-06-27 21:54:10 +01:00
#include <stdio.h>
int main(int argc, const char **argv)
{
2026-03-16 10:35:43 +00:00
fx_file *dest;
fx_path *path = fx_path_create_from_cstr("data.txt");
fx_result result = fx_file_open(
NULL, path, FX_FILE_WRITE_ONLY | FX_FILE_CREATE, &dest);
if (fx_result_is_error(result)) {
fx_throw(result);
2025-06-27 21:54:10 +01:00
return -1;
}
size_t nr_read = 0;
2026-03-16 10:35:43 +00:00
fx_stream_buffer *buf = fx_stream_buffer_create_dynamic(1024);
fx_stream_read_all_bytes_s(fx_stdin, dest, buf, &nr_read);
2025-06-27 21:54:10 +01:00
printf("done. read %zu bytes total.\n", nr_read);
2025-11-03 21:29:59 +00:00
2026-03-16 10:35:43 +00:00
fx_path_unref(path);
fx_file_unref(dest);
2025-06-27 21:54:10 +01:00
return 0;
}