UNPKG

@silver-zepp/easy-storage

Version:

The Easy Storage library offers a suite of storage solutions designed for ZeppOS applications, providing a range of data persistence strategies to accommodate different data management needs.

3 lines (2 loc) 1.47 kB
/** @about Easy Storage @min_zeppos 2.0 @author: Silver, Zepp Health. @license: MIT */ import{listDirectory,loadJson,makeDirectory,readAsset,readFile,removeFile,saveJson,stat,writeAsset,writeFile}from"./core/core";export class Storage{static WriteJson(filename,json){saveJson(filename,json)}static ReadJson(filename,strinfigy=false){return!strinfigy?loadJson(filename):JSON.stringify(loadJson(filename))}static WriteFile(filename,data){writeFile(filename,data)}static ReadFile(filename){return readFile(filename)}static RemoveFile(filename){return removeFile(filename)}static WriteAsset(filename,data){writeAsset(filename,data)}static ReadAsset(filename){return readAsset(filename)}static MakeDirectory(dirname){return makeDirectory(dirname)}static ListDirectory(dirname){return listDirectory(dirname)}static FileInfo(path){return stat(path)}static Exists(path){const info=Storage.FileInfo(path);return info!==null&&info!==undefined&&typeof info==="object"}static CopyFile(src,dest){const data=Storage.ReadFile(src);if(data!=="")Storage.WriteFile(dest,data)}static MoveFile(src,dest){Storage.CopyFile(src,dest);Storage.RemoveFile(src)}static IsFile(path){const info=Storage.FileInfo(path);return info?info.isFile:false}static IsDir(path){const info=Storage.FileInfo(path);return info?info.isDir:false}static FileSize(path){const info=Storage.FileInfo(path);return info?info.size:0}static FileChangeTime(path){const info=Storage.FileInfo(path);return info?info.mtimeMs:0}}