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

Functions

bool sbufFSFileIn (StreamBuffer *sb, FSFile *file, bool close)
 
bool sbufFSFilePRegisterPull (StreamBuffer *sb, FSFile *file, bool close)
 

Detailed Description

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

Function Documentation

◆ sbufFSFileIn()

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

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

Reads a filesystem 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)
fileFilesystem 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:

FSFile *file = fsOpen(_S"data.bin", FS_Read, 0);
StreamBuffer *sb = sbufCreate(4096);
sbufStrCRegisterPush(sb, &output);
sbufFSFileIn(sb, file, true); // file is closed automatically
struct FSFile FSFile
Definition file.h:29
FSFile * fsOpen(strref path, flags_t flags)
@ FS_Read
Open for reading.
Definition file.h:36
bool sbufFSFileIn(StreamBuffer *sb, FSFile *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

◆ sbufFSFilePRegisterPull()

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

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

Registers a filesystem 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 sbufFSFileIn() when you need finer control over when data is read.

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