geonix 1.8.10 → 1.8.11
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/package.json +5 -5
- package/src/Connection.js +2 -2
- package/test/.env +1 -0
- package/test/package.json +3 -1
- package/test/stream.js +1 -1
- package/test/stream2.js +43 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geonix",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "",
|
|
6
6
|
"bin": {
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"cookie-parser": "^1.4.6",
|
|
19
|
-
"express": "^4.18.
|
|
19
|
+
"express": "^4.18.2",
|
|
20
20
|
"express-async-errors": "^3.1.1",
|
|
21
21
|
"express-ws": "^5.0.2",
|
|
22
22
|
"multer": "^1.4.5-lts.1",
|
|
23
|
-
"nats": "^2.
|
|
24
|
-
"semver": "^7.
|
|
25
|
-
"ws": "^8.
|
|
23
|
+
"nats": "^2.16.0",
|
|
24
|
+
"semver": "^7.5.4",
|
|
25
|
+
"ws": "^8.13.0"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"registry": "https://registry.npmjs.org/"
|
package/src/Connection.js
CHANGED
|
@@ -102,10 +102,10 @@ class Connection {
|
|
|
102
102
|
if (payload.length > this.getMaxPayloadSize())
|
|
103
103
|
payload = codec.encode(Stream(JSON.stringify({ $r: respondTo, p: json })))
|
|
104
104
|
|
|
105
|
-
await this.#nc.publish(subject, payload)
|
|
106
|
-
|
|
107
105
|
let response = await this.#nc.subscribe(respondTo, { max: 1, ...options })
|
|
108
106
|
|
|
107
|
+
await this.#nc.publish(subject, payload)
|
|
108
|
+
|
|
109
109
|
for await (let event of response)
|
|
110
110
|
return codec.decode(event.data)
|
|
111
111
|
}
|
package/test/.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
TRANSPORT=nats://phobos.tria.hr:4222
|
package/test/package.json
CHANGED
package/test/stream.js
CHANGED
|
@@ -8,7 +8,7 @@ await connection.waitUntilReady()
|
|
|
8
8
|
|
|
9
9
|
const hash = data => createHash('sha512').update(data).digest('base64')
|
|
10
10
|
|
|
11
|
-
const PAYLOAD_SIZE = 1024 * 1024 *
|
|
11
|
+
const PAYLOAD_SIZE = 1024 * 1024 * 10
|
|
12
12
|
const TEMP_FILE = '/tmp/geonix.stream_test'
|
|
13
13
|
|
|
14
14
|
console.time('test')
|
package/test/stream2.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import 'dotenv/config'
|
|
2
|
+
import { randomBytes } from 'node:crypto'
|
|
3
|
+
import { Stream, Remote, getReadable, connection, Service, streamToBuffer } from 'geonix'
|
|
4
|
+
import { createWriteStream, readFileSync } from 'node:fs'
|
|
5
|
+
import { createHash } from 'node:crypto'
|
|
6
|
+
import { pipeline } from 'node:stream/promises'
|
|
7
|
+
|
|
8
|
+
const hash = data => createHash('sha256').update(data).digest('base64')
|
|
9
|
+
const self = Remote('StreamTest')
|
|
10
|
+
|
|
11
|
+
class StreamTest extends Service {
|
|
12
|
+
|
|
13
|
+
async onStart() {
|
|
14
|
+
const perform = async (n) => {
|
|
15
|
+
const fileName = `${n}.random`
|
|
16
|
+
const { checksum, stream } = await self.readFile(fileName)
|
|
17
|
+
const data = await streamToBuffer(stream)
|
|
18
|
+
const verification = hash(data)
|
|
19
|
+
|
|
20
|
+
console.log(`${fileName} - ${data.length} bytes - ${checksum === verification}`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const jobs = []
|
|
24
|
+
for (let n = 0; n < 1024; n++)
|
|
25
|
+
jobs.push(perform(n))
|
|
26
|
+
|
|
27
|
+
await Promise.all(jobs)
|
|
28
|
+
|
|
29
|
+
console.log('done')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async readFile(fileName, size = 1024 * Math.round(Math.random() * 1024)) {
|
|
33
|
+
const bytes = randomBytes(size)
|
|
34
|
+
const checksum = hash(bytes)
|
|
35
|
+
|
|
36
|
+
console.log(size)
|
|
37
|
+
return { checksum, stream: Stream(bytes) }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
StreamTest.start()
|