random-access-web
Advanced tools
Comparing version 2.0.2 to 2.0.3
76
index.js
@@ -24,3 +24,3 @@ /* global self */ | ||
if (typeof options === 'string') options = { name: options } | ||
return mutableStorage(options) | ||
return require('./mutable-file-wrapper.js')(options) | ||
} | ||
@@ -36,75 +36,1 @@ } else if (idb) { | ||
module.exports = storage | ||
function mutableStorage (options) { | ||
const randomAccess = require('random-access-storage') | ||
const mutableAccess = require('random-access-idb-mutable-file') | ||
let mounted = null | ||
let loading = null | ||
function doMount () { | ||
return mutableAccess.mount(options).then((requestFile) => { | ||
mounted = requestFile | ||
loading = null | ||
}) | ||
} | ||
return (name) => { | ||
let file = null | ||
return randomAccess({ | ||
open: function (req) { | ||
if (!mounted) { | ||
loading = doMount() | ||
} | ||
if(loading) { | ||
loading.then(() => { | ||
this._open(req) | ||
}, (err) => { | ||
req.callback(err) | ||
}) | ||
return | ||
} | ||
file = mounted(name) | ||
file._open(req) | ||
}, | ||
openReadonly: function (req) { | ||
if (!mounted) { | ||
loading = doMount() | ||
} | ||
if(loading) { | ||
loading.then(() => { | ||
this._openReadonly(req) | ||
}, (err) => { | ||
req.callback(err) | ||
}) | ||
return | ||
} | ||
file = mounted(name) | ||
file._openReadonly(req) | ||
}, | ||
write: function (req) { | ||
file._write(req) | ||
}, | ||
read: function (req) { | ||
file._read(req) | ||
}, | ||
del: function (req) { | ||
file._del(req) | ||
}, | ||
stat: function (req) { | ||
file._stat(req) | ||
}, | ||
close: function (req) { | ||
file._close(req) | ||
}, | ||
destroy: function (req) { | ||
file._destroy(req) | ||
} | ||
}) | ||
} | ||
} |
{ | ||
"name": "random-access-web", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Chooses the fastest random access backend based on the user's browser", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build-test": "browserify test.js > test-bundle.js" | ||
}, | ||
@@ -27,8 +28,15 @@ "repository": { | ||
"dependencies": { | ||
"random-access-idb-mutable-file": "^0.3.0", | ||
"@sammacbeth/random-access-idb-mutable-file": "^0.1.1", | ||
"random-access-chrome-file": "^1.1.2", | ||
"random-access-idb": "^1.2.1", | ||
"random-access-idb-mutable-file": "^0.3.0", | ||
"random-access-memory": "^3.1.1", | ||
"random-access-storage": "^1.3.0" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^16.3.0", | ||
"hyperdrive": "^9.14.5", | ||
"random-access-test": "github:random-access-storage/random-access-test", | ||
"tape": "^4.11.0" | ||
} | ||
} |
6564
7
121
6
4
+ Added@sammacbeth/random-access-idb-mutable-file@0.1.1(transitive)