From bb42fa52c8619e6dd4a44ea8faec63b0f3a99620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=AF=92=E6=88=88?= <838854435@qq.com> Date: Thu, 11 Dec 2025 15:19:51 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0react-native-fs?= =?UTF-8?q?=E4=B8=AD=E8=8B=B1=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/react-native-fs.md | 126 +++++++++++++++++++++++++++++++++++++++ zh-cn/react-native-fs.md | 126 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 252 insertions(+) diff --git a/en/react-native-fs.md b/en/react-native-fs.md index 445ee5419..146204c83 100644 --- a/en/react-native-fs.md +++ b/en/react-native-fs.md @@ -288,6 +288,22 @@ Verified in the following versions. | PicturesDirectoryPath | System Path | string | No | Windows | No | Windows only | | RoamingDirectoryPath | System Path | string | No | Windows | No | Windows only | +**DocumentDirectoryPath** static value : + +/data/storage/el2/base/haps/entry/files + +**CachesDirectoryPath** static value : + +/data/storage/el2/base/haps/entry/cache + +**TemporaryDirectoryPath** static value : + +/data/storage/el2/base/temp + +**LibraryDirectoryPath** static value : + +/data/storage/el2/base/preferences + ## 5. APIs > [!TIP] The **Platform** column indicates the platform where the properties are supported in the original third-party library. @@ -333,6 +349,116 @@ Verified in the following versions. | getAllExternalFilesDirs | Returns an array with the absolute paths to application-specific directories on all shared/external storage devices where the application can place persistent files it owns. | function | Android | No | No | Android only | | pathForGroup | Returns the absolute path to the directory shared for all applications with the same security group identifier. | function | iOS | No | No | iOS only | +**mkdir method parameters ** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| -------- | ------------------------------------------- | ------------ | -------- | ----------- | ----------------- | +| filepath | Folder creation path | string | yes | iOS/Android | yes | +| options | Configuration options when creating folders | MkdirOptions | no | IOS | no | + +**exists method parameters ** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| -------- | ----------- | ------ | -------- | ----------- | ----------------- | +| filepath | File Path | string | yes | iOS/Android | yes | + +**readFile method parameters ** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ----------------- | ---------------- | ------ | -------- | ----------- | ----------------- | +| filepath | File Path | string | yes | iOS/Android | yes | +| encodingOrOptions | Encoding Options | any | no | iOS/Android | yes | + +**readFileAssets method parameters ** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ----------------- | ---------------- | ------ | -------- | ----------- | ----------------- | +| filepath | File Path | string | yes | iOS/Android | yes | +| encodingOrOptions | Encoding Options | any | no | iOS/Android | yes | + +**Writefile method parameters ** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ----------------- | ------------------------- | ------ | -------- | ----------- | ----------------- | +| filepath | File Path | string | yes | iOS/Android | yes | +| contents | The content to be written | string | yes | iOS/Android | yes | +| encodingOrOptions | Encoding Options | any | no | iOS/Android | yes | + +**appendFile method parameters ** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ----------------- | ------------------- | ------ | -------- | ----------- | ----------------- | +| filepath | File Path | string | yes | iOS/Android | yes | +| contents | Content to be added | string | yes | iOS/Android | yes | +| encodingOrOptions | Encoding Options | stirng | no | iOS/Android | yes | + +**copyFile method parameters ** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| -------- | --------------------------------- | ----------- | -------- | ----------- | ----------------- | +| filepath | Path to the source file | string | yes | iOS/Android | yes | +| destPath | Destination Path | string | yes | iOS/Android | yes | +| options | iOS File Protection Level Options | FileOptions | no | iOS | no | + +**unlink method parameters ** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| -------- | ----------------------- | ------ | -------- | ----------- | ----------------- | +| filepath | Path to the source file | string | yes | iOS/Android | yes | + +**hash method parameters ** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| --------- | ----------------------- | ------ | -------- | ----------- | ----------------- | +| filepath | Path to the source file | string | yes | iOS/Android | yes | +| algorithm | Verification Algorithm | string | yes | iOS/Android | yes | + +**moveFile method parameters ** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| -------- | --------------------------------- | ----------- | -------- | ----------- | ----------------- | +| filepath | Path to the source file | string | yes | iOS/Android | yes | +| destPath | Destination Path | string | yes | iOS/Android | yes | +| options | iOS File Protection Level Options | FileOptions | no | iOS | no | + +**read method parameters ** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ----------------- | -------------------------- | ------ | -------- | ----------- | ----------------- | +| filepath | File location | string | yes | iOS/Android | yes | +| length | Number of bytes read | number | no | iOS/Android | yes | +| positon | Start position for reading | number | no | iOS/Android | yes | +| encodingOrOptions | Encoding Options | any | no | iOS/Android | yes | + +**write method parameters ** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ----------------- | -------------------------- | ------ | -------- | ----------- | ----------------- | +| filepath | File path | string | yes | iOS/Android | yes | +| contents | Content to be written | string | yes | iOS/Android | yes | +| positon | Start position for writing | number | no | iOS/Android | yes | +| encodingOrOptions | Encoding Options | any | no | iOS/Android | yes | + +**touch method parameters ** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| -------- | ------------------ | ------ | -------- | ----------- | ----------------- | +| filepath | File Path | string | yes | iOS/Android | yes | +| mtime | Modification Time | Date | no | iOS/Android | yes | +| ctime | Status Change Time | Date | no | iOS/Android | yes | + +**stat method parameters ** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| -------- | ----------- | ------ | -------- | ----------- | ----------------- | +| filepath | File Path | string | yes | iOS/Android | yes | + +**readDir method parameters ** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ------- | ----------- | ------ | -------- | ----------- | ----------------- | +| dirpath | Folder path | string | yes | iOS/Android | yes | + ## 6. Known Issues - [ ] The algorithm parameter algorithm in the hash API of HarmonyOS currently only supports "md5", "sha1", and "sha256". Other related algorithm parameters are currently not supported. Problem: [issue#1](https://github.com/react-native-oh-library/react-native-fs/issues/1) diff --git a/zh-cn/react-native-fs.md b/zh-cn/react-native-fs.md index 36eb14fe5..fa9b846af 100644 --- a/zh-cn/react-native-fs.md +++ b/zh-cn/react-native-fs.md @@ -289,6 +289,22 @@ ohpm install | PicturesDirectoryPath | 图片目录 | string | No | Windows | No | Windows only | | RoamingDirectoryPath | 漫游目录 | string | No | Windows | No | Windows only | +**DocumentDirectoryPath**静态值: + +/data/storage/el2/base/haps/entry/files + +**CachesDirectoryPath**静态值: + +/data/storage/el2/base/haps/entry/cache + +**TemporaryDirectoryPath**静态值: + +/data/storage/el2/base/temp + +**LibraryDirectoryPath**静态值: + +/data/storage/el2/base/preferences + ## 5. API > [!TIP] "Platform"列表示该属性在原三方库上支持的平台。 @@ -334,6 +350,116 @@ ohpm install | getAllExternalFilesDirs | 返回一个数组,包含应用程序可以存放其拥有的持久性文件的所有共享/外部存储设备上,应用专属目录的绝对路径 | function | Android | No | No | Android only | | pathForGroup | 返回所有具有相同安全组标识符的应用程序所共享的目录的绝对路径 | function | iOS | No | No | iOS only | +**mkdir方法参数** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| -------- | -------------------- | ------------ | -------- | ----------- | ----------------- | +| filepath | 文件夹创建路径 | string | yes | iOS/Android | yes | +| options | 创建文件夹时配置选项 | MkdirOptions | no | IOS | no | + +**exists方法参数** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| -------- | ------------ | ------ | -------- | ----------- | ----------------- | +| filepath | 文件所在路径 | string | yes | iOS/Android | yes | + +**readFile方法参数** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ----------------- | ------------ | ------ | -------- | ----------- | ----------------- | +| filepath | 文件所在路径 | string | yes | iOS/Android | yes | +| encodingOrOptions | 编码选项 | any | no | iOS/Android | yes | + +**readFileAssets方法参数** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ----------------- | ------------ | ------ | -------- | ----------- | ----------------- | +| filepath | 文件所在路径 | string | yes | iOS/Android | yes | +| encodingOrOptions | 编码选项 | any | no | iOS/Android | yes | + +**Writefile方法参数** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ----------------- | ------------ | ------ | -------- | ----------- | ----------------- | +| filepath | 文件所在路径 | string | yes | iOS/Android | yes | +| contents | 要写入的内容 | string | yes | iOS/Android | yes | +| encodingOrOptions | 编码选项 | any | no | iOS/Android | yes | + +**appendFile方法参数** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ----------------- | ------------ | ------ | -------- | ----------- | ----------------- | +| filepath | 文件所在路径 | string | yes | iOS/Android | yes | +| contents | 要追加的内容 | string | yes | iOS/Android | yes | +| encodingOrOptions | 编码选项 | stirng | no | iOS/Android | yes | + +**copyFile方法参数** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| -------- | ------------------- | ----------- | -------- | ----------- | ----------------- | +| filepath | 源文件所在路径 | string | yes | iOS/Android | yes | +| destPath | 目标路径 | string | yes | iOS/Android | yes | +| options | IOS文件保护级别选项 | FileOptions | no | iOS | no | + +**unlink方法参数** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| -------- | -------------- | ------ | -------- | ----------- | ----------------- | +| filepath | 源文件所在路径 | string | yes | iOS/Android | yes | + +**hash方法参数** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| --------- | -------------- | ------ | -------- | ----------- | ----------------- | +| filepath | 源文件所在路径 | string | yes | iOS/Android | yes | +| algorithm | 校验算法 | string | yes | iOS/Android | yes | + +**moveFile方法参数** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| -------- | ------------------- | ----------- | -------- | ----------- | ----------------- | +| filepath | 源文件所在路径 | string | yes | iOS/Android | yes | +| destPath | 目标路径 | string | yes | iOS/Android | yes | +| options | IOS文件保护级别选项 | FileOptions | no | iOS | no | + +**read方法参数** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ----------------- | -------------- | ------ | -------- | ----------- | ----------------- | +| filepath | 文件所在路径 | string | yes | iOS/Android | yes | +| length | 读取的字节数 | number | no | iOS/Android | yes | +| positon | 读取的起始位置 | number | no | iOS/Android | yes | +| encodingOrOptions | 编码选项 | any | no | iOS/Android | yes | + +**write方法参数** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ----------------- | -------------- | ------ | -------- | ----------- | ----------------- | +| filepath | 文件所在路径。 | string | yes | iOS/Android | yes | +| contents | 写入的内容 | string | yes | iOS/Android | yes | +| positon | 写入的起始位置 | number | no | iOS/Android | yes | +| encodingOrOptions | 编码选项 | any | no | iOS/Android | yes | + +**touch方法参数** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| -------- | ------------ | ------ | -------- | ----------- | ----------------- | +| filepath | 文件所在路径 | string | yes | iOS/Android | yes | +| mtime | 修改时间 | Date | no | iOS/Android | yes | +| ctime | 状态变更时间 | Date | no | iOS/Android | yes | + +**stat方法参数** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| -------- | ------------ | ------ | -------- | ----------- | ----------------- | +| filepath | 文件所在路径 | string | yes | iOS/Android | yes | + +**readDir 方法参数** + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ------- | -------------- | ------ | -------- | ----------- | ----------------- | +| dirpath | 文件夹所在路径 | string | yes | iOS/Android | yes | + ## 6. 遗留问题 - [ ] HarmonyOS 的 hash 哈希 API 中关于算法参数 algorithm 目前仅支持"md5"、"sha1"、 "sha256",其他相关算法参数目前不支持,问题: [issue#1](https://github.com/react-native-oh-library/react-native-fs/issues/1) -- Gitee