diff options
| author | TazyFoundSoup <gardendistrict0x0@outlook.com> | 2026-01-15 20:04:23 +1100 |
|---|---|---|
| committer | TazyFoundSoup <gardendistrict0x0@outlook.com> | 2026-01-15 20:04:23 +1100 |
| commit | d0fc19a97c7f115dca25f2b39b6a9fbe337b31a3 (patch) | |
| tree | 94ec8ed9bcc0a9fba9b9239c9e88ceaf150115b2 | |
| parent | a48603e468359e347e5478047feed3fe35bcc396 (diff) | |
feat(streams): Add streams
| -rw-r--r-- | include/tinyff/stream.h | 27 | ||||
| -rw-r--r-- | src/stream.c | 17 |
2 files changed, 44 insertions, 0 deletions
diff --git a/include/tinyff/stream.h b/include/tinyff/stream.h new file mode 100644 index 0000000..2cfdeaa --- /dev/null +++ b/include/tinyff/stream.h @@ -0,0 +1,27 @@ +#ifndef STREAM_H +#define STREAM_H + +#include <stddef.h> +#include <stdio.h> + + +#define FF_NULL_STREAM {0} + + +// WARNING: This is just for reading streams for now +// Until I finally add encoding to PNG, it will remain read-only + +typedef size_t (*ff_read_cb)(void *ptr, size_t size, void *user); + +typedef struct { + ff_read_cb read; + void *user; +} ff_stream; + +// Default reads for common types (just FILE for now, memory later) +size_t ff_file_read(void *ptr, size_t size, void *user); + +// Stream creation helpers +ff_stream ff_create_file_stream(FILE *f); + +#endif
\ No newline at end of file diff --git a/src/stream.c b/src/stream.c new file mode 100644 index 0000000..a68db43 --- /dev/null +++ b/src/stream.c @@ -0,0 +1,17 @@ +#include "stream.h" + +size_t ff_file_read(void *ptr, size_t size, void *user) +{ + FILE *f = (FILE *)user; + return fread(ptr, size, 1, f); +} + +ff_stream ff_create_file_stream(FILE *f) +{ + ff_stream stream; + stream.read = ff_file_read; + stream.user = (void *)f; + return stream; +} + +// Memory stream coming soon
\ No newline at end of file |
