Storage
is a utility library that provides static methods for direct file operations. This includes reading and writing JSON objects, text, and binary data directly to and from the filesystem.
npm i @silver-zepp/easy-storage
import { Storage } from "@silver-zepp/easy-storage";
Storage.WriteFile("log.txt", "log entry example");
console.log(Storage.ReadFile("log.txt"));
WriteJson(filename,json)
: Writes a JSON object to a file.ReadJson(filename)
: Reads a JSON object from a file.WriteFile(filename, data)
: Writes data to a file.ReadFile(filename)
: Reads data from a file.RemoveFile(filename)
: Deletes a file.WriteAsset(filename, data)
: Writes data to an asset file.ReadAsset(filename)
: Reads data from an asset file.MakeDirectory(dirname)
: Creates a new directory.ListDirectory(dirname)
: Lists contents of a directory.
Writes a JSON object to a specified file.
filename
{string} - The name of the file to write the JSON object to.json
{object} - The JSON object to be written.
Storage.WriteJson('config.json', { key: 'value' });
Reads a JSON object from a specified file.
filename
{string} - The name of the file to read the JSON object from.
const config = Storage.ReadJson('config.json');
object
- The JSON object read from the file.
Writes data to a specified file.
filename
{string} - The name of the file to write data to.data
{string|ArrayBuffer} - The data to be written.
Storage.WriteFile('example.txt', 'Hello, World!');
Reads data from a specified file.
filename
{string} - The name of the file to read data from.
const data = Storage.ReadFile('example.txt');
string
- The data read from the file.
Removes a specified file from the filesystem.
filename
{string} - The name of the file to be removed.
Storage.RemoveFile('obsolete_data.txt');
Methods for writing to and reading from asset files, functioning similarly to their file counterparts but intended for asset management.