CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
File Consumers

Functions

bool _sbufFileOut (StreamBuffer *sb, File *file, bool close)
 
bool _sbufFileCRegisterPush (StreamBuffer *sb, File *file, bool close)
 

Detailed Description

Functions for using files as stream buffer data sinks.

Function Documentation

◆ _sbufFileCRegisterPush()

bool _sbufFileCRegisterPush ( StreamBuffer *  sb,
File file,
bool  close 
)

bool sbufFileCRegisterPush(StreamBuffer *sb, File *file, bool close)

Registers a file as a consumer with the stream buffer in push mode.

In push mode, data is automatically written to the file as it becomes available from the producer. Use this instead of sbufFileOut() when you need the producer and consumer to operate asynchronously.

The registration holds its own reference to the file until the consumer slot is handed back, so the caller may release its own at any time after this returns.

Parameters
sbThe stream buffer
fileFile to write to. With close set, the caller's reference is handed over with it and the handle must not be used again
closeIf true, the file is closed when the consumer finishes
Returns
true on success, false if registration failed

◆ _sbufFileOut()

bool _sbufFileOut ( StreamBuffer *  sb,
File file,
bool  close 
)

bool sbufFileOut(StreamBuffer *sb, File *file, bool close)

Consumes all available data from the buffer and writes it to a file.

Reads data from the stream buffer until the producer finishes (EOF) and writes it to the file in chunks.

Parameters
sbThe stream buffer
fileFile to write to (optionally closed based on close parameter)
closeIf true, the file is closed after writing
Returns
true on success, false on error

Example:

VFSFile *file = vfsOpen(vfs, _SL("output.txt"), FS_Write | FS_Create);
StreamBuffer *sb = sbufCreate(4096);
sbufStrPRegisterPull(sb, inputData);
sbufFileOut(sb, file, true); // file is closed automatically
@ FS_Write
Open for writing.
Definition fs.h:322
@ FS_Create
Create file if it doesn't exist.
Definition fs.h:323
VFSFile * vfsOpen(VFS *vfs, strref path, flags_t flags)
#define sbufCreate(targetsz,...)
Definition streambuf.h:275
bool sbufStrPRegisterPull(StreamBuffer *sb, strref str)
#define _SL(s)
Inline ASCII string literal with compile-time embedded length (STR_LEN8). Content must be < 200 bytes...
Definition strliteral.h:207