Loading...
Searching...
No Matches
stream.h
1#pragma once
2#include <stdlib.h>
3#include <stdint.h>
4#include <stdbool.h>
5#include <storage/storage.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11typedef struct Stream Stream;
12
13typedef enum {
14 StreamOffsetFromCurrent,
15 StreamOffsetFromStart,
16 StreamOffsetFromEnd,
17} StreamOffset;
18
19typedef enum {
20 StreamDirectionForward,
21 StreamDirectionBackward,
22} StreamDirection;
23
24typedef bool (*StreamWriteCB)(Stream* stream, const void* context);
25
30void stream_free(Stream* stream);
31
36void stream_clean(Stream* stream);
37
44bool stream_eof(Stream* stream);
45
54bool stream_seek(Stream* stream, int32_t offset, StreamOffset offset_type);
55
64bool stream_seek_to_char(Stream* stream, char c, StreamDirection direction);
65
71size_t stream_tell(Stream* stream);
72
78size_t stream_size(Stream* stream);
79
87size_t stream_write(Stream* stream, const uint8_t* data, size_t size);
88
96size_t stream_read(Stream* stream, uint8_t* data, size_t count);
97
107bool stream_delete_and_insert(
108 Stream* stream,
109 size_t delete_size,
110 StreamWriteCB write_callback,
111 const void* context);
112
113/********************************** Some random helpers starts here **********************************/
114
122bool stream_read_line(Stream* stream, FuriString* str_result);
123
128bool stream_rewind(Stream* stream);
129
136size_t stream_write_char(Stream* stream, char c);
137
144size_t stream_write_string(Stream* stream, FuriString* string);
145
152size_t stream_write_cstring(Stream* stream, const char* string);
153
161size_t stream_write_format(Stream* stream, const char* format, ...)
162 _ATTRIBUTE((__format__(__printf__, 2, 3)));
163
171size_t stream_write_vaformat(Stream* stream, const char* format, va_list args);
172
182bool stream_insert(Stream* stream, const uint8_t* data, size_t size);
183
191bool stream_insert_char(Stream* stream, char c);
192
200bool stream_insert_string(Stream* stream, FuriString* string);
201
209bool stream_insert_cstring(Stream* stream, const char* string);
210
219bool stream_insert_format(Stream* stream, const char* format, ...)
220 _ATTRIBUTE((__format__(__printf__, 2, 3)));
221
230bool stream_insert_vaformat(Stream* stream, const char* format, va_list args);
231
240bool stream_delete_and_insert_char(Stream* stream, size_t delete_size, char c);
241
250bool stream_delete_and_insert_string(Stream* stream, size_t delete_size, FuriString* string);
251
260bool stream_delete_and_insert_cstring(Stream* stream, size_t delete_size, const char* string);
261
271bool stream_delete_and_insert_format(Stream* stream, size_t delete_size, const char* format, ...)
272 _ATTRIBUTE((__format__(__printf__, 3, 4)));
273
283bool stream_delete_and_insert_vaformat(
284 Stream* stream,
285 size_t delete_size,
286 const char* format,
287 va_list args);
288
297bool stream_delete(Stream* stream, size_t size);
298
306size_t stream_copy(Stream* stream_from, Stream* stream_to, size_t size);
307
314size_t stream_copy_full(Stream* stream_from, Stream* stream_to);
315
324bool stream_split(Stream* stream, Stream* stream_left, Stream* stream_right);
325
333size_t stream_load_from_file(Stream* stream, Storage* storage, const char* path);
334
343size_t stream_save_to_file(Stream* stream, Storage* storage, const char* path, FS_OpenMode mode);
344
349void stream_dump_data(Stream* stream);
350
351#ifdef __cplusplus
352}
353#endif
APIs for working with storages, directories and files.
Definition string.c:4
Definition storage_i.h:23
Definition stream_i.h:40