Factory for creating platform-specific random-access-storage files.
$ npm install @dxos/random-access-multi-storage
import { createStorage } from '@dxos/random-access-multi-storage';
const storage = createStorage('./dir');
const file = storage('test.txt')
file.write(0, Buffer('hello'), err => {
file.read(0, 5, (err, data) => {
console.log(data.toString())
})
});
createStorage(rootPath: String, storageType?: StorageType) => RandomAccessStorage
Create a RandomAccessStorage based in the storageType
. If storageType
is not specified, return a default RandomAccessStorage
depending on the environment.
rootPath
: Root path to store the files.storageType
: Storage type.Available storages:
import { STORAGE_CHROME, STORAGE_FIREFOX, ... } from '@dxos/random-access-multi-storage'
browser
STORAGE_CHROME
: Store files using random-access-chrome-file and the Chromium File System API. Default in Chrome.STORAGE_FIREFOX
: Store files using random-access-idb-mutable-file and the Firefox IDBMutableFile. Default in Firefox.STORAGE_IDB
: Store files in an IDB database using random-access-idb. Fallback.STORAGE_RAM
: random-access-memory.node
STORAGE_NODE
: Store files in the real filesystem random-access-file. Default.STORAGE_RAM
: random-access-memory.PRs accepted.
GPL-3.0 © dxos