smc-hub
Version:
CoCalc: Backend webserver component
76 lines (62 loc) • 1.96 kB
JavaScript
// Generated by CoffeeScript 2.5.1
(function() {
//########################################################################
// This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
// License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
//########################################################################
/*
Filesystem based bucket -- same api as gcloud bucket.
Motivation: in KuCalc we use gcsfuse to just mount the smc-blobs bucket
defined in smc-gcloud.
*/
var FilesystemBucket, defaults, fs, misc, required;
fs = require('fs');
({defaults} = misc = require('smc-util/misc'));
required = defaults.required;
exports.filesystem_bucket = function(opts) {
opts = defaults(opts, {
name: required
});
if (!opts.name) {
throw Error("bucket name must be specified");
}
return new FilesystemBucket(opts.name);
};
FilesystemBucket = class FilesystemBucket {
constructor(path) {
this.blob_path = this.blob_path.bind(this);
this.write = this.write.bind(this);
this.read = this.read.bind(this);
this.delete = this.delete.bind(this);
this.path = path;
}
blob_path(name) {
return `${this.path}/${name}`;
}
write(opts) {
opts = defaults(opts, {
name: required,
content: required,
cb: required
});
return fs.writeFile(this.blob_path(opts.name), opts.content, opts.cb);
}
read(opts) {
opts = defaults(opts, {
name: required,
cb: required
});
return fs.readFile(this.blob_path(opts.name), opts.cb);
}
delete(opts) {
opts = defaults(opts, {
name: required,
cb: void 0
});
return fs.unlink(this.blob_path(opts.name), function(err) {
return typeof opts.cb === "function" ? opts.cb(err) : void 0;
});
}
};
}).call(this);
//# sourceMappingURL=filesystem-bucket.js.map