Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/database/filesystem-bucket.coffee
Views: 687
#########################################################################1# This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2# License: MS-RSL – see LICENSE.md for details3#########################################################################45###6Filesystem based bucket -- same api as gcloud bucket.78Motivation: in KuCalc we use gcsfuse to just mount the smc-blobs bucket9defined in smc-gcloud.10###1112fs = require('fs')1314{defaults} = misc = require('@cocalc/util/misc')15required = defaults.required1617exports.filesystem_bucket = (opts) ->18opts = defaults opts,19name : required20if not opts.name21throw Error("bucket name must be specified")22return new FilesystemBucket(opts.name)2324class FilesystemBucket25constructor: (@path) ->2627blob_path: (name) =>28return "#{@path}/#{name}"2930write: (opts) =>31opts = defaults opts,32name : required33content : required34cb : required35fs.writeFile(@blob_path(opts.name), opts.content, opts.cb)363738read: (opts) =>39opts = defaults opts,40name : required41cb : required42fs.readFile(@blob_path(opts.name), opts.cb)4344delete: (opts) =>45opts = defaults opts,46name : required47cb : undefined48fs.unlink(@blob_path(opts.name), (err)->opts.cb?(err))4950