</li>
</ul>
-</div><section id="introduction">
-<h2 id="introduction">Introduction</h2>
-<p>This chapter describes how to use the <a class="reference external" href="https://developers.google.com/native-client/peppercpp/classpp_1_1_file_i_o">FileIO API</a>
-to read and write files using a local secure data store.</p>
+</div><h2 id="introduction">Introduction</h2>
+<p>This section describes how to use the <a class="reference external" href="/native-client/pepper_stable/cpp/classpp_1_1_file_i_o">FileIO API</a> to read and write
+files using a local secure data store.</p>
<p>You might use the File IO API with the URL Loading APIs to create an overall
data download and caching solution for your NaCl applications. For example:</p>
<ol class="arabic simple">
<li>Load the file into memory using the File IO API when needed by your
application.</li>
</ol>
-<p>The example discussed in this chapter is included in the SDK in the directory
+<p>The example discussed in this section is included in the SDK in the directory
<code>examples/api/file_io</code>.</p>
-</section><section id="reference-information">
<h2 id="reference-information">Reference information</h2>
<p>For reference information related to FileIO, see the following documentation:</p>
<ul class="small-gap">
-<li><a class="reference external" href="https://developers.google.com/native-client/peppercpp/file__io_8h">file_io.h</a> - API
-to create a FileIO object</li>
-<li><a class="reference external" href="https://developers.google.com/native-client/peppercpp/file__ref_8h">file_ref.h</a> - API
-to create a file reference or “weak pointer” to a file in a file system</li>
-<li><a class="reference external" href="https://developers.google.com/native-client/peppercpp/file__system_8h">file_system.h</a> -
-API to create a file system associated with a file</li>
+<li><a class="reference external" href="/native-client/pepper_stable/cpp/file__io_8h">file_io.h</a> - API to create a
+FileIO object</li>
+<li><a class="reference external" href="/native-client/pepper_stable/cpp/file__ref_8h">file_ref.h</a> - API to create
+a file reference or “weak pointer” to a file in a file system</li>
+<li><a class="reference external" href="/native-client/pepper_stable/cpp/file__system_8h">file_system.h</a> - API to
+create a file system associated with a file</li>
</ul>
-</section><section id="local-file-i-o">
<h2 id="local-file-i-o">Local file I/O</h2>
<p>Chrome provides an obfuscated, restricted area on disk to which a web app can
safely <a class="reference external" href="https://developers.google.com/chrome/whitepapers/storage#persistent">read and write files</a>. The
Chrome, and is not removed unless your application deletes it or the user
manually deletes it. There is no limit to the amount of local data you can
use, other than the actual space available on the local drive.</p>
-<section id="enabling-local-file-i-o">
-<span id="enabling-file-access"></span><span id="quota-management"></span><h3 id="enabling-local-file-i-o"><span id="enabling-file-access"></span><span id="quota-management"></span>Enabling local file I/O</h3>
+<h3 id="enabling-local-file-i-o"><span id="enabling-file-access"></span><span id="quota-management"></span>Enabling local file I/O</h3>
<p>The easiest way to enable the writing of persistent local data is to include
-the <a class="reference external" href="http://developer.chrome.com/extensions/declare_permissions.html#unlimitedStorage">unlimitedStorage permission</a>
-in your Chrome Web Store manifest file. With this permission you can use the
-Pepper FileIO API without the need to request disk space at run time. When
-the user installs the app Chrome displays a message announcing that the app
-writes to the local disk.</p>
+the <a class="reference external" href="/extensions/declare_permissions#unlimitedStorage">unlimitedStorage permission</a> in your Chrome Web Store
+manifest file. With this permission you can use the Pepper FileIO API without
+the need to request disk space at run time. When the user installs the app
+Chrome displays a message announcing that the app writes to the local disk.</p>
<p>If you do not use the <code>unlimitedStorage</code> permission you must include
JavaScript code that calls the <a class="reference external" href="http://updates.html5rocks.com/2011/11/Quota-Management-API-Fast-Facts">HTML5 Quota Management API</a> to
explicitly request local disk space before using the FileIO API. In this case
Chrome will prompt the user to accept a requestQuota call every time one is
made.</p>
-</section><section id="testing-local-file-i-o">
<h3 id="testing-local-file-i-o">Testing local file I/O</h3>
<p>You should be aware that using the <code>unlimitedStorage</code> manifest permission
constrains the way you can test your app. Three of the four techniques
you need to include JavaScript code that calls the HTML5 Quota Management API.
When you deliver your application you can replace this code with the
<code>unlimitedStorage</code> manifest permission.</p>
-</section></section><section id="the-file-io-example">
<h2 id="the-file-io-example">The <code>file_io</code> example</h2>
<p>The Native Client SDK includes an example, <code>file_io</code>, that demonstrates how
to read and write a local disk file. Since you will probably run the example
</ul>
<p>The remainder of this section covers the code in the <code>file_io.cc</code> file for
reading and writing files.</p>
-<section id="file-i-o-overview">
<h3 id="file-i-o-overview">File I/O overview</h3>
<p>Like many Pepper APIs, the File IO API includes a set of methods that execute
asynchronously and that invoke callback functions in your Native Client module.
structures normally.</p>
<p>The high-level flow for the <code>file_io</code> example is described below. Note that
methods in the namespace <code>pp</code> are part of the Pepper C++ API.</p>
-</section><section id="creating-and-writing-a-file">
<h3 id="creating-and-writing-a-file">Creating and writing a file</h3>
<p>Following are the high-level steps involved in creating and writing to a
file:</p>
write, <code>Write</code> is called again.</li>
<li>When there is no more data to write, call <code>pp::FileIO::Flush</code>.</li>
</ol>
-</section><section id="opening-and-reading-a-file">
<h3 id="opening-and-reading-a-file">Opening and reading a file</h3>
<p>Following are the high-level steps involved in opening and reading a file:</p>
<ol class="arabic simple">
until <code>Read</code> completes. If there is more data to read, <code>Read</code> is called
again.</li>
</ol>
-</section><section id="deleting-a-file">
<h3 id="deleting-a-file">Deleting a file</h3>
<p>Deleting a file is straightforward: call <code>pp::FileRef::Delete</code>. The thread is
blocked until <code>Delete</code> completes.</p>
-</section><section id="making-a-directory">
<h3 id="making-a-directory">Making a directory</h3>
<p>Making a directory is also straightforward: call <code>pp::File::MakeDirectory</code>.
The thread is blocked until <code>MakeDirectory</code> completes.</p>
-</section><section id="listing-the-contents-of-a-directory">
<h3 id="listing-the-contents-of-a-directory">Listing the contents of a directory</h3>
<p>Following are the high-level steps involved in listing a directory:</p>
<ol class="arabic simple">
<code>ListCallback</code> which packages up the results into a string message, and
sends it to JavaScript.</li>
</ol>
-</section></section><section id="file-io-deep-dive">
<h2 id="file-io-deep-dive"><code>file_io</code> deep dive</h2>
<p>The <code>file_io</code> example displays a user interface with a couple of fields and
several buttons. Following is a screenshot of the <code>file_io</code> example:</p>
clicking <code>Save</code>, then switching to the <code>Load File</code> operation, and
clicking <code>Load</code>.</p>
<p>Let’s take a look at what is going on under the hood.</p>
-<section id="opening-a-file-system-and-preparing-for-file-i-o">
<h3 id="opening-a-file-system-and-preparing-for-file-i-o">Opening a file system and preparing for file I/O</h3>
<p><code>pp::Instance::Init</code> is called when an instance of a module is created. In
this example, <code>Init</code> starts a new thread (via the <code>pp::SimpleThread</code>
}
}
</pre>
-</section><section id="handling-messages-from-javascript">
<h3 id="handling-messages-from-javascript">Handling messages from JavaScript</h3>
<p>When you click the <code>Save</code> button, JavaScript posts a message to the NaCl
module with the file operation to perform sent as a string (See <a class="reference internal" href="/native-client/devguide/coding/message-system.html"><em>Messaging
}
}
</pre>
-</section><section id="saving-a-file">
<h3 id="saving-a-file">Saving a file</h3>
<p><code>FileIoInstance::Save</code> is called when the <code>Save</code> button is pressed. First,
it checks to see that the FileSystem has been successfully opened:</p>
return;
}
</pre>
-</section><section id="loading-a-file">
<h3 id="loading-a-file">Loading a file</h3>
<p><code>FileIoInstance::Load</code> is called when the <code>Load</code> button is pressed. Like
the <code>Save</code> function, <code>Load</code> first checks to see if the FileSystem has been
PostMessage("DISP|" + string_data);
ShowStatusMessage("Load success");
</pre>
-</section><section id="id1">
<h3 id="id1">Deleting a file</h3>
<p><code>FileIoInstance::Delete</code> is called when the <code>Delete</code> button is pressed.
First, it checks whether the FileSystem has been opened, and creates a new
return;
}
</pre>
-</section><section id="listing-files-in-a-directory">
<h3 id="listing-files-in-a-directory">Listing files in a directory</h3>
<p><code>FileIoInstance::List</code> is called when the <code>List Directory</code> button is
pressed. Like all other operations, it checks whether the FileSystem has been
ShowStatusMessage("List success");
}
</pre>
-</section><section id="making-a-new-directory">
<h3 id="making-a-new-directory">Making a new directory</h3>
<p><code>FileIoInstance::MakeDir</code> is called when the <code>Make Directory</code> button is
pressed. Like all other operations, it checks whether the FileSystem has been
}
ShowStatusMessage("Make directory success");
</pre>
-</section></section></section>
+</section>
{{/partials.standard_nacl_article}}