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