Skip to content

Instantly share code, notes, and snippets.

@ralphtheninja
Created February 1, 2022 23:21
Show Gist options
  • Save ralphtheninja/12b4f4bdc2fa82730d46321b8d45ad97 to your computer and use it in GitHub Desktop.
Save ralphtheninja/12b4f4bdc2fa82730d46321b8d45ad97 to your computer and use it in GitHub Desktop.
mixmap storage wrapper
/**
* Storage wrapper object for relaying operations to backend.
*/
module.exports = function (backend) {
var storageFn = function (name) {
return {
write: function (offset, buf, cb) {
cb(new Error('write not implemented'))
},
truncate: function (length, cb) {
cb(new Error('truncate not implemented'))
},
del: function (cb) {
cb(new Error('del not implemented'))
},
sync: function (cb) {
cb(new Error('sync not implemented'))
},
length: function (cb) {
backend.length(name, cb)
},
read: function (offset, length, cb) {
backend.read(name,offset, length, cb)
}
}
}
storageFn.getBackend = function () { return backend }
storageFn.setBackend = function (_backend) { backend = _backend }
storageFn.destroy = function (name, cb) { backend.destroy(name, cb) }
return storageFn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment