Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 45319 of LocalFileSystemSync

  • Revision slug: DOM/File_API/File_System_API/LocalFileSystemSync
  • Revision title: LocalFileSystemSync
  • Revision id: 45319
  • Created:
  • Creator: grendel
  • Is current revision? No
  • Comment Beefed up Basic Concepts and examples; 50 words added, 57 words removed

Revision Content

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.

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

Constant Value Description
TEMPORARY 0

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

PERSISTENT 1 Storage 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().

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:

SECURITY_ERR
The application does not have permission to access the file system interface. 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 an FileException with the following code:

ENCODING_ERR
The syntax of the URL was invalid.
NOT_FOUND_ERR
The URL was structurally correct, but refers to a resource that does not exist.
SECURITY_ERR
The application does not have permission to access the file system interface.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 13{{ property_prefix("webkit") }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatNo() }} 0.16{{ property_prefix("webkit") }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}

See also

Specification:{{ spec("https://dev.w3.org/2009/dap/file-system/pub/FileSystem/", "File API: Directories and System Specification", "WD") }}

Reference: File System API

Introduction: Basic Concepts About the File System API

Revision Source

<p>The <code>LocalFileSystemSync</code> interface of the <a href="/en/DOM/File_API/File_System_API" title="en/DOM/File_API/File_System_APIB">File System API</a> gives you access to a sandboxed file system. It is intended to be used with <a href="/en/DOM/Worker" title="en/DOM/Worker"> WebWorkers</a>. The methods are implemented by <a href="/en/DOM/Worker" title="En/DOM/Worker">worker</a> objects.</p>
<h2>About this document</h2>
<p>This document was last updated on March 2, 2012 and follows the <a class="external" href="https://www.w3.org/TR/file-system-api/">W3C Specifications (Working Draft)</a> drafted on April 19, 2011.</p>
<h2>Basic concepts</h2>
<p>You can request access to a sandboxed file system by requesting <code>LocalFileSystemSync</code> object from within a web worker. The global methods in the <code>window</code> object <code>requestFileSystemSync()</code> and <code>resolveLocalFileSystemSyncURL()</code> methods are exposed to the Worker's global scope. Calling <code>window.requestFileSystemSync()</code> for creates new storage for your web app.</p>
<p>For more concepts, see the counterpart <a href="/en/DOM/File_API/File_System_API/LocalFileSystem#Basic_concepts" title="https://developer.mozilla.org/en/DOM/File_API/File_System_API/LocalFileSystem#Basic_concepts">article for the asynchronous API</a>.</p>
<h3>Example</h3>
<pre class="brush: js">//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*/);</pre>
<p>Because you are using a synchronous API, you don't need success and error callbacks.</p><h2>Method overview</h2>
<table class="standard-table"> <tbody> <tr> <td><code>FileSystemSync <a href="#requestFileSystemSync" title="#requestFileSystemSync">requestFileSystemSync</a> (in unsigned short <em>type</em>, in long long <em>size</em>) raises <a href="/en/DOM/File_API/File_System_API/FileException" title="en/DOM/File_API/File_System_API/FileException">FileException</a>; </code></td> </tr> <tr> <td><code>EntrySync <a href="#resolveLocalFileSystemSyncURL" title="resolveLocalFileSystemSyncURL">resolveLocalFileSystemSyncURL</a> (in DOMString <em>url</em>) raises <a href="/en/DOM/File_API/File_System_API/FileException" title="en/DOM/File_API/File_System_API/FileException">FileException</a>;</code></td> </tr> </tbody>
</table>
<h2>Constants</h2>
<table class="standard-table"> <thead> <tr> <th scope="col">Constant</th> <th scope="col">Value</th> <th scope="col">Description</th> </tr> </thead> <tbody> <tr> <td><a name="const_temporary"><code>TEMPORARY</code></a></td> <td><code>0</code></td> <td> <p>Transient storage that can be be removed by the browser at its discretion.</p> </td> </tr> <tr> <td><a name="const_persistent"><code>PERSISTENT</code></a></td> <td><code>1</code></td> <td>Storage that stays in the browser unless the user or the app expunges it.</td> </tr> </tbody>
</table>
<h2>Methods</h2>
<h3 name="requestFileSystem">requestFileSystemSync()</h3>
<p>Requests a file system where data should be stored. You access a sandboxed file system by requesting a <code>LocalFileSystemSync</code> object from within a web worker using this global method, <code>window.requestFileSystemSync()</code>.</p>
<pre><code>FileSystemSync</code> requestFileSystemSync(
  in unsigned short type, 
  in unsigned long long size  
);</pre>
<h5>Parameters</h5>
<dl> <dt>type</dt> <dd>The storage type of the file system. The values can be either <code><a href="#const_temporary">TEMPORARY</a></code> or <code><a href="#const_persistent">PERSISTENT</a></code>.</dd> <dt>size</dt> <dd>The storage space—in bytes—that you need for your app.</dd>
</dl>
<h5>Returns</h5>
<dl> <dt><code><a href="/en/DOM/File_API/File_System_API/FileSystemSync" title="en/DOM/File_API/File_System_API/FileSystemSync">FileSystemSync</a></code></dt> <dd>An object that represents the file system.</dd>
</dl>
<h5>Exceptions</h5>
<p>This method can raise an <a href="/en/DOM/File_API/File_System_API/FileException" title="en/DOM/File_API/File_System_API/FileException">FileException</a> with the following code:</p>
<dl> <dt><code>SECURITY_ERR</code></dt> <dd>The application does not have permission to access the file system interface. You cannot run from <code>file://</code>. For more details, see the <a href="/en/DOM/File_APIs/Filesystem/Basic_Concepts_About_the_Filesystem_API#You_cannot_run_your_app_from_file:.2F.2F" title="https://developer.mozilla.org/en/DOM/File_APIs/Filesystem/Basic_Concepts_About_the_Filesystem_API#You_cannot_run_your_app_from_file:.2F.2F">article on basic concepts</a>.</dd>
</dl>
<h3 name="resolveLocalFileSystemSyncURL()">resolveLocalFileSystemSyncURL()</h3>
<p>Allows the user to look up the <code>Entry</code> for a file or directory referred to by a local URL.</p>
<pre>void resolveLocalFileSystemURL(
  in DOMString url  
);</pre>
<h5>Parameter</h5>
<dl> <dt>url</dt> <dd>The URL of a local file in the file system.</dd>
</dl>
<h5>Returns</h5>
<dl> <dt><code><a href="/en/DOM/File_API/File_System_API/EntrySync" title="en/DOM/File_API/File_System_API/EntrySync">EntrySync</a></code></dt> <dd>An object that represents entries in the file system.</dd>
</dl>
<h5>Exceptions</h5>
<p>This method can raise an <a href="/en/DOM/File_API/File_System_API/FileException" title="en/DOM/File_API/File_System_API/FileException">FileException</a> with the following code:</p>
<dl> <dt><code>ENCODING_ERR</code></dt> <dd>The syntax of the URL was invalid.</dd> <dt><code>NOT_FOUND_ERR</code></dt> <dd>The URL was structurally correct, but refers to a resource that does not exist.</dd> <dt><code>SECURITY_ERR</code></dt> <dd>The application does not have permission to access the file system interface.</dd>
</dl>
<h2 name="Browser_Compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari (WebKit)</th> </tr> <tr> <td>Basic support</td> <td>13{{ property_prefix("webkit") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Chrome for Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Phone</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatNo() }}</td> <td>0.16{{ property_prefix("webkit") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> </tbody> </table>
</div>
<h2>See also</h2>
<p>Specification:{{ spec("https://dev.w3.org/2009/dap/file-system/pub/FileSystem/", "File API: Directories and System Specification", "WD") }}</p>
<p>Reference: <a href="/en/DOM/File_API/File_System_API" title="en/DOM/File_API/File_System_API">File System API</a></p>
<p>Introduction: <a href="/en/DOM/File_APIs/Filesystem/Basic_Concepts_About_the_Filesystem_API" title="en/DOM/File_APIs/Filesystem/Basic_Concepts_About_the_Filesystem_API">Basic Concepts About the File System API</a></p>
Revert to this revision