random-access-web
Advanced tools
Comparing version 1.1.0 to 2.0.0
112
index.js
@@ -1,28 +0,108 @@ | ||
const global = (typeof window !== 'undefined') ? window : self; | ||
/* global self */ | ||
const global = (typeof window !== 'undefined') ? window : self | ||
const requestFileSystem = global.requestFileSystem || global.webkitRequestFileSystem | ||
const mutableFile = global.IDBMutableFile | ||
const idb = global.indexedDB | ||
const DEFAULT_DB_NAME = 'random-access-web' | ||
let init = async (options={}) => { | ||
if(typeof options === 'string') options = {name: options} | ||
const name = options.name || DEFAULT_DB_NAME | ||
return require('random-access-idb')(name) | ||
let storage = () => require('random-access-memory') | ||
if (requestFileSystem) { | ||
storage = (options) => { | ||
const RACF = require('random-access-chrome-file') | ||
if ((typeof options === 'object') && options.maxSize) { | ||
RACF.DEFAULT_MAX_SIZE = options.maxSize | ||
} | ||
return RACF | ||
} | ||
} else if (mutableFile) { | ||
storage = (options = {}) => { | ||
if (typeof options === 'string') options = { name: options } | ||
return mutableStorage(options) | ||
} | ||
} else if (idb) { | ||
storage = (options = {}) => { | ||
if (typeof options === 'string') options = { name: options } | ||
const name = options.name || DEFAULT_DB_NAME | ||
return require('random-access-idb')(name, options) | ||
} | ||
} | ||
if(requestFileSystem) { | ||
init = async (options) => { | ||
return require('random-access-chrome-file') | ||
module.exports = storage | ||
function mutableStorage (options) { | ||
const randomAccess = require('random-access-storage') | ||
const mutableAccess = require('@sammacbeth/random-access-idb-mutable-file') | ||
let mounted = null | ||
let loading = null | ||
function doMount () { | ||
return mutableAccess.mount(options).then((requestFile) => { | ||
mounted = requestFile | ||
loading = null | ||
}) | ||
} | ||
} else if(mutableFile) { | ||
init = async (options) => { | ||
const RandomAccess = require('@sammacbeth/random-access-idb-mutable-file') | ||
return RandomAccess.mount() | ||
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) | ||
} | ||
}) | ||
} | ||
} | ||
module.exports = { | ||
init | ||
} |
{ | ||
"name": "random-access-web", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Chooses the fastest random access backend based on the user's browser", | ||
@@ -29,4 +29,6 @@ "main": "index.js", | ||
"random-access-chrome-file": "^1.1.2", | ||
"random-access-idb": "^1.2.1" | ||
"random-access-idb": "^1.2.1", | ||
"random-access-memory": "^3.1.1", | ||
"random-access-storage": "^1.3.0" | ||
} | ||
} |
@@ -9,5 +9,5 @@ # random-access-web | ||
```js | ||
const RandomAccessWeb = require('random-access-web') | ||
const RAW = require('random-access-web') | ||
const storage = await RandomAccessWeb.init() | ||
const storage = RAW('dats') | ||
@@ -14,0 +14,0 @@ const dat = new DatJs({ |
Sorry, the diff of this file is not supported yet
4714
93
5
+ Addedrandom-access-memory@^3.1.1
+ Addedrandom-access-storage@^1.3.0
+ Addedb4a@1.6.6(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedis-options@1.0.2(transitive)
+ Addedqueue-tick@1.0.1(transitive)
+ Addedrandom-access-memory@3.1.4(transitive)
+ Addedrandom-access-storage@1.4.3(transitive)