merkle-btree
Version:
Content-addressed b-tree
34 lines (26 loc) • 919 B
JavaScript
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var IPFSStorage = function () {
function IPFSStorage(ipfs) {
_classCallCheck(this, IPFSStorage);
this.ipfs = ipfs;
}
IPFSStorage.prototype.put = function put(value) {
return this.ipfs.files.add(new Buffer(value, "utf8")).then(function (res) {
return res[0].hash;
});
};
IPFSStorage.prototype.get = function get(key) {
return this.ipfs.files.cat(key).then(function (file) {
return file.toString("utf8");
});
};
IPFSStorage.prototype.remove = function remove() {
// Apparently js-ipfs files are autoremoved if they are not pinned
return Promise.resolve();
};
IPFSStorage.prototype.clear = function clear() {
return Promise.resolve();
};
return IPFSStorage;
}();
export default IPFSStorage;