Left: | ||
Right: |
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"]) |
Sebastian Noack
2016/09/08 15:27:22
Please check for entry["compressed"], otherwise, i
| |
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)); |
Sebastian Noack
2016/09/08 15:27:22
(Why) do we need to call JSON.stringifiy() here? I
Oleksandr
2016/09/08 23:51:57
'data' here is an array of strings, which are line
| |
92 ext.storage.remove(key); | 92 ext.storage.remove(key); |
93 entry[key] = {lastModified: Date.now(), content: processedData, | 93 entry[key] = {lastModified: Date.now(), content: processedData, |
94 compressed: true}; | 94 compressed: true}; |
95 window.localStorage.setItem(key, JSON.stringify(entry[key])); | 95 window.localStorage.setItem(key, JSON.stringify(entry[key])); |
96 callback(); | 96 callback(); |
97 } | 97 } |
98 }, | 98 }, |
99 | 99 |
100 statFile: function(file, callback) | 100 statFile: function(file, callback) |
101 { | 101 { |
102 function onLoaded(entry) | 102 function onLoaded(entry) |
103 { | 103 { |
104 callback(null, { | 104 callback(null, { |
105 exists: true, | 105 exists: true, |
106 lastModified: entry.lastModified | 106 lastModified: entry.lastModified |
107 }); | 107 }); |
108 } | 108 } |
109 | 109 |
110 loadFile(file).then(onLoaded, callback); | 110 loadFile(file).then(onLoaded, callback); |
111 } | 111 } |
112 }; | 112 }; |
LEFT | RIGHT |