UNPKG

merkle-btree

Version:
58 lines (43 loc) 1.29 kB
'use strict'; exports.__esModule = true; var _crypto = require('crypto'); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var RAMStorage = function () { function RAMStorage() { _classCallCheck(this, RAMStorage); this.storage = {}; } RAMStorage.prototype.put = function put(value) { var _this = this; return new Promise(function (resolve) { (0, _crypto.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; }(); exports.default = RAMStorage; module.exports = exports['default'];