| 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 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 { | 55 { |
| 56 return new FakeFile(path); | 56 return new FakeFile(path); |
| 57 }, | 57 }, |
| 58 | 58 |
| 59 readFromFile: function(file, listener, callback) | 59 readFromFile: function(file, listener, callback) |
| 60 { | 60 { |
| 61 function onLoaded(entry) | 61 function onLoaded(entry) |
| 62 { | 62 { |
| 63 if ("content" in entry) | 63 if ("content" in entry) |
| 64 { | 64 { |
| 65 if ("compressed" in entry) | 65 if (entry["compressed"]) |
| 66 entry.content = JSON.parse(LZString.decompressFromUTF16(entry.content)
); | 66 entry.content = JSON.parse(LZString.decompressFromUTF16(entry.content)
); |
| 67 for (let line of entry.content) | 67 for (let line of entry.content) |
| 68 listener.process(line); | 68 listener.process(line); |
| 69 } | 69 } |
| 70 callback(null); | 70 callback(null); |
| 71 } | 71 } |
| 72 | 72 |
| 73 loadFile(file).then(onLoaded, callback); | 73 loadFile(file).then(onLoaded, callback); |
| 74 }, | 74 }, |
| 75 | 75 |
| 76 writeToFile: function(file, data, callback) | 76 writeToFile: function(file, data, callback) |
| 77 { | 77 { |
| 78 let entry = {}; | 78 let entry = {}; |
| 79 let key = fileToKey(file); | 79 let key = fileToKey(file); |
| 80 | 80 |
| 81 if (typeof browser == "undefined") | 81 if (typeof browser == "undefined") |
| 82 { | 82 { |
| 83 entry[key] = {lastModified: Date.now(), content: data}; | 83 entry[key] = {lastModified: Date.now(), content: data}; |
| 84 ext.storage.set(entry, callback); | 84 ext.storage.set(entry, callback); |
| 85 } | 85 } |
| 86 else | 86 else |
| 87 { | 87 { |
| 88 // Edge cannot write files larger than 1Mb (500k string in UTF-16) via | 88 // Edge cannot write files larger than 1Mb (500k string in UTF-16) via |
| 89 // storage API. However it does not always raise an exception when trying | 89 // storage API. However it does not always raise an exception when trying |
| 90 // to do so. The solution is to compress and fallback to localStorage | 90 // to do so. The solution is to compress and fallback to localStorage. |
| 91 let processedData = LZString.compressToUTF16(JSON.stringify(data)); | 91 let processedData = LZString.compressToUTF16(JSON.stringify(data)); |
| 92 ext.storage.remove(key); | 92 ext.storage.remove(key); |
| 93 entry[key] = {lastModified: Date.now(), | 93 entry[key] = {lastModified: Date.now(), content: processedData, |
| 94 content: processedData, | |
| 95 compressed: true}; | 94 compressed: true}; |
| 96 window.localStorage.setItem(key, JSON.stringify(entry[key])); | 95 window.localStorage.setItem(key, JSON.stringify(entry[key])); |
| 97 callback(); | 96 callback(); |
| 98 } | 97 } |
| 99 }, | 98 }, |
| 100 | 99 |
| 101 statFile: function(file, callback) | 100 statFile: function(file, callback) |
| 102 { | 101 { |
| 103 function onLoaded(entry) | 102 function onLoaded(entry) |
| 104 { | 103 { |
| 105 callback(null, { | 104 callback(null, { |
| 106 exists: true, | 105 exists: true, |
| 107 lastModified: entry.lastModified | 106 lastModified: entry.lastModified |
| 108 }); | 107 }); |
| 109 } | 108 } |
| 110 | 109 |
| 111 loadFile(file).then(onLoaded, callback); | 110 loadFile(file).then(onLoaded, callback); |
| 112 } | 111 } |
| 113 }; | 112 }; |
| LEFT | RIGHT |