LocalFileSystemSync - Web APIs 编辑

Non-standard

This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The LocalFileSystemSync interface of the File System API gives you access to a sandboxed file system. It is intended to be used with WebWorkers. The methods are implemented by worker objects.

About this document

This document was last updated on March 2, 2012 and follows the W3C Specifications (Working Draft) drafted on April 19, 2011.

This specification is more or less abandonned, failing to get significant traction.

Basic concepts

You can request access to a sandboxed file system by requesting LocalFileSystemSync object from within a web worker. The global methods in the window object requestFileSystemSync() and resolveLocalFileSystemSyncURL() methods are exposed to the Worker's global scope. Calling window.requestFileSystemSync() for creates new storage for your web app.

For more concepts, see the counterpart article for the asynchronous API.

Example

//Taking care of the browser-specific prefix
window.requestFileSystemSync  = window.requestFileSystemSync || window.webkitRequestFileSystemSync;

// The first parameter defines the type of storage: persistent or temporary
// Next, set the size of space needed (in bytes)
// initFs is the success callback
// And the last one is the error callback
// for denial of access and other errors.

var fs = requestFileSystemSync(TEMPORARY, 1024*1024 /*1MB*/);

Because you are using a synchronous API, you don't need success and error callbacks.

Method overview

FileSystemSync requestFileSystemSync (in unsigned short type, in long long size) raises FileException;
EntrySync resolveLocalFileSystemSyncURL (in DOMString url) raises FileException;

Constants

ConstantValueDescription
TEMPORARY0

Transient storage that can be removed by the browser at its discretion.

PERSISTENT1Storage that stays in the browser unless the user or the app expunges it.

Methods

requestFileSystemSync()

Requests a file system where data should be stored. You access a sandboxed file system by requesting a LocalFileSystemSync object from within a web worker using this global method, window.requestFileSystemSync(). [ RESEARCH ]

FileSystemSync requestFileSystemSync(
  in unsigned short type,
  in unsigned long long size
);
Parameters
type
The storage type of the file system. The values can be either TEMPORARY or PERSISTENT.
size
The storage space—in bytes—that you need for your app.
Returns
FileSystemSync
An object that represents the file system.
Exceptions

This method can raise an FileException with the following code:

ExceptionDescription
SECURITY_ERRORThe application does not have permission to access the file system interface. For example, you cannot run from file://. For more details, see the article on basic concepts.

resolveLocalFileSystemSyncURL()

Allows the user to look up the Entry for a file or directory referred to by a local URL.

void resolveLocalFileSystemURL(
  in DOMString url
);
Parameter
url
The URL of a local file in the file system.
Returns
EntrySync
An object that represents entries in the file system.
Exceptions

This method can raise a FileException with the following codes:

ExceptionDescription
ENCODING_ERRThe syntax of the URL was invalid.
NOT_FOUND_ERRThe URL was structurally correct, but refers to a resource that does not exist.
SECURITY_ERRThe application does not have permission to access the file system interface.

See also

Specification:File API: Directories and System SpecificationWD

Reference: File System API

Introduction: Basic Concepts About the File System API

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:92 次

字数:7512

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文