@theia/process 1.34.2 → 1.34.3

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.
Files changed (70) hide show
  1. package/LICENSE +641 -641
  2. package/README.md +30 -30
  3. package/lib/common/process-common-module.d.ts +3 -3
  4. package/lib/common/process-common-module.js +22 -22
  5. package/lib/common/process-manager-types.d.ts +35 -35
  6. package/lib/common/process-manager-types.js +23 -23
  7. package/lib/common/shell-command-builder.d.ts +49 -49
  8. package/lib/common/shell-command-builder.js +174 -174
  9. package/lib/common/shell-command-builder.slow-spec.d.ts +9 -9
  10. package/lib/common/shell-command-builder.slow-spec.js +404 -404
  11. package/lib/common/shell-quoting.d.ts +91 -91
  12. package/lib/common/shell-quoting.js +145 -145
  13. package/lib/common/shell-quoting.spec.d.ts +1 -1
  14. package/lib/common/shell-quoting.spec.js +170 -170
  15. package/lib/node/dev-null-stream.d.ts +17 -17
  16. package/lib/node/dev-null-stream.js +41 -41
  17. package/lib/node/index.d.ts +6 -6
  18. package/lib/node/index.js +33 -33
  19. package/lib/node/multi-ring-buffer.d.ts +68 -68
  20. package/lib/node/multi-ring-buffer.js +310 -310
  21. package/lib/node/multi-ring-buffer.spec.d.ts +1 -1
  22. package/lib/node/multi-ring-buffer.spec.js +422 -422
  23. package/lib/node/process-backend-module.d.ts +3 -3
  24. package/lib/node/process-backend-module.js +56 -56
  25. package/lib/node/process-manager.d.ts +33 -33
  26. package/lib/node/process-manager.js +113 -113
  27. package/lib/node/process.d.ts +95 -95
  28. package/lib/node/process.js +153 -153
  29. package/lib/node/pseudo-pty.d.ts +22 -22
  30. package/lib/node/pseudo-pty.js +38 -38
  31. package/lib/node/raw-process.d.ts +45 -45
  32. package/lib/node/raw-process.js +115 -115
  33. package/lib/node/raw-process.spec.d.ts +1 -1
  34. package/lib/node/raw-process.spec.js +164 -164
  35. package/lib/node/task-terminal-process.d.ts +10 -10
  36. package/lib/node/task-terminal-process.js +47 -47
  37. package/lib/node/terminal-process.d.ts +49 -49
  38. package/lib/node/terminal-process.js +180 -180
  39. package/lib/node/terminal-process.spec.d.ts +1 -1
  40. package/lib/node/terminal-process.spec.js +89 -89
  41. package/lib/node/test/process-test-container.d.ts +2 -2
  42. package/lib/node/test/process-test-container.js +28 -28
  43. package/lib/node/utils.d.ts +16 -16
  44. package/lib/node/utils.js +77 -77
  45. package/package.json +4 -4
  46. package/src/common/process-common-module.ts +22 -22
  47. package/src/common/process-manager-types.ts +58 -58
  48. package/src/common/shell-command-builder.slow-spec.ts +486 -486
  49. package/src/common/shell-command-builder.ts +187 -187
  50. package/src/common/shell-quoting.spec.ts +176 -176
  51. package/src/common/shell-quoting.ts +236 -236
  52. package/src/common/tests/$weird(),file=name.js +1 -1
  53. package/src/common/tests/white space.js +1 -1
  54. package/src/node/dev-null-stream.ts +47 -47
  55. package/src/node/index.ts +22 -22
  56. package/src/node/multi-ring-buffer.spec.ts +486 -486
  57. package/src/node/multi-ring-buffer.ts +348 -348
  58. package/src/node/process-backend-module.ts +67 -67
  59. package/src/node/process-manager.ts +107 -107
  60. package/src/node/process.ts +207 -207
  61. package/src/node/pseudo-pty.ts +54 -54
  62. package/src/node/raw-process.spec.ts +199 -199
  63. package/src/node/raw-process.ts +156 -156
  64. package/src/node/string-argv.d.ts +21 -21
  65. package/src/node/task-terminal-process.ts +41 -41
  66. package/src/node/terminal-process.spec.ts +104 -104
  67. package/src/node/terminal-process.ts +198 -198
  68. package/src/node/test/process-fork-test.js +22 -22
  69. package/src/node/test/process-test-container.ts +27 -27
  70. package/src/node/utils.ts +79 -79
@@ -1,311 +1,311 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2017 Ericsson and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
- return c > 3 && r && Object.defineProperty(target, key, r), r;
22
- };
23
- var __metadata = (this && this.__metadata) || function (k, v) {
24
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
- };
26
- var __param = (this && this.__param) || function (paramIndex, decorator) {
27
- return function (target, key) { decorator(target, key, paramIndex); }
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.MultiRingBuffer = exports.MultiRingBufferOptions = exports.MultiRingBufferReadableStream = void 0;
31
- const stream = require("stream");
32
- const inversify_1 = require("@theia/core/shared/inversify");
33
- /**
34
- * The MultiRingBuffer is a ring buffer implementation that allows
35
- * multiple independent readers.
36
- *
37
- * These readers are created using the getReader or getStream functions
38
- * to create a reader that can be read using deq() or one that is a readable stream.
39
- */
40
- class MultiRingBufferReadableStream extends stream.Readable {
41
- constructor(ringBuffer, reader, encoding = 'utf8') {
42
- super();
43
- this.ringBuffer = ringBuffer;
44
- this.reader = reader;
45
- this.encoding = encoding;
46
- this.more = false;
47
- this.disposed = false;
48
- this.setEncoding(encoding);
49
- }
50
- _read(size) {
51
- this.more = true;
52
- this.deq(size);
53
- }
54
- _destroy(err, callback) {
55
- this.ringBuffer.closeStream(this);
56
- this.ringBuffer.closeReader(this.reader);
57
- this.disposed = true;
58
- this.removeAllListeners();
59
- callback(err);
60
- }
61
- onData() {
62
- if (this.more === true) {
63
- this.deq(-1);
64
- }
65
- }
66
- deq(size) {
67
- if (this.disposed === true) {
68
- return;
69
- }
70
- let buffer = undefined;
71
- do {
72
- buffer = this.ringBuffer.deq(this.reader, size, this.encoding);
73
- if (buffer !== undefined) {
74
- this.more = this.push(buffer, this.encoding);
75
- }
76
- } while (buffer !== undefined && this.more === true && this.disposed === false);
77
- }
78
- dispose() {
79
- this.destroy();
80
- }
81
- }
82
- exports.MultiRingBufferReadableStream = MultiRingBufferReadableStream;
83
- exports.MultiRingBufferOptions = Symbol('MultiRingBufferOptions');
84
- let MultiRingBuffer = class MultiRingBuffer {
85
- constructor(options) {
86
- this.options = options;
87
- this.head = -1;
88
- this.tail = -1;
89
- this.readerId = 0;
90
- this.maxSize = options.size;
91
- if (options.encoding !== undefined) {
92
- this.encoding = options.encoding;
93
- }
94
- else {
95
- this.encoding = 'utf8';
96
- }
97
- this.buffer = Buffer.alloc(this.maxSize);
98
- this.readers = new Map();
99
- this.streams = new Map();
100
- }
101
- enq(str, encoding = 'utf8') {
102
- let buffer = Buffer.from(str, encoding);
103
- // Take the last elements of string if it's too big, drop the rest
104
- if (buffer.length > this.maxSize) {
105
- buffer = buffer.slice(buffer.length - this.maxSize);
106
- }
107
- if (buffer.length === 0) {
108
- return;
109
- }
110
- // empty
111
- if (this.head === -1 && this.tail === -1) {
112
- this.head = 0;
113
- this.tail = 0;
114
- buffer.copy(this.buffer, this.head, 0, buffer.length);
115
- this.head = buffer.length - 1;
116
- this.onData(0);
117
- return;
118
- }
119
- const startHead = this.inc(this.head, 1).newPos;
120
- if (this.inc(startHead, buffer.length).wrap === true) {
121
- buffer.copy(this.buffer, startHead, 0, this.maxSize - startHead);
122
- buffer.copy(this.buffer, 0, this.maxSize - startHead);
123
- }
124
- else {
125
- buffer.copy(this.buffer, startHead);
126
- }
127
- this.incTails(buffer.length);
128
- this.head = this.inc(this.head, buffer.length).newPos;
129
- this.onData(startHead);
130
- }
131
- getReader() {
132
- this.readers.set(this.readerId, this.tail);
133
- return this.readerId++;
134
- }
135
- closeReader(id) {
136
- this.readers.delete(id);
137
- }
138
- getStream(encoding) {
139
- const reader = this.getReader();
140
- const readableStream = new MultiRingBufferReadableStream(this, reader, encoding);
141
- this.streams.set(readableStream, reader);
142
- return readableStream;
143
- }
144
- closeStream(readableStream) {
145
- this.streams.delete(readableStream);
146
- }
147
- onData(start) {
148
- /* Any stream that has read everything already
149
- * Should go back to the last buffer in start offset */
150
- for (const [id, pos] of this.readers) {
151
- if (pos === -1) {
152
- this.readers.set(id, start);
153
- }
154
- }
155
- /* Notify the streams there's new data. */
156
- for (const [readableStream] of this.streams) {
157
- readableStream.onData();
158
- }
159
- }
160
- deq(id, size = -1, encoding = 'utf8') {
161
- const pos = this.readers.get(id);
162
- if (pos === undefined || pos === -1) {
163
- return undefined;
164
- }
165
- if (size === 0) {
166
- return undefined;
167
- }
168
- let buffer = '';
169
- const maxDeqSize = this.sizeForReader(id);
170
- const wrapped = this.isWrapped(pos, this.head);
171
- let deqSize;
172
- if (size === -1) {
173
- deqSize = maxDeqSize;
174
- }
175
- else {
176
- deqSize = Math.min(size, maxDeqSize);
177
- }
178
- if (wrapped === false) { // no wrap
179
- buffer = this.buffer.toString(encoding, pos, pos + deqSize);
180
- }
181
- else { // wrap
182
- buffer = buffer.concat(this.buffer.toString(encoding, pos, this.maxSize), this.buffer.toString(encoding, 0, deqSize - (this.maxSize - pos)));
183
- }
184
- const lastIndex = this.inc(pos, deqSize - 1).newPos;
185
- // everything is read
186
- if (lastIndex === this.head) {
187
- this.readers.set(id, -1);
188
- }
189
- else {
190
- this.readers.set(id, this.inc(pos, deqSize).newPos);
191
- }
192
- return buffer;
193
- }
194
- sizeForReader(id) {
195
- const pos = this.readers.get(id);
196
- if (pos === undefined) {
197
- return 0;
198
- }
199
- return this.sizeFrom(pos, this.head, this.isWrapped(pos, this.head));
200
- }
201
- size() {
202
- return this.sizeFrom(this.tail, this.head, this.isWrapped(this.tail, this.head));
203
- }
204
- isWrapped(from, to) {
205
- if (to < from) {
206
- return true;
207
- }
208
- else {
209
- return false;
210
- }
211
- }
212
- sizeFrom(from, to, wrap) {
213
- if (from === -1 || to === -1) {
214
- return 0;
215
- }
216
- else {
217
- if (wrap === false) {
218
- return to - from + 1;
219
- }
220
- else {
221
- return to + 1 + this.maxSize - from;
222
- }
223
- }
224
- }
225
- emptyForReader(id) {
226
- const pos = this.readers.get(id);
227
- if (pos === undefined || pos === -1) {
228
- return true;
229
- }
230
- else {
231
- return false;
232
- }
233
- }
234
- empty() {
235
- if (this.head === -1 && this.tail === -1) {
236
- return true;
237
- }
238
- else {
239
- return false;
240
- }
241
- }
242
- streamsSize() {
243
- return this.streams.size;
244
- }
245
- readersSize() {
246
- return this.readers.size;
247
- }
248
- /**
249
- * Dispose all the attached readers/streams.
250
- */
251
- dispose() {
252
- for (const readableStream of this.streams.keys()) {
253
- readableStream.dispose();
254
- }
255
- }
256
- /* Position should be incremented if it goes pass end. */
257
- shouldIncPos(pos, end, size) {
258
- const { newPos: newHead, wrap } = this.inc(end, size);
259
- /* Tail Head */
260
- if (this.isWrapped(pos, end) === false) {
261
- // Head needs to wrap to push the tail
262
- if (wrap === true && newHead >= pos) {
263
- return true;
264
- }
265
- }
266
- else { /* Head Tail */
267
- // If we wrap head is pushing tail, or if it goes over pos
268
- if (wrap === true || newHead >= pos) {
269
- return true;
270
- }
271
- }
272
- return false;
273
- }
274
- incTailSize(pos, head, size) {
275
- const { newPos: newHead } = this.inc(head, size);
276
- /* New tail is 1 past newHead. */
277
- return this.inc(newHead, 1);
278
- }
279
- incTail(pos, size) {
280
- if (this.shouldIncPos(pos, this.head, size) === false) {
281
- return { newPos: pos, wrap: false };
282
- }
283
- return this.incTailSize(pos, this.head, size);
284
- }
285
- /* Increment the main tail and all the reader positions. */
286
- incTails(size) {
287
- this.tail = this.incTail(this.tail, size).newPos;
288
- for (const [id, pos] of this.readers) {
289
- if (pos !== -1) {
290
- if (this.shouldIncPos(pos, this.tail, size) === true) {
291
- this.readers.set(id, this.tail);
292
- }
293
- }
294
- }
295
- }
296
- inc(pos, size) {
297
- if (size === 0) {
298
- return { newPos: pos, wrap: false };
299
- }
300
- const newPos = (pos + size) % this.maxSize;
301
- const wrap = newPos <= pos;
302
- return { newPos, wrap };
303
- }
304
- };
305
- MultiRingBuffer = __decorate([
306
- (0, inversify_1.injectable)(),
307
- __param(0, (0, inversify_1.inject)(exports.MultiRingBufferOptions)),
308
- __metadata("design:paramtypes", [Object])
309
- ], MultiRingBuffer);
310
- exports.MultiRingBuffer = MultiRingBuffer;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2017 Ericsson and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __metadata = (this && this.__metadata) || function (k, v) {
24
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
+ };
26
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
27
+ return function (target, key) { decorator(target, key, paramIndex); }
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.MultiRingBuffer = exports.MultiRingBufferOptions = exports.MultiRingBufferReadableStream = void 0;
31
+ const stream = require("stream");
32
+ const inversify_1 = require("@theia/core/shared/inversify");
33
+ /**
34
+ * The MultiRingBuffer is a ring buffer implementation that allows
35
+ * multiple independent readers.
36
+ *
37
+ * These readers are created using the getReader or getStream functions
38
+ * to create a reader that can be read using deq() or one that is a readable stream.
39
+ */
40
+ class MultiRingBufferReadableStream extends stream.Readable {
41
+ constructor(ringBuffer, reader, encoding = 'utf8') {
42
+ super();
43
+ this.ringBuffer = ringBuffer;
44
+ this.reader = reader;
45
+ this.encoding = encoding;
46
+ this.more = false;
47
+ this.disposed = false;
48
+ this.setEncoding(encoding);
49
+ }
50
+ _read(size) {
51
+ this.more = true;
52
+ this.deq(size);
53
+ }
54
+ _destroy(err, callback) {
55
+ this.ringBuffer.closeStream(this);
56
+ this.ringBuffer.closeReader(this.reader);
57
+ this.disposed = true;
58
+ this.removeAllListeners();
59
+ callback(err);
60
+ }
61
+ onData() {
62
+ if (this.more === true) {
63
+ this.deq(-1);
64
+ }
65
+ }
66
+ deq(size) {
67
+ if (this.disposed === true) {
68
+ return;
69
+ }
70
+ let buffer = undefined;
71
+ do {
72
+ buffer = this.ringBuffer.deq(this.reader, size, this.encoding);
73
+ if (buffer !== undefined) {
74
+ this.more = this.push(buffer, this.encoding);
75
+ }
76
+ } while (buffer !== undefined && this.more === true && this.disposed === false);
77
+ }
78
+ dispose() {
79
+ this.destroy();
80
+ }
81
+ }
82
+ exports.MultiRingBufferReadableStream = MultiRingBufferReadableStream;
83
+ exports.MultiRingBufferOptions = Symbol('MultiRingBufferOptions');
84
+ let MultiRingBuffer = class MultiRingBuffer {
85
+ constructor(options) {
86
+ this.options = options;
87
+ this.head = -1;
88
+ this.tail = -1;
89
+ this.readerId = 0;
90
+ this.maxSize = options.size;
91
+ if (options.encoding !== undefined) {
92
+ this.encoding = options.encoding;
93
+ }
94
+ else {
95
+ this.encoding = 'utf8';
96
+ }
97
+ this.buffer = Buffer.alloc(this.maxSize);
98
+ this.readers = new Map();
99
+ this.streams = new Map();
100
+ }
101
+ enq(str, encoding = 'utf8') {
102
+ let buffer = Buffer.from(str, encoding);
103
+ // Take the last elements of string if it's too big, drop the rest
104
+ if (buffer.length > this.maxSize) {
105
+ buffer = buffer.slice(buffer.length - this.maxSize);
106
+ }
107
+ if (buffer.length === 0) {
108
+ return;
109
+ }
110
+ // empty
111
+ if (this.head === -1 && this.tail === -1) {
112
+ this.head = 0;
113
+ this.tail = 0;
114
+ buffer.copy(this.buffer, this.head, 0, buffer.length);
115
+ this.head = buffer.length - 1;
116
+ this.onData(0);
117
+ return;
118
+ }
119
+ const startHead = this.inc(this.head, 1).newPos;
120
+ if (this.inc(startHead, buffer.length).wrap === true) {
121
+ buffer.copy(this.buffer, startHead, 0, this.maxSize - startHead);
122
+ buffer.copy(this.buffer, 0, this.maxSize - startHead);
123
+ }
124
+ else {
125
+ buffer.copy(this.buffer, startHead);
126
+ }
127
+ this.incTails(buffer.length);
128
+ this.head = this.inc(this.head, buffer.length).newPos;
129
+ this.onData(startHead);
130
+ }
131
+ getReader() {
132
+ this.readers.set(this.readerId, this.tail);
133
+ return this.readerId++;
134
+ }
135
+ closeReader(id) {
136
+ this.readers.delete(id);
137
+ }
138
+ getStream(encoding) {
139
+ const reader = this.getReader();
140
+ const readableStream = new MultiRingBufferReadableStream(this, reader, encoding);
141
+ this.streams.set(readableStream, reader);
142
+ return readableStream;
143
+ }
144
+ closeStream(readableStream) {
145
+ this.streams.delete(readableStream);
146
+ }
147
+ onData(start) {
148
+ /* Any stream that has read everything already
149
+ * Should go back to the last buffer in start offset */
150
+ for (const [id, pos] of this.readers) {
151
+ if (pos === -1) {
152
+ this.readers.set(id, start);
153
+ }
154
+ }
155
+ /* Notify the streams there's new data. */
156
+ for (const [readableStream] of this.streams) {
157
+ readableStream.onData();
158
+ }
159
+ }
160
+ deq(id, size = -1, encoding = 'utf8') {
161
+ const pos = this.readers.get(id);
162
+ if (pos === undefined || pos === -1) {
163
+ return undefined;
164
+ }
165
+ if (size === 0) {
166
+ return undefined;
167
+ }
168
+ let buffer = '';
169
+ const maxDeqSize = this.sizeForReader(id);
170
+ const wrapped = this.isWrapped(pos, this.head);
171
+ let deqSize;
172
+ if (size === -1) {
173
+ deqSize = maxDeqSize;
174
+ }
175
+ else {
176
+ deqSize = Math.min(size, maxDeqSize);
177
+ }
178
+ if (wrapped === false) { // no wrap
179
+ buffer = this.buffer.toString(encoding, pos, pos + deqSize);
180
+ }
181
+ else { // wrap
182
+ buffer = buffer.concat(this.buffer.toString(encoding, pos, this.maxSize), this.buffer.toString(encoding, 0, deqSize - (this.maxSize - pos)));
183
+ }
184
+ const lastIndex = this.inc(pos, deqSize - 1).newPos;
185
+ // everything is read
186
+ if (lastIndex === this.head) {
187
+ this.readers.set(id, -1);
188
+ }
189
+ else {
190
+ this.readers.set(id, this.inc(pos, deqSize).newPos);
191
+ }
192
+ return buffer;
193
+ }
194
+ sizeForReader(id) {
195
+ const pos = this.readers.get(id);
196
+ if (pos === undefined) {
197
+ return 0;
198
+ }
199
+ return this.sizeFrom(pos, this.head, this.isWrapped(pos, this.head));
200
+ }
201
+ size() {
202
+ return this.sizeFrom(this.tail, this.head, this.isWrapped(this.tail, this.head));
203
+ }
204
+ isWrapped(from, to) {
205
+ if (to < from) {
206
+ return true;
207
+ }
208
+ else {
209
+ return false;
210
+ }
211
+ }
212
+ sizeFrom(from, to, wrap) {
213
+ if (from === -1 || to === -1) {
214
+ return 0;
215
+ }
216
+ else {
217
+ if (wrap === false) {
218
+ return to - from + 1;
219
+ }
220
+ else {
221
+ return to + 1 + this.maxSize - from;
222
+ }
223
+ }
224
+ }
225
+ emptyForReader(id) {
226
+ const pos = this.readers.get(id);
227
+ if (pos === undefined || pos === -1) {
228
+ return true;
229
+ }
230
+ else {
231
+ return false;
232
+ }
233
+ }
234
+ empty() {
235
+ if (this.head === -1 && this.tail === -1) {
236
+ return true;
237
+ }
238
+ else {
239
+ return false;
240
+ }
241
+ }
242
+ streamsSize() {
243
+ return this.streams.size;
244
+ }
245
+ readersSize() {
246
+ return this.readers.size;
247
+ }
248
+ /**
249
+ * Dispose all the attached readers/streams.
250
+ */
251
+ dispose() {
252
+ for (const readableStream of this.streams.keys()) {
253
+ readableStream.dispose();
254
+ }
255
+ }
256
+ /* Position should be incremented if it goes pass end. */
257
+ shouldIncPos(pos, end, size) {
258
+ const { newPos: newHead, wrap } = this.inc(end, size);
259
+ /* Tail Head */
260
+ if (this.isWrapped(pos, end) === false) {
261
+ // Head needs to wrap to push the tail
262
+ if (wrap === true && newHead >= pos) {
263
+ return true;
264
+ }
265
+ }
266
+ else { /* Head Tail */
267
+ // If we wrap head is pushing tail, or if it goes over pos
268
+ if (wrap === true || newHead >= pos) {
269
+ return true;
270
+ }
271
+ }
272
+ return false;
273
+ }
274
+ incTailSize(pos, head, size) {
275
+ const { newPos: newHead } = this.inc(head, size);
276
+ /* New tail is 1 past newHead. */
277
+ return this.inc(newHead, 1);
278
+ }
279
+ incTail(pos, size) {
280
+ if (this.shouldIncPos(pos, this.head, size) === false) {
281
+ return { newPos: pos, wrap: false };
282
+ }
283
+ return this.incTailSize(pos, this.head, size);
284
+ }
285
+ /* Increment the main tail and all the reader positions. */
286
+ incTails(size) {
287
+ this.tail = this.incTail(this.tail, size).newPos;
288
+ for (const [id, pos] of this.readers) {
289
+ if (pos !== -1) {
290
+ if (this.shouldIncPos(pos, this.tail, size) === true) {
291
+ this.readers.set(id, this.tail);
292
+ }
293
+ }
294
+ }
295
+ }
296
+ inc(pos, size) {
297
+ if (size === 0) {
298
+ return { newPos: pos, wrap: false };
299
+ }
300
+ const newPos = (pos + size) % this.maxSize;
301
+ const wrap = newPos <= pos;
302
+ return { newPos, wrap };
303
+ }
304
+ };
305
+ MultiRingBuffer = __decorate([
306
+ (0, inversify_1.injectable)(),
307
+ __param(0, (0, inversify_1.inject)(exports.MultiRingBufferOptions)),
308
+ __metadata("design:paramtypes", [Object])
309
+ ], MultiRingBuffer);
310
+ exports.MultiRingBuffer = MultiRingBuffer;
311
311
  //# sourceMappingURL=multi-ring-buffer.js.map
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=multi-ring-buffer.spec.d.ts.map