-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
34 lines (28 loc) · 1011 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* 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 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 require('./mutable-file-wrapper.js')(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)
}
}
module.exports = storage