cryptpad/www/common/inner/cache.js

36 lines
985 B
JavaScript
Raw Normal View History

define([
], function () {
var S = {};
S.create = function (sframeChan) {
var getBlobCache = function (id, cb) {
sframeChan.query('Q_GET_BLOB_CACHE', {id:id}, function (err, data) {
var e = err || (data && data.error);
if (e) { return void cb(e); }
if (!data || typeof(data) !== "object") { return void cb('EINVAL'); }
2020-11-30 13:40:07 +00:00
var u8 = Uint8Array.from(data);
cb(null, u8);
});
};
var setBlobCache = function (id, u8, cb) {
2020-11-30 13:40:07 +00:00
var array = [].slice.call(u8);
sframeChan.query('Q_SET_BLOB_CACHE', {
id: id,
2020-11-30 13:40:07 +00:00
u8: array
}, function (err, data) {
var e = err || (data && data.error) || undefined;
cb(e);
});
};
return {
getBlobCache: getBlobCache,
setBlobCache: setBlobCache
};
};
return S;
});