Random Access Multi Storage
Factory for creating platform-specific random-access-storage files.
Install
$ npm install @dxos/random-access-multi-storage
Usage
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())
})
});
API
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 { StorageType, ... } from '@dxos/random-access-multi-storage'
-
browser
-
StorageType.CHROME
: Store files using random-access-chrome-file and the Chromium File System API. Default in Chrome. -
StorageType.FIREFOX
: Store files using random-access-idb-mutable-file and the Firefox IDBMutableFile. Default in Firefox. -
StorageType.IDB
: Store files in an IDB database using random-access-idb. Fallback. -
StorageType.RAM
: random-access-memory.
-
-
node
-
StorageType.NODE
: Store files in the real filesystem random-access-file. Default. -
StorageType.RAM
: random-access-memory.
-
Contributing
PRs accepted.
License
GPL-3.0 © dxos