docs
Docs
C++ API
C API
Search API
Ctrl K
1.4
2.0
latest
1.4
Ultralight C API
1.4.0
Toggle main menu visibility
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
28
#include <
Ultralight/CAPI/CAPI_Defines.h
>
29
30
#ifdef __cplusplus
31
extern
"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
///
42
typedef
bool (*
ULFileSystemFileExistsCallback
)(
ULString
path);
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
///
53
typedef
ULString
(*
ULFileSystemGetFileMimeTypeCallback
)(
ULString
path);
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
///
65
typedef
ULString
(*
ULFileSystemGetFileCharsetCallback
)(
ULString
path);
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
///
75
typedef
ULBuffer
(*
ULFileSystemOpenFileCallback
)(
ULString
path);
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
///
83
typedef
struct
{
84
ULFileSystemFileExistsCallback
file_exists
;
85
ULFileSystemGetFileMimeTypeCallback
get_file_mime_type
;
86
ULFileSystemGetFileCharsetCallback
get_file_charset
;
87
ULFileSystemOpenFileCallback
open_file
;
88
}
ULFileSystem
;
89
90
#ifdef __cplusplus
91
}
// extern "C"
92
#endif
93
94
#endif
// ULTRALIGHT_CAPI_FILESYSTEM_H
CAPI_Defines.h
Various defines and utility functions for the C API.
ULString
struct C_String * ULString
Definition
CAPI_Defines.h:65
ULBuffer
struct C_Buffer * ULBuffer
Definition
CAPI_Defines.h:66
ULFileSystemFileExistsCallback
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
ULFileSystemGetFileCharsetCallback
ULString(*) ULFileSystemGetFileCharsetCallback(ULString path)
Get the charset / encoding of the file (eg "utf-8").
Definition
CAPI_FileSystem.h:65
ULFileSystemGetFileMimeTypeCallback
ULString(*) ULFileSystemGetFileMimeTypeCallback(ULString path)
Get the mime-type of the file (eg "text/html").
Definition
CAPI_FileSystem.h:53
ULFileSystemOpenFileCallback
ULBuffer(*) ULFileSystemOpenFileCallback(ULString path)
Open file for reading and map it to a Buffer.
Definition
CAPI_FileSystem.h:75
ULFileSystem
User-defined file system interface.
Definition
CAPI_FileSystem.h:83
ULFileSystem::open_file
ULFileSystemOpenFileCallback open_file
Definition
CAPI_FileSystem.h:87
ULFileSystem::get_file_charset
ULFileSystemGetFileCharsetCallback get_file_charset
Definition
CAPI_FileSystem.h:86
ULFileSystem::file_exists
ULFileSystemFileExistsCallback file_exists
Definition
CAPI_FileSystem.h:84
ULFileSystem::get_file_mime_type
ULFileSystemGetFileMimeTypeCallback get_file_mime_type
Definition
CAPI_FileSystem.h:85
Ultralight
CAPI
CAPI_FileSystem.h
Docs
C++ API
C API
Version
1.4
2.0
latest
1.4