Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/project/conat/files/read.ts
1712 views
1
/*
2
3
DEVELOPMENT:
4
5
6
1. Stop files:read service running in the project by running this in your browser:
7
8
await cc.client.conat_client.projectApi(cc.current()).system.terminate({service:'files:read'})
9
10
{status: 'terminated', service: 'files:read'}
11
12
You can also skip step 1 if you instead set COMPUTE_SERVER_ID to something nonzero...
13
14
2. Setup the project environment variables. Then start the server in node:
15
16
17
~/cocalc/src/packages/project/conat$ . project-env.sh
18
$ node
19
Welcome to Node.js v18.17.1.
20
Type ".help" for more information.
21
22
require('@cocalc/project/conat/files/read').init()
23
24
25
*/
26
27
import "@cocalc/project/conat/env"; // ensure conat env available
28
29
import { createReadStream as fs_createReadStream } from "fs";
30
import { compute_server_id, project_id } from "@cocalc/project/data";
31
import { join } from "path";
32
import {
33
createServer,
34
close as closeReadServer,
35
} from "@cocalc/conat/files/read";
36
37
function createReadStream(path: string) {
38
if (path[0] != "/" && process.env.HOME) {
39
path = join(process.env.HOME, path);
40
}
41
return fs_createReadStream(path);
42
}
43
44
// the project should call this on startup:
45
export async function init() {
46
await createServer({ project_id, compute_server_id, createReadStream });
47
}
48
49
export async function close() {
50
await closeReadServer({ project_id, compute_server_id });
51
}
52
53