Home Reference Source Test
public class | source

IndexDBStorage

You can directly use an instance of this class. indexDBStorage

Extends:

BaseStorage → IndexDBStorage

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);
});

Test:

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:

NameTypeAttributeDescription
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 correctName(filePath: *): * source

Params:

NameTypeAttributeDescription
filePath *

Return:

*

public async deleteFileByPrefix(filePath: String ): Promise source

delete all files with name match prefix pattern return list of deleted files

Params:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
filePath String

Return:

Promise

List of filenames