非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。
文件和目录条目 API 模拟本地文件系统,Web APP 可以在其中导航和访问文件。可以开发在虚拟、沙盒文件系统中读取、写入和创建文件和/或目录的 APP。
由于这是非标准 API,其规范目前不在标准轨道中,所以记住并非所有浏览器都有实现且可能仅实现一小部分,这点很重要。检查 浏览器兼容性 章节了解细节。
存在 2 种很类似的 API,取决于是期望异步行为还是同步行为。同步 API 旨在在用于
Worker
并返回期望值。异步 API 不会被阻塞,且函数和 API 不会返回值;相反,需要提供回调函数以在到达时处理响应。
Firefox 对文件和目录条目 API 的实现非常有限;不支持创建文件。仅用于访问由用户选择的文件在文件
<input>
元素 (见
HTMLInputElement
) 或当文件或目录被提供给 Web 站点或 APP 使用
拖放
。Firefox 未实现同步 API。小心谨慎检查使用 API 的任何部分的浏览器兼容性,并参阅
Firefox 中的文件和目录条目 API 支持
了解更多细节。
有 2 种方式能访问当前规范草案中定义的文件系统:
drop
事件对于拖放,可以调用
DataTransferItem.webkitGetAsEntry()
以获取
FileSystemEntry
对于掉落项。若结果不是
null
,那么它是拖入文件或目录,可以使用文件系统调用处理它。
HTMLInputElement.webkitEntries
特性允许您访问
FileSystemFileEntry
对象对于目前选中文件,但仅当它们被拖放到文件选择器上时 (
bug 1326031
)。若
HTMLInputElement.webkitdirectory
is
true
,
<input>
元素代之是目录拾取器,和获取
FileSystemDirectoryEntry
对象对于每个选中目录。
异步 API 应该用于大多数操作,以防止文件系统的访问阻塞整个浏览器若在主线程中使用。它包括以下接口:
FileSystem
表示文件系统。
FileSystemEntry
The basic interface representing a single entry in a file system. This is implemented by other interfaces which represent files or directories.
FileSystemFileEntry
表示文件系统中的单个文件。
FileSystemDirectoryEntry
表示文件系统中的单个目录。
FileSystemDirectoryReader
FileSystemDirectoryEntry.createReader()
, this interface provides the functionality which lets you read the contents of a directory.
FileSystemFlags
FileError
Represents an error which is generated by asynchronous file system calls.
There are also two global functions (which are not part of the specification at this time and are implemented only by Google Chrome). They're available on the
Window
object and implemented in
LocalFileSystem
:
requestFileSystem()
and
resolveLocalFileSystemURL()
.
The synchronous API is should only be used in
Worker
s; these calls block until they're finished executing, and simply return the results instead of using callbacks. Using them on the main thread will block the browser, which is naughty. The interfaces below otherwise mirror the ones from the asynchronous API.
FileSystemSync
表示文件系统。
FileSystemEntrySync
The basic interface representing a single entry in a file system. This is implemented by other interfaces which represent files or directories.
FileSystemFileEntrySync
表示文件系统中的单个文件。
FileSystemDirectoryEntrySync
表示文件系统中的单个目录。
FileSystemDirectoryReaderSync
FileSystemDirectoryEntrySync.createReader()
, this interface provides the functionality which lets you read the contents of a directory.
FileException
Represents an error which is generated by synchronous file system calls.
There are also two global functions (which are not part of the specification at this time and are implemented only by Google Chrome). They're available on the
Worker
object and implemented in
LocalFileSystemSync
:
requestFileSystemSync()
and
resolveLocalFileSystemSyncURL()
.
LocalFileSystem
使您可以访问沙盒文件系统。
LocalFileSystemSync
LockedFile
提供采用所有必要锁来处理给定文件的工具。
元数据
| 规范 | 状态 | 注释 |
|---|---|---|
| 文件和目录条目 API | 草案 | 提议 API 草案 |
此 API 没有正式的 W3C 或 WHATWG (Web 超文本应用程序技术工作组) 规范。
FileSystem
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
FileSystem
|
Chrome
7
Alternate Name
|
Edge
≤18
Prefixed
|
Firefox 50 | IE 不支持 No |
Opera
15
Prefixed
|
Safari 11.1 |
WebView Android
≤37
Alternate Name
|
Chrome Android
18
Alternate Name
|
Firefox Android 50 |
Opera Android
14
Prefixed
|
Safari iOS 11.3 |
Samsung Internet Android
1.0
Prefixed
|
完整支持
不支持
见实现注意事项。
使用非标名称。
要求使用供应商前缀或不同名称。
FileSystemSync
property
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
FileSystemSync
非标
|
Chrome
13
Prefixed
|
Edge
≤79
Prefixed
|
Firefox 不支持 No | IE 不支持 No |
Opera
15
Prefixed
|
Safari
6
Prefixed
|
WebView Android
≤37
Prefixed
|
Chrome Android
18
Prefixed
|
Firefox Android 不支持 No |
Opera Android
14
Prefixed
|
Safari iOS
6
Prefixed
|
Samsung Internet Android
1.0
Prefixed
|
完整支持
不支持
非标。预期跨浏览器支持较差。
要求使用供应商前缀或不同名称。
FileError
FileException
FileHandle
FileRequest
FileSystemDirectoryEntry
FileSystemDirectoryEntrySync
FileSystemDirectoryReader
FileSystemDirectoryReaderSync
FileSystemEntry
FileSystemEntrySync
FileSystemFileEntry
FileSystemFileEntrySync
FileSystemFlags
FileSystem
FileSystemSync
HTMLInputElement
LocalFileSystem
LocalFileSystemSync
LockedFile
元数据