mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-12-23 18:31:08 +00:00
WORKERFS performance fix for reads; prepend "__" to store avoid local storage corruption
This commit is contained in:
parent
6670e27035
commit
2e37e22eb8
@ -53,6 +53,8 @@ TODO:
|
||||
- how to revert included files?
|
||||
- go to error in include files
|
||||
- BOM in upload/download?
|
||||
- don't mess with localStorage when migrating!
|
||||
|
||||
|
||||
WEB WORKER FORMAT
|
||||
|
||||
|
@ -112,7 +112,7 @@ function copyFromOldStorageFormat(platformid:string, newstore, callback:()=>void
|
||||
|
||||
function createNewPersistentStore(platformid:string, callback:()=>void) {
|
||||
var store = localforage.createInstance({
|
||||
name: platformid,
|
||||
name: "__" + platformid,
|
||||
version: 2.0
|
||||
});
|
||||
copyFromOldStorageFormat(platformid, store, callback);
|
||||
|
@ -337,10 +337,29 @@ function loadNative(modulename, debug) {
|
||||
|
||||
// mount the filesystem at /share
|
||||
function setupFS(FS, name) {
|
||||
var WORKERFS = FS.filesystems['WORKERFS']
|
||||
FS.mkdir('/share');
|
||||
FS.mount(FS.filesystems['WORKERFS'], {
|
||||
FS.mount(WORKERFS, {
|
||||
packages: [{ metadata: fsMeta[name], blob: fsBlob[name] }]
|
||||
}, '/share');
|
||||
// fix for slow Blob operations by caching typed arrays
|
||||
// https://github.com/kripken/emscripten/blob/incoming/src/library_workerfs.js
|
||||
var reader = WORKERFS.reader;
|
||||
var blobcache = {};
|
||||
WORKERFS.stream_ops.read = function (stream, buffer, offset, length, position) {
|
||||
if (position >= stream.node.size) return 0;
|
||||
var contents = blobcache[stream.path];
|
||||
if (!contents) {
|
||||
var ab = reader.readAsArrayBuffer(stream.node.contents);
|
||||
contents = blobcache[stream.path] = new Uint8Array(ab);
|
||||
}
|
||||
if (position + length > contents.length)
|
||||
length = contents.length - position;
|
||||
for (var i=0; i<length; i++) {
|
||||
buffer[offset+i] = contents[position+i];
|
||||
}
|
||||
return length;
|
||||
};
|
||||
}
|
||||
|
||||
var print_fn = function(s) {
|
||||
|
@ -63,8 +63,12 @@ describe('Store', function() {
|
||||
assert.equal('true', localItems['__migrated__TEST']);
|
||||
store.getItem('test', function(err, result) {
|
||||
if (err) done(err);
|
||||
// did it convert?
|
||||
assert.equal(result, 'a');
|
||||
assert.equal(7, localMods);
|
||||
// did we not mess with original storage?
|
||||
assert.equal(localStorage.getItem('_TEST/test'), 'a');
|
||||
assert.equal(localStorage.getItem('_TEST/local/test'), 'b');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user