split-frames 2.4.5 → 2.5.1
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 +13 -13
- package/README.md +263 -263
- package/lib/cjs/SplitFrames.d.ts +52 -0
- package/lib/cjs/SplitFrames.js +385 -0
- package/lib/cjs/checkers/checkTagsValidity.d.ts +2 -0
- package/lib/cjs/checkers/checkTagsValidity.js +20 -0
- package/lib/cjs/checkers/initData.d.ts +2 -0
- package/lib/cjs/checkers/initData.js +89 -0
- package/lib/cjs/main.cjs +8 -0
- package/lib/cjs/main.d.cts +2 -0
- package/package.json +95 -96
- package/lib/checkers/checkTagsValidity.js +0 -26
- package/lib/checkers/initData.js +0 -123
- package/lib/digesters/digestEndOnly.js +0 -73
- package/lib/digesters/digestNoStartNoEnd.js +0 -38
- package/lib/digesters/digestStartAndEnd.js +0 -92
- package/lib/digesters/digestStartOnly.js +0 -71
- package/lib/index.d.ts +0 -55
- package/lib/main.js +0 -377
package/package.json
CHANGED
|
@@ -1,96 +1,95 @@
|
|
|
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
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
"homepage": "https://github.com/Psychopoulet/split-frames#readme",
|
|
88
|
-
"repository": {
|
|
89
|
-
"type": "git",
|
|
90
|
-
"url": "git://github.com/Psychopoulet/split-frames"
|
|
91
|
-
},
|
|
92
|
-
"bugs": {
|
|
93
|
-
"url": "https://github.com/Psychopoulet/split-frames/issues"
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "split-frames",
|
|
3
|
+
"version": "2.5.1",
|
|
4
|
+
"description": "Split Buffer frames from streams",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"typings": "./lib/cjs/main.d.cts",
|
|
7
|
+
"main": "./lib/cjs/main.cjs",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"require": {
|
|
11
|
+
"types": "./lib/cjs/main.d.cts",
|
|
12
|
+
"default": "./lib/cjs/main.cjs"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"prepare": "husky",
|
|
18
|
+
"clean": "npx rimraf lib/cjs",
|
|
19
|
+
"build": "npm run-script clean && npx tsc --project \"./tsconfig.json\"",
|
|
20
|
+
"lint": "npx eslint --config .eslintrc-src.js --ext .cts,.ts ./lib/src/**/* && npx eslint --config .eslintrc-tests.js ./bin/*.js ./test/**/*.js",
|
|
21
|
+
"check-requires": "npx used-deps-analyzer \"./package.json\" \"./lib/src\" --no-dev --overkill \"fs-extra\" \"node-promfs\"",
|
|
22
|
+
"check-updates": "npx check-version-modules",
|
|
23
|
+
"unit-tests": "npm run-script build && npx nyc --reporter=html --reporter=text mocha",
|
|
24
|
+
"tests": "npm run-script lint && npm run-script check-requires && npm run-script check-updates && npm run-script unit-tests"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"/bin",
|
|
28
|
+
"/lib/cjs",
|
|
29
|
+
"/public"
|
|
30
|
+
],
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=16.0.0"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "22.7.8",
|
|
37
|
+
"check-version-modules": "2.1.2",
|
|
38
|
+
"colors": "1.4.0",
|
|
39
|
+
"eslint-plugin-personnallinter": "git+ssh://git@github.com/Psychopoulet/eslint-plugin-personnallinter",
|
|
40
|
+
"husky": "9.1.6",
|
|
41
|
+
"mocha": "10.7.3",
|
|
42
|
+
"nyc": "17.1.0",
|
|
43
|
+
"rimraf": "6.0.1",
|
|
44
|
+
"typescript": "5.6.3",
|
|
45
|
+
"used-deps-analyzer": "0.1.8"
|
|
46
|
+
},
|
|
47
|
+
"optionalDependencies": {},
|
|
48
|
+
"husky": {
|
|
49
|
+
"hooks": {
|
|
50
|
+
"pre-commit": "npm run-script lint",
|
|
51
|
+
"pre-push": "npm run-script unit-tests",
|
|
52
|
+
"pre-receive": "npm run-script tests"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"keywords": [
|
|
56
|
+
"frame",
|
|
57
|
+
"Buffer",
|
|
58
|
+
"buffer",
|
|
59
|
+
"split",
|
|
60
|
+
"formate",
|
|
61
|
+
"parse",
|
|
62
|
+
"escape",
|
|
63
|
+
"bit",
|
|
64
|
+
"stream",
|
|
65
|
+
"Transform",
|
|
66
|
+
"transform",
|
|
67
|
+
"STX",
|
|
68
|
+
"ETX",
|
|
69
|
+
"ACK",
|
|
70
|
+
"WAK",
|
|
71
|
+
"NAK",
|
|
72
|
+
"DLE",
|
|
73
|
+
"industrial",
|
|
74
|
+
"protocol",
|
|
75
|
+
"LRC",
|
|
76
|
+
"MSB",
|
|
77
|
+
"LSB"
|
|
78
|
+
],
|
|
79
|
+
"author": "Sébastien VIDAL",
|
|
80
|
+
"contributors": [
|
|
81
|
+
{
|
|
82
|
+
"name": "07ke",
|
|
83
|
+
"url": "https://github.com/07ke"
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"license": "ISC",
|
|
87
|
+
"homepage": "https://github.com/Psychopoulet/split-frames#readme",
|
|
88
|
+
"repository": {
|
|
89
|
+
"type": "git",
|
|
90
|
+
"url": "git://github.com/Psychopoulet/split-frames"
|
|
91
|
+
},
|
|
92
|
+
"bugs": {
|
|
93
|
+
"url": "https://github.com/Psychopoulet/split-frames/issues"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
module.exports = (tags) => {
|
|
4
|
-
|
|
5
|
-
let result = true;
|
|
6
|
-
|
|
7
|
-
if (
|
|
8
|
-
"number" !== typeof tags && "object" !== typeof tags && !(tags instanceof Array || tags instanceof Buffer)
|
|
9
|
-
) {
|
|
10
|
-
result = false;
|
|
11
|
-
}
|
|
12
|
-
else if ("object" === typeof tags && tags instanceof Array) {
|
|
13
|
-
|
|
14
|
-
for (let i = 0; i < tags.length; ++i) {
|
|
15
|
-
|
|
16
|
-
if ("number" !== typeof tags[i] && "object" !== typeof tags[i] && !(tags[i] instanceof Buffer)) {
|
|
17
|
-
result = false; break;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return result;
|
|
25
|
-
|
|
26
|
-
};
|
package/lib/checkers/initData.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
eslint complexity: [ "error", { "max": 30 } ]
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
// deps
|
|
8
|
-
|
|
9
|
-
// natives
|
|
10
|
-
const { join } = require("node:path");
|
|
11
|
-
|
|
12
|
-
// locals
|
|
13
|
-
const checkTagsValidity = require(join(__dirname, "checkTagsValidity.js"));
|
|
14
|
-
|
|
15
|
-
// consts
|
|
16
|
-
|
|
17
|
-
const ALLOWED_CONTROL_BITS_OPTIONS = [ "none", "end+1", "end+2" ];
|
|
18
|
-
|
|
19
|
-
// module
|
|
20
|
-
|
|
21
|
-
module.exports = (options) => {
|
|
22
|
-
|
|
23
|
-
const result = {
|
|
24
|
-
"startWith": null,
|
|
25
|
-
"startTimeout": null,
|
|
26
|
-
"endWith": null,
|
|
27
|
-
"escapeWith": null,
|
|
28
|
-
"escaped": [],
|
|
29
|
-
"specifics": {},
|
|
30
|
-
"controlBits": ""
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
if ("undefined" !== typeof options) {
|
|
34
|
-
|
|
35
|
-
if ("object" !== typeof options) {
|
|
36
|
-
throw new TypeError("parameter sended is not an object");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
else if ("undefined" !== typeof options.startWith && !checkTagsValidity(options.startWith)) {
|
|
40
|
-
throw new TypeError("startWith parameter sended is not a number, Buffer, or an Array of numbers");
|
|
41
|
-
}
|
|
42
|
-
else if ("undefined" !== typeof options.startTimeout && "number" !== typeof options.startTimeout) {
|
|
43
|
-
throw new TypeError("startTimeout parameter sended is not a number");
|
|
44
|
-
}
|
|
45
|
-
else if ("undefined" !== typeof options.endWith && !checkTagsValidity(options.endWith)) {
|
|
46
|
-
throw new TypeError("endWith parameter sended is not a number, Buffer, or an Array of numbers");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
else if ("undefined" !== typeof options.escapeWith && "number" !== typeof options.escapeWith) {
|
|
50
|
-
throw new TypeError("escapeWith parameter sended is not a number");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
else if ("undefined" !== typeof options.specifics && "object" !== typeof options.specifics) {
|
|
54
|
-
throw new TypeError("escapeWith parameter sended is not an object");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
else if ("undefined" !== typeof options.controlBits && "string" !== typeof options.controlBits) {
|
|
58
|
-
throw new TypeError("controlBits parameter sended is not a string");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
else if ("undefined" !== typeof options.controlBits && !ALLOWED_CONTROL_BITS_OPTIONS.includes(options.controlBits)) {
|
|
62
|
-
throw new Error("controlBits option sended is not in [ \"" + ALLOWED_CONTROL_BITS_OPTIONS.join("\", \"") + "\" ]");
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
else {
|
|
66
|
-
|
|
67
|
-
result.startWith = "undefined" !== typeof options.startWith ? options.startWith : null;
|
|
68
|
-
result.startTimeout = "undefined" !== typeof options.startTimeout ? options.startTimeout : 200;
|
|
69
|
-
result.endWith = "undefined" !== typeof options.endWith ? options.endWith : null;
|
|
70
|
-
|
|
71
|
-
result.escapeWith = "undefined" !== typeof options.escapeWith ? options.escapeWith : null;
|
|
72
|
-
result.escaped = "undefined" !== typeof options.escaped ? options.escaped : [];
|
|
73
|
-
|
|
74
|
-
for (let i = 0; i < result.escaped.length; ++i) {
|
|
75
|
-
|
|
76
|
-
if ("number" !== typeof result.escaped[i]) {
|
|
77
|
-
throw new TypeError("escaped parameter n°" + i + " sended is not a number");
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if ("object" === typeof options.specifics) {
|
|
83
|
-
|
|
84
|
-
Object.keys(options.specifics).forEach((key) => {
|
|
85
|
-
|
|
86
|
-
if ("undefined" !== typeof options.specifics[key]) {
|
|
87
|
-
|
|
88
|
-
if (!checkTagsValidity(options.specifics[key])) {
|
|
89
|
-
|
|
90
|
-
throw new Error(
|
|
91
|
-
"\"" + options.specifics[key] + "\" specifics option" +
|
|
92
|
-
" sended is not a number, or an Array of numbers"
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
else if (
|
|
97
|
-
null !== options.specifics[key] &&
|
|
98
|
-
null !== result.startWith && null === result.endWith
|
|
99
|
-
) {
|
|
100
|
-
|
|
101
|
-
throw new Error(
|
|
102
|
-
"If you want to use \"" + options.specifics[key] + "\" specific option," +
|
|
103
|
-
" you have to use \"endWith\" option"
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
result.specifics = "undefined" !== typeof options.specifics ? options.specifics : {};
|
|
115
|
-
result.controlBits = "undefined" !== typeof options.controlBits ? options.controlBits : "none";
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return result;
|
|
122
|
-
|
|
123
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
eslint no-invalid-this: 0, no-implicit-globals: 0
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
// private
|
|
8
|
-
|
|
9
|
-
// method
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Extract specific tags
|
|
13
|
-
* @param {SplitFrames} self : pointer
|
|
14
|
-
* @returns {void}
|
|
15
|
-
*/
|
|
16
|
-
function _extractSpecifics (self) {
|
|
17
|
-
|
|
18
|
-
let found = false;
|
|
19
|
-
|
|
20
|
-
Object.keys(self._specifics).forEach((key) => {
|
|
21
|
-
|
|
22
|
-
if (0 === self._frame.indexOf(self._specifics[key])) {
|
|
23
|
-
|
|
24
|
-
found = true;
|
|
25
|
-
|
|
26
|
-
const size = "object" === typeof self._specifics[key] && self._specifics[key] instanceof Buffer ?
|
|
27
|
-
self._specifics[key].length : 1;
|
|
28
|
-
|
|
29
|
-
self.emit(key);
|
|
30
|
-
|
|
31
|
-
self._frame = Buffer.from(self._frame.slice(size, self._frame.length));
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (found) {
|
|
38
|
-
_extractSpecifics(self);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
module.exports = function digestEndOnly () {
|
|
44
|
-
|
|
45
|
-
_extractSpecifics(this);
|
|
46
|
-
|
|
47
|
-
const firstEnd = this._searchFirstEnd();
|
|
48
|
-
|
|
49
|
-
// no end tag detected
|
|
50
|
-
if (!firstEnd) {
|
|
51
|
-
this._digesting = false;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// first end tag detected
|
|
55
|
-
else {
|
|
56
|
-
|
|
57
|
-
// extract first frame
|
|
58
|
-
this.push(Buffer.from(this._frame.slice(0, firstEnd.end)));
|
|
59
|
-
|
|
60
|
-
// remove extracted frame from main one
|
|
61
|
-
this._frame = Buffer.from(this._frame.slice(firstEnd.end, this._frame.length));
|
|
62
|
-
|
|
63
|
-
// second full frame detected
|
|
64
|
-
if (-1 < this._searchTags(this._endWith)) {
|
|
65
|
-
this._digest();
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
this._digesting = false;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
eslint no-invalid-this: 0
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
module.exports = function digestNoStartNoEnd () {
|
|
8
|
-
|
|
9
|
-
const KEYS = Object.keys(this._specifics);
|
|
10
|
-
|
|
11
|
-
if (KEYS.length) {
|
|
12
|
-
|
|
13
|
-
KEYS.forEach((key) => {
|
|
14
|
-
|
|
15
|
-
const size = "object" === typeof this._specifics[key] && this._specifics[key] instanceof Buffer ? this._specifics[key].length : 1;
|
|
16
|
-
|
|
17
|
-
for (let foundAt = this._searchTags(this._specifics[key]); -1 < foundAt; foundAt = this._searchTags(this._specifics[key])) {
|
|
18
|
-
|
|
19
|
-
this.emit(key);
|
|
20
|
-
|
|
21
|
-
this._frame = Buffer.from(Buffer.concat([
|
|
22
|
-
this._frame.slice(0, foundAt),
|
|
23
|
-
this._frame.slice(foundAt + size, this._frame.length)
|
|
24
|
-
]));
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
this.push(Buffer.from(this._frame));
|
|
33
|
-
|
|
34
|
-
this._frame = Buffer.from([]);
|
|
35
|
-
|
|
36
|
-
this._digesting = false;
|
|
37
|
-
|
|
38
|
-
};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
eslint no-unmodified-loop-condition:0, no-invalid-this: 0
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
module.exports = function digestStartAndEnd () {
|
|
8
|
-
|
|
9
|
-
const KEYS = Object.keys(this._specifics);
|
|
10
|
-
|
|
11
|
-
if (KEYS.length) {
|
|
12
|
-
|
|
13
|
-
KEYS.forEach((key) => {
|
|
14
|
-
|
|
15
|
-
const firstStart = this._searchFirstStart();
|
|
16
|
-
|
|
17
|
-
const size = "object" === typeof this._specifics[key] && this._specifics[key] instanceof Buffer ? this._specifics[key].length : 1;
|
|
18
|
-
|
|
19
|
-
for (
|
|
20
|
-
let foundAt = this._searchTags(this._specifics[key]), i = 0;
|
|
21
|
-
-1 < foundAt && (!firstStart || foundAt < firstStart.start - i);
|
|
22
|
-
foundAt = this._searchTags(this._specifics[key]), i += size
|
|
23
|
-
) {
|
|
24
|
-
|
|
25
|
-
this.emit(key);
|
|
26
|
-
|
|
27
|
-
this._frame = Buffer.from(Buffer.concat([
|
|
28
|
-
this._frame.slice(0, foundAt),
|
|
29
|
-
this._frame.slice(foundAt + size, this._frame.length)
|
|
30
|
-
]));
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const firstStart = this._searchFirstStart();
|
|
39
|
-
|
|
40
|
-
// no start tag detected
|
|
41
|
-
if (!firstStart) {
|
|
42
|
-
|
|
43
|
-
this._frame = Buffer.from([]);
|
|
44
|
-
this._digesting = false;
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// start tag detected
|
|
49
|
-
else {
|
|
50
|
-
|
|
51
|
-
const firstEnd = this._searchFirstEnd();
|
|
52
|
-
|
|
53
|
-
// end tag not detected
|
|
54
|
-
if (!firstEnd) {
|
|
55
|
-
|
|
56
|
-
// remove useless bits
|
|
57
|
-
this._frame = 0 < firstStart.start ? Buffer.from(this._frame.slice(firstStart.start, this._frame.length)) : this._frame;
|
|
58
|
-
this._digesting = false;
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// end tag detected
|
|
63
|
-
else {
|
|
64
|
-
|
|
65
|
-
this.push(Buffer.from(this._frame.slice(firstStart.start, firstEnd.end)));
|
|
66
|
-
|
|
67
|
-
// remove extracted frame from main one
|
|
68
|
-
this._frame = Buffer.from(this._frame.slice(firstEnd.end, this._frame.length));
|
|
69
|
-
|
|
70
|
-
// search specifics
|
|
71
|
-
let foundSpecific = false;
|
|
72
|
-
for (let i = 0; i < KEYS.length && !foundSpecific; ++i) {
|
|
73
|
-
|
|
74
|
-
if (-1 < this._searchTags(this._specifics[KEYS[i]])) {
|
|
75
|
-
foundSpecific = true; break;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// specific detected or second start detected (force minimal data length)
|
|
81
|
-
if (foundSpecific || -1 < this._searchTags(this._startWith, 1)) {
|
|
82
|
-
this._digest();
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
this._digesting = false;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
eslint no-invalid-this: 0
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
module.exports = function digestStartOnly () {
|
|
8
|
-
|
|
9
|
-
if (this._timeoutDigest) {
|
|
10
|
-
clearTimeout(this._timeoutDigest);
|
|
11
|
-
this._timeoutDigest = null;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const firstStart = this._searchFirstStart();
|
|
15
|
-
|
|
16
|
-
// no start tag detected
|
|
17
|
-
if (!firstStart) {
|
|
18
|
-
|
|
19
|
-
this._frame = Buffer.from([]);
|
|
20
|
-
this._digesting = false;
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// first start tag detected
|
|
25
|
-
else {
|
|
26
|
-
|
|
27
|
-
const nextStartAt = this._searchTags(this._startWith, firstStart.end);
|
|
28
|
-
|
|
29
|
-
// second start tag not detected
|
|
30
|
-
if (-1 >= nextStartAt) {
|
|
31
|
-
|
|
32
|
-
// remove useless bits
|
|
33
|
-
this._frame = 0 < firstStart.start ? Buffer.from(this._frame.slice(firstStart.start, this._frame.length)) : this._frame;
|
|
34
|
-
this._digesting = false;
|
|
35
|
-
|
|
36
|
-
this._timeoutDigest = setTimeout(() => {
|
|
37
|
-
|
|
38
|
-
clearTimeout(this._timeoutDigest);
|
|
39
|
-
this._timeoutDigest = null;
|
|
40
|
-
|
|
41
|
-
this.push(Buffer.from(this._frame.slice(firstStart.start, this._frame.length)));
|
|
42
|
-
|
|
43
|
-
this._frame = Buffer.from([]);
|
|
44
|
-
this._digesting = false;
|
|
45
|
-
|
|
46
|
-
}, this._startTimeout);
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// second start tag detected
|
|
51
|
-
else {
|
|
52
|
-
|
|
53
|
-
// extract first frame
|
|
54
|
-
this.push(Buffer.from(this._frame.slice(firstStart.start, nextStartAt)));
|
|
55
|
-
|
|
56
|
-
// remove extracted frame from main one
|
|
57
|
-
this._frame = Buffer.from(this._frame.slice(nextStartAt, this._frame.length));
|
|
58
|
-
|
|
59
|
-
// second full frame detected (force minimal data length)
|
|
60
|
-
if (-1 < this._searchTags(this._startWith, 1)) {
|
|
61
|
-
this._digest();
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
this._digesting = false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
};
|
package/lib/index.d.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
declare module "split-frames" {
|
|
4
|
-
|
|
5
|
-
import { Transform } from "node:stream";
|
|
6
|
-
|
|
7
|
-
type ControlBits = "none" | "end+1" | "end+2";
|
|
8
|
-
type Tag = number | Buffer | Array<number>;
|
|
9
|
-
|
|
10
|
-
interface SearchedBits {
|
|
11
|
-
"start": number;
|
|
12
|
-
"end": number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface iOptions {
|
|
16
|
-
"startWith"?: Tag;
|
|
17
|
-
"startTimeout"?: number;
|
|
18
|
-
"endWith"?: Tag;
|
|
19
|
-
"escapeWith"?: Tag;
|
|
20
|
-
"escaped"?: Array<number>;
|
|
21
|
-
"specifics"?: { [key:string]: Tag };
|
|
22
|
-
"controlBits"?: ControlBits;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
class Splitter extends Transform {
|
|
26
|
-
|
|
27
|
-
protected _frame: Buffer;
|
|
28
|
-
protected _digesting: boolean;
|
|
29
|
-
|
|
30
|
-
// from params
|
|
31
|
-
protected _startWith: Tag;
|
|
32
|
-
protected _startTimeout: number;
|
|
33
|
-
protected _endWith: Tag;
|
|
34
|
-
protected _escapeWith: number;
|
|
35
|
-
protected _escaped: Array<number>;
|
|
36
|
-
protected _specifics: object;
|
|
37
|
-
protected _controlBits: ControlBits;
|
|
38
|
-
|
|
39
|
-
// constructor
|
|
40
|
-
|
|
41
|
-
constructor (params?: iOptions);
|
|
42
|
-
|
|
43
|
-
// methods
|
|
44
|
-
protected _searchFirstTag(tag: Tag, beginWith?: number): SearchedBits;
|
|
45
|
-
protected _searchFirstStart(): SearchedBits;
|
|
46
|
-
protected _searchFirstEnd(): SearchedBits;
|
|
47
|
-
protected _searchTags(tag: Tag, beginWith?: number): number;
|
|
48
|
-
protected _digest(): void;
|
|
49
|
-
protected _digester(): void;
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export = Splitter;
|
|
54
|
-
|
|
55
|
-
}
|