| OLD | NEW |
| 1 {{+bindTo:partials.standard_nacl_article}} | 1 {{+bindTo:partials.standard_nacl_article}} |
| 2 | 2 |
| 3 <section id="file-i-o"> | 3 <section id="file-i-o"> |
| 4 <span id="devguide-coding-fileio"></span><h1 id="file-i-o"><span id="devguide-co
ding-fileio"></span>File I/O</h1> | 4 <span id="devguide-coding-fileio"></span><h1 id="file-i-o"><span id="devguide-co
ding-fileio"></span>File I/O</h1> |
| 5 <div class="contents local" id="contents" style="display: none"> | 5 <div class="contents local" id="contents" style="display: none"> |
| 6 <ul class="small-gap"> | 6 <ul class="small-gap"> |
| 7 <li><a class="reference internal" href="#introduction" id="id2">Introduction</a>
</li> | 7 <li><a class="reference internal" href="#introduction" id="id2">Introduction</a>
</li> |
| 8 <li><a class="reference internal" href="#reference-information" id="id3">Referen
ce information</a></li> | 8 <li><a class="reference internal" href="#reference-information" id="id3">Referen
ce information</a></li> |
| 9 <li><p class="first"><a class="reference internal" href="#local-file-i-o" id="id
4">Local file I/O</a></p> | 9 <li><p class="first"><a class="reference internal" href="#local-file-i-o" id="id
4">Local file I/O</a></p> |
| 10 <ul class="small-gap"> | 10 <ul class="small-gap"> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 <li><a class="reference internal" href="#loading-a-file" id="id18">Loading a fil
e</a></li> | 30 <li><a class="reference internal" href="#loading-a-file" id="id18">Loading a fil
e</a></li> |
| 31 <li><a class="reference internal" href="#id1" id="id19">Deleting a file</a></li> | 31 <li><a class="reference internal" href="#id1" id="id19">Deleting a file</a></li> |
| 32 <li><a class="reference internal" href="#listing-files-in-a-directory" id="id20"
>Listing files in a directory</a></li> | 32 <li><a class="reference internal" href="#listing-files-in-a-directory" id="id20"
>Listing files in a directory</a></li> |
| 33 <li><a class="reference internal" href="#making-a-new-directory" id="id21">Makin
g a new directory</a></li> | 33 <li><a class="reference internal" href="#making-a-new-directory" id="id21">Makin
g a new directory</a></li> |
| 34 </ul> | 34 </ul> |
| 35 </li> | 35 </li> |
| 36 </ul> | 36 </ul> |
| 37 | 37 |
| 38 </div><section id="introduction"> | 38 </div><section id="introduction"> |
| 39 <h2 id="introduction">Introduction</h2> | 39 <h2 id="introduction">Introduction</h2> |
| 40 <p>This chapter describes how to use the <a class="reference external" href="htt
ps://developers.google.com/native-client/peppercpp/classpp_1_1_file_i_o">FileIO
API</a> | 40 <p>This chapter describes how to use the <a class="reference external" href="/na
tive-client/pepper_stable/cpp/classpp_1_1_file_i_o">FileIO API</a> to read and w
rite |
| 41 to read and write files using a local secure data store.</p> | 41 files using a local secure data store.</p> |
| 42 <p>You might use the File IO API with the URL Loading APIs to create an overall | 42 <p>You might use the File IO API with the URL Loading APIs to create an overall |
| 43 data download and caching solution for your NaCl applications. For example:</p> | 43 data download and caching solution for your NaCl applications. For example:</p> |
| 44 <ol class="arabic simple"> | 44 <ol class="arabic simple"> |
| 45 <li>Use the File IO APIs to check the local disk to see if a file exists that | 45 <li>Use the File IO APIs to check the local disk to see if a file exists that |
| 46 your program needs.</li> | 46 your program needs.</li> |
| 47 <li>If the file exists locally, load it into memory using the File IO API. If | 47 <li>If the file exists locally, load it into memory using the File IO API. If |
| 48 the file doesn’t exist locally, use the URL Loading API to retrieve the | 48 the file doesn’t exist locally, use the URL Loading API to retrieve the |
| 49 file from the server.</li> | 49 file from the server.</li> |
| 50 <li>Use the File IO API to write the file to disk.</li> | 50 <li>Use the File IO API to write the file to disk.</li> |
| 51 <li>Load the file into memory using the File IO API when needed by your | 51 <li>Load the file into memory using the File IO API when needed by your |
| 52 application.</li> | 52 application.</li> |
| 53 </ol> | 53 </ol> |
| 54 <p>The example discussed in this chapter is included in the SDK in the directory | 54 <p>The example discussed in this chapter is included in the SDK in the directory |
| 55 <code>examples/api/file_io</code>.</p> | 55 <code>examples/api/file_io</code>.</p> |
| 56 </section><section id="reference-information"> | 56 </section><section id="reference-information"> |
| 57 <h2 id="reference-information">Reference information</h2> | 57 <h2 id="reference-information">Reference information</h2> |
| 58 <p>For reference information related to FileIO, see the following documentation:
</p> | 58 <p>For reference information related to FileIO, see the following documentation:
</p> |
| 59 <ul class="small-gap"> | 59 <ul class="small-gap"> |
| 60 <li><a class="reference external" href="https://developers.google.com/native-cli
ent/peppercpp/file__io_8h">file_io.h</a> - API | 60 <li><a class="reference external" href="/native-client/pepper_stable/cpp/file__i
o_8h">file_io.h</a> - API to create a |
| 61 to create a FileIO object</li> | 61 FileIO object</li> |
| 62 <li><a class="reference external" href="https://developers.google.com/native-cli
ent/peppercpp/file__ref_8h">file_ref.h</a> - API | 62 <li><a class="reference external" href="/native-client/pepper_stable/cpp/file__r
ef_8h">file_ref.h</a> - API to create |
| 63 to create a file reference or “weak pointer” to a file in a file sys
tem</li> | 63 a file reference or “weak pointer” to a file in a file system</li> |
| 64 <li><a class="reference external" href="https://developers.google.com/native-cli
ent/peppercpp/file__system_8h">file_system.h</a> - | 64 <li><a class="reference external" href="/native-client/pepper_stable/cpp/file__s
ystem_8h">file_system.h</a> - API to |
| 65 API to create a file system associated with a file</li> | 65 create a file system associated with a file</li> |
| 66 </ul> | 66 </ul> |
| 67 </section><section id="local-file-i-o"> | 67 </section><section id="local-file-i-o"> |
| 68 <h2 id="local-file-i-o">Local file I/O</h2> | 68 <h2 id="local-file-i-o">Local file I/O</h2> |
| 69 <p>Chrome provides an obfuscated, restricted area on disk to which a web app can | 69 <p>Chrome provides an obfuscated, restricted area on disk to which a web app can |
| 70 safely <a class="reference external" href="https://developers.google.com/chrome/
whitepapers/storage#persistent">read and write files</a>. The | 70 safely <a class="reference external" href="https://developers.google.com/chrome/
whitepapers/storage#persistent">read and write files</a>. The |
| 71 Pepper FileIO, FileRef, and FileSystem APIs (collectively called the File IO | 71 Pepper FileIO, FileRef, and FileSystem APIs (collectively called the File IO |
| 72 APIs) allow you to access this sandboxed local disk so you can read and write | 72 APIs) allow you to access this sandboxed local disk so you can read and write |
| 73 files and manage caching yourself. The data is persistent between launches of | 73 files and manage caching yourself. The data is persistent between launches of |
| 74 Chrome, and is not removed unless your application deletes it or the user | 74 Chrome, and is not removed unless your application deletes it or the user |
| 75 manually deletes it. There is no limit to the amount of local data you can | 75 manually deletes it. There is no limit to the amount of local data you can |
| 76 use, other than the actual space available on the local drive.</p> | 76 use, other than the actual space available on the local drive.</p> |
| 77 <section id="enabling-local-file-i-o"> | 77 <section id="enabling-local-file-i-o"> |
| 78 <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="quot
a-management"></span>Enabling local file I/O</h3> | 78 <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="quot
a-management"></span>Enabling local file I/O</h3> |
| 79 <p>The easiest way to enable the writing of persistent local data is to include | 79 <p>The easiest way to enable the writing of persistent local data is to include |
| 80 the <a class="reference external" href="http://developer.chrome.com/extensions/d
eclare_permissions.html#unlimitedStorage">unlimitedStorage permission</a> | 80 the <a class="reference external" href="/extensions/declare_permissions#unlimite
dStorage">unlimitedStorage permission</a> in your Chrome Web Store |
| 81 in your Chrome Web Store manifest file. With this permission you can use the | 81 manifest file. With this permission you can use the Pepper FileIO API without |
| 82 Pepper FileIO API without the need to request disk space at run time. When | 82 the need to request disk space at run time. When the user installs the app |
| 83 the user installs the app Chrome displays a message announcing that the app | 83 Chrome displays a message announcing that the app writes to the local disk.</p> |
| 84 writes to the local disk.</p> | |
| 85 <p>If you do not use the <code>unlimitedStorage</code> permission you must inclu
de | 84 <p>If you do not use the <code>unlimitedStorage</code> permission you must inclu
de |
| 86 JavaScript code that calls the <a class="reference external" href="http://update
s.html5rocks.com/2011/11/Quota-Management-API-Fast-Facts">HTML5 Quota Management
API</a> to | 85 JavaScript code that calls the <a class="reference external" href="http://update
s.html5rocks.com/2011/11/Quota-Management-API-Fast-Facts">HTML5 Quota Management
API</a> to |
| 87 explicitly request local disk space before using the FileIO API. In this case | 86 explicitly request local disk space before using the FileIO API. In this case |
| 88 Chrome will prompt the user to accept a requestQuota call every time one is | 87 Chrome will prompt the user to accept a requestQuota call every time one is |
| 89 made.</p> | 88 made.</p> |
| 90 </section><section id="testing-local-file-i-o"> | 89 </section><section id="testing-local-file-i-o"> |
| 91 <h3 id="testing-local-file-i-o">Testing local file I/O</h3> | 90 <h3 id="testing-local-file-i-o">Testing local file I/O</h3> |
| 92 <p>You should be aware that using the <code>unlimitedStorage</code> manifest per
mission | 91 <p>You should be aware that using the <code>unlimitedStorage</code> manifest per
mission |
| 93 constrains the way you can test your app. Three of the four techniques | 92 constrains the way you can test your app. Three of the four techniques |
| 94 described in <a class="reference internal" href="/native-client/devguide/devcycl
e/running.html"><em>Running Native Client Applications</em></a> | 93 described in <a class="reference internal" href="/native-client/devguide/devcycl
e/running.html"><em>Running Native Client Applications</em></a> |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 PP_MAKEDIRECTORYFLAG_NONE, pp::BlockUntilComplete()); | 488 PP_MAKEDIRECTORYFLAG_NONE, pp::BlockUntilComplete()); |
| 490 if (result != PP_OK) { | 489 if (result != PP_OK) { |
| 491 ShowErrorMessage("Make directory failed", result); | 490 ShowErrorMessage("Make directory failed", result); |
| 492 return; | 491 return; |
| 493 } | 492 } |
| 494 ShowStatusMessage("Make directory success"); | 493 ShowStatusMessage("Make directory success"); |
| 495 </pre> | 494 </pre> |
| 496 </section></section></section> | 495 </section></section></section> |
| 497 | 496 |
| 498 {{/partials.standard_nacl_article}} | 497 {{/partials.standard_nacl_article}} |
| OLD | NEW |