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-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 |
(...skipping 12 matching lines...) Expand all Loading... |
23 { | 23 { |
24 return keyPrefix + fileName; | 24 return keyPrefix + fileName; |
25 } | 25 } |
26 | 26 |
27 function loadFile(fileName) | 27 function loadFile(fileName) |
28 { | 28 { |
29 return new Promise((resolve, reject) => | 29 return new Promise((resolve, reject) => |
30 { | 30 { |
31 localforage.getItem(fileToKey(fileName), (err, value) => | 31 localforage.getItem(fileToKey(fileName), (err, value) => |
32 { | 32 { |
33 if (err || !value) | 33 if (err || value == null) |
34 reject({type: "NoSuchFile"}); | 34 reject({type: "NoSuchFile"}); |
35 else | 35 else |
36 resolve(value); | 36 resolve(value); |
37 }); | 37 }); |
38 }); | 38 }); |
39 } | 39 } |
40 | 40 |
41 function saveFile(fileName, data) | 41 function saveFile(fileName, data) |
42 { | 42 { |
43 let key = fileToKey(fileName); | 43 let key = fileToKey(fileName); |
(...skipping 25 matching lines...) Expand all Loading... |
69 * Name of the file to be read | 69 * Name of the file to be read |
70 * @param {TextSink} listener | 70 * @param {TextSink} listener |
71 * Function that will be called for each line in the file | 71 * Function that will be called for each line in the file |
72 * @return {Promise} | 72 * @return {Promise} |
73 * Promise to be resolved or rejected once the operation is completed | 73 * Promise to be resolved or rejected once the operation is completed |
74 */ | 74 */ |
75 readFromFile(fileName, listener) | 75 readFromFile(fileName, listener) |
76 { | 76 { |
77 return loadFile(fileName).then(entry => | 77 return loadFile(fileName).then(entry => |
78 { | 78 { |
79 if ("content" in entry) | 79 for (let line of entry.content) |
80 { | 80 listener(line); |
81 for (let line of entry.content) | |
82 listener(line); | |
83 } | |
84 }); | 81 }); |
85 }, | 82 }, |
86 | 83 |
87 /** | 84 /** |
88 * Writes text lines to a file. | 85 * Writes text lines to a file. |
89 * @param {string} fileName | 86 * @param {string} fileName |
90 * Name of the file to be written | 87 * Name of the file to be written |
91 * @param {Iterable.<string>} data | 88 * @param {Iterable.<string>} data |
92 * An array-like or iterable object containing the lines (without line | 89 * An array-like or iterable object containing the lines (without line |
93 * endings) | 90 * endings) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 lastModified: entry.lastModified | 156 lastModified: entry.lastModified |
160 }; | 157 }; |
161 }).catch(error => | 158 }).catch(error => |
162 { | 159 { |
163 if (error.type == "NoSuchFile") | 160 if (error.type == "NoSuchFile") |
164 return {exists: false}; | 161 return {exists: false}; |
165 throw error; | 162 throw error; |
166 }); | 163 }); |
167 } | 164 } |
168 }; | 165 }; |
LEFT | RIGHT |