Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/io.js

Issue 6612223174639616: Issue 1602 - Use ES6 generators instead of legacy generators (Closed)
Patch Set: Created March 31, 2015, 6:24 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/filterStorage.js ('k') | lib/notification.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } catch (e) {} 62 } catch (e) {}
63 63
64 return null; 64 return null;
65 }, 65 },
66 66
67 /** 67 /**
68 * Reads strings from a file asynchronously, calls listener.process() with 68 * Reads strings from a file asynchronously, calls listener.process() with
69 * each line read and with a null parameter once the read operation is done. 69 * each line read and with a null parameter once the read operation is done.
70 * The callback will be called when the operation is done. 70 * The callback will be called when the operation is done.
71 */ 71 */
72 readFromFile: function(/**nsIFile*/ file, /**Object*/ listener, /**Function*/ callback) 72 readFromFile: function*(/**nsIFile*/ file, /**Object*/ listener, /**Function*/ callback)
73 { 73 {
74 try 74 try
75 { 75 {
76 let processing = false; 76 let processing = false;
77 let buffer = ""; 77 let buffer = "";
78 let loaded = false; 78 let loaded = false;
79 let error = null; 79 let error = null;
80 80
81 let onProgress = function(data) 81 let onProgress = function(data)
82 { 82 {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 catch (e) 187 catch (e)
188 { 188 {
189 callback(e); 189 callback(e);
190 } 190 }
191 }, 191 },
192 192
193 /** 193 /**
194 * Writes string data to a file in UTF-8 format asynchronously. The callback 194 * Writes string data to a file in UTF-8 format asynchronously. The callback
195 * will be called when the write operation is done. 195 * will be called when the write operation is done.
196 */ 196 */
197 writeToFile: function(/**nsIFile*/ file, /**Iterator*/ data, /**Function*/ cal lback) 197 writeToFile: function*(/**nsIFile*/ file, /**Iterator*/ data, /**Function*/ ca llback)
198 { 198 {
199 try 199 try
200 { 200 {
201 let encoder = new TextEncoder(); 201 let encoder = new TextEncoder();
202 202
203 Task.spawn(function() 203 Task.spawn(function()
204 { 204 {
205 // This mimics OS.File.writeAtomic() but writes in chunks. 205 // This mimics OS.File.writeAtomic() but writes in chunks.
206 let tmpPath = file.path + ".tmp"; 206 let tmpPath = file.path + ".tmp";
207 let f = yield OS.File.open(tmpPath, {write: true, truncate: true}); 207 let f = yield OS.File.open(tmpPath, {write: true, truncate: true});
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 else 323 else
324 callback(e); 324 callback(e);
325 }); 325 });
326 } 326 }
327 catch(e) 327 catch(e)
328 { 328 {
329 callback(e); 329 callback(e);
330 } 330 }
331 } 331 }
332 } 332 }
OLDNEW
« no previous file with comments | « lib/filterStorage.js ('k') | lib/notification.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld