-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (60 loc) · 2.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Require Node.js Dependencies
const { createReadStream } = require("fs");
const { resolve } = require("path");
// Require Third-party Dependencies
const TcpSdk = require("@slimio/tcp-sdk");
// CONSTANTS
const TCP_CONNECT_TIMEOUT_MS = 1000;
const fileToTransfer = [
"Addon-alerting-1.0.0.tar",
"Addon-gate-1.0.0.tar",
"Addon-gate-1.0.1.tar",
"Addon-gate-1.1.0.tar",
"Addon-gate-1.1.2.tar",
"Addon-socket-1.0.0.tar"
];
async function transferFile(client, fileName) {
try {
const id = await client.sendOne("prism.start_bundle", fileName);
const readStream = createReadStream(resolve("archives", fileName));
for await (const chunk of readStream) {
await client.sendOne("prism.send_bundle", [id, chunk.toJSON()]);
}
const result = await client.sendOne("prism.end_bundle", id);
}
catch (err) {
console.log(err);
}
}
async function sendFiles(client) {
console.time("transfer");
// await Promise.all(fileToTransfer.map((file) => transferFile(client, file)));
console.log("start !");
const id = await client.sendOne("prism.start_bundle", "Addon-aggregator-0.1.0.tar");
const readStream = createReadStream(resolve("archives", "Addon-aggregator-0.1.0.tar"));
console.log("send !");
for await (const chunk of readStream) {
await client.sendOne("prism.send_bundle", [id, chunk.toJSON()]);
}
console.log("end !");
const result = await client.sendOne("prism.end_bundle", id);
console.timeEnd("transfer");
}
async function install(client) {
await client.sendOne("prism.install_archive", [10, "0.1.0"]);
}
async function main() {
// const client = new TcpSdk({ host: "79.92.140.15", port: 5002 });
const client = new TcpSdk({ host: "localhost", port: 1337 });
client.catch((err) => console.error(err));
await client.once("connect", TCP_CONNECT_TIMEOUT_MS);
console.log("connected !");
await sendFiles(client);
console.log("install !");
await install(client);
console.log("end install !");
client.close();
// const result = await client.sendOne("prism.receive_bundle", readStream);
// console.log(result);
}
main().catch(console.error);