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

Functions

bool sbufFSFileOut (StreamBuffer *sb, FSFile *file, bool close)
 
bool sbufFSFileCRegisterPush (StreamBuffer *sb, FSFile *file, bool close)
 

Detailed Description

Functions for using low-level filesystem files as stream buffer data sinks.

Function Documentation

◆ sbufFSFileCRegisterPush()

bool sbufFSFileCRegisterPush ( StreamBuffer *  sb,
FSFile file,
bool  close 
)

bool sbufFSFileCRegisterPush(StreamBuffer *sb, FSFile *file, bool close)

Registers a filesystem 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 sbufFSFileOut() when you need the producer and consumer to operate asynchronously.

Parameters
sbThe stream buffer
fileFilesystem file to write to (optionally closed when consumer finishes)
closeIf true, the file is closed when the consumer finishes
Returns
true on success, false if registration failed

◆ sbufFSFileOut()

bool sbufFSFileOut ( StreamBuffer *  sb,
FSFile file,
bool  close 
)

bool sbufFSFileOut(StreamBuffer *sb, FSFile *file, bool close)

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

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

IMPORTANT: The stream buffer is invalidated after this call.

Parameters
sbThe stream buffer (invalidated after call)
fileFilesystem file 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:

FSFile *file = fsOpen(_S"output.bin", FS_Write | FS_Create, 0);
StreamBuffer *sb = sbufCreate(4096);
sbufStrPRegisterPull(sb, inputData);
sbufFSFileOut(sb, file, true); // file is closed automatically
struct FSFile FSFile
Definition file.h:29
FSFile * fsOpen(strref path, flags_t flags)
@ FS_Write
Open for writing.
Definition file.h:37
@ FS_Create
Create file if it doesn't exist.
Definition file.h:38
bool sbufFSFileOut(StreamBuffer *sb, FSFile *file, bool close)
StreamBuffer * sbufCreate(size_t targetsz)
bool sbufStrPRegisterPull(StreamBuffer *sb, strref str)
#define _S
Creates a static ASCII string from a string literal.
Definition strbase.h:392