split-frames 2.5.1 → 2.6.0
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 +1 -1
- package/README.md +9 -4
- package/lib/cjs/SplitFrames.d.ts +1 -1
- package/lib/cjs/SplitFrames.js +28 -13
- package/lib/cjs/checkers/checkTagsValidity.js +6 -4
- package/lib/cjs/checkers/initData.js +70 -65
- package/package.json +43 -27
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
# split-frames
|
|
2
2
|
Split Buffer frames from streams
|
|
3
3
|
|
|
4
|
-
[](https://coveralls.io/github/Psychopoulet/split-frames)
|
|
6
|
-
[](https://david-dm.org/Psychopoulet/split-frames)
|
|
7
|
-
[](https://david-dm.org/Psychopoulet/split-frames?type=dev)
|
|
4
|
+
[](https://sonarcloud.io/summary/new_code?id=Psychopoulet_split-frames)
|
|
8
5
|
[](https://github.com/Psychopoulet/split-frames/issues)
|
|
9
6
|
[](https://github.com/Psychopoulet/split-frames/pulls)
|
|
10
7
|
|
|
8
|
+
[](https://sonarcloud.io/summary/new_code?id=Psychopoulet_split-frames)
|
|
9
|
+
[](https://sonarcloud.io/summary/new_code?id=Psychopoulet_split-frames)
|
|
10
|
+
[](https://sonarcloud.io/summary/new_code?id=Psychopoulet_split-frames)
|
|
11
|
+
[](https://sonarcloud.io/summary/new_code?id=Psychopoulet_split-frames)
|
|
12
|
+
[](https://sonarcloud.io/summary/new_code?id=Psychopoulet_split-frames)
|
|
13
|
+
|
|
14
|
+
[](https://snyk.io/test/github/Psychopoulet/split-frames)
|
|
15
|
+
|
|
11
16
|
## Installation
|
|
12
17
|
|
|
13
18
|
```bash
|
package/lib/cjs/SplitFrames.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export default class SplitFrames extends Transform {
|
|
|
33
33
|
protected _controlBits: iConf["controlBits"];
|
|
34
34
|
protected _digester: (enc?: BufferEncoding) => void;
|
|
35
35
|
constructor(options?: iOptions);
|
|
36
|
-
_transform(chunk: Buffer, enc: BufferEncoding, cb: (err?: Error | null, data?:
|
|
36
|
+
_transform(chunk: Buffer, enc: BufferEncoding, cb: (err?: Error | null, data?: unknown) => void): void;
|
|
37
37
|
protected _chooseDigester(): (enc?: BufferEncoding) => void;
|
|
38
38
|
protected _digest(enc?: BufferEncoding): void;
|
|
39
39
|
private _digestNoStartNoEnd;
|
package/lib/cjs/SplitFrames.js
CHANGED
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
/*
|
|
3
|
+
eslint-disable no-unmodified-loop-condition
|
|
4
|
+
*/
|
|
5
|
+
// => no-unmodified-loop-condition is disabled to allow data generation in a loop (_digestStartAndEnd)
|
|
3
6
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
7
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
8
|
};
|
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
// deps
|
|
7
11
|
// natives
|
|
8
12
|
const node_stream_1 = require("node:stream");
|
|
9
13
|
// locals
|
|
10
14
|
const initData_1 = __importDefault(require("./checkers/initData"));
|
|
11
15
|
// module
|
|
12
16
|
class SplitFrames extends node_stream_1.Transform {
|
|
17
|
+
// attributes
|
|
18
|
+
// protected
|
|
19
|
+
_frame;
|
|
20
|
+
_digesting;
|
|
21
|
+
_timeoutDigest;
|
|
22
|
+
// from params
|
|
23
|
+
_startWith;
|
|
24
|
+
_startTimeout;
|
|
25
|
+
_endWith;
|
|
26
|
+
_escapeWith;
|
|
27
|
+
_escaped;
|
|
28
|
+
_specifics;
|
|
29
|
+
_controlBits;
|
|
30
|
+
// dynamic digester
|
|
31
|
+
_digester;
|
|
13
32
|
// constructor
|
|
14
33
|
constructor(options) {
|
|
15
34
|
super();
|
|
@@ -41,20 +60,16 @@ class SplitFrames extends node_stream_1.Transform {
|
|
|
41
60
|
}
|
|
42
61
|
// protected
|
|
43
62
|
_chooseDigester() {
|
|
44
|
-
let digester = undefined;
|
|
45
63
|
if (undefined === this._startWith && undefined === this._endWith) {
|
|
46
|
-
|
|
64
|
+
return this._digestNoStartNoEnd.bind(this);
|
|
47
65
|
}
|
|
48
66
|
else if (undefined !== this._startWith && undefined === this._endWith) {
|
|
49
|
-
|
|
67
|
+
return this._digestStartOnly.bind(this);
|
|
50
68
|
}
|
|
51
69
|
else if (undefined === this._startWith && undefined !== this._endWith) {
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
digester = this._digestStartAndEnd;
|
|
70
|
+
return this._digestEndOnly.bind(this);
|
|
56
71
|
}
|
|
57
|
-
return
|
|
72
|
+
return this._digestStartAndEnd.bind(this);
|
|
58
73
|
}
|
|
59
74
|
_digest(enc) {
|
|
60
75
|
if (!this._frame.length) {
|
|
@@ -166,7 +181,8 @@ class SplitFrames extends node_stream_1.Transform {
|
|
|
166
181
|
this._frame = Buffer.from(this._frame.slice(size, this._frame.length));
|
|
167
182
|
}
|
|
168
183
|
});
|
|
169
|
-
|
|
184
|
+
// disabled due to malfunction
|
|
185
|
+
if (found) { // eslint-disable-line @typescript-eslint/no-unnecessary-condition
|
|
170
186
|
this._extractSpecifics();
|
|
171
187
|
}
|
|
172
188
|
}
|
|
@@ -206,7 +222,7 @@ class SplitFrames extends node_stream_1.Transform {
|
|
|
206
222
|
this._frame = Buffer.from(this._frame.slice(firstEnd.end, this._frame.length));
|
|
207
223
|
// search specifics
|
|
208
224
|
let foundSpecific = false;
|
|
209
|
-
for (let i = 0; i < KEYS.length
|
|
225
|
+
for (let i = 0; i < KEYS.length; ++i) {
|
|
210
226
|
if (-1 < this._searchTags(this._specifics[KEYS[i]])) {
|
|
211
227
|
foundSpecific = true;
|
|
212
228
|
break;
|
|
@@ -359,8 +375,7 @@ class SplitFrames extends node_stream_1.Transform {
|
|
|
359
375
|
for (let i = 0; i < tags.length; ++i) {
|
|
360
376
|
// number | Buffer
|
|
361
377
|
if ("number" === typeof tags[i]
|
|
362
|
-
|| ("object" === typeof tags[i]
|
|
363
|
-
&& tags[i] instanceof Buffer)) {
|
|
378
|
+
|| ("object" === typeof tags[i] && tags[i] instanceof Buffer)) {
|
|
364
379
|
const _foundAt = this._frame.indexOf(tags[i], beginAt);
|
|
365
380
|
if (-1 < _foundAt && (-1 >= foundAt || _foundAt < foundAt)) {
|
|
366
381
|
foundAt = _foundAt;
|
|
@@ -9,10 +9,12 @@ function checkTagsValidity(tags) {
|
|
|
9
9
|
result = false;
|
|
10
10
|
}
|
|
11
11
|
else if ("object" === typeof tags && tags instanceof Array) {
|
|
12
|
-
for (
|
|
13
|
-
if ("number" !== typeof
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
for (const tag of tags) {
|
|
13
|
+
if ("number" !== typeof tag) {
|
|
14
|
+
if ("object" !== typeof tag || !(tag instanceof Buffer)) {
|
|
15
|
+
result = false;
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
}
|
|
@@ -15,75 +15,80 @@ const ALLOWED_CONTROL_BITS_OPTIONS = [
|
|
|
15
15
|
];
|
|
16
16
|
// module
|
|
17
17
|
function initData(options) {
|
|
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
|
-
throw new TypeError("escapeWith parameter sended is not an object");
|
|
45
|
-
}
|
|
46
|
-
else if ("undefined" !== typeof options.controlBits && "string" !== typeof options.controlBits) {
|
|
47
|
-
throw new TypeError("controlBits parameter sended is not a string");
|
|
48
|
-
}
|
|
49
|
-
else if ("undefined" !== typeof options.controlBits && !ALLOWED_CONTROL_BITS_OPTIONS.includes(options.controlBits)) {
|
|
50
|
-
throw new Error("controlBits option sended is not in [ \"" + ALLOWED_CONTROL_BITS_OPTIONS.join("\", \"") + "\" ]");
|
|
18
|
+
if ("undefined" === typeof options) {
|
|
19
|
+
return {
|
|
20
|
+
"startTimeout": 200,
|
|
21
|
+
"escaped": [],
|
|
22
|
+
"specifics": {},
|
|
23
|
+
"controlBits": "none"
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if ("object" !== typeof options) {
|
|
27
|
+
throw new TypeError("parameter is not an object");
|
|
28
|
+
}
|
|
29
|
+
else if ("undefined" !== typeof options.startWith && !(0, checkTagsValidity_1.default)(options.startWith)) {
|
|
30
|
+
throw new TypeError("startWith parameter is not a number, Buffer, or an Array of numbers");
|
|
31
|
+
}
|
|
32
|
+
else if ("undefined" !== typeof options.startTimeout && "number" !== typeof options.startTimeout) {
|
|
33
|
+
throw new TypeError("startTimeout parameter is not a number");
|
|
34
|
+
}
|
|
35
|
+
else if ("undefined" !== typeof options.endWith && !(0, checkTagsValidity_1.default)(options.endWith)) {
|
|
36
|
+
throw new TypeError("endWith parameter is not a number, Buffer, or an Array of numbers");
|
|
37
|
+
}
|
|
38
|
+
else if ("undefined" !== typeof options.escapeWith && "number" !== typeof options.escapeWith) {
|
|
39
|
+
throw new TypeError("escapeWith parameter is not a number");
|
|
40
|
+
}
|
|
41
|
+
else if ("undefined" !== typeof options.escaped) {
|
|
42
|
+
if (!(0, checkTagsValidity_1.default)(options.escaped)) {
|
|
43
|
+
throw new TypeError("escaped parameter is not a number, Buffer, or an Array of numbers");
|
|
51
44
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
result.startTimeout = options.startTimeout;
|
|
57
|
-
}
|
|
58
|
-
result.escapeWith = "undefined" !== typeof options.escapeWith ? options.escapeWith : undefined;
|
|
59
|
-
if ("undefined" !== typeof options.escaped) {
|
|
60
|
-
result.escaped = options.escaped;
|
|
61
|
-
}
|
|
62
|
-
for (let i = 0; i < result.escaped.length; ++i) {
|
|
63
|
-
if ("number" !== typeof result.escaped[i]) {
|
|
64
|
-
throw new TypeError("escaped parameter n°" + i + " sended is not a number");
|
|
45
|
+
if (Array.isArray(options.escaped)) {
|
|
46
|
+
for (let i = 0; i < options.escaped.length; ++i) {
|
|
47
|
+
if ("number" !== typeof options.escaped[i]) {
|
|
48
|
+
throw new TypeError("escaped parameter n°" + i + " is not a number");
|
|
65
49
|
}
|
|
66
50
|
}
|
|
67
|
-
if ("object" === typeof options.specifics) {
|
|
68
|
-
const specifics = options.specifics;
|
|
69
|
-
Object.keys(specifics).forEach((key) => {
|
|
70
|
-
if ("undefined" !== typeof specifics[key]) {
|
|
71
|
-
if (!(0, checkTagsValidity_1.default)(specifics[key])) {
|
|
72
|
-
throw new Error("\"" + specifics[key] + "\" specifics option"
|
|
73
|
-
+ " sended is not a number, or an Array of numbers");
|
|
74
|
-
}
|
|
75
|
-
else if (undefined !== specifics[key]
|
|
76
|
-
&& undefined !== result.startWith
|
|
77
|
-
&& undefined === result.endWith) {
|
|
78
|
-
throw new Error("If you want to use \"" + specifics[key] + "\" specific option,"
|
|
79
|
-
+ " you have to use \"endWith\" option");
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
result.specifics = "undefined" !== typeof options.specifics ? options.specifics : {};
|
|
85
|
-
result.controlBits = "undefined" !== typeof options.controlBits ? options.controlBits : "none";
|
|
86
51
|
}
|
|
87
52
|
}
|
|
53
|
+
else if ("undefined" !== typeof options.specifics && "object" !== typeof options.specifics) {
|
|
54
|
+
throw new TypeError("specifics parameter is not an object");
|
|
55
|
+
}
|
|
56
|
+
else if ("undefined" !== typeof options.controlBits && "string" !== typeof options.controlBits) {
|
|
57
|
+
throw new TypeError("controlBits parameter is not a string");
|
|
58
|
+
}
|
|
59
|
+
else if ("undefined" !== typeof options.controlBits && !ALLOWED_CONTROL_BITS_OPTIONS.includes(options.controlBits)) {
|
|
60
|
+
throw new Error("controlBits option is not in [ \"" + ALLOWED_CONTROL_BITS_OPTIONS.join("\", \"") + "\" ]");
|
|
61
|
+
}
|
|
62
|
+
const result = {
|
|
63
|
+
"startTimeout": options.startTimeout ?? 200,
|
|
64
|
+
"escaped": options.escaped ?? [],
|
|
65
|
+
"specifics": options.specifics ?? {},
|
|
66
|
+
"controlBits": options.controlBits ?? "none"
|
|
67
|
+
};
|
|
68
|
+
if ("undefined" !== typeof options.startWith) {
|
|
69
|
+
result.startWith = options.startWith;
|
|
70
|
+
}
|
|
71
|
+
if ("undefined" !== typeof options.endWith) {
|
|
72
|
+
result.endWith = options.endWith;
|
|
73
|
+
}
|
|
74
|
+
if ("undefined" !== typeof options.escapeWith) {
|
|
75
|
+
result.escapeWith = options.escapeWith;
|
|
76
|
+
}
|
|
77
|
+
if ("object" === typeof options.specifics) {
|
|
78
|
+
const specifics = options.specifics;
|
|
79
|
+
Object.keys(specifics).forEach((key) => {
|
|
80
|
+
if ("undefined" !== typeof specifics[key]) {
|
|
81
|
+
if (!(0, checkTagsValidity_1.default)(specifics[key])) {
|
|
82
|
+
throw new Error("\"" + String(specifics[key]) + "\" specifics option"
|
|
83
|
+
+ " is not a number, or an Array of numbers");
|
|
84
|
+
}
|
|
85
|
+
else if ("undefined" !== typeof result.startWith
|
|
86
|
+
&& "undefined" === typeof result.endWith) {
|
|
87
|
+
throw new Error("If you want to use \"" + String(specifics[key]) + "\" specific option,"
|
|
88
|
+
+ " you have to use \"endWith\" option");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
88
93
|
return result;
|
|
89
94
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
+
|
|
2
3
|
"name": "split-frames",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Split Buffer frames from streams",
|
|
4
|
+
"version": "2.6.0",
|
|
5
|
+
"description": "Split Buffer frames from streams.",
|
|
6
|
+
|
|
5
7
|
"type": "commonjs",
|
|
6
8
|
"typings": "./lib/cjs/main.d.cts",
|
|
9
|
+
|
|
7
10
|
"main": "./lib/cjs/main.cjs",
|
|
8
11
|
"exports": {
|
|
9
12
|
".": {
|
|
@@ -13,43 +16,54 @@
|
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
18
|
},
|
|
19
|
+
|
|
16
20
|
"scripts": {
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
"lint": "npx eslint --config .eslintrc-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
"
|
|
21
|
+
|
|
22
|
+
"prepare": "npx husky || true",
|
|
23
|
+
|
|
24
|
+
"lint-back": "npx eslint --config .eslintrc-back.js --ext .ts,.cts,.mts ./lib/src/**/*",
|
|
25
|
+
"lint-tests": "npx eslint --config .eslintrc-tests.js --ext .js,.cjs,.mjs ./test/**/*",
|
|
26
|
+
"lint": "npm run lint-back && npm run lint-tests",
|
|
27
|
+
|
|
28
|
+
"clean-back": "npx rimraf ./lib/cjs",
|
|
29
|
+
"clean": "npm run clean-back",
|
|
30
|
+
|
|
31
|
+
"build-back": "npm run clean-back && npx tsc --project ./tsconfig.json",
|
|
32
|
+
"build": "npm run build-back",
|
|
33
|
+
|
|
34
|
+
"check-requires": "npx used-deps-analyzer ./package.json ./lib/src --no-dev",
|
|
35
|
+
"check-updates": "npx check-version-modules --no-fail-at-major --fail-at-minor --fail-at-patch",
|
|
36
|
+
"unit-tests": "npm run build && npx nyc --reporter=html --reporter=text mocha",
|
|
37
|
+
|
|
38
|
+
"tests": "npm run lint && npm run check-requires && npm run check-updates && npm run unit-tests"
|
|
39
|
+
|
|
25
40
|
},
|
|
41
|
+
|
|
26
42
|
"files": [
|
|
27
|
-
"/
|
|
28
|
-
"/lib/cjs",
|
|
29
|
-
"/public"
|
|
43
|
+
"lib/cjs"
|
|
30
44
|
],
|
|
31
45
|
"engines": {
|
|
32
|
-
"node": ">=
|
|
46
|
+
"node": ">=22.22.0"
|
|
33
47
|
},
|
|
48
|
+
|
|
34
49
|
"dependencies": {},
|
|
35
50
|
"devDependencies": {
|
|
36
|
-
"@types/node": "
|
|
37
|
-
"check-version-modules": "2.
|
|
51
|
+
"@types/node": "25.5.0",
|
|
52
|
+
"check-version-modules": "2.2.2",
|
|
38
53
|
"colors": "1.4.0",
|
|
39
54
|
"eslint-plugin-personnallinter": "git+ssh://git@github.com/Psychopoulet/eslint-plugin-personnallinter",
|
|
40
|
-
"husky": "9.1.
|
|
41
|
-
"mocha": "
|
|
42
|
-
"nyc": "
|
|
43
|
-
"rimraf": "6.
|
|
44
|
-
"typescript": "5.
|
|
45
|
-
"used-deps-analyzer": "0.
|
|
55
|
+
"husky": "9.1.7",
|
|
56
|
+
"mocha": "11.7.5",
|
|
57
|
+
"nyc": "18.0.0",
|
|
58
|
+
"rimraf": "6.1.3",
|
|
59
|
+
"typescript": "5.9.3",
|
|
60
|
+
"used-deps-analyzer": "0.2.0"
|
|
46
61
|
},
|
|
47
|
-
|
|
62
|
+
|
|
48
63
|
"husky": {
|
|
49
64
|
"hooks": {
|
|
50
|
-
"pre-commit": "npm run
|
|
51
|
-
"pre-push": "npm run
|
|
52
|
-
"pre-receive": "npm run-script tests"
|
|
65
|
+
"pre-commit": "npm run lint",
|
|
66
|
+
"pre-push": "npm run unit-tests"
|
|
53
67
|
}
|
|
54
68
|
},
|
|
55
69
|
"keywords": [
|
|
@@ -84,12 +98,14 @@
|
|
|
84
98
|
}
|
|
85
99
|
],
|
|
86
100
|
"license": "ISC",
|
|
101
|
+
|
|
87
102
|
"homepage": "https://github.com/Psychopoulet/split-frames#readme",
|
|
88
103
|
"repository": {
|
|
89
104
|
"type": "git",
|
|
90
|
-
"url": "git://github.com/Psychopoulet/split-frames"
|
|
105
|
+
"url": "git://github.com/Psychopoulet/split-frames.git"
|
|
91
106
|
},
|
|
92
107
|
"bugs": {
|
|
93
108
|
"url": "https://github.com/Psychopoulet/split-frames/issues"
|
|
94
109
|
}
|
|
110
|
+
|
|
95
111
|
}
|