๐Ÿ“ฆ EasyFlashStorage for ZeppOS

Description

EasyFlashStorage provides a filesystem-based storage solution for large or persistent data, suitable for cases where data size exceeds the practical limits of in-memory storage.

To install the library run (from the root of your project)

npm i @silver-zepp/easy-storage

[ ๐Ÿ“ Download examples ]

[ ๐Ÿ“ Class Map ]

[ ๐Ÿ“ API Reference ]

[ โฌ…๏ธ Back to Index ]

Example

import { EasyFlashStorage } from "@silver-zepp/easy-storage";
const flash = new EasyFlashStorage();

flash.setKey("config", { theme: "dark", notifications: true, ... });
console.log(flash.getKey("config"));

๐Ÿ“ EasyFlashStorage Class Map ย 

๐Ÿ“ EasyFlashStorage API Reference

constructor(directory = "easy_flash_storage")

Initializes the storage with a specified directory.

Parameters

Examples

const flash = new EasyFlashStorage();
// or
const custom_dir_storage = new EasyFlashStorage('my_custom_dir');

setKey(key, value)

Stores or updates a value associated with a key. The value is serialized to JSON and written to a file named after the key.

Parameters

Examples

flash.setKey('config', { theme: 'dark' });

getKey(key)

Retrieves the value associated with the specified key from the storage.

Parameters

Examples

console.log(flash.getKey('config'));

Returns

any - The value associated with the key, or undefined if not found.

hasKey(key)

Checks if the specified key exists in the storage.

Parameters

Examples

console.log(flash.hasKey('config')); // true or false

Returns

boolean - True if the key exists, false otherwise.

removeKey(key)

Removes the specified key and its associated file from the storage.

Parameters

Examples

flash.removeKey('config');

getAllKeys(stringify = false)

Retrieves all keys stored in the storage, optionally stringified.

Parameters

Examples

console.log(flash.getAllKeys());
console.log(flash.getAllKeys(true));

Returns

string | array - The keys as a JSON string if stringify is true, or as an array if false.

deleteAll()

Removes all keys and their associated values from the storage.

Examples

flash.deleteAll();

printAllKeys()

Prints all keys and their associated values to the console.

Examples

flash.printAllKeys();

dataSize(key, unit = 'B')

Returns the size of the data associated with a specific key.

Parameters

Examples

console.log(flash.dataSize('config'));
console.log(flash.dataSize('config', 'KB'));

size(unit = 'B')

Calculates the total size of all stored data.

Parameters

Examples

console.log(flash.size());
console.log(flash.size('KB'));