Left: | ||
Right: |
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-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 13 matching lines...) Expand all Loading... | |
24 | 24 |
25 function loadFile(file, successCallback, errorCallback) | 25 function loadFile(file, successCallback, errorCallback) |
26 { | 26 { |
27 let key = fileToKey(file); | 27 let key = fileToKey(file); |
28 | 28 |
29 ext.storage.get([key], function(items) | 29 ext.storage.get([key], function(items) |
30 { | 30 { |
31 let entry = items[key]; | 31 let entry = items[key]; |
32 | 32 |
33 if (entry) | 33 if (entry) |
34 successCallback(entry); | 34 { |
35 if (typeof entry.content.multipartKeys != "undefined") | |
Sebastian Noack
2016/03/30 12:06:38
Please leave loadFile() untouched. There is no rea
| |
36 { | |
37 var multipartData = []; | |
38 ext.storage.get(entry.content.multipartKeys, function(parts) | |
39 { | |
40 for (var part in parts) | |
41 { | |
42 multipartData = multipartData.concat(parts[part]); | |
43 } | |
44 entry.content = multipartData; | |
45 successCallback(entry); | |
46 }, errorCallback); | |
47 } | |
48 else | |
49 { | |
50 successCallback(entry); | |
51 } | |
52 } | |
35 else | 53 else |
54 { | |
36 errorCallback(new Error("File doesn't exist")); | 55 errorCallback(new Error("File doesn't exist")); |
56 } | |
37 }); | 57 }); |
38 } | 58 } |
39 | 59 // Save the file, splitting it into chunks, if required. |
40 function saveFile(file, data, callback) | 60 function saveFile(file, data, callback) |
41 { | 61 { |
42 ext.storage.set( | 62 var storageList = {}; |
43 fileToKey(file), | 63 // Note: In future this should probably be something like |
64 // browser.storage.local.QUOTA_BYTES_PER_ITEM | |
65 var chunkSize = 104856; | |
Sebastian Noack
2016/03/30 12:06:37
They told me that each character is two bytes. Mor
Oleksandr
2016/03/31 09:59:54
Yes, strings are UTF-16 in Edge, unlike in Chrome
| |
66 if ((data.length > chunkSize) && (typeof browser == "object")) | |
67 { | |
68 for (var dataSize = 0; dataSize < data.length; dataSize += chunkSize) | |
44 { | 69 { |
45 content: data, | 70 var key = fileToKey(file) + "_" + dataSize; |
71 storageList[key] = data.slice(dataSize, dataSize + chunkSize); | |
Sebastian Noack
2016/03/30 12:06:38
Note that data is an array of strings, where each
Oleksandr
2016/03/31 09:59:54
Yep. For some reason I did not notice the data com
| |
72 } | |
73 storageList[fileToKey(file)] = { | |
74 content: { multipartKeys: Object.keys(storageList) }, | |
Sebastian Noack
2016/03/30 12:06:38
We can easily reconstruct the keys for the chunks.
| |
46 lastModified: Date.now() | 75 lastModified: Date.now() |
47 }, | 76 }; |
48 callback | 77 } |
49 ); | 78 else |
79 { | |
80 storageList[fileToKey(file)] = { | |
81 content: data, | |
82 lastModified: Date.now() | |
83 }; | |
84 } | |
85 ext.storage.setMultiple(storageList, callback); | |
50 } | 86 } |
51 | 87 |
52 exports.IO = | 88 exports.IO = |
53 { | 89 { |
54 resolveFilePath: function(path) | 90 resolveFilePath: function(path) |
55 { | 91 { |
56 return new FakeFile(path); | 92 return new FakeFile(path); |
57 }, | 93 }, |
58 | 94 |
59 readFromFile: function(file, listener, callback) | 95 readFromFile: function(file, listener, callback) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 { | 145 { |
110 callback(null, { | 146 callback(null, { |
111 exists: true, | 147 exists: true, |
112 lastModified: entry.lastModified | 148 lastModified: entry.lastModified |
113 }); | 149 }); |
114 } | 150 } |
115 | 151 |
116 loadFile(file, onLoaded, callback); | 152 loadFile(file, onLoaded, callback); |
117 } | 153 } |
118 }; | 154 }; |
OLD | NEW |