Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/io.js

Issue 29339112: Issue 3716 - Split up files stored in storage.local (Closed)
Patch Set: Created March 30, 2016, 4:50 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« chrome/ext/background.js ('K') | « chrome/ext/background.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 =
« chrome/ext/background.js ('K') | « chrome/ext/background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld