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

Functions

bool sbufFileOut (StreamBuffer *sb, VFSFile *file, bool close)
 
bool sbufFileCRegisterPush (StreamBuffer *sb, VFSFile *file, bool close)
 

Detailed Description

Functions for using VFS files as stream buffer data sinks.

Function Documentation

◆ sbufFileCRegisterPush()

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

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

Registers a VFS 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.

Parameters
sbThe stream buffer
fileVFS 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

◆ sbufFileOut()

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

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

Consumes all available data from the buffer and writes it to a VFS 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)
fileVFS 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:

VFSFile *file = vfsOpen(vfs, _S"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 file.h:37
@ FS_Create
Create file if it doesn't exist.
Definition file.h:38
struct VFSFile VFSFile
Definition vfs.h:44
VFSFile * vfsOpen(VFS *vfs, strref path, flags_t flags)
bool sbufFileOut(StreamBuffer *sb, VFSFile *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