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.
@@ -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 "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
- }
package/lib/main.js DELETED
@@ -1,373 +0,0 @@
1
- /*
2
- eslint no-implicit-globals: 0, no-extra-parens: 0, complexity: [ "error", { "max": 25 } ]
3
- */
4
-
5
- "use strict";
6
-
7
- // deps
8
-
9
- const { join } = require("path");
10
-
11
- const _initData = require(join(__dirname, "checkers", "initData.js"));
12
-
13
- let _digestNoStartNoEnd = null;
14
- let _digestStartOnly = null;
15
- let _digestEndOnly = null;
16
- let _digestStartAndEnd = null;
17
-
18
- // private
19
-
20
- // methods
21
-
22
- /**
23
- * Test tags compatibility
24
- * @param {number|Array} startWith : startWith tags
25
- * @param {number|Array} endWith : endWith tags
26
- * @returns {function} digester
27
- */
28
- function _chooseDigester (startWith, endWith) {
29
-
30
- let digester = null;
31
-
32
- if (null === startWith && null === endWith) {
33
-
34
- if (!_digestNoStartNoEnd) {
35
- _digestNoStartNoEnd = require(join(__dirname, "digesters", "digestNoStartNoEnd.js"));
36
- }
37
-
38
- digester = _digestNoStartNoEnd;
39
-
40
- }
41
- else if (null !== startWith && null === endWith) {
42
-
43
- if (!_digestStartOnly) {
44
- _digestStartOnly = require(join(__dirname, "digesters", "digestStartOnly.js"));
45
- }
46
-
47
- digester = _digestStartOnly;
48
-
49
- }
50
- else if (null === startWith && null !== endWith) {
51
-
52
- if (!_digestEndOnly) {
53
- _digestEndOnly = require(join(__dirname, "digesters", "digestEndOnly.js"));
54
- }
55
-
56
- digester = _digestEndOnly;
57
-
58
- }
59
- else {
60
-
61
- if (!_digestStartAndEnd) {
62
- _digestStartAndEnd = require(join(__dirname, "digesters", "digestStartAndEnd.js"));
63
- }
64
-
65
- digester = _digestStartAndEnd;
66
-
67
- }
68
-
69
- return digester;
70
-
71
- }
72
-
73
- // module
74
-
75
- module.exports = class SplitFrames extends require("stream").Transform {
76
-
77
- constructor (options) {
78
-
79
- super(options);
80
-
81
- const validatedOptions = _initData(options);
82
-
83
- this._startWith = validatedOptions.startWith;
84
- this._startTimeout = validatedOptions.startTimeout;
85
- this._endWith = validatedOptions.endWith;
86
-
87
- this._escapeWith = validatedOptions.escapeWith;
88
- this._escaped = validatedOptions.escaped;
89
-
90
- this._specifics = validatedOptions.specifics;
91
-
92
- this._controlBits = validatedOptions.controlBits;
93
-
94
- this._frame = Buffer.from([]);
95
- this._digesting = false;
96
-
97
- this._digester = _chooseDigester(this._startWith, this._endWith);
98
-
99
- }
100
-
101
- _digest () {
102
-
103
- if (!this._frame.length) {
104
- this._digesting = false;
105
- }
106
- else {
107
-
108
- this._digesting = true;
109
-
110
- try {
111
- this._digester();
112
- }
113
- catch (e) {
114
- this.emit("error", e);
115
- }
116
-
117
- }
118
-
119
- }
120
-
121
- _transform (chunk, enc, cb) {
122
-
123
- if (chunk.length) {
124
-
125
- this._frame = Buffer.concat([ this._frame, chunk ]);
126
-
127
- if (!this._digesting) {
128
- this._digest();
129
- }
130
-
131
- }
132
-
133
- cb();
134
-
135
- }
136
-
137
- _searchTags (tags, beginAt = 0) {
138
-
139
- // number
140
- if ("number" === typeof tags) {
141
- return this._searchNumberTags(tags, beginAt);
142
- }
143
-
144
- // Buffer | Array
145
- else if ("object" === typeof tags) {
146
- return this._searchBufferOrArrayTags(tags, beginAt);
147
- }
148
-
149
- return -1;
150
-
151
- }
152
-
153
- _searchNumberTags (tags, beginAt) {
154
-
155
- const foundAt = this._frame.indexOf(tags, beginAt);
156
-
157
- // escaped
158
- if (
159
- 0 < foundAt &&
160
- this._escaped.includes(this._frame[foundAt]) &&
161
- this._frame[foundAt - 1] === this._escapeWith
162
- ) {
163
-
164
- // escaper not escaped
165
- if (!this._escaped.includes(this._escapeWith) || 1 >= foundAt || this._frame[foundAt - 2] !== this._escapeWith) {
166
- return this._searchTags(tags, foundAt + 1);
167
- }
168
-
169
- }
170
-
171
- return foundAt;
172
-
173
- }
174
-
175
- _searchBufferOrArrayTags (tags, beginAt) {
176
-
177
- // Buffer
178
- if (tags instanceof Buffer) {
179
- return this._frame.indexOf(tags, beginAt);
180
- }
181
-
182
- // Array
183
- else if (tags instanceof Array) {
184
-
185
- let foundAt = -1;
186
- let type = "";
187
-
188
- for (let i = 0; i < tags.length; ++i) {
189
-
190
- // number | Buffer
191
- if ("number" === typeof tags[i] || ("object" === typeof tags[i] && tags[i] instanceof Buffer)) {
192
-
193
- const _foundAt = this._frame.indexOf(tags[i], beginAt);
194
-
195
- if (-1 < _foundAt && (-1 >= foundAt || _foundAt < foundAt)) {
196
- foundAt = _foundAt;
197
- type = typeof tags[i];
198
- }
199
-
200
- }
201
-
202
- }
203
-
204
- // escaped
205
- if (
206
- "number" === type && 0 < foundAt &&
207
- this._escaped.includes(this._frame[foundAt]) &&
208
- this._frame[foundAt - 1] === this._escapeWith
209
- ) {
210
-
211
- // escaper not escaped
212
- if (!this._escaped.includes(this._escapeWith) || 1 >= foundAt || this._frame[foundAt - 2] !== this._escapeWith) {
213
- foundAt = this._searchTags(tags, foundAt + 1);
214
- }
215
-
216
- }
217
-
218
- return foundAt;
219
-
220
- }
221
-
222
- return -1;
223
-
224
- }
225
-
226
- _searchFirstTag (tag, beginAt = 0) {
227
-
228
- let startAt = -1;
229
- let endAt = -1;
230
-
231
- // number
232
- if ("number" === typeof tag) {
233
-
234
- const find = this._searchFirstNumberTag(tag, beginAt);
235
-
236
- startAt = find.start;
237
- endAt = find.end;
238
-
239
- }
240
-
241
- // Buffer | Array
242
- else if ("object" === typeof tag) {
243
-
244
- const find = this._searchFirstBufferOrArrayTag(tag, beginAt);
245
-
246
- startAt = find.start;
247
- endAt = find.end;
248
-
249
- }
250
-
251
- // not found
252
- if (-1 >= startAt || -1 >= endAt) {
253
- return null;
254
- }
255
-
256
- // escaped
257
- else if (
258
- 0 < startAt &&
259
- // must be a number to be escaped
260
- 1 === endAt - startAt &&
261
- this._escaped.includes(this._frame[startAt]) && this._frame[startAt - 1] === this._escapeWith
262
- ) {
263
-
264
- // escaper not escaped
265
- if (!this._escaped.includes(this._escapeWith) || 1 >= startAt || this._frame[startAt - 2] !== this._escapeWith) {
266
- return this._searchFirstTag(tag, endAt + 1);
267
- }
268
- else {
269
-
270
- return {
271
- "start": startAt,
272
- "end": endAt
273
- };
274
-
275
- }
276
-
277
- }
278
-
279
- // not escaped
280
- else {
281
-
282
- return {
283
- "start": startAt,
284
- "end": endAt
285
- };
286
-
287
- }
288
-
289
- }
290
-
291
- _searchFirstNumberTag (tag, beginAt) {
292
-
293
- const startAt = this._frame.indexOf(tag, beginAt);
294
-
295
- return {
296
- "start": startAt,
297
- "end": startAt + 1
298
- };
299
-
300
- }
301
-
302
- _searchFirstBufferOrArrayTag (tag, beginAt) {
303
-
304
- let startAt = -1;
305
- let endAt = -1;
306
-
307
- // Buffer
308
- if (tag instanceof Buffer) {
309
-
310
- startAt = this._frame.indexOf(tag, beginAt);
311
- endAt = startAt + tag.length;
312
-
313
- }
314
-
315
- // Array
316
- else if (tag instanceof Array) {
317
-
318
- for (let i = 0; i < tag.length; ++i) {
319
-
320
- // number | Buffer
321
- if ("number" === typeof tag[i] ||
322
- ("object" === typeof tag[i] && tag[i] instanceof Buffer)
323
- ) {
324
-
325
- const _startAt = this._frame.indexOf(tag[i], beginAt);
326
-
327
- if (-1 < _startAt && (-1 >= startAt || _startAt < startAt)) {
328
- startAt = _startAt;
329
- endAt = startAt + ("number" === typeof tag[i] ? 1 : tag[i].length);
330
- }
331
-
332
- }
333
-
334
- }
335
-
336
- }
337
-
338
- return {
339
- "start": startAt,
340
- "end": endAt
341
- };
342
-
343
- }
344
-
345
- _searchFirstStart () {
346
- return this._searchFirstTag(this._startWith);
347
- }
348
-
349
- _searchFirstEnd () {
350
-
351
- const firstTag = this._searchFirstTag(this._endWith);
352
-
353
- if (firstTag) {
354
-
355
- if ("end+1" === this._controlBits) {
356
- firstTag.end += 1;
357
- }
358
- else if ("end+2" === this._controlBits) {
359
- firstTag.end += 2;
360
- }
361
-
362
- // end tag detected but without valid control bits length
363
- if (firstTag.end > this._frame.length) {
364
- return null;
365
- }
366
-
367
- }
368
-
369
- return firstTag;
370
-
371
- }
372
-
373
- };
@@ -1,37 +0,0 @@
1
-
2
- "use strict";
3
-
4
- // deps
5
-
6
- const { exec } = require("child_process");
7
- const { join } = require("path");
8
- const { unlink } = require("fs");
9
-
10
- // consts
11
-
12
- const MAX_TIMEOUT = 10000;
13
-
14
- // tests
15
-
16
- describe("compilation typescript", () => {
17
-
18
- after((done) => {
19
-
20
- unlink(join(__dirname, "typescript", "compilation.js"), (err) => {
21
- return err ? done(err) : done();
22
- });
23
-
24
- });
25
-
26
- it("should compile typescript file", (done) => {
27
-
28
- exec("tsc " + join(__dirname, "typescript", "compilation.ts"), {
29
- "cwd": join(__dirname, ".."),
30
- "windowsHide": true
31
- }, (err) => {
32
- return err ? done(err) : done();
33
- });
34
-
35
- }).timeout(MAX_TIMEOUT);
36
-
37
- });