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

Side by Side Diff: lib/io.js

Issue 5740786045943808: Issue 189 - Implement API changes from #117, #153, #192 in libadblockplus (Closed)
Patch Set: Created April 14, 2014, 9:14 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
« lib/init.js ('K') | « lib/init.js ('k') | lib/prefs.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 <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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 var IO = exports.IO = 18 var IO = exports.IO =
19 { 19 {
20 lineBreak: "\n", 20 lineBreak: "\n",
21 21
22 resolveFilePath: function(path) 22 resolveFilePath: function(path)
23 { 23 {
24 return new FakeFile(_fileSystem.resolve(path)); 24 return new FakeFile(_fileSystem.resolve(path));
25 }, 25 },
26 26
27 readFromFile: function(file, decode, listener, callback, timeLineID) 27 readFromFile: function(file, listener, callback, timeLineID)
28 { 28 {
29 if ("spec" in file && /^defaults\b/.test(file.spec))
30 {
31 // Code attempts to read the default patterns.ini, we don't have that.
32 // Make sure to execute first-run actions instead.
33 callback(null);
34 return;
35 }
36
37 _fileSystem.read(file.path, function(result) 29 _fileSystem.read(file.path, function(result)
38 { 30 {
39 if (result.error) 31 if (result.error)
40 callback(result.error); 32 callback(result.error);
41 else 33 else
42 { 34 {
43 var lines = result.content.split(/[\r\n]+/); 35 var lines = result.content.split(/[\r\n]+/);
44 for (var i = 0; i < lines.length; i++) 36 for (var i = 0; i < lines.length; i++)
45 listener.process(lines[i]); 37 listener.process(lines[i]);
46 listener.process(null); 38 listener.process(null);
47 callback(null); 39 callback(null);
48 } 40 }
49 }); 41 });
50 }, 42 },
51 43
52 writeToFile: function(file, encode, data, callback, timeLineID) 44 writeToFile: function(file, data, callback, timeLineID)
53 { 45 {
54 var content = data.join(this.lineBreak) + this.lineBreak; 46 var content = data.join(this.lineBreak) + this.lineBreak;
55 _fileSystem.write(file.path, content, callback); 47 _fileSystem.write(file.path, content, callback);
56 }, 48 },
57 49
58 copyFile: function(fromFile, toFile, callback) 50 copyFile: function(fromFile, toFile, callback)
59 { 51 {
60 // Simply combine read and write operations 52 // Simply combine read and write operations
61 var data = []; 53 var data = [];
62 this.readFromFile(fromFile, false, { 54 this.readFromFile(fromFile, {
63 process: function(line) 55 process: function(line)
64 { 56 {
65 if (line !== null) 57 if (line !== null)
66 data.push(line); 58 data.push(line);
67 } 59 }
68 }, function(e) 60 }, function(e)
69 { 61 {
70 if (e) 62 if (e)
71 callback(e); 63 callback(e);
72 else 64 else
73 this.writeToFile(toFile, false, data, callback); 65 this.writeToFile(toFile, data, callback);
74 }.bind(this)); 66 }.bind(this));
75 }, 67 },
76 68
77 renameFile: function(fromFile, newName, callback) 69 renameFile: function(fromFile, newName, callback)
78 { 70 {
79 _fileSystem.move(fromFile.path, newName, callback); 71 _fileSystem.move(fromFile.path, newName, callback);
80 }, 72 },
81 73
82 removeFile: function(file, callback) 74 removeFile: function(file, callback)
83 { 75 {
84 _fileSystem.remove(file.path, callback); 76 _fileSystem.remove(file.path, callback);
85 }, 77 },
86 78
87 statFile: function(file, callback) 79 statFile: function(file, callback)
88 { 80 {
89 _fileSystem.stat(file.path, function(result) 81 _fileSystem.stat(file.path, function(result)
90 { 82 {
91 callback(result.error, result); 83 callback(result.error, result);
92 }); 84 });
93 } 85 }
94 }; 86 };
OLDNEW
« lib/init.js ('K') | « lib/init.js ('k') | lib/prefs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld