docs
Loading...
Searching...
No Matches
CAPI_FileSystem.h
Go to the documentation of this file.
1///
2/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3/// A license is required for commercial use. https://ultralig.ht
4///
5
6///
7/// @file CAPI_FileSystem.h
8///
9/// User-defined file system interface.
10///
11/// `#include <Ultralight/CAPI/CAPI_FileSystem.h>`
12///
13/// The library uses this to load file data (ie, raw file bytes) for a given file URL
14/// (eg, `file:///page.html`) .
15///
16/// You can provide the library with your own FileSystem implementation (ULFileSystem) so that file
17/// data is provided directly by your application (eg, from memory, from a virtual file system,
18/// etc).
19///
20/// ## Threading
21///
22/// The library calls these callbacks from the thread you created the Renderer on and from a
23/// background thread it uses to load `file:///` URLs. The two can be inside your callbacks at the
24/// same time, so your implementation **must** be safe to call from more than one thread at once
25/// (guard any state your callbacks share).
26///
27/// @see ulPlatformSetFileSystem
28///
29#ifndef ULTRALIGHT_CAPI_FILESYSTEM_H
30#define ULTRALIGHT_CAPI_FILESYSTEM_H
31
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/******************************************************************************
39 * File System
40 *****************************************************************************/
41
42///
43/// The callback invoked when the FileSystem wants to check if a file path exists, return true if it
44/// exists.
45///
47
48///
49/// Get the mime-type of the file (eg "text/html").
50///
51/// This is usually determined by analyzing the file extension.
52///
53/// If a mime-type cannot be determined, you should return "application/unknown" for this value.
54///
55/// The library will consume the result and call ulDestroyString() after this call returns.
56///
58
59///
60/// Get the charset / encoding of the file (eg "utf-8").
61///
62/// This is only important for text-based files and is usually determined by analyzing the
63/// contents of the file.
64///
65/// If a charset cannot be determined, it's usually safe to return "utf-8" for this value.
66///
67/// The library will consume the result and call ulDestroyString() after this call returns.
68///
70
71///
72/// Open file for reading and map it to a Buffer.
73///
74/// To minimize copies, you should map the requested file into memory and use ulCreateBuffer()
75/// to wrap the data pointer (unmapping should be performed in the destruction callback).
76///
77/// @param path Relative file path. Valid only for the duration of this callback.
78///
79/// @return A new ULBuffer wrapping the file data. The library takes ownership and will call
80/// ulDestroyBuffer() when done. Return NULL if the file cannot be opened.
81///
83
84///
85/// User-defined file system interface.
86///
87/// You should implement each of these callbacks, then pass an instance of this struct containing
88/// your callbacks to ulPlatformSetFileSystem().
89///
96
97#ifdef __cplusplus
98} // extern "C"
99#endif
100
101#endif // ULTRALIGHT_CAPI_FILESYSTEM_H
bool(*) ULFileSystemFileExistsCallback(ULString path)
The callback invoked when the FileSystem wants to check if a file path exists, return true if it exis...
Definition CAPI_FileSystem.h:46
ULString(*) ULFileSystemGetFileCharsetCallback(ULString path)
Get the charset / encoding of the file (eg "utf-8").
Definition CAPI_FileSystem.h:69
ULString(*) ULFileSystemGetFileMimeTypeCallback(ULString path)
Get the mime-type of the file (eg "text/html").
Definition CAPI_FileSystem.h:57
ULBuffer(*) ULFileSystemOpenFileCallback(ULString path)
Open file for reading and map it to a Buffer.
Definition CAPI_FileSystem.h:82
Various defines and utility functions for the C API.
struct C_String * ULString
Opaque handle to a String object.
Definition CAPI_Defines.h:96
struct C_Buffer * ULBuffer
Opaque handle to a Buffer object.
Definition CAPI_Defines.h:99
User-defined file system interface.
Definition CAPI_FileSystem.h:90
ULFileSystemOpenFileCallback open_file
Definition CAPI_FileSystem.h:94
ULFileSystemGetFileCharsetCallback get_file_charset
Definition CAPI_FileSystem.h:93
ULFileSystemFileExistsCallback file_exists
Definition CAPI_FileSystem.h:91
ULFileSystemGetFileMimeTypeCallback get_file_mime_type
Definition CAPI_FileSystem.h:92