CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/project/servers/hub/read-text-file-from-project.ts
Views: 687
1
import * as message from "@cocalc/util/message";
2
import { readFile } from "fs/promises";
3
4
export default async function readTextFileFromProject(
5
socket,
6
mesg
7
): Promise<void> {
8
const { path } = mesg;
9
try {
10
const content = (await readFile(path)).toString();
11
socket.write_mesg(
12
"json",
13
message.text_file_read_from_project({ id: mesg.id, content })
14
);
15
} catch (err) {
16
socket.write_mesg(
17
"json",
18
message.error({ id: mesg.id, error: err.message })
19
);
20
}
21
}
22
23