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

Side by Side Diff: lib/io.js

Issue 4831974724206592: Issue 192 - Clean up from #153 (Closed)
Patch Set: Created April 14, 2014, 6:56 a.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') | no next file » | 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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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, /**Boolean*/ decode, /**Object*/ lis tener, /**Function*/ callback, /**String*/ timeLineID) 72 readFromFile: function(/**nsIFile*/ file, /**Object*/ listener, /**Function*/ callback, /**String*/ timeLineID)
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 yield f.close(); 196 yield f.close();
197 }.bind(this)).then(onSuccess, onError); 197 }.bind(this)).then(onSuccess, onError);
198 } 198 }
199 catch (e) 199 catch (e)
200 { 200 {
201 callback(e); 201 callback(e);
202 } 202 }
203 }, 203 },
204 204
205 /** 205 /**
206 * Writes string data to a file asynchronously, optionally encodes it into 206 * Writes string data to a file in UTF-8 format asynchronously. The callback
207 * UTF-8 first. The callback will be called when the write operation is done. 207 * will be called when the write operation is done.
208 */ 208 */
209 writeToFile: function(/**nsIFile*/ file, /**Boolean*/ encode, /**Iterator*/ da ta, /**Function*/ callback, /**String*/ timeLineID) 209 writeToFile: function(/**nsIFile*/ file, /**Iterator*/ data, /**Function*/ cal lback, /**String*/ timeLineID)
210 { 210 {
211 try 211 try
212 { 212 {
213 let encoder = new TextEncoder(); 213 let encoder = new TextEncoder();
214 214
215 Task.spawn(function() 215 Task.spawn(function()
216 { 216 {
217 // This mimics OS.File.writeAtomic() but writes in chunks. 217 // This mimics OS.File.writeAtomic() but writes in chunks.
218 let tmpPath = file.path + ".tmp"; 218 let tmpPath = file.path + ".tmp";
219 let f = yield OS.File.open(tmpPath, {write: true, truncate: true}); 219 let f = yield OS.File.open(tmpPath, {write: true, truncate: true});
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 else 335 else
336 callback(e); 336 callback(e);
337 }); 337 });
338 } 338 }
339 catch(e) 339 catch(e)
340 { 340 {
341 callback(e); 341 callback(e);
342 } 342 }
343 } 343 }
344 } 344 }
OLDNEW
« no previous file with comments | « lib/filterStorage.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld