Ultralight C++ API 1.4.0
|
#include <Ultralight/platform/FileSystem.h>
User-defined file system interface.
The library uses this to load file data (ie, raw file bytes) for a given file URL (eg, file:///page.html
) .
You can provide the library with your own FileSystem implementation so that file data is provided directly by your application (eg, from memory, from a virtual file system, etc).
A platform-specific implementation of FileSystem is provided for you when you call App::Create().
If you are using Renderer::Create(), you must provide your own. You can still use AppCore's implementation however– see the helper functions defined in <AppCore/Platform.h>.
To provide your own custom FileSystem implementation, you should inherit from this class, handle the virtual member functions, and then pass an instance of your class to Platform::set_file_system() before calling Renderer::Create() or App::Create().
Public Member Functions | |
virtual | ~FileSystem () |
virtual bool | FileExists (const String &file_path)=0 |
Check if a file exists within the file system. | |
virtual String | GetFileMimeType (const String &file_path)=0 |
Get the mime-type of a file (eg "text/html"). | |
virtual String | GetFileCharset (const String &file_path)=0 |
Get the charset / encoding of a file (eg "utf-8", "iso-8859-1"). | |
virtual RefPtr< Buffer > | OpenFile (const String &file_path)=0 |
Open a file for reading and map it to a Buffer. | |
|
virtual |
|
pure virtual |
Check if a file exists within the file system.
file_path | Relative file path (the string following the file:/// prefix) |
Get the charset / encoding of a file (eg "utf-8", "iso-8859-1").
file_path | Relative file path (the string following the file:/// prefix) |
Get the mime-type of a file (eg "text/html").
This is usually determined by analyzing the file extension.
If a mime-type cannot be determined, this should return "application/unknown".
file_path | Relative file path (the string following the file:/// prefix) |
Open a file for reading and map it to a Buffer.
To minimize copies, you should map the requested file into memory and use Buffer::Create() to wrap the data pointer (unmapping should be performed in the destruction callback).
File data addresses returned from this function should generally be aligned to 16-byte boundaries (the default alignment on most operating systems– if you're using C stdlib or C++ STL functions this is already handled for you).
This requirement is currently necessary when loading the ICU data file (eg, icudt67l.dat), and may be relaxed for other files (but you may still see a performance benefit due to cache line alignment).
If you can't guarantee alignment or are unsure, you can use Buffer::CreateFromCopy to copy the file data content to an aligned block (at the expense of data duplication).
file_path | Relative file path (the string following the file:/// prefix) |