LEFT | RIGHT |
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 |
| 18 "use strict"; |
17 | 19 |
18 const keyPrefix = "file:"; | 20 const keyPrefix = "file:"; |
19 | 21 |
20 function fileToKey(file) | 22 function fileToKey(file) |
21 { | 23 { |
22 return keyPrefix + (file instanceof FakeFile ? file.path : file.spec); | 24 return keyPrefix + (file instanceof FakeFile ? file.path : file.spec); |
23 } | 25 } |
24 | 26 |
25 function loadFile(file, successCallback, errorCallback) | 27 function loadFile(file, successCallback, errorCallback) |
26 { | 28 { |
(...skipping 17 matching lines...) Expand all Loading... |
44 { | 46 { |
45 content: Array.from(data), | 47 content: Array.from(data), |
46 lastModified: Date.now() | 48 lastModified: Date.now() |
47 }, | 49 }, |
48 callback | 50 callback |
49 ); | 51 ); |
50 } | 52 } |
51 | 53 |
52 exports.IO = | 54 exports.IO = |
53 { | 55 { |
54 resolveFilePath: path => new FakeFile(path), | 56 resolveFilePath(path) { return new FakeFile(path); }, |
55 | 57 |
56 readFromFile: (file, listener, callback) => | 58 readFromFile(file, listener, callback) |
57 { | 59 { |
58 function onLoaded(entry) | 60 function onLoaded(entry) |
59 { | 61 { |
60 for (let line of entry.content) | 62 for (let line of entry.content) |
61 listener.process(line); | 63 listener.process(line); |
62 | 64 |
63 listener.process(null); | 65 listener.process(null); |
64 callback(null); | 66 callback(null); |
65 } | 67 } |
66 | 68 |
67 loadFile(file, onLoaded, callback); | 69 loadFile(file, onLoaded, callback); |
68 }, | 70 }, |
69 | 71 |
70 writeToFile: (file, data, callback) => | 72 writeToFile(file, data, callback) |
71 { | 73 { |
72 saveFile(file, data, callback); | 74 saveFile(file, data, callback); |
73 }, | 75 }, |
74 | 76 |
75 copyFile: (fromFile, toFile, callback) => | 77 copyFile(fromFile, toFile, callback) |
76 { | 78 { |
77 function onLoaded(entry) | 79 function onLoaded(entry) |
78 { | 80 { |
79 saveFile(toFile, entry.content, callback); | 81 saveFile(toFile, entry.content, callback); |
80 } | 82 } |
81 | 83 |
82 loadFile(fromFile, onLoaded, callback); | 84 loadFile(fromFile, onLoaded, callback); |
83 }, | 85 }, |
84 | 86 |
85 renameFile: (fromFile, newName, callback) => | 87 renameFile(fromFile, newName, callback) |
86 { | 88 { |
87 function onLoaded(entry) | 89 function onLoaded(entry) |
88 { | 90 { |
89 ext.storage.remove(fileToKey(fromFile), () => | 91 ext.storage.remove(fileToKey(fromFile), () => |
90 { | 92 { |
91 ext.storage.set(keyPrefix + newName, entry, callback); | 93 ext.storage.set(keyPrefix + newName, entry, callback); |
92 }); | 94 }); |
93 } | 95 } |
94 | 96 |
95 loadFile(fromFile, onLoaded, callback); | 97 loadFile(fromFile, onLoaded, callback); |
96 }, | 98 }, |
97 | 99 |
98 removeFile: (file, callback) => | 100 removeFile(file, callback) |
99 { | 101 { |
100 ext.storage.remove(fileToKey(file), callback); | 102 ext.storage.remove(fileToKey(file), callback); |
101 }, | 103 }, |
102 | 104 |
103 statFile: (file, callback) => | 105 statFile(file, callback) |
104 { | 106 { |
105 function onLoaded(entry) | 107 function onLoaded(entry) |
106 { | 108 { |
107 callback(null, { | 109 callback(null, { |
108 exists: true, | 110 exists: true, |
109 lastModified: entry.lastModified | 111 lastModified: entry.lastModified |
110 }); | 112 }); |
111 } | 113 } |
112 | 114 |
113 loadFile(file, onLoaded, callback); | 115 loadFile(file, onLoaded, callback); |
114 } | 116 } |
115 }; | 117 }; |
LEFT | RIGHT |