RAM virtual files

Functions

char * oslGetTempFileName ()
 
void oslSetTempFileData (void *data, int size, int *type)
 
int oslAddVirtualFileList (OSL_VIRTUALFILENAME *vfl, int numberOfEntries)
 
void oslRemoveVirtualFileList (OSL_VIRTUALFILENAME *vfl, int numberOfEntries)
 

Detailed Description

There are two virtual file sources available by default: memory and file.

Function Documentation

char* oslGetTempFileName ( )
inline

Gets the name of the temporary file. See oslSetTempFileData for a code sample.

void oslSetTempFileData ( void *  data,
int  size,
int *  type 
)

Sets the data associated to a temporary file.

//Binary data representing a JPG file
const int test_data[] = {...};
//The file is 1280 bytes (it's the length of the test_data array)
const int test_data_size = 1280;
//Set data for the temporary file
oslSetTempFileData(test_data, test_data_size, &VF_MEMORY);
//Load a JPG file using the temporary file (oslGetTempFileName to get its name)
int oslAddVirtualFileList ( OSL_VIRTUALFILENAME vfl,
int  numberOfEntries 
)

Adds a list of virtual files. You will then be able to open these files as if they were real.

Parameters
vflPointer to an array of OSL_VIRTUALFILENAME entries
numberOfEntriesNumber of OSL_VIRTUALFILENAME entries in the array
//Binary data representing a JPG file
const int test_jpg[] = {...};
const char *text = "This is a text file";
//Each entry consists of a name, a pointer to the data, the size of the data, and
//a file type. See the OSL_VIRTUALFILENAME documentation for more information.
OSL_VIRTUALFILENAME ram_files[] = {
{"ram:/test.jpg", (void*)test_jpg, sizeof(test_jpg), &VF_MEMORY},
{"ram:/something.txt", (void*)text, strlen(text), &VF_MEMORY},
};
//Add these files to the list
oslAddVirtualFileList(ram_files, oslNumberof(ram_files));
//We can now open them as if they were real files...
VirtualFileOpen("ram:/something.txt", 0, VF_AUTO, VF_O_READ);
[...]
void oslRemoveVirtualFileList ( OSL_VIRTUALFILENAME vfl,
int  numberOfEntries 
)

Removes file entries from the virtual file list.

OSL_VIRTUALFILENAME ram_files[] = {
[..]
};
//Add these files to the list
oslAddVirtualFileList(ram_files, oslNumberof(ram_files));
//Removing them is as simple as adding them
oslRemoveVirtualFileList(ram_files, oslNumberof(ram_files));