@cocalc/project
Version:
CoCalc: project daemon
25 lines (23 loc) • 881 B
JavaScript
;
/*
Write a text file.
EXAMPLE:
curl -u `cat .smc/secret_token`: -d path=a.txt -d content="bar" http://localhost:`cat .smc/api-server.port`/api/v1/write-text-file
*/
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("util");
const fs_1 = require("fs");
const server_1 = require("./server");
async function writeTextFile({ path, content }) {
const dbg = server_1.client.dbg("write-text-file");
dbg(`path="${path}"`);
if (typeof path != "string") {
throw Error(`provide the path as a string -- got path="${path}"`);
}
if (typeof content != "string") {
throw Error(`provide the content as a string -- got content of type ${typeof content}`);
}
return await (0, util_1.promisify)(fs_1.writeFile)(path, content);
}
exports.default = writeTextFile;
//# sourceMappingURL=write-text-file.js.map