Index: lib/io.js |
=================================================================== |
--- a/lib/io.js |
+++ b/lib/io.js |
@@ -31,22 +31,58 @@ |
let entry = items[key]; |
if (entry) |
- successCallback(entry); |
+ { |
+ if (typeof entry.content.multipartKeys != "undefined") |
Sebastian Noack
2016/03/30 12:06:38
Please leave loadFile() untouched. There is no rea
|
+ { |
+ var multipartData = []; |
+ ext.storage.get(entry.content.multipartKeys, function(parts) |
+ { |
+ for (var part in parts) |
+ { |
+ multipartData = multipartData.concat(parts[part]); |
+ } |
+ entry.content = multipartData; |
+ successCallback(entry); |
+ }, errorCallback); |
+ } |
+ else |
+ { |
+ successCallback(entry); |
+ } |
+ } |
else |
+ { |
errorCallback(new Error("File doesn't exist")); |
+ } |
}); |
} |
- |
+// Save the file, splitting it into chunks, if required. |
function saveFile(file, data, callback) |
{ |
- ext.storage.set( |
- fileToKey(file), |
+ var storageList = {}; |
+ // Note: In future this should probably be something like |
+ // browser.storage.local.QUOTA_BYTES_PER_ITEM |
+ 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
|
+ if ((data.length > chunkSize) && (typeof browser == "object")) |
+ { |
+ for (var dataSize = 0; dataSize < data.length; dataSize += chunkSize) |
{ |
- content: data, |
+ var key = fileToKey(file) + "_" + dataSize; |
+ 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
|
+ } |
+ storageList[fileToKey(file)] = { |
+ content: { multipartKeys: Object.keys(storageList) }, |
Sebastian Noack
2016/03/30 12:06:38
We can easily reconstruct the keys for the chunks.
|
lastModified: Date.now() |
- }, |
- callback |
- ); |
+ }; |
+ } |
+ else |
+ { |
+ storageList[fileToKey(file)] = { |
+ content: data, |
+ lastModified: Date.now() |
+ }; |
+ } |
+ ext.storage.setMultiple(storageList, callback); |
} |
exports.IO = |