UNPKG

@kyve/core-beta

Version:

🚀 The base KYVE node implementation.

43 lines (42 loc) • 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LevelDBCache = void 0; const fs_1 = require("fs"); const level_1 = require("level"); class LevelDBCache { constructor() { this.name = "LevelDBCache"; } async init(path) { this.path = path; if (!(0, fs_1.existsSync)(this.path)) { (0, fs_1.mkdirSync)(this.path, { recursive: true }); } this.db = new level_1.Level(this.path, { valueEncoding: "json", }); await this.drop(); } async put(key, value) { await this.db.put(key, value); } async get(key) { return await this.db.get(key); } async exists(key) { try { await this.db.get(key); return true; } catch { return false; } } async del(key) { await this.db.del(key); } async drop() { await this.db.clear(); } } exports.LevelDBCache = LevelDBCache;