Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: chrome/common/extensions/docs/server2/templates/articles/app_storage.html

Issue 10914284: Rename chrome.fileSystem apis to be expandable to directories if we wish. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Typo Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 <h1>Manage Data</h1> 1 <h1>Manage Data</h1>
2 2
3 3
4 <p> 4 <p>
5 Almost every aspect of app development involves some element 5 Almost every aspect of app development involves some element
6 of sending or receiving data. 6 of sending or receiving data.
7 Starting with the basics, 7 Starting with the basics,
8 you should use an MVC framework to help you design and implement your app 8 you should use an MVC framework to help you design and implement your app
9 so that data is completely separate from the app's view on that data 9 so that data is completely separate from the app's view on that data
10 (see <a href="app_frameworks.html">MVC Architecture</a>). 10 (see <a href="app_frameworks.html">MVC Architecture</a>).
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 <p> 160 <p>
161 The following code opens the file (read-only) and 161 The following code opens the file (read-only) and
162 reads it as text using a <code>FileReader</code> object. 162 reads it as text using a <code>FileReader</code> object.
163 If the file doesn't exist, an error is thrown. 163 If the file doesn't exist, an error is thrown.
164 </p> 164 </p>
165 165
166 <pre> 166 <pre>
167 var chosenFileEntry = null; 167 var chosenFileEntry = null;
168 168
169 chooseFileButton.addEventListener('click', function(e) { 169 chooseFileButton.addEventListener('click', function(e) {
170 chrome.fileSystem.chooseFile({type: 'openFile'}, function(readOnlyEntry) { 170 chrome.fileSystem.chooseEntry({type: 'openFile'}, function(readOnlyEntry) {
171 171
172 readOnlyEntry.file(function(file) { 172 readOnlyEntry.file(function(file) {
173 var reader = new FileReader(); 173 var reader = new FileReader();
174 174
175 reader.onerror = errorHandler; 175 reader.onerror = errorHandler;
176 reader.onloadend = function(e) { 176 reader.onloadend = function(e) {
177 console.log(e.target.result); 177 console.log(e.target.result);
178 }; 178 };
179 179
180 reader.readAsText(file); 180 reader.readAsText(file);
181 }); 181 });
182 }); 182 });
183 }); 183 });
184 </pre> 184 </pre>
185 185
186 <h2 id="write">Writing a file</h2> 186 <h2 id="write">Writing a file</h2>
187 187
188 <p> 188 <p>
189 The two common use-cases 189 The two common use-cases
190 for writing a file are "Save" and "Save as". 190 for writing a file are "Save" and "Save as".
191 The following code creates a 191 The following code creates a
192 <code>writableFileEntry</code> 192 <code>writableEntry</code>
193 from the read-only <code>chosenFileEntry</code> and 193 from the read-only <code>chosenFileEntry</code> and
194 writes the selected file to it. 194 writes the selected file to it.
195 </p> 195 </p>
196 196
197 <pre> 197 <pre>
198 chrome.fileSystem.getWritableFileEntry(chosenFileEntry, function(writableFileEn try) { 198 chrome.fileSystem.getWritableEntry(chosenFileEntry, function(writableFileEntry) {
199 writableFileEntry.createWriter(function(writer) { 199 writableFileEntry.createWriter(function(writer) {
200 writer.onerror = errorHandler; 200 writer.onerror = errorHandler;
201 writer.onwriteend = callback; 201 writer.onwriteend = callback;
202 202
203 chosenFileEntry.file(function(file) { 203 chosenFileEntry.file(function(file) {
204 writer.write(file); 204 writer.write(file);
205 }); 205 });
206 }, errorHandler); 206 }, errorHandler);
207 }); 207 });
208 </pre> 208 </pre>
209 209
210 <p> 210 <p>
211 The following code creates a new file 211 The following code creates a new file
212 with "Save as" functionality and 212 with "Save as" functionality and
213 writes the new blob to the file 213 writes the new blob to the file
214 using the <code>writer.write()</code> method. 214 using the <code>writer.write()</code> method.
215 </p> 215 </p>
216 216
217 <pre> 217 <pre>
218 chrome.fileSystem.chooseFile({type: 'saveFile'}, function(writableFileEntry) { 218 chrome.fileSystem.chooseEntry({type: 'saveFile'}, function(writableFileEntry) {
219 writableFileEntry.createWriter(function(writer) { 219 writableFileEntry.createWriter(function(writer) {
220 writer.onerror = errorHandler; 220 writer.onerror = errorHandler;
221 writer.onwriteend = function(e) { 221 writer.onwriteend = function(e) {
222 console.log('write complete'); 222 console.log('write complete');
223 }; 223 };
224 writer.write(new Blob(['1234567890'], {type: 'text/plain'})); 224 writer.write(new Blob(['1234567890'], {type: 'text/plain'}));
225 }, errorHandler); 225 }, errorHandler);
226 }); 226 });
227 </pre> 227 </pre>
228 228
229 <p class="backtotop"><a href="#top">Back to top</a></p> 229 <p class="backtotop"><a href="#top">Back to top</a></p>
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/file_system.idl ('k') | chrome/renderer/resources/extensions/file_system_custom_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698