Skip to content

Commit

Permalink
[zh-cn]: sync translation for FileSystemHandle and all its members (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
skyclouds2001 authored May 15, 2024
1 parent d3362c2 commit 0677957
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 38 deletions.
16 changes: 9 additions & 7 deletions files/zh-cn/web/api/filesystemhandle/index.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
---
title: FileSystemHandle
slug: Web/API/FileSystemHandle
l10n:
sourceCommit: be3c45cd7a4d5c04139eceae10f7368251cdca64
---

{{securecontext_header}}{{APIRef("File System Access API")}}
{{securecontext_header}}{{APIRef("File System API")}}{{AvailableInWorkers}}

{{domxref('File System Access API')}} 的 **`FileSystemHandle`** 接口是代表一个文件或一个目录的对象。多个句柄可以代表同一个条目。在大多数情况下,你不会直接使用 `FileSystemHandle`,而是会用到它的 {{domxref('FileSystemFileHandle')}} 和 {{domxref('FileSystemDirectoryHandle')}} 子接口。
{{domxref('File System API', '文件系统 API', '', 'nocode')}} 的 **`FileSystemHandle`** 接口是代表一个文件或一个目录的对象。多个句柄可以代表同一个条目。在大多数情况下,你不会直接使用 `FileSystemHandle`,而是会用到它的 {{domxref('FileSystemFileHandle')}} 和 {{domxref('FileSystemDirectoryHandle')}} 子接口。

## 基于 FileSystemHandle 的接口

以下是基于 FileSystemHandle 的接口的列表。
以下是基于 `FileSystemHandle` 的接口的列表。

- {{domxref("FileSystemFileHandle")}}
- {{domxref("FileSystemFileHandle")}} {{SecureContext_Inline}}
- : 提供一个指向文件条目的句柄。
- {{domxref("FileSystemDirectoryHandle")}}
- {{domxref("FileSystemDirectoryHandle")}} {{SecureContext_Inline}}
- : 提供一个指向目录条目的句柄。

## 实例属性
Expand All @@ -26,7 +28,7 @@ slug: Web/API/FileSystemHandle
## 实例方法

- {{domxref('FileSystemHandle.isSameEntry()', 'isSameEntry()')}}
- : 比对两个{{domxref("FileSystemHandle", "句柄", "", 1)}}以查看两者关联的条目(文件或目录)是否相符。
- : 比对两个句柄以查看两者关联的条目(文件或目录)是否相符。
- {{domxref('FileSystemHandle.queryPermission()', 'queryPermission()')}} {{Experimental_Inline}}
- : 查询当前句柄目前的权限状态。
- {{domxref('FileSystemHandle.remove', 'remove()')}} {{Experimental_Inline}} {{Non-standard_Inline}}
Expand Down Expand Up @@ -108,4 +110,4 @@ function removeMatches(fileEntry, entriesArr) {
## 参见

- [文件系统 API](/zh-CN/docs/Web/API/File_System_API)
- [文件系统访问 API:简化本地文件访问](https://developer.chrome.com/articles/file-system-access/)
- [文件系统访问 API:简化本地文件访问](https://developer.chrome.com/docs/capabilities/web-apis/file-system-access)
14 changes: 6 additions & 8 deletions files/zh-cn/web/api/filesystemhandle/issameentry/index.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---
title: FileSystemHandle:isSameEntry() 方法
slug: Web/API/FileSystemHandle/isSameEntry
l10n:
sourceCommit: f10fbe2d2dc4857bf29ce955689a7ba7c1ffac8b
---

{{securecontext_header}}{{APIRef("File System Access API")}}
{{securecontext_header}}{{APIRef("File System API")}}{{AvailableInWorkers}}

{{domxref("FileSystemHandle")}} 接口的 **`isSameEntry()`** 方法用于比对两个{{domxref("FileSystemHandle", "句柄", "", 1)}}以查看两者关联的条目(文件或目录)是否相符。
{{domxref("FileSystemHandle")}} 接口的 **`isSameEntry()`** 方法用于比对两个{{domxref("FileSystemHandle", "句柄", "", "nocode")}}以查看两者关联的条目(文件或目录)是否相符。

## 语法

Expand All @@ -20,11 +22,7 @@ isSameEntry(fileSystemHandle)

### 返回值

返回一个 {{jsxref('Boolean')}} 值,如果条目相符则此值为 `true`

### 异常

不抛出异常。
一个兑现{{jsxref('Boolean', '布尔值', '', 'nocode')}}的 Promise。

## 示例

Expand All @@ -49,4 +47,4 @@ function removeMatches(fileEntry, entriesArr) {
## 参见

- [文件系统 API](/zh-CN/docs/Web/API/File_System_API)
- [文件系统访问 API:简化本地文件访问](https://developer.chrome.com/articles/file-system-access/)
- [文件系统访问 API:简化本地文件访问](https://developer.chrome.com/docs/capabilities/web-apis/file-system-access)
6 changes: 4 additions & 2 deletions files/zh-cn/web/api/filesystemhandle/kind/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
title: FileSystemHandle:kind 属性
slug: Web/API/FileSystemHandle/kind
l10n:
sourceCommit: f10fbe2d2dc4857bf29ce955689a7ba7c1ffac8b
---

{{securecontext_header}}{{APIRef("File System Access API")}}
{{securecontext_header}}{{APIRef("File System API")}}{{AvailableInWorkers}}

{{domxref("FileSystemHandle")}} 接口的 **`kind`** 只读属性返回条目的类型。如果关联的条目是一个文件,则此值为 `'file'`,否则为 `'directory'`。其用于在遍历目录内容时区分文件和目录。

Expand Down Expand Up @@ -45,4 +47,4 @@ async function getFile() {
## 参见

- [文件系统 API](/zh-CN/docs/Web/API/File_System_API)
- [文件系统访问 API:简化本地文件访问](https://developer.chrome.com/articles/file-system-access/)
- [文件系统访问 API:简化本地文件访问](https://developer.chrome.com/docs/capabilities/web-apis/file-system-access)
6 changes: 4 additions & 2 deletions files/zh-cn/web/api/filesystemhandle/name/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
title: FileSystemHandle:name 属性
slug: Web/API/FileSystemHandle/name
l10n:
sourceCommit: f10fbe2d2dc4857bf29ce955689a7ba7c1ffac8b
---

{{securecontext_header}}{{APIRef("File System Access API")}}
{{securecontext_header}}{{APIRef("File System API")}}{{AvailableInWorkers}}

{{domxref("FileSystemHandle")}} 接口的 **`name`** 只读属性返回句柄所代表的条目的名称。

Expand Down Expand Up @@ -38,4 +40,4 @@ async function getFile() {
## 参见

- [文件系统 API](/zh-CN/docs/Web/API/File_System_API)
- [文件系统访问 API:简化本地文件访问](https://developer.chrome.com/articles/file-system-access/)
- [文件系统访问 API:简化本地文件访问](https://developer.chrome.com/docs/capabilities/web-apis/file-system-access)
18 changes: 11 additions & 7 deletions files/zh-cn/web/api/filesystemhandle/querypermission/index.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
---
title: FileSystemHandle:queryPermission() 方法
slug: Web/API/FileSystemHandle/queryPermission
l10n:
sourceCommit: be3c45cd7a4d5c04139eceae10f7368251cdca64
---

{{securecontext_header}}{{APIRef("File System Access API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("File System API")}}{{AvailableInWorkers}}{{SeeCompatTable}}

{{domxref("FileSystemHandle")}} 接口的 **`queryPermission()`** 方法用于查询当前句柄目前的权限状态。

## 语法

```js-nolint
queryPermission(fileSystemHandlePermissionDescriptor)
queryPermission(descriptor)
```

### 参数

- FileSystemHandlePermissionDescriptor {{optional_inline}}
- `descriptor` {{optional_inline}}

- : 一个对象,指定需要查询的权限模式,包含以下选项:

- `'mode'`:可以是 `'read'``'readwrite'`
- `'mode'` {{optional_inline}}

- : 可以是 `'read'``'readwrite'`

### 返回值

{{domxref('PermissionStatus.state')}},值为 `'granted'``'denied'``'prompt'` 三者之一
一个兑现 {{domxref("PermissionStatus")}} 对象的 {{jsxref("Promise")}}

如果此方法返回了“prompt”,则站点必须在对句柄进行任何操作前调用 requestPermission() 请求授权。如果此方法返回了“denied”,则任何操作都会被拒绝。从本地文件系统句柄构造器返回的句柄通常会在初始时对只读权限状态返回“granted”。但是,除开用户收回了权限的情况,从 IndexedDB 获取的句柄也有可能会返回“prompt”。
如果 {{domxref('PermissionStatus.state')}} 返回了“prompt”,则站点必须在对句柄进行任何操作前调用 `requestPermission()` 请求授权。如果此方法返回了“denied”,则任何操作都会被拒绝。从本地文件系统句柄构造器返回的句柄通常会在初始时对只读权限状态返回“granted”。但是,除开用户收回了权限的情况,从 IndexedDB 获取的句柄也有可能会返回“prompt”。

### 异常

Expand Down Expand Up @@ -72,4 +76,4 @@ async function verifyPermission(fileHandle, withWrite) {
## 参见

- [文件系统 API](/zh-CN/docs/Web/API/File_System_API)
- [文件系统访问 API:简化本地文件访问](https://developer.chrome.com/articles/file-system-access/)
- [文件系统访问 API:简化本地文件访问](https://developer.chrome.com/docs/capabilities/web-apis/file-system-access)
15 changes: 9 additions & 6 deletions files/zh-cn/web/api/filesystemhandle/remove/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
title: FileSystemHandle:remove() 方法
slug: Web/API/FileSystemHandle/remove
l10n:
sourceCommit: be3c45cd7a4d5c04139eceae10f7368251cdca64
---

{{securecontext_header}}{{APIRef("File System Access API")}}{{SeeCompatTable}}{{Non-standard_header}}
{{securecontext_header}}{{APIRef("File System API")}}{{AvailableInWorkers}}{{SeeCompatTable}}{{Non-standard_header}}

{{domxref("FileSystemHandle")}} 接口的 **`remove()`** 方法用于向底层文件系统请求移除句柄所代表的条目。

Expand All @@ -14,6 +16,7 @@ slug: Web/API/FileSystemHandle/remove
## 语法

```js-nolint
remove()
remove(options)
```

Expand All @@ -31,17 +34,17 @@ remove(options)
### 异常

- `InvalidModificationError` {{domxref("DOMException")}}
- : 如果 `recursive` 被设为 `false` 并且要移除的条目是包含子项的目录时,会抛出此异常
- : 如果 `recursive` 被设为 `false` 并且要移除的条目是包含子项的目录时,则抛出此异常
- `NoModificationAllowedError` {{domxref("DOMException")}}
- : 如果浏览器无法获得该条目的独占锁定,则抛出此异常。
- `NotAllowedError` {{domxref("DOMException")}}
- : 如果 {{domxref('PermissionStatus')}} 不为 `granted`抛出此异常
- : 如果 {{domxref('PermissionStatus')}} 不为 `granted`则抛出此异常
- `NotFoundError` {{domxref("DOMException")}}
- : 如果找不到该条目则抛出此异常
- : 如果找不到该条目,则抛出此异常

## 示例

我们的 [FileSystemHandle.remove() 演示](https://filesystemhandle-remove.glitch.me/)(参阅[源代码](https://glitch.com/edit/#!/filesystemhandle-remove))是个用于创建文件的应用。你可以在 {{htmlelement("textarea")}} 中输入文本然后按下“Save file” {{htmlelement("button")}},然后应用会打开一个文件选择器以允许你将输入的文本保存到你在你的本地文件系统中选择的文件。你还可以删除你创建的文件。
我们的 [`FileSystemHandle.remove()` 演示](https://filesystemhandle-remove.glitch.me/)(参阅[源代码](https://glitch.com/edit/#!/filesystemhandle-remove))是个用于创建文件的应用。你可以在 {{htmlelement("textarea")}} 中输入文本然后按下“Save file” {{htmlelement("button")}},然后应用会打开一个文件选择器以允许你将输入的文本保存到你在你的本地文件系统中选择的文件。你还可以删除你创建的文件。

这个应用不能让你查看创建出的文件的内容,也无法在重载或关闭页面后仍然保持与底层文件系统同步。也就是说,如果你不在重载或关闭标签页前删除你创建的文件,那这些文件仍然会存留于你的文件系统中。

Expand Down Expand Up @@ -77,7 +80,7 @@ async function deleteFile(e) {

## 规范

{{Specifications}}
此特性不属于任何规范的一部分,但将来可能会成为标准的一部分。有关详细信息,请参阅 [_whatwg/fs#9_](https://github.com/whatwg/fs/pull/9)

## 浏览器兼容性

Expand Down
16 changes: 10 additions & 6 deletions files/zh-cn/web/api/filesystemhandle/requestpermission/index.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
---
title: FileSystemHandle:requestPermission() 方法
slug: Web/API/FileSystemHandle/requestPermission
l10n:
sourceCommit: be3c45cd7a4d5c04139eceae10f7368251cdca64
---

{{securecontext_header}}{{APIRef("File System Access API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("File System API")}}{{AvailableInWorkers}}{{SeeCompatTable}}

{{domxref("FileSystemHandle")}} 接口的 **`queryPermission()`** 方法用于为文件句柄请求读取或读写权限。

## 语法

```js-nolint
requestPermission(fileSystemHandlePermissionDescriptor)
requestPermission(descriptor)
```

### 参数

- FileSystemHandlePermissionDescriptor {{optional_inline}}
- `descriptor` {{optional_inline}}

- : 一个对象,指定需要查询的权限模式,包含以下选项:

- `'mode'`:可以是 `'read'``'readwrite'`
- `'mode'` {{optional_inline}}

- : 可以是 `'read'``'readwrite'`

### 返回值

{{domxref('PermissionStatus.state')}},值为 `'granted'``'denied'``'prompt'` 三者之一
一个兑现 {{domxref("PermissionStatus")}} 对象的 {{jsxref("Promise")}}

### 异常

Expand Down Expand Up @@ -70,4 +74,4 @@ async function verifyPermission(fileHandle, withWrite) {
## 参见

- [文件系统 API](/zh-CN/docs/Web/API/File_System_API)
- [文件系统访问 API:简化本地文件访问](https://developer.chrome.com/articles/file-system-access/)
- [文件系统访问 API:简化本地文件访问](https://developer.chrome.com/docs/capabilities/web-apis/file-system-access)

0 comments on commit 0677957

Please sign in to comment.