docs: update resources API docs

This commit is contained in:
2026-03-20 02:35:35 +08:00
parent fd792b7df1
commit ea756c0177
314 changed files with 9439 additions and 1360 deletions

View File

@@ -0,0 +1,55 @@
# Read
读取资源包中指定文件的内容。
## 方法签名
```cpp
Containers::Array<Core::uint8> Read(const Containers::String& relativePath) const;
```
## 详细描述
从资源包中读取指定文件的完整内容并返回。如果文件不存在或读取失败,返回空的数组。
文件内容以字节数组形式返回,适用于读取二进制资源如图像、音频、着色器等。
## 参数
| 参数名 | 类型 | 描述 |
|--------|------|------|
| `relativePath` | `const Containers::String&` | 文件的相对路径 |
## 返回值
| 类型 | 描述 |
|------|------|
| `Containers::Array<Core::uint8>` | 文件内容的字节数组,失败时返回空数组 |
## 示例
```cpp
ResourcePackage package;
package.Open("assets/resources.xcp");
// 读取图像文件
Array<uint8> imageData = package.Read("textures/player.png");
if (!imageData.Empty()) {
printf("Loaded image: %zu bytes\n", imageData.Size());
}
// 读取文本文件(需要额外处理 UTF-8 编码)
Array<uint8> textData = package.Read("config/settings.txt");
if (!textData.Empty()) {
// 转换为字符串
String text(reinterpret_cast<const char*>(textData.Data()), textData.Size());
}
// 读取着色器
Array<uint8> shaderData = package.Read("shaders/pbr.glsl");
```
## 相关方法
- [Exists](exists.md) - 检查文件存在
- [GetSize](getsize.md) - 获取文件大小