Skip to main content

Streamer

The Streamer plugin provides a flexible interface for managing and interacting with application files and archives. It integrates with the Source interface to map all application file opening events into the Streamer. The plugin supports searching for files within known resources and allows accessing resources without specifying the full path.

Additionally, user-defined directories and archives can be added to the Streamer, and these resources will be handled transparently within the application. The plugin also supports embedding resources directly into the application binary using Blob includes.

info

The ArchiveStream extensions can be used for custom resource access.

#include <system/streamer/include/TellusimStreamer.h>

Example

The following example demonstrates how to create a Streamer, load files and directories recursively, and interact with resources using streams:

// create streamer
Streamer::Flags flags = Streamer::FlagNone;
flags |= Streamer::FlagCase; // enable case sensivity
flags |= Streamer::FlagRecursive; // enable scan recursion
Streamer streamer(flags);

// recursive directory and archive loading
if(!streamer.loadDirectory("data")) return false;

// streamer archive
//if(!streamer.loadArchive("data/archive.zip")) return false;

// streamer directory
//if(!streamer.loadDirectory("data/directory")) return false;

// print streamer files
for(uint32_t i = 0; i < streamer.getNumFiles(); i++) {
TS_LOGT(Message, "{0}: {1}\n", streamer.getFileName(i), String::fromBytes(streamer.getFileSize(i)));
}

Source source;

// archive stream
if(source.open("archive.txt")) {
TS_LOGF(Message, "%s\n", source.gets().get());
source.close();
}

// directory stream
if(source.open("file.txt")) {
TS_LOGF(Message, "%s\n", source.gets().get());
source.close();
}