UNPKG

merkle-btree

Version:
53 lines (40 loc) 1.2 kB
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } import { randomBytes } from 'crypto'; var RAMStorage = function () { function RAMStorage() { _classCallCheck(this, RAMStorage); this.storage = {}; } RAMStorage.prototype.put = function put(value) { var _this = this; return new Promise(function (resolve) { randomBytes(32, function (err, buffer) { var key = buffer.toString('base64'); _this.storage[key] = value; resolve(key); }); }); }; RAMStorage.prototype.get = function get(key) { var _this2 = this; return new Promise(function (resolve) { resolve(_this2.storage[key]); }); }; RAMStorage.prototype.remove = function remove(key) { var _this3 = this; return new Promise(function (resolve) { delete _this3.storage[key]; resolve(); }); }; RAMStorage.prototype.clear = function clear() { var _this4 = this; return new Promise(function (resolve) { _this4.storage = {}; resolve(); }); }; return RAMStorage; }(); export default RAMStorage;