diff --git a/doc/notes.txt b/doc/notes.txt index fba114c5..d9dc6d53 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -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 diff --git a/src/store.ts b/src/store.ts index a89f0071..7406c2cc 100644 --- a/src/store.ts +++ b/src/store.ts @@ -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); diff --git a/src/worker/workermain.js b/src/worker/workermain.js index 413dc2bf..afa9911b 100644 --- a/src/worker/workermain.js +++ b/src/worker/workermain.js @@ -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