IndexDBStorage
Extends:
This indexDBStorage class is the default consistent storage based on leveldown storage with support file extends: png, csv, text by those corresponding mixins. { mixWith: { 'node': [LevelDownMixins, TextFileMixins, PNGFileMixins, CSVFileMixins], 'web': [LevelJSMixins, TextFileMixins, PNGFileMixins, CSVFileMixins] } }
Example:
import { indexDBStorage } from 'causal-net.storage';
(async ()=>{
await indexDBStorage.writeFile('/temp','12345');
let content = await indexDBStorage.readFile('/temp');
console.log({content});
//get file list
let listFiles = await indexDBStorage.getFileList('/');
console.log({listFiles});
//fetch png image and save pixel data into file
const url = 'https://avatars3.githubusercontent.com/u/43268620?s=200&v=4';
await indexDBStorage.fetchPNGFile(url, 'icon');
const pixelArray = await indexDBStorage.readPNGFile('icon');
console.log({ pixelArray });
let ops = [
{ type: 'put', key: 'temp', value: '123445' },
{ type: 'del', key: 'temp' }];
//batch does not support 'get' type
let batchResult = await indexDBStorage.batch(ops);
console.log({batchResult});
})().catch(err=>{
console.error(err);
});
Method Summary
Public Methods | ||
public |
async batch(key: String ): Promise Batch operation with Array of ops |
|
public |
correctName(filePath: *): * |
|
public |
async deleteFileByPrefix(filePath: String ): Promise delete all files with name match prefix pattern return list of deleted files |
|
public |
async getFileList(filePath: String ): Promise get list of file base on prefix |
Public Methods
public async batch(key: String ): Promise source
Batch operation with Array of ops
Params:
Name | Type | Attribute | Description |
key | String |
Return:
Promise | key promise |
Example:
let ops = [
{ type: 'put', key: 'temp', value: '123445' },
{ type: 'del', key: 'temp' }];
//batch does not support 'get' type
let batchResult = await indexDBStorage.batch(ops);
public async deleteFileByPrefix(filePath: String ): Promise source
delete all files with name match prefix pattern return list of deleted files
Params:
Name | Type | Attribute | Description |
filePath | String | pattern of file path |
Return:
Promise | deleted files list promise |
public async getFileList(filePath: String ): Promise source
get list of file base on prefix
Params:
Name | Type | Attribute | Description |
filePath | String |
Return:
Promise | List of filenames |