split-frames 2.4.4 → 2.5.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/lib/cjs/SplitFrames.d.ts +57 -0
- package/lib/cjs/SplitFrames.js +384 -0
- package/lib/cjs/checkers/checkTagsValidity.d.ts +3 -0
- package/lib/cjs/checkers/checkTagsValidity.js +18 -0
- package/lib/cjs/checkers/initData.d.ts +2 -0
- package/lib/cjs/checkers/initData.js +85 -0
- package/lib/cjs/main.cjs +8 -0
- package/lib/cjs/main.d.cts +2 -0
- package/package.json +53 -24
- package/.coveralls.yml +0 -1
- package/.eslintrc.js +0 -296
- package/.travis.yml +0 -8
- package/lib/checkers/checkTagsValidity.js +0 -26
- package/lib/checkers/initData.js +0 -119
- 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 -373
- package/test/0_compilation_typescript.js +0 -37
- package/test/0_parameters.js +0 -394
- package/test/1_withoutTags.js +0 -81
- package/test/2_endOnly.js +0 -297
- package/test/2_startOnly.js +0 -345
- package/test/3_startAndEnd.js +0 -325
- package/test/4_specifics.js +0 -283
- package/test/5_documentation.js +0 -363
- package/test/typescript/compilation.ts +0 -38
package/LICENSE
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import { Transform } from "node:stream";
|
|
5
|
+
export declare type tTagObject = {
|
|
6
|
+
[key: string]: tTag;
|
|
7
|
+
};
|
|
8
|
+
export declare type tControlBits = "none" | "end+1" | "end+2";
|
|
9
|
+
export declare type tTag = number | Buffer | Array<number> | Array<Buffer>;
|
|
10
|
+
export interface iSearchedBits {
|
|
11
|
+
"start": number;
|
|
12
|
+
"end": number;
|
|
13
|
+
}
|
|
14
|
+
export interface iOptions {
|
|
15
|
+
"startWith"?: tTag;
|
|
16
|
+
"startTimeout"?: number;
|
|
17
|
+
"endWith"?: tTag;
|
|
18
|
+
"escapeWith"?: tTag;
|
|
19
|
+
"escaped"?: Array<number>;
|
|
20
|
+
"specifics"?: tTagObject;
|
|
21
|
+
"controlBits"?: tControlBits;
|
|
22
|
+
}
|
|
23
|
+
export interface iConf extends iOptions {
|
|
24
|
+
"escaped": Array<number>;
|
|
25
|
+
"specifics": tTagObject;
|
|
26
|
+
"controlBits": tControlBits;
|
|
27
|
+
}
|
|
28
|
+
export default class SplitFrames extends Transform {
|
|
29
|
+
protected _frame: Buffer;
|
|
30
|
+
protected _digesting: boolean;
|
|
31
|
+
protected _timeoutDigest: NodeJS.Timeout | null;
|
|
32
|
+
protected _startWith: iConf["startWith"];
|
|
33
|
+
protected _startTimeout: iConf["startTimeout"];
|
|
34
|
+
protected _endWith: iConf["endWith"];
|
|
35
|
+
protected _escapeWith: iConf["escapeWith"];
|
|
36
|
+
protected _escaped: iConf["escaped"];
|
|
37
|
+
protected _specifics: iConf["specifics"];
|
|
38
|
+
protected _controlBits: iConf["controlBits"];
|
|
39
|
+
protected _digester: (enc?: BufferEncoding) => void;
|
|
40
|
+
constructor(options?: iOptions);
|
|
41
|
+
_transform(chunk: Buffer, enc: BufferEncoding, cb: (err?: Error | null, data?: any) => void): void;
|
|
42
|
+
protected _chooseDigester(): (enc?: BufferEncoding) => void;
|
|
43
|
+
protected _digest(enc?: BufferEncoding): void;
|
|
44
|
+
private _digestNoStartNoEnd;
|
|
45
|
+
private _digestStartOnly;
|
|
46
|
+
private _digestEndOnly;
|
|
47
|
+
private _extractSpecifics;
|
|
48
|
+
private _digestStartAndEnd;
|
|
49
|
+
private _searchFirstTag;
|
|
50
|
+
private _searchFirstNumberTag;
|
|
51
|
+
private _searchFirstBufferOrArrayTag;
|
|
52
|
+
private _searchFirstStart;
|
|
53
|
+
private _searchFirstEnd;
|
|
54
|
+
private _searchTags;
|
|
55
|
+
private _searchNumberTags;
|
|
56
|
+
private _searchBufferOrArrayTags;
|
|
57
|
+
}
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// deps
|
|
7
|
+
// natives
|
|
8
|
+
const node_stream_1 = require("node:stream");
|
|
9
|
+
// locals
|
|
10
|
+
const initData_1 = __importDefault(require("./checkers/initData"));
|
|
11
|
+
;
|
|
12
|
+
;
|
|
13
|
+
;
|
|
14
|
+
// module
|
|
15
|
+
class SplitFrames extends node_stream_1.Transform {
|
|
16
|
+
// constructor
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super();
|
|
19
|
+
this._frame = Buffer.from([]);
|
|
20
|
+
this._digesting = false;
|
|
21
|
+
this._timeoutDigest = null;
|
|
22
|
+
// from params
|
|
23
|
+
const validatedOptions = (0, initData_1.default)(options);
|
|
24
|
+
this._startWith = validatedOptions.startWith;
|
|
25
|
+
this._startTimeout = validatedOptions.startTimeout;
|
|
26
|
+
this._endWith = validatedOptions.endWith;
|
|
27
|
+
this._escapeWith = validatedOptions.escapeWith;
|
|
28
|
+
this._escaped = validatedOptions.escaped;
|
|
29
|
+
this._specifics = validatedOptions.specifics;
|
|
30
|
+
this._controlBits = validatedOptions.controlBits;
|
|
31
|
+
// dynamic digester
|
|
32
|
+
this._digester = this._chooseDigester();
|
|
33
|
+
}
|
|
34
|
+
// methods
|
|
35
|
+
// public
|
|
36
|
+
_transform(chunk, enc, cb) {
|
|
37
|
+
if (chunk.length) {
|
|
38
|
+
this._frame = Buffer.concat([this._frame, chunk]);
|
|
39
|
+
if (!this._digesting) {
|
|
40
|
+
this._digest(enc);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return cb();
|
|
44
|
+
}
|
|
45
|
+
// protected
|
|
46
|
+
_chooseDigester() {
|
|
47
|
+
let digester = undefined;
|
|
48
|
+
if (undefined === this._startWith && undefined === this._endWith) {
|
|
49
|
+
digester = this._digestNoStartNoEnd;
|
|
50
|
+
}
|
|
51
|
+
else if (undefined !== this._startWith && undefined === this._endWith) {
|
|
52
|
+
digester = this._digestStartOnly;
|
|
53
|
+
}
|
|
54
|
+
else if (undefined === this._startWith && undefined !== this._endWith) {
|
|
55
|
+
digester = this._digestEndOnly;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
digester = this._digestStartAndEnd;
|
|
59
|
+
}
|
|
60
|
+
return digester;
|
|
61
|
+
}
|
|
62
|
+
_digest(enc) {
|
|
63
|
+
if (!this._frame.length) {
|
|
64
|
+
this._digesting = false;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this._digesting = true;
|
|
68
|
+
try {
|
|
69
|
+
this._digester(enc);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
this.emit("error", e);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// private
|
|
77
|
+
// digesters
|
|
78
|
+
_digestNoStartNoEnd() {
|
|
79
|
+
const KEYS = Object.keys(this._specifics);
|
|
80
|
+
if (KEYS.length) {
|
|
81
|
+
KEYS.forEach((key) => {
|
|
82
|
+
const size = "object" === typeof this._specifics[key] && this._specifics[key] instanceof Buffer ? this._specifics[key].length : 1;
|
|
83
|
+
for (let foundAt = this._searchTags(this._specifics[key]); -1 < foundAt; foundAt = this._searchTags(this._specifics[key])) {
|
|
84
|
+
this.emit(key);
|
|
85
|
+
this._frame = Buffer.from(Buffer.concat([
|
|
86
|
+
this._frame.slice(0, foundAt),
|
|
87
|
+
this._frame.slice(foundAt + size, this._frame.length)
|
|
88
|
+
]));
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
this.push(Buffer.from(this._frame));
|
|
93
|
+
this._frame = Buffer.from([]);
|
|
94
|
+
this._digesting = false;
|
|
95
|
+
}
|
|
96
|
+
_digestStartOnly(enc) {
|
|
97
|
+
if (this._timeoutDigest) {
|
|
98
|
+
clearTimeout(this._timeoutDigest);
|
|
99
|
+
this._timeoutDigest = null;
|
|
100
|
+
}
|
|
101
|
+
const firstStart = this._searchFirstStart();
|
|
102
|
+
// no start tag detected
|
|
103
|
+
if (!firstStart) {
|
|
104
|
+
this._frame = Buffer.from([]);
|
|
105
|
+
this._digesting = false;
|
|
106
|
+
}
|
|
107
|
+
// first start tag detected
|
|
108
|
+
else {
|
|
109
|
+
const nextStartAt = this._searchTags(this._startWith, firstStart.end);
|
|
110
|
+
// second start tag not detected
|
|
111
|
+
if (-1 >= nextStartAt) {
|
|
112
|
+
// remove useless bits
|
|
113
|
+
this._frame = 0 < firstStart.start ? Buffer.from(this._frame.slice(firstStart.start, this._frame.length)) : this._frame;
|
|
114
|
+
this._digesting = false;
|
|
115
|
+
this._timeoutDigest = setTimeout(() => {
|
|
116
|
+
clearTimeout(this._timeoutDigest);
|
|
117
|
+
this._timeoutDigest = null;
|
|
118
|
+
this.push(Buffer.from(this._frame.slice(firstStart.start, this._frame.length)));
|
|
119
|
+
this._frame = Buffer.from([]);
|
|
120
|
+
this._digesting = false;
|
|
121
|
+
}, this._startTimeout);
|
|
122
|
+
}
|
|
123
|
+
// second start tag detected
|
|
124
|
+
else {
|
|
125
|
+
// extract first frame
|
|
126
|
+
this.push(Buffer.from(this._frame.slice(firstStart.start, nextStartAt)));
|
|
127
|
+
// remove extracted frame from main one
|
|
128
|
+
this._frame = Buffer.from(this._frame.slice(nextStartAt, this._frame.length));
|
|
129
|
+
// second full frame detected (force minimal data length)
|
|
130
|
+
if (-1 < this._searchTags(this._startWith, 1)) {
|
|
131
|
+
this._digest(enc);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
this._digesting = false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
_digestEndOnly(enc) {
|
|
140
|
+
this._extractSpecifics();
|
|
141
|
+
const firstEnd = this._searchFirstEnd();
|
|
142
|
+
// no end tag detected
|
|
143
|
+
if (!firstEnd) {
|
|
144
|
+
this._digesting = false;
|
|
145
|
+
}
|
|
146
|
+
// first end tag detected
|
|
147
|
+
else {
|
|
148
|
+
// extract first frame
|
|
149
|
+
this.push(Buffer.from(this._frame.slice(0, firstEnd.end)));
|
|
150
|
+
// remove extracted frame from main one
|
|
151
|
+
this._frame = Buffer.from(this._frame.slice(firstEnd.end, this._frame.length));
|
|
152
|
+
// second full frame detected
|
|
153
|
+
if (-1 < this._searchTags(this._endWith)) {
|
|
154
|
+
this._digest(enc);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
this._digesting = false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
_extractSpecifics() {
|
|
162
|
+
let found = false;
|
|
163
|
+
Object.keys(this._specifics).forEach((key) => {
|
|
164
|
+
if (0 === this._frame.indexOf(this._specifics[key])) {
|
|
165
|
+
found = true;
|
|
166
|
+
const size = "object" === typeof this._specifics[key] && this._specifics[key] instanceof Buffer ?
|
|
167
|
+
this._specifics[key].length : 1;
|
|
168
|
+
this.emit(key);
|
|
169
|
+
this._frame = Buffer.from(this._frame.slice(size, this._frame.length));
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
if (found) {
|
|
173
|
+
this._extractSpecifics();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
_digestStartAndEnd(enc) {
|
|
177
|
+
const KEYS = Object.keys(this._specifics);
|
|
178
|
+
if (KEYS.length) {
|
|
179
|
+
KEYS.forEach((key) => {
|
|
180
|
+
const firstStart = this._searchFirstStart();
|
|
181
|
+
const size = "object" === typeof this._specifics[key] && this._specifics[key] instanceof Buffer ? this._specifics[key].length : 1;
|
|
182
|
+
for (let foundAt = this._searchTags(this._specifics[key]), i = 0; -1 < foundAt && (!firstStart || foundAt < firstStart.start - i); foundAt = this._searchTags(this._specifics[key]), i += size) {
|
|
183
|
+
this.emit(key);
|
|
184
|
+
this._frame = Buffer.from(Buffer.concat([
|
|
185
|
+
this._frame.slice(0, foundAt),
|
|
186
|
+
this._frame.slice(foundAt + size, this._frame.length)
|
|
187
|
+
]));
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
const firstStart = this._searchFirstStart();
|
|
192
|
+
// no start tag detected
|
|
193
|
+
if (!firstStart) {
|
|
194
|
+
this._frame = Buffer.from([]);
|
|
195
|
+
this._digesting = false;
|
|
196
|
+
}
|
|
197
|
+
// start tag detected
|
|
198
|
+
else {
|
|
199
|
+
const firstEnd = this._searchFirstEnd();
|
|
200
|
+
// end tag not detected
|
|
201
|
+
if (!firstEnd) {
|
|
202
|
+
// remove useless bits
|
|
203
|
+
this._frame = 0 < firstStart.start ? Buffer.from(this._frame.slice(firstStart.start, this._frame.length)) : this._frame;
|
|
204
|
+
this._digesting = false;
|
|
205
|
+
}
|
|
206
|
+
// end tag detected
|
|
207
|
+
else {
|
|
208
|
+
this.push(Buffer.from(this._frame.slice(firstStart.start, firstEnd.end)));
|
|
209
|
+
// remove extracted frame from main one
|
|
210
|
+
this._frame = Buffer.from(this._frame.slice(firstEnd.end, this._frame.length));
|
|
211
|
+
// search specifics
|
|
212
|
+
let foundSpecific = false;
|
|
213
|
+
for (let i = 0; i < KEYS.length && !foundSpecific; ++i) {
|
|
214
|
+
if (-1 < this._searchTags(this._specifics[KEYS[i]])) {
|
|
215
|
+
foundSpecific = true;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
// specific detected or second start detected (force minimal data length)
|
|
220
|
+
if (foundSpecific || -1 < this._searchTags(this._startWith, 1)) {
|
|
221
|
+
this._digest(enc);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
this._digesting = false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// search tag
|
|
230
|
+
_searchFirstTag(tag, beginAt = 0) {
|
|
231
|
+
let startAt = -1;
|
|
232
|
+
let endAt = -1;
|
|
233
|
+
// number
|
|
234
|
+
if ("number" === typeof tag) {
|
|
235
|
+
const find = this._searchFirstNumberTag(tag, beginAt);
|
|
236
|
+
startAt = find.start;
|
|
237
|
+
endAt = find.end;
|
|
238
|
+
}
|
|
239
|
+
// Buffer | Array
|
|
240
|
+
else if ("object" === typeof tag) {
|
|
241
|
+
const find = this._searchFirstBufferOrArrayTag(tag, beginAt);
|
|
242
|
+
startAt = find.start;
|
|
243
|
+
endAt = find.end;
|
|
244
|
+
}
|
|
245
|
+
// not found
|
|
246
|
+
if (-1 >= startAt || -1 >= endAt) {
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
// escaped
|
|
250
|
+
else if (0 < startAt &&
|
|
251
|
+
// must be a number to be escaped
|
|
252
|
+
1 === endAt - startAt &&
|
|
253
|
+
this._escaped.includes(this._frame[startAt]) && this._frame[startAt - 1] === this._escapeWith) {
|
|
254
|
+
// escaper not escaped
|
|
255
|
+
if (!this._escaped.includes(this._escapeWith) || 1 >= startAt || this._frame[startAt - 2] !== this._escapeWith) {
|
|
256
|
+
return this._searchFirstTag(tag, endAt + 1);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
return {
|
|
260
|
+
"start": startAt,
|
|
261
|
+
"end": endAt
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
// not escaped
|
|
266
|
+
else {
|
|
267
|
+
return {
|
|
268
|
+
"start": startAt,
|
|
269
|
+
"end": endAt
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
_searchFirstNumberTag(tag, beginAt) {
|
|
274
|
+
const startAt = this._frame.indexOf(tag, beginAt);
|
|
275
|
+
return {
|
|
276
|
+
"start": startAt,
|
|
277
|
+
"end": startAt + 1
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
_searchFirstBufferOrArrayTag(tag, beginAt) {
|
|
281
|
+
let startAt = -1;
|
|
282
|
+
let endAt = -1;
|
|
283
|
+
// Buffer
|
|
284
|
+
if (tag instanceof Buffer) {
|
|
285
|
+
startAt = this._frame.indexOf(tag, beginAt);
|
|
286
|
+
endAt = startAt + tag.length;
|
|
287
|
+
}
|
|
288
|
+
// Array
|
|
289
|
+
else if (tag instanceof Array) {
|
|
290
|
+
for (let i = 0; i < tag.length; ++i) {
|
|
291
|
+
// number | Buffer
|
|
292
|
+
if ("number" === typeof tag[i] ||
|
|
293
|
+
("object" === typeof tag[i] && tag[i] instanceof Buffer)) {
|
|
294
|
+
const _startAt = this._frame.indexOf(tag[i], beginAt);
|
|
295
|
+
if (-1 < _startAt && (-1 >= startAt || _startAt < startAt)) {
|
|
296
|
+
startAt = _startAt;
|
|
297
|
+
endAt = startAt + ("number" === typeof tag[i] ? 1 : tag[i].length);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
"start": startAt,
|
|
304
|
+
"end": endAt
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
_searchFirstStart() {
|
|
308
|
+
return this._searchFirstTag(this._startWith);
|
|
309
|
+
}
|
|
310
|
+
_searchFirstEnd() {
|
|
311
|
+
const firstTag = this._searchFirstTag(this._endWith);
|
|
312
|
+
if (firstTag) {
|
|
313
|
+
if ("end+1" === this._controlBits) {
|
|
314
|
+
firstTag.end += 1;
|
|
315
|
+
}
|
|
316
|
+
else if ("end+2" === this._controlBits) {
|
|
317
|
+
firstTag.end += 2;
|
|
318
|
+
}
|
|
319
|
+
// end tag detected but without valid control bits length
|
|
320
|
+
if (firstTag.end > this._frame.length) {
|
|
321
|
+
return undefined;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return firstTag;
|
|
325
|
+
}
|
|
326
|
+
_searchTags(tags, beginAt = 0) {
|
|
327
|
+
// number
|
|
328
|
+
if ("number" === typeof tags) {
|
|
329
|
+
return this._searchNumberTags(tags, beginAt);
|
|
330
|
+
}
|
|
331
|
+
// Buffer | Array
|
|
332
|
+
else if ("object" === typeof tags) {
|
|
333
|
+
return this._searchBufferOrArrayTags(tags, beginAt);
|
|
334
|
+
}
|
|
335
|
+
return -1;
|
|
336
|
+
}
|
|
337
|
+
_searchNumberTags(tags, beginAt) {
|
|
338
|
+
const foundAt = this._frame.indexOf(tags, beginAt);
|
|
339
|
+
// escaped
|
|
340
|
+
if (0 < foundAt &&
|
|
341
|
+
this._escaped.includes(this._frame[foundAt]) &&
|
|
342
|
+
this._frame[foundAt - 1] === this._escapeWith) {
|
|
343
|
+
// escaper not escaped
|
|
344
|
+
if (!this._escaped.includes(this._escapeWith) || 1 >= foundAt || this._frame[foundAt - 2] !== this._escapeWith) {
|
|
345
|
+
return this._searchTags(tags, foundAt + 1);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return foundAt;
|
|
349
|
+
}
|
|
350
|
+
_searchBufferOrArrayTags(tags, beginAt) {
|
|
351
|
+
// Buffer
|
|
352
|
+
if (tags instanceof Buffer) {
|
|
353
|
+
return this._frame.indexOf(tags, beginAt);
|
|
354
|
+
}
|
|
355
|
+
// Array
|
|
356
|
+
else if (tags instanceof Array) {
|
|
357
|
+
let foundAt = -1;
|
|
358
|
+
let type = "undefined";
|
|
359
|
+
for (let i = 0; i < tags.length; ++i) {
|
|
360
|
+
// number | Buffer
|
|
361
|
+
if ("number" === typeof tags[i] || ("object" === typeof tags[i] && tags[i] instanceof Buffer)) {
|
|
362
|
+
const _foundAt = this._frame.indexOf(tags[i], beginAt);
|
|
363
|
+
if (-1 < _foundAt && (-1 >= foundAt || _foundAt < foundAt)) {
|
|
364
|
+
foundAt = _foundAt;
|
|
365
|
+
type = typeof tags[i];
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
// escaped
|
|
370
|
+
if ("number" === type && 0 < foundAt &&
|
|
371
|
+
this._escaped.includes(this._frame[foundAt]) &&
|
|
372
|
+
this._frame[foundAt - 1] === this._escapeWith) {
|
|
373
|
+
// escaper not escaped
|
|
374
|
+
if (!this._escaped.includes(this._escapeWith) || 1 >= foundAt || this._frame[foundAt - 2] !== this._escapeWith) {
|
|
375
|
+
foundAt = this._searchTags(tags, foundAt + 1);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return foundAt;
|
|
379
|
+
}
|
|
380
|
+
return -1;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
exports.default = SplitFrames;
|
|
384
|
+
;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// module
|
|
4
|
+
exports.default = (tags) => {
|
|
5
|
+
let result = true;
|
|
6
|
+
if ("number" !== typeof tags && "object" !== typeof tags) {
|
|
7
|
+
result = false;
|
|
8
|
+
}
|
|
9
|
+
else if ("object" === typeof tags && tags instanceof Array) {
|
|
10
|
+
for (let i = 0; i < tags.length; ++i) {
|
|
11
|
+
if ("number" !== typeof tags[i] && "object" !== typeof tags[i] && !(tags[i] instanceof Buffer)) {
|
|
12
|
+
result = false;
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// deps
|
|
7
|
+
// locals
|
|
8
|
+
const checkTagsValidity_1 = __importDefault(require("./checkTagsValidity"));
|
|
9
|
+
// consts
|
|
10
|
+
const ALLOWED_CONTROL_BITS_OPTIONS = ["none", "end+1", "end+2"];
|
|
11
|
+
// module
|
|
12
|
+
function initData(options) {
|
|
13
|
+
const result = {
|
|
14
|
+
"startWith": undefined,
|
|
15
|
+
"startTimeout": 200,
|
|
16
|
+
"endWith": undefined,
|
|
17
|
+
"escapeWith": undefined,
|
|
18
|
+
"escaped": [],
|
|
19
|
+
"specifics": {},
|
|
20
|
+
"controlBits": "none"
|
|
21
|
+
};
|
|
22
|
+
if ("undefined" !== typeof options) {
|
|
23
|
+
if ("object" !== typeof options) {
|
|
24
|
+
throw new TypeError("parameter sended is not an object");
|
|
25
|
+
}
|
|
26
|
+
else if ("undefined" !== typeof options.startWith && !(0, checkTagsValidity_1.default)(options.startWith)) {
|
|
27
|
+
throw new TypeError("startWith parameter sended is not a number, Buffer, or an Array of numbers");
|
|
28
|
+
}
|
|
29
|
+
else if ("undefined" !== typeof options.startTimeout && "number" !== typeof options.startTimeout) {
|
|
30
|
+
throw new TypeError("startTimeout parameter sended is not a number");
|
|
31
|
+
}
|
|
32
|
+
else if ("undefined" !== typeof options.endWith && !(0, checkTagsValidity_1.default)(options.endWith)) {
|
|
33
|
+
throw new TypeError("endWith parameter sended is not a number, Buffer, or an Array of numbers");
|
|
34
|
+
}
|
|
35
|
+
else if ("undefined" !== typeof options.escapeWith && "number" !== typeof options.escapeWith) {
|
|
36
|
+
throw new TypeError("escapeWith parameter sended is not a number");
|
|
37
|
+
}
|
|
38
|
+
else if ("undefined" !== typeof options.specifics && "object" !== typeof options.specifics) {
|
|
39
|
+
throw new TypeError("escapeWith parameter sended is not an object");
|
|
40
|
+
}
|
|
41
|
+
else if ("undefined" !== typeof options.controlBits && "string" !== typeof options.controlBits) {
|
|
42
|
+
throw new TypeError("controlBits parameter sended is not a string");
|
|
43
|
+
}
|
|
44
|
+
else if ("undefined" !== typeof options.controlBits && !ALLOWED_CONTROL_BITS_OPTIONS.includes(options.controlBits)) {
|
|
45
|
+
throw new Error("controlBits option sended is not in [ \"" + ALLOWED_CONTROL_BITS_OPTIONS.join("\", \"") + "\" ]");
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
result.startWith = "undefined" !== typeof options.startWith ? options.startWith : undefined;
|
|
49
|
+
result.endWith = "undefined" !== typeof options.endWith ? options.endWith : undefined;
|
|
50
|
+
if ("undefined" !== typeof options.startTimeout) {
|
|
51
|
+
result.startTimeout = options.startTimeout;
|
|
52
|
+
}
|
|
53
|
+
result.escapeWith = "undefined" !== typeof options.escapeWith ? options.escapeWith : undefined;
|
|
54
|
+
if ("undefined" !== typeof options.escaped) {
|
|
55
|
+
result.escaped = options.escaped;
|
|
56
|
+
}
|
|
57
|
+
for (let i = 0; i < result.escaped.length; ++i) {
|
|
58
|
+
if ("number" !== typeof result.escaped[i]) {
|
|
59
|
+
throw new TypeError("escaped parameter n°" + i + " sended is not a number");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if ("object" === typeof options.specifics) {
|
|
63
|
+
const specifics = options.specifics;
|
|
64
|
+
Object.keys(specifics).forEach((key) => {
|
|
65
|
+
if ("undefined" !== typeof specifics[key]) {
|
|
66
|
+
if (!(0, checkTagsValidity_1.default)(specifics[key])) {
|
|
67
|
+
throw new Error("\"" + specifics[key] + "\" specifics option" +
|
|
68
|
+
" sended is not a number, or an Array of numbers");
|
|
69
|
+
}
|
|
70
|
+
else if (undefined !== specifics[key] &&
|
|
71
|
+
undefined !== result.startWith && undefined === result.endWith) {
|
|
72
|
+
throw new Error("If you want to use \"" + specifics[key] + "\" specific option," +
|
|
73
|
+
" you have to use \"endWith\" option");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
result.specifics = "undefined" !== typeof options.specifics ? options.specifics : {};
|
|
79
|
+
result.controlBits = "undefined" !== typeof options.controlBits ? options.controlBits : "none";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
exports.default = initData;
|
|
85
|
+
;
|
package/lib/cjs/main.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
// deps
|
|
6
|
+
// locals
|
|
7
|
+
const SplitFrames_1 = __importDefault(require("./SplitFrames"));
|
|
8
|
+
module.exports = SplitFrames_1.default;
|
package/package.json
CHANGED
|
@@ -1,26 +1,62 @@
|
|
|
1
1
|
{
|
|
2
|
+
|
|
2
3
|
"name": "split-frames",
|
|
3
|
-
"version": "2.
|
|
4
|
+
"version": "2.5.0",
|
|
4
5
|
"description": "Split Buffer frames from streams",
|
|
5
|
-
|
|
6
|
-
"
|
|
6
|
+
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"typings": "./lib/cjs/main.d.cts",
|
|
9
|
+
"main": "./lib/cjs/main.cjs",
|
|
10
|
+
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./lib/cjs/main.d.cts",
|
|
15
|
+
"default": "./lib/cjs/main.cjs"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
|
|
7
20
|
"scripts": {
|
|
8
|
-
|
|
21
|
+
|
|
22
|
+
"build": "node ./removeOldBuild.js && npx tsc --project \"./tsconfig.json\"",
|
|
23
|
+
|
|
24
|
+
"lint": "npx eslint ./test/**/*.js",
|
|
25
|
+
"check-requires": "npx used-deps-analyzer \"./package.json\" \"./src\" --no-dev --overkill \"fs-extra\" \"node-promfs\"",
|
|
9
26
|
"check-updates": "npx check-version-modules",
|
|
10
|
-
"unit-tests": "npx nyc --reporter=html --reporter=text mocha",
|
|
11
|
-
|
|
27
|
+
"unit-tests": "npm run build && npx nyc --reporter=html --reporter=text mocha",
|
|
28
|
+
|
|
29
|
+
"tests": "npm run-script lint && npm run check-requires && npm run-script check-updates && npm run-script unit-tests",
|
|
12
30
|
"ci": "npm run-script tests && npx nyc report --reporter=text-lcov | coveralls"
|
|
31
|
+
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
"files": [
|
|
35
|
+
"/lib"
|
|
36
|
+
],
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=16.0.0"
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
"dependencies": {},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "20.5.7",
|
|
44
|
+
"check-version-modules": "1.5.0",
|
|
45
|
+
"coveralls": "3.1.1",
|
|
46
|
+
"eslint": "8.48.0",
|
|
47
|
+
"husky": "8.0.3",
|
|
48
|
+
"mocha": "10.2.0",
|
|
49
|
+
"nyc": "15.1.0",
|
|
50
|
+
"used-deps-analyzer": "0.1.6"
|
|
13
51
|
},
|
|
52
|
+
"optionalDependencies": {},
|
|
53
|
+
|
|
14
54
|
"husky": {
|
|
15
55
|
"hooks": {
|
|
16
56
|
"pre-commit": "npm run-script lint",
|
|
17
57
|
"pre-push": "npm run-script tests"
|
|
18
58
|
}
|
|
19
59
|
},
|
|
20
|
-
"repository": {
|
|
21
|
-
"type": "git",
|
|
22
|
-
"url": "git://github.com/Psychopoulet/split-frames"
|
|
23
|
-
},
|
|
24
60
|
"keywords": [
|
|
25
61
|
"frame",
|
|
26
62
|
"Buffer",
|
|
@@ -47,21 +83,14 @@
|
|
|
47
83
|
],
|
|
48
84
|
"author": "Sébastien VIDAL",
|
|
49
85
|
"license": "ISC",
|
|
86
|
+
|
|
87
|
+
"homepage": "https://github.com/Psychopoulet/split-frames#readme",
|
|
88
|
+
"repository": {
|
|
89
|
+
"type": "git",
|
|
90
|
+
"url": "git://github.com/Psychopoulet/split-frames"
|
|
91
|
+
},
|
|
50
92
|
"bugs": {
|
|
51
93
|
"url": "https://github.com/Psychopoulet/split-frames/issues"
|
|
52
|
-
},
|
|
53
|
-
"dependencies": {},
|
|
54
|
-
"devDependencies": {
|
|
55
|
-
"@types/node": "18.11.9",
|
|
56
|
-
"check-version-modules": "1.3.5",
|
|
57
|
-
"coveralls": "3.1.1",
|
|
58
|
-
"eslint": "8.27.0",
|
|
59
|
-
"husky": "8.0.2",
|
|
60
|
-
"mocha": "10.1.0",
|
|
61
|
-
"nyc": "15.1.0"
|
|
62
|
-
},
|
|
63
|
-
"homepage": "https://github.com/Psychopoulet/split-frames#readme",
|
|
64
|
-
"engines": {
|
|
65
|
-
"node": ">=16.0.0"
|
|
66
94
|
}
|
|
95
|
+
|
|
67
96
|
}
|
package/.coveralls.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
service_name: travis-ci
|