OLD | NEW |
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 "use strict"; | 18 "use strict"; |
19 | 19 |
20 function readFileAsync(fileName) | 20 function readFileAsync(fileName) |
21 { | 21 { |
22 return new Promise((resolve, reject) => | 22 return new Promise((resolve, reject) => |
23 { | 23 { |
24 _fileSystem.read(fileName, (result) => | 24 _fileSystem.read(fileName, resolve, reject); |
25 { | |
26 if (result.error) | |
27 return reject(result.error); | |
28 resolve(result); | |
29 }); | |
30 }); | 25 }); |
31 } | 26 } |
32 | 27 |
33 function writeFileAsync(fileName, content) | 28 function writeFileAsync(fileName, content) |
34 { | 29 { |
35 return new Promise((resolve, reject) => | 30 return new Promise((resolve, reject) => |
36 { | 31 { |
37 _fileSystem.write(fileName, content, (error) => | 32 _fileSystem.write(fileName, content, (error) => |
38 { | 33 { |
39 if (error) | 34 if (error) |
40 return reject(error); | 35 return reject(error); |
41 resolve(); | 36 resolve(); |
42 }); | 37 }); |
43 }); | 38 }); |
44 } | 39 } |
45 | 40 |
46 exports.IO = | 41 exports.IO = |
47 { | 42 { |
48 lineBreak: "\n", | 43 lineBreak: "\n", |
49 | 44 |
50 readFromFile(fileName, listener) | 45 readFromFile(fileName, listener) |
51 { | 46 { |
52 return new Promise((resolve, reject) => | 47 return new Promise((resolve, reject) => |
53 { | 48 { |
54 _fileSystem.readFromFile(fileName, listener, (error) => | 49 _fileSystem.readFromFile(fileName, listener, resolve, reject); |
55 { | |
56 if (error) | |
57 return reject(error); | |
58 resolve(); | |
59 }); | |
60 }); | 50 }); |
61 }, | 51 }, |
62 | 52 |
63 writeToFile(fileName, generator) | 53 writeToFile(fileName, generator) |
64 { | 54 { |
65 let content = Array.from(generator).join(this.lineBreak) + this.lineBreak; | 55 let content = Array.from(generator).join(this.lineBreak) + this.lineBreak; |
66 return writeFileAsync(fileName, content); | 56 return writeFileAsync(fileName, content); |
67 }, | 57 }, |
68 | 58 |
69 copyFile(fromFileName, toFileName) | 59 copyFile(fromFileName, toFileName) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 { | 94 { |
105 _fileSystem.stat(fileName, (result) => | 95 _fileSystem.stat(fileName, (result) => |
106 { | 96 { |
107 if (result.error) | 97 if (result.error) |
108 return reject(result.error); | 98 return reject(result.error); |
109 resolve(result); | 99 resolve(result); |
110 }); | 100 }); |
111 }); | 101 }); |
112 } | 102 } |
113 }; | 103 }; |
OLD | NEW |