sabcom 0.0.1 → 0.0.2
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/LICENSE +21 -0
- package/README.md +122 -0
- package/package.json +16 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ivan Zakharchanka
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# SABCOM
|
|
2
|
+
|
|
3
|
+
[![Coverage Status][codecov-image]][codecov-url]
|
|
4
|
+
[![Github Build Status][github-image]][github-url]
|
|
5
|
+
[![NPM version][npm-image]][npm-url]
|
|
6
|
+
[![Downloads][downloads-image]][npm-url]
|
|
7
|
+
[![Snyk][snyk-image]][snyk-url]
|
|
8
|
+
|
|
9
|
+
A TypeScript/Node.js library for inter-thread communication using SharedArrayBuffer with atomic operations and V8 serialization.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Thread-safe communication** using atomic operations
|
|
14
|
+
- **Chunked data transfer** for large payloads
|
|
15
|
+
- **V8 serialization** for complex data types
|
|
16
|
+
- **Timeout handling** with configurable timeouts
|
|
17
|
+
- **Zero-copy operations** where possible
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install sabcom
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Basic Example
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { write, read } from 'sabcom';
|
|
31
|
+
|
|
32
|
+
// Create a shared buffer (1MB)
|
|
33
|
+
const buffer = new SharedArrayBuffer(1024 * 1024);
|
|
34
|
+
|
|
35
|
+
// Writer thread
|
|
36
|
+
const data = { message: 'Hello World', numbers: [1, 2, 3, 4, 5] };
|
|
37
|
+
write(data, buffer);
|
|
38
|
+
|
|
39
|
+
// Reader thread
|
|
40
|
+
const received = read(buffer);
|
|
41
|
+
console.log(received); // { message: 'Hello World', numbers: [1, 2, 3, 4, 5] }
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### With Custom Timeout
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// 10 second timeout
|
|
48
|
+
write(data, buffer, 10000);
|
|
49
|
+
const received = read(buffer, 10000);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## API Reference
|
|
53
|
+
|
|
54
|
+
### `write(data: unknown, buffer: SharedArrayBuffer, timeout?: number): void`
|
|
55
|
+
|
|
56
|
+
Writes data to the shared buffer using chunked transfer.
|
|
57
|
+
|
|
58
|
+
- `data` - Any serializable data
|
|
59
|
+
- `buffer` - SharedArrayBuffer for communication
|
|
60
|
+
- `timeout` - Timeout in milliseconds (default: 5000)
|
|
61
|
+
|
|
62
|
+
**Throws:**
|
|
63
|
+
- `Error` - On handshake or chunk timeout
|
|
64
|
+
|
|
65
|
+
### `read(buffer: SharedArrayBuffer, timeout?: number): unknown`
|
|
66
|
+
|
|
67
|
+
Reads data from the shared buffer.
|
|
68
|
+
|
|
69
|
+
- `buffer` - SharedArrayBuffer for communication
|
|
70
|
+
- `timeout` - Timeout in milliseconds (default: 5000)
|
|
71
|
+
|
|
72
|
+
**Returns:** Deserialized data
|
|
73
|
+
|
|
74
|
+
**Throws:**
|
|
75
|
+
- `Error` - On timeout or integrity failure
|
|
76
|
+
|
|
77
|
+
## Protocol
|
|
78
|
+
|
|
79
|
+
The library uses a header-based protocol with atomic operations:
|
|
80
|
+
|
|
81
|
+
1. **READY** - Buffer available for new transfer
|
|
82
|
+
2. **HANDSHAKE** - Writer sends total size and chunk count
|
|
83
|
+
3. **PAYLOAD** - Chunked data transfer with integrity checks
|
|
84
|
+
|
|
85
|
+
### Buffer Layout
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
[Header: 4 * HEADER_VALUES bytes] [Payload: remaining bytes]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Error Handling
|
|
92
|
+
|
|
93
|
+
- **Handshake timeout** - Reader not ready within timeout
|
|
94
|
+
- **Chunk timeout** - Individual chunk transfer timeout
|
|
95
|
+
- **Integrity failure** - Chunk index mismatch
|
|
96
|
+
- **Invalid state** - Unexpected semaphore state
|
|
97
|
+
|
|
98
|
+
## Thread Safety
|
|
99
|
+
|
|
100
|
+
Uses `Atomics.wait()`, `Atomics.notify()`, and `Atomics.store()` for synchronization. Requires SharedArrayBuffer support and proper threading context.
|
|
101
|
+
|
|
102
|
+
## Requirements
|
|
103
|
+
|
|
104
|
+
- Node.js with SharedArrayBuffer support
|
|
105
|
+
- Multi-threaded environment (Worker threads, etc.)
|
|
106
|
+
- V8 engine for serialization
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
License [The MIT License](./LICENSE)
|
|
112
|
+
Copyright (c) 2025 Ivan Zakharchanka
|
|
113
|
+
|
|
114
|
+
[npm-url]: https://www.npmjs.com/package/sabcom
|
|
115
|
+
[downloads-image]: https://img.shields.io/npm/dw/sabcom.svg?maxAge=43200
|
|
116
|
+
[npm-image]: https://img.shields.io/npm/v/sabcom.svg?maxAge=43200
|
|
117
|
+
[github-url]: https://github.com/3axap4eHko/sabcom/actions
|
|
118
|
+
[github-image]: https://github.com/3axap4eHko/sabcom/actions/workflows/build.yml/badge.svg?branch=master
|
|
119
|
+
[codecov-url]: https://codecov.io/gh/3axap4eHko/sabcom
|
|
120
|
+
[codecov-image]: https://codecov.io/gh/3axap4eHko/sabcom/branch/master/graph/badge.svg?maxAge=43200
|
|
121
|
+
[snyk-url]: https://snyk.io/test/npm/sabcom/latest
|
|
122
|
+
[snyk-image]: https://snyk.io/test/github/3axap4eHko/sabcom/badge.svg?maxAge=43200
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sabcom",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "A TypeScript/Node.js library for inter-thread communication using SharedArrayBuffer with atomic operations and V8 serialization",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
7
7
|
"main": "build/index.cjs",
|
|
@@ -14,7 +14,20 @@
|
|
|
14
14
|
"build",
|
|
15
15
|
"src/index.ts"
|
|
16
16
|
],
|
|
17
|
-
"
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/3axap4eHko/sabcom.git"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"SharedArrayBuffer",
|
|
23
|
+
"shared",
|
|
24
|
+
"atomic",
|
|
25
|
+
"buffer",
|
|
26
|
+
"thread",
|
|
27
|
+
"worker",
|
|
28
|
+
"communication"
|
|
29
|
+
],
|
|
30
|
+
"license": "MIT",
|
|
18
31
|
"author": {
|
|
19
32
|
"name": "Ivan Zakharchanka",
|
|
20
33
|
"email": "3axap4eHko@gmail.com",
|