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

Functions

bool sbufFileIn (StreamBuffer *sb, VFSFile *file, bool close)
 
bool sbufFilePRegisterPull (StreamBuffer *sb, VFSFile *file, bool close)
 

Detailed Description

Functions for using VFS files as stream buffer data sources.

Function Documentation

◆ sbufFileIn()

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

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

Reads a VFS file and pushes its entire contents into a stream buffer.

Automatically chunks the data based on the stream buffer's target size for efficient operation. The stream buffer is automatically finished after all data is read.

IMPORTANT: The stream buffer is invalidated after this call.

Parameters
sbThe stream buffer (invalidated after call)
fileVFS file to read from (optionally closed based on close parameter)
closeIf true, the file is closed after reading
Returns
true on success, false on error

Example:

VFSFile *file = vfsOpen(vfs, _S"data.txt", FS_Read);
StreamBuffer *sb = sbufCreate(4096);
sbufStrCRegisterPush(sb, &output);
sbufFileIn(sb, file, true); // file is closed automatically
@ FS_Read
Open for reading.
Definition file.h:36
struct VFSFile VFSFile
Definition vfs.h:44
VFSFile * vfsOpen(VFS *vfs, strref path, flags_t flags)
bool sbufFileIn(StreamBuffer *sb, VFSFile *file, bool close)
StreamBuffer * sbufCreate(size_t targetsz)
bool sbufStrCRegisterPush(StreamBuffer *sb, string *strout)
#define _S
Creates a static ASCII string from a string literal.
Definition strbase.h:392

◆ sbufFilePRegisterPull()

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

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

Registers a VFS file as a producer with the stream buffer in pull mode.

In pull mode, the consumer pulls data as needed, and the file is read in chunks on demand. Use this instead of sbufFileIn() when you need finer control over when data is read.

Parameters
sbThe stream buffer
fileVFS file to read from (optionally closed when producer finishes)
closeIf true, the file is closed when the producer finishes
Returns
true on success, false if registration failed