From 82dc919d7c4cb026f79bc3fa0fe2b9624d11b8ad Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Thu, 17 Aug 2023 10:29:12 +0800 Subject: [PATCH] add_fileuri Signed-off-by: 18721213663 --- .../reference/apis/js-apis-file-fileuri.md | 64 +++++++++++++++++++ .../reference/apis/js-apis-file-fs.md | 37 +++++++++++ 2 files changed, 101 insertions(+) diff --git a/zh-cn/application-dev/reference/apis/js-apis-file-fileuri.md b/zh-cn/application-dev/reference/apis/js-apis-file-fileuri.md index d513e8427c..4f7ff5dd93 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-file-fileuri.md +++ b/zh-cn/application-dev/reference/apis/js-apis-file-fileuri.md @@ -40,6 +40,70 @@ export default class EntryAbility extends UIAbility { FA模型context的具体获取方法参见[FA模型](js-apis-inner-app-context.md#Context模块)。 +## FileUri10+ + +### 属性 + +**系统能力**:SystemCapability.FileManagement.AppFileService + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| path10+ | string | 是 | 否 | 获取FileUri对应路径名 | +| name10+ | string | 是 | 否 | 获取FileUri对应文件名 | + +### constructor10+ + +constructor(uriOrPath: string) + +constructor是FileUri的构造函数。 + +**系统能力:** SystemCapability.FileManagement.AppFileService + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| uriOrPath | string | 是 | uri或路径。uri类型:
-  应用沙箱URI:file://\/\
-  公共目录文件类URI:file://docs/storage/Users/currentUser/\
-  公共目录媒体类URI:file://media/\/IMG_DATATIME_ID/\ | + +**错误码:** + +以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)。 +| 错误码ID | 错误信息 | +| ---------------------------- | ---------- | +| 13900005 | I/O error | +| 13900042 | Unknown error | + +**示例:** + +```js +let path = pathDir + '/test'; +let uri = fileuri.getUriFromPath(filePath); // file:///data/storage/el2/base/haps/entry/files/test +let fileUriObject = new fileuri.FileUri(uri); +console.info("The name of FileUri is " + fileUriObject.name); +``` + +### toString10+ + +toString(): string + +**系统能力:** SystemCapability.FileManagement.AppFileService + +返回字符串类型uri。 + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| string | 返回字符串类型uri | + +**示例:** + +```js +let path = pathDir + '/test'; +let fileUriObject = new fileuri.FileUri(path); +console.info("The uri of FileUri is " + fileUriObject.toString()); +``` + ## fileUri.getUriFromPath getUriFromPath(path: string): string diff --git a/zh-cn/application-dev/reference/apis/js-apis-file-fs.md b/zh-cn/application-dev/reference/apis/js-apis-file-fs.md index 73c7620e5c..8c1df075bf 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-file-fs.md +++ b/zh-cn/application-dev/reference/apis/js-apis-file-fs.md @@ -533,6 +533,41 @@ copyDir(src: string, dest: string, mode?: number, callback: AsyncCallback\ }); ``` +## fs.dup10+ + +dup(fd: number): File + +将文件描述符转化为File。 + +**系统能力**:SystemCapability.FileManagement.File.FileIO + +**参数:** + + | 参数名 | 类型 | 必填 | 说明 | + | ------ | ------ | ---- | --------------------------- | + | fd | number | 是 | 文件描述符。 | + +**返回值:** + + | 类型 | 说明 | + | ------------------- | ---------------------------- | + | [File](#file) | 打开的File对象。 | + +**错误码:** + +接口抛出错误码的详细介绍请参见[基础文件IO错误码](../errorcodes/errorcode-filemanagement.md#基础文件io错误码)。 + +**示例:** + + ```js + // convert fd to file + let fd = 0; // fd comes from other modules + let file = fs.dup(fd); + console.info("The name of the file is " + file.name); + fs.closeSync(file); + ``` + + ## fs.mkdir mkdir(path: string): Promise<void> @@ -3263,6 +3298,8 @@ readSync(buffer: ArrayBuffer, options?: { offset?: number; length?: number; }): | 名称 | 类型 | 可读 | 可写 | 说明 | | ---- | ------ | ---- | ---- | ------- | | fd | number | 是 | 否 | 打开的文件描述符。 | +| path10+ | string | 是 | 否 | 文件路径。 | +| name10+ | string | 是 | 否 | 文件名。 | ### lock -- GitLab