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
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
#pragma once
9
#include <
Ultralight/Defines.h
>
10
#include <
Ultralight/String.h
>
11
#include <
Ultralight/Buffer.h
>
12
13
namespace
ultralight
{
14
15
///
16
/// User-defined file system interface.
17
///
18
/// The library uses this to load file data (ie, raw file bytes) for a given file URL
19
/// (eg, `file:///page.html`) .
20
///
21
/// You can provide the library with your own FileSystem implementation so that file data is
22
/// provided directly by your application (eg, from memory, from a virtual file system, etc).
23
///
24
/// ## Default Implementation
25
///
26
/// A platform-specific implementation of FileSystem is provided for you when you call
27
/// App::Create().
28
///
29
/// If you are using Renderer::Create(), you **must** provide your own. You can still use AppCore's
30
/// implementation however-- see the helper functions defined in <AppCore/Platform.h>.
31
///
32
/// ## Setting the File System
33
///
34
/// To provide your own custom FileSystem implementation, you should inherit from this class,
35
/// handle the virtual member functions, and then pass an instance of your class to
36
/// Platform::set_file_system() before calling Renderer::Create() or App::Create().
37
///
38
class
UExport
FileSystem
{
39
public
:
40
virtual
~FileSystem
();
41
42
///
43
/// Check if a file exists within the file system.
44
///
45
/// @param file_path Relative file path (the string following the file:/// prefix)
46
///
47
/// @return Returns whether or not a file exists at the path specified.
48
///
49
virtual
bool
FileExists
(
const
String
& file_path) = 0;
50
51
///
52
/// Get the mime-type of a file (eg "text/html").
53
///
54
/// This is usually determined by analyzing the file extension.
55
///
56
/// If a mime-type cannot be determined, this should return "application/unknown".
57
///
58
/// @param file_path Relative file path (the string following the file:/// prefix)
59
///
60
/// @return Returns whether or not a file exists at the path specified.
61
///
62
virtual
String
GetFileMimeType
(
const
String
& file_path) = 0;
63
64
///
65
/// Get the charset / encoding of a file (eg "utf-8", "iso-8859-1").
66
///
67
/// @note This is only applicable for text-based files (eg, "text/html", "text/plain") and is
68
/// usually determined by analyzing the contents of the file.
69
///
70
/// @param file_path Relative file path (the string following the file:/// prefix)
71
///
72
/// @return Returns the charset of the specified file. If a charset cannot be determined, a safe
73
/// default to return is "utf-8".
74
///
75
virtual
String
GetFileCharset
(
const
String
& file_path) = 0;
76
77
///
78
/// Open a file for reading and map it to a Buffer.
79
///
80
/// To minimize copies, you should map the requested file into memory and use Buffer::Create()
81
/// to wrap the data pointer (unmapping should be performed in the destruction callback).
82
///
83
/// @note
84
/// \parblock
85
/// File data addresses returned from this function should generally be aligned to 16-byte
86
/// boundaries (the default alignment on most operating systems-- if you're using C stdlib or
87
/// C++ STL functions this is already handled for you).
88
///
89
/// This requirement is currently necessary when loading the ICU data file (eg, icudt67l.dat),
90
/// and may be relaxed for other files (but you may still see a performance benefit due to cache
91
/// line alignment).
92
///
93
/// If you can't guarantee alignment or are unsure, you can use Buffer::CreateFromCopy to copy
94
/// the file data content to an aligned block (at the expense of data duplication).
95
/// \endparblock
96
///
97
/// @param file_path Relative file path (the string following the file:/// prefix)
98
///
99
/// @return If the file was able to be opened, this returns a Buffer object representing the
100
/// contents of the file. If the file was unable to be opened, you should return nullptr.
101
///
102
virtual
RefPtr<Buffer>
OpenFile
(
const
String
& file_path) = 0;
103
};
104
105
}
// namespace ultralight
Buffer.h
UExport
#define UExport
Definition
Exports.h:25
String.h
Defines.h
ultralight::FileSystem
User-defined file system interface.
Definition
FileSystem.h:38
ultralight::FileSystem::OpenFile
virtual RefPtr< Buffer > OpenFile(const String &file_path)=0
Open a file for reading and map it to a Buffer.
ultralight::FileSystem::GetFileCharset
virtual String GetFileCharset(const String &file_path)=0
Get the charset / encoding of a file (eg "utf-8", "iso-8859-1").
ultralight::FileSystem::~FileSystem
virtual ~FileSystem()
ultralight::FileSystem::FileExists
virtual bool FileExists(const String &file_path)=0
Check if a file exists within the file system.
ultralight::FileSystem::GetFileMimeType
virtual String GetFileMimeType(const String &file_path)=0
Get the mime-type of a file (eg "text/html").
ultralight::RefPtr
A nullable smart pointer.
Definition
RefPtr.h:79
ultralight::String
Unicode string container with conversions for UTF-8, UTF-16, and UTF-32.
Definition
String.h:34
ultralight
Definition
Bitmap.h:14
Ultralight
platform
FileSystem.h
Docs
C++ API
C API
Version
1.4
2.0
latest
1.4