nerdbank-streams 2.10.37-alpha → 2.10.69
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/js/AcceptanceParameters.d.ts +4 -4
- package/js/AcceptanceParameters.js +2 -2
- package/js/Channel.d.ts +71 -70
- package/js/Channel.js +219 -219
- package/js/Channel.js.map +1 -1
- package/js/ChannelOptions.d.ts +4 -4
- package/js/ChannelOptions.js +2 -2
- package/js/ControlCode.d.ts +30 -30
- package/js/ControlCode.js +34 -34
- package/js/ControlCode.js.map +1 -1
- package/js/Deferred.d.ts +39 -39
- package/js/Deferred.js +67 -67
- package/js/FrameHeader.d.ts +20 -20
- package/js/FrameHeader.js +39 -39
- package/js/FullDuplexStream.d.ts +10 -10
- package/js/FullDuplexStream.js +31 -31
- package/js/IChannelOfferEventArgs.d.ts +17 -17
- package/js/IChannelOfferEventArgs.js +2 -2
- package/js/IDisposableObservable.d.ts +4 -4
- package/js/IDisposableObservable.js +2 -2
- package/js/MultiplexingStream.d.ts +220 -218
- package/js/MultiplexingStream.js +624 -610
- package/js/MultiplexingStream.js.map +1 -1
- package/js/MultiplexingStreamFormatters.d.ts +90 -89
- package/js/MultiplexingStreamFormatters.js +302 -302
- package/js/MultiplexingStreamOptions.d.ts +18 -18
- package/js/MultiplexingStreamOptions.js +2 -2
- package/js/OfferParameters.d.ts +6 -6
- package/js/OfferParameters.js +2 -2
- package/js/QualifiedChannelId.d.ts +25 -25
- package/js/QualifiedChannelId.js +38 -38
- package/js/QualifiedChannelId.js.map +1 -1
- package/js/Utilities.d.ts +12 -11
- package/js/Utilities.js +154 -154
- package/js/index.d.ts +8 -8
- package/js/index.js +15 -15
- package/package.json +18 -18
- package/src/MultiplexingStream.ts +18 -1
package/js/OfferParameters.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export interface OfferParameters {
|
|
2
|
-
/** The name of the channel. */
|
|
3
|
-
name: string;
|
|
4
|
-
/** The maximum number of bytes that may be transmitted and not yet acknowledged as processed by the remote party. */
|
|
5
|
-
remoteWindowSize?: number;
|
|
6
|
-
}
|
|
1
|
+
export interface OfferParameters {
|
|
2
|
+
/** The name of the channel. */
|
|
3
|
+
name: string;
|
|
4
|
+
/** The maximum number of bytes that may be transmitted and not yet acknowledged as processed by the remote party. */
|
|
5
|
+
remoteWindowSize?: number;
|
|
6
|
+
}
|
package/js/OfferParameters.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=OfferParameters.js.map
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
export interface QualifiedChannelId {
|
|
2
|
-
/** Gets the channel ID. */
|
|
3
|
-
readonly id: number;
|
|
4
|
-
/** Gets a value indicating where the channel originated. */
|
|
5
|
-
readonly source: ChannelSource;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* An enumeration of the possible sources of a channel.
|
|
9
|
-
* @description The ordinal values are chosen so as to make flipping the perspective as easy as negating the value,
|
|
10
|
-
* while leaving the Seeded value unchanged.
|
|
11
|
-
*/
|
|
12
|
-
export declare enum ChannelSource {
|
|
13
|
-
/** The channel was offered by this MultiplexingStream instance to the other party. */
|
|
14
|
-
Local = 1,
|
|
15
|
-
/** The channel was offered to this MultiplexingStream instance by the other party. */
|
|
16
|
-
Remote = -1,
|
|
17
|
-
/**
|
|
18
|
-
* The channel was seeded during construction via the Options.SeededChannels collection.
|
|
19
|
-
* This channel is to be accepted by both parties.
|
|
20
|
-
*/
|
|
21
|
-
Seeded = 0
|
|
22
|
-
}
|
|
23
|
-
export declare namespace QualifiedChannelId {
|
|
24
|
-
function toString(id: QualifiedChannelId): string;
|
|
25
|
-
}
|
|
1
|
+
export interface QualifiedChannelId {
|
|
2
|
+
/** Gets the channel ID. */
|
|
3
|
+
readonly id: number;
|
|
4
|
+
/** Gets a value indicating where the channel originated. */
|
|
5
|
+
readonly source: ChannelSource;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* An enumeration of the possible sources of a channel.
|
|
9
|
+
* @description The ordinal values are chosen so as to make flipping the perspective as easy as negating the value,
|
|
10
|
+
* while leaving the Seeded value unchanged.
|
|
11
|
+
*/
|
|
12
|
+
export declare enum ChannelSource {
|
|
13
|
+
/** The channel was offered by this MultiplexingStream instance to the other party. */
|
|
14
|
+
Local = 1,
|
|
15
|
+
/** The channel was offered to this MultiplexingStream instance by the other party. */
|
|
16
|
+
Remote = -1,
|
|
17
|
+
/**
|
|
18
|
+
* The channel was seeded during construction via the Options.SeededChannels collection.
|
|
19
|
+
* This channel is to be accepted by both parties.
|
|
20
|
+
*/
|
|
21
|
+
Seeded = 0
|
|
22
|
+
}
|
|
23
|
+
export declare namespace QualifiedChannelId {
|
|
24
|
+
function toString(id: QualifiedChannelId): string;
|
|
25
|
+
}
|
package/js/QualifiedChannelId.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QualifiedChannelId = exports.ChannelSource = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* An enumeration of the possible sources of a channel.
|
|
6
|
-
* @description The ordinal values are chosen so as to make flipping the perspective as easy as negating the value,
|
|
7
|
-
* while leaving the Seeded value unchanged.
|
|
8
|
-
*/
|
|
9
|
-
var ChannelSource;
|
|
10
|
-
(function (ChannelSource) {
|
|
11
|
-
/** The channel was offered by this MultiplexingStream instance to the other party. */
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
13
|
-
ChannelSource[ChannelSource["Local"] = 1] = "Local";
|
|
14
|
-
/** The channel was offered to this MultiplexingStream instance by the other party. */
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
16
|
-
ChannelSource[ChannelSource["Remote"] = -1] = "Remote";
|
|
17
|
-
/**
|
|
18
|
-
* The channel was seeded during construction via the Options.SeededChannels collection.
|
|
19
|
-
* This channel is to be accepted by both parties.
|
|
20
|
-
*/
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
22
|
-
ChannelSource[ChannelSource["Seeded"] = 0] = "Seeded";
|
|
23
|
-
})(ChannelSource
|
|
24
|
-
// tslint:disable-next-line: no-namespace
|
|
25
|
-
var QualifiedChannelId;
|
|
26
|
-
(function (QualifiedChannelId) {
|
|
27
|
-
function toString(id) {
|
|
28
|
-
const sourceName = id.source === ChannelSource.Local
|
|
29
|
-
? 'local'
|
|
30
|
-
: id.source === ChannelSource.Remote
|
|
31
|
-
? 'remote'
|
|
32
|
-
: id.source === ChannelSource.Seeded
|
|
33
|
-
? 'seeded'
|
|
34
|
-
: 'unknown';
|
|
35
|
-
return `${id.id} (${sourceName})`;
|
|
36
|
-
}
|
|
37
|
-
QualifiedChannelId.toString = toString;
|
|
38
|
-
})(QualifiedChannelId
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QualifiedChannelId = exports.ChannelSource = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* An enumeration of the possible sources of a channel.
|
|
6
|
+
* @description The ordinal values are chosen so as to make flipping the perspective as easy as negating the value,
|
|
7
|
+
* while leaving the Seeded value unchanged.
|
|
8
|
+
*/
|
|
9
|
+
var ChannelSource;
|
|
10
|
+
(function (ChannelSource) {
|
|
11
|
+
/** The channel was offered by this MultiplexingStream instance to the other party. */
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
13
|
+
ChannelSource[ChannelSource["Local"] = 1] = "Local";
|
|
14
|
+
/** The channel was offered to this MultiplexingStream instance by the other party. */
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
16
|
+
ChannelSource[ChannelSource["Remote"] = -1] = "Remote";
|
|
17
|
+
/**
|
|
18
|
+
* The channel was seeded during construction via the Options.SeededChannels collection.
|
|
19
|
+
* This channel is to be accepted by both parties.
|
|
20
|
+
*/
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
22
|
+
ChannelSource[ChannelSource["Seeded"] = 0] = "Seeded";
|
|
23
|
+
})(ChannelSource || (exports.ChannelSource = ChannelSource = {}));
|
|
24
|
+
// tslint:disable-next-line: no-namespace
|
|
25
|
+
var QualifiedChannelId;
|
|
26
|
+
(function (QualifiedChannelId) {
|
|
27
|
+
function toString(id) {
|
|
28
|
+
const sourceName = id.source === ChannelSource.Local
|
|
29
|
+
? 'local'
|
|
30
|
+
: id.source === ChannelSource.Remote
|
|
31
|
+
? 'remote'
|
|
32
|
+
: id.source === ChannelSource.Seeded
|
|
33
|
+
? 'seeded'
|
|
34
|
+
: 'unknown';
|
|
35
|
+
return `${id.id} (${sourceName})`;
|
|
36
|
+
}
|
|
37
|
+
QualifiedChannelId.toString = toString;
|
|
38
|
+
})(QualifiedChannelId || (exports.QualifiedChannelId = QualifiedChannelId = {}));
|
|
39
39
|
//# sourceMappingURL=QualifiedChannelId.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QualifiedChannelId.js","sourceRoot":"","sources":["../src/QualifiedChannelId.ts"],"names":[],"mappings":";;;AAQA;;;;GAIG;AACH,IAAY,aAeX;AAfD,WAAY,aAAa;IACxB,sFAAsF;IACtF,gEAAgE;IAChE,mDAAS,CAAA;IAET,sFAAsF;IACtF,gEAAgE;IAChE,sDAAW,CAAA;IAEX;;;OAGG;IACH,gEAAgE;IAChE,qDAAU,CAAA;AACX,CAAC,EAfW,aAAa,
|
|
1
|
+
{"version":3,"file":"QualifiedChannelId.js","sourceRoot":"","sources":["../src/QualifiedChannelId.ts"],"names":[],"mappings":";;;AAQA;;;;GAIG;AACH,IAAY,aAeX;AAfD,WAAY,aAAa;IACxB,sFAAsF;IACtF,gEAAgE;IAChE,mDAAS,CAAA;IAET,sFAAsF;IACtF,gEAAgE;IAChE,sDAAW,CAAA;IAEX;;;OAGG;IACH,gEAAgE;IAChE,qDAAU,CAAA;AACX,CAAC,EAfW,aAAa,6BAAb,aAAa,QAexB;AAED,yCAAyC;AACzC,IAAiB,kBAAkB,CAYlC;AAZD,WAAiB,kBAAkB;IAClC,SAAgB,QAAQ,CAAC,EAAsB;QAC9C,MAAM,UAAU,GACf,EAAE,CAAC,MAAM,KAAK,aAAa,CAAC,KAAK;YAChC,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,EAAE,CAAC,MAAM,KAAK,aAAa,CAAC,MAAM;gBACpC,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,EAAE,CAAC,MAAM,KAAK,aAAa,CAAC,MAAM;oBACpC,CAAC,CAAC,QAAQ;oBACV,CAAC,CAAC,SAAS,CAAA;QACb,OAAO,GAAG,EAAE,CAAC,EAAE,KAAK,UAAU,GAAG,CAAA;IAClC,CAAC;IAVe,2BAAQ,WAUvB,CAAA;AACF,CAAC,EAZgB,kBAAkB,kCAAlB,kBAAkB,QAYlC"}
|
package/js/Utilities.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function getBufferFrom(readable: NodeJS.ReadableStream, size: number, allowEndOfStream
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import CancellationToken from 'cancellationtoken';
|
|
4
|
+
import { IDisposableObservable } from './IDisposableObservable';
|
|
5
|
+
export declare function writeAsync(stream: NodeJS.WritableStream, chunk: any): Promise<void>;
|
|
6
|
+
export declare function writeSubstream(stream: NodeJS.WritableStream): NodeJS.WritableStream;
|
|
7
|
+
export declare function readSubstream(stream: NodeJS.ReadableStream): NodeJS.ReadableStream;
|
|
8
|
+
export declare function getBufferFrom(readable: NodeJS.ReadableStream, size: number, allowEndOfStream?: false, cancellationToken?: CancellationToken): Promise<Buffer>;
|
|
9
|
+
export declare function getBufferFrom(readable: NodeJS.ReadableStream, size: number, allowEndOfStream: true, cancellationToken?: CancellationToken): Promise<Buffer | null>;
|
|
10
|
+
export declare function throwIfDisposed(value: IDisposableObservable): void;
|
|
11
|
+
export declare function requireInteger(parameterName: string, value: number, serializedByteLength: number, signed?: 'unsigned' | 'signed'): void;
|
|
12
|
+
export declare function removeFromQueue<T>(value: T, queue: T[]): void;
|
package/js/Utilities.js
CHANGED
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeFromQueue = exports.requireInteger = exports.throwIfDisposed = exports.getBufferFrom = exports.readSubstream = exports.writeSubstream = exports.writeAsync = void 0;
|
|
4
|
-
const stream_1 = require("stream");
|
|
5
|
-
const Deferred_1 = require("./Deferred");
|
|
6
|
-
async function writeAsync(stream, chunk) {
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
stream.write(chunk, (err) => {
|
|
9
|
-
if (err) {
|
|
10
|
-
reject(err);
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
resolve();
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
exports.writeAsync = writeAsync;
|
|
19
|
-
function writeSubstream(stream) {
|
|
20
|
-
return new stream_1.Writable({
|
|
21
|
-
async write(chunk, _, callback) {
|
|
22
|
-
try {
|
|
23
|
-
const dv = new DataView(new ArrayBuffer(4));
|
|
24
|
-
dv.setUint32(0, chunk.length, false);
|
|
25
|
-
await writeAsync(stream, Buffer.from(dv.buffer));
|
|
26
|
-
await writeAsync(stream, chunk);
|
|
27
|
-
callback();
|
|
28
|
-
}
|
|
29
|
-
catch (err) {
|
|
30
|
-
callback(err);
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
final(callback) {
|
|
34
|
-
// Write the terminating 0 length sequence.
|
|
35
|
-
stream.write(new Uint8Array(4), callback);
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
exports.writeSubstream = writeSubstream;
|
|
40
|
-
function readSubstream(stream) {
|
|
41
|
-
return new stream_1.Readable({
|
|
42
|
-
async read(_) {
|
|
43
|
-
const lenBuffer = await getBufferFrom(stream, 4);
|
|
44
|
-
const dv = new DataView(lenBuffer.buffer, lenBuffer.byteOffset, lenBuffer.length);
|
|
45
|
-
const chunkSize = dv.getUint32(0, false);
|
|
46
|
-
if (chunkSize === 0) {
|
|
47
|
-
this.push(null);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
// TODO: make this *stream* instead of read as an atomic chunk.
|
|
51
|
-
const payload = await getBufferFrom(stream, chunkSize);
|
|
52
|
-
this.push(payload);
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
exports.readSubstream = readSubstream;
|
|
57
|
-
async function getBufferFrom(readable, size, allowEndOfStream = false, cancellationToken) {
|
|
58
|
-
const streamEnded = new Deferred_1.Deferred();
|
|
59
|
-
if (size === 0) {
|
|
60
|
-
return Buffer.from([]);
|
|
61
|
-
}
|
|
62
|
-
let readBuffer = null;
|
|
63
|
-
let index = 0;
|
|
64
|
-
while (size > 0) {
|
|
65
|
-
cancellationToken === null || cancellationToken === void 0 ? void 0 : cancellationToken.throwIfCancelled();
|
|
66
|
-
let availableSize = readable.readableLength;
|
|
67
|
-
if (!availableSize) {
|
|
68
|
-
// Check the end of stream
|
|
69
|
-
if (readable.readableEnded || streamEnded.isCompleted) {
|
|
70
|
-
// stream is closed
|
|
71
|
-
if (!allowEndOfStream) {
|
|
72
|
-
throw new Error('Stream terminated before required bytes were read.');
|
|
73
|
-
}
|
|
74
|
-
// Returns what has been read so far
|
|
75
|
-
if (readBuffer === null) {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
// we need trim extra spaces
|
|
79
|
-
return readBuffer.subarray(0, index);
|
|
80
|
-
}
|
|
81
|
-
// we retain this behavior when availableSize === false
|
|
82
|
-
// to make existing unit tests happy (which assumes we will try to read stream when no data is ready.)
|
|
83
|
-
availableSize = size;
|
|
84
|
-
}
|
|
85
|
-
else if (availableSize > size) {
|
|
86
|
-
availableSize = size;
|
|
87
|
-
}
|
|
88
|
-
const newBuffer = readable.read(availableSize);
|
|
89
|
-
if (newBuffer) {
|
|
90
|
-
if (newBuffer.length < availableSize && !allowEndOfStream) {
|
|
91
|
-
throw new Error('Stream terminated before required bytes were read.');
|
|
92
|
-
}
|
|
93
|
-
if (readBuffer === null) {
|
|
94
|
-
if (availableSize === size || newBuffer.length < availableSize) {
|
|
95
|
-
// in the fast pass, we read the entire data once, and donot allocate an extra array.
|
|
96
|
-
return newBuffer;
|
|
97
|
-
}
|
|
98
|
-
// if we read partial data, we need allocate a buffer to join all data together.
|
|
99
|
-
readBuffer = Buffer.alloc(size);
|
|
100
|
-
}
|
|
101
|
-
// now append new data to the buffer
|
|
102
|
-
newBuffer.copy(readBuffer, index);
|
|
103
|
-
size -= newBuffer.length;
|
|
104
|
-
index += newBuffer.length;
|
|
105
|
-
}
|
|
106
|
-
if (size > 0) {
|
|
107
|
-
const bytesAvailable = new Deferred_1.Deferred();
|
|
108
|
-
const bytesAvailableCallback = bytesAvailable.resolve.bind(bytesAvailable);
|
|
109
|
-
const streamEndedCallback = streamEnded.resolve.bind(streamEnded);
|
|
110
|
-
readable.once('readable', bytesAvailableCallback);
|
|
111
|
-
readable.once('end', streamEndedCallback);
|
|
112
|
-
try {
|
|
113
|
-
const endPromise = Promise.race([bytesAvailable.promise, streamEnded.promise]);
|
|
114
|
-
await (cancellationToken ? cancellationToken.racePromise(endPromise) : endPromise);
|
|
115
|
-
}
|
|
116
|
-
finally {
|
|
117
|
-
readable.removeListener('readable', bytesAvailableCallback);
|
|
118
|
-
readable.removeListener('end', streamEndedCallback);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return readBuffer;
|
|
123
|
-
}
|
|
124
|
-
exports.getBufferFrom = getBufferFrom;
|
|
125
|
-
function throwIfDisposed(value) {
|
|
126
|
-
if (value.isDisposed) {
|
|
127
|
-
throw new Error('disposed');
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
exports.throwIfDisposed = throwIfDisposed;
|
|
131
|
-
function requireInteger(parameterName, value, serializedByteLength, signed = 'signed') {
|
|
132
|
-
if (!Number.isInteger(value)) {
|
|
133
|
-
throw new Error(`${parameterName} must be an integer.`);
|
|
134
|
-
}
|
|
135
|
-
let bits = serializedByteLength * 8;
|
|
136
|
-
if (signed === 'signed') {
|
|
137
|
-
bits--;
|
|
138
|
-
}
|
|
139
|
-
const maxValue = Math.pow(2, bits) - 1;
|
|
140
|
-
const minValue = signed === 'signed' ? -Math.pow(2, bits) : 0;
|
|
141
|
-
if (value > maxValue || value < minValue) {
|
|
142
|
-
throw new Error(`${parameterName} must be in the range ${minValue}-${maxValue}.`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
exports.requireInteger = requireInteger;
|
|
146
|
-
function removeFromQueue(value, queue) {
|
|
147
|
-
if (queue) {
|
|
148
|
-
const idx = queue.indexOf(value);
|
|
149
|
-
if (idx >= 0) {
|
|
150
|
-
queue.splice(idx, 1);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
exports.removeFromQueue = removeFromQueue;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeFromQueue = exports.requireInteger = exports.throwIfDisposed = exports.getBufferFrom = exports.readSubstream = exports.writeSubstream = exports.writeAsync = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
const Deferred_1 = require("./Deferred");
|
|
6
|
+
async function writeAsync(stream, chunk) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
stream.write(chunk, (err) => {
|
|
9
|
+
if (err) {
|
|
10
|
+
reject(err);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
resolve();
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.writeAsync = writeAsync;
|
|
19
|
+
function writeSubstream(stream) {
|
|
20
|
+
return new stream_1.Writable({
|
|
21
|
+
async write(chunk, _, callback) {
|
|
22
|
+
try {
|
|
23
|
+
const dv = new DataView(new ArrayBuffer(4));
|
|
24
|
+
dv.setUint32(0, chunk.length, false);
|
|
25
|
+
await writeAsync(stream, Buffer.from(dv.buffer));
|
|
26
|
+
await writeAsync(stream, chunk);
|
|
27
|
+
callback();
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
callback(err);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
final(callback) {
|
|
34
|
+
// Write the terminating 0 length sequence.
|
|
35
|
+
stream.write(new Uint8Array(4), callback);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.writeSubstream = writeSubstream;
|
|
40
|
+
function readSubstream(stream) {
|
|
41
|
+
return new stream_1.Readable({
|
|
42
|
+
async read(_) {
|
|
43
|
+
const lenBuffer = await getBufferFrom(stream, 4);
|
|
44
|
+
const dv = new DataView(lenBuffer.buffer, lenBuffer.byteOffset, lenBuffer.length);
|
|
45
|
+
const chunkSize = dv.getUint32(0, false);
|
|
46
|
+
if (chunkSize === 0) {
|
|
47
|
+
this.push(null);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// TODO: make this *stream* instead of read as an atomic chunk.
|
|
51
|
+
const payload = await getBufferFrom(stream, chunkSize);
|
|
52
|
+
this.push(payload);
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
exports.readSubstream = readSubstream;
|
|
57
|
+
async function getBufferFrom(readable, size, allowEndOfStream = false, cancellationToken) {
|
|
58
|
+
const streamEnded = new Deferred_1.Deferred();
|
|
59
|
+
if (size === 0) {
|
|
60
|
+
return Buffer.from([]);
|
|
61
|
+
}
|
|
62
|
+
let readBuffer = null;
|
|
63
|
+
let index = 0;
|
|
64
|
+
while (size > 0) {
|
|
65
|
+
cancellationToken === null || cancellationToken === void 0 ? void 0 : cancellationToken.throwIfCancelled();
|
|
66
|
+
let availableSize = readable.readableLength;
|
|
67
|
+
if (!availableSize) {
|
|
68
|
+
// Check the end of stream
|
|
69
|
+
if (readable.readableEnded || streamEnded.isCompleted) {
|
|
70
|
+
// stream is closed
|
|
71
|
+
if (!allowEndOfStream) {
|
|
72
|
+
throw new Error('Stream terminated before required bytes were read.');
|
|
73
|
+
}
|
|
74
|
+
// Returns what has been read so far
|
|
75
|
+
if (readBuffer === null) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
// we need trim extra spaces
|
|
79
|
+
return readBuffer.subarray(0, index);
|
|
80
|
+
}
|
|
81
|
+
// we retain this behavior when availableSize === false
|
|
82
|
+
// to make existing unit tests happy (which assumes we will try to read stream when no data is ready.)
|
|
83
|
+
availableSize = size;
|
|
84
|
+
}
|
|
85
|
+
else if (availableSize > size) {
|
|
86
|
+
availableSize = size;
|
|
87
|
+
}
|
|
88
|
+
const newBuffer = readable.read(availableSize);
|
|
89
|
+
if (newBuffer) {
|
|
90
|
+
if (newBuffer.length < availableSize && !allowEndOfStream) {
|
|
91
|
+
throw new Error('Stream terminated before required bytes were read.');
|
|
92
|
+
}
|
|
93
|
+
if (readBuffer === null) {
|
|
94
|
+
if (availableSize === size || newBuffer.length < availableSize) {
|
|
95
|
+
// in the fast pass, we read the entire data once, and donot allocate an extra array.
|
|
96
|
+
return newBuffer;
|
|
97
|
+
}
|
|
98
|
+
// if we read partial data, we need allocate a buffer to join all data together.
|
|
99
|
+
readBuffer = Buffer.alloc(size);
|
|
100
|
+
}
|
|
101
|
+
// now append new data to the buffer
|
|
102
|
+
newBuffer.copy(readBuffer, index);
|
|
103
|
+
size -= newBuffer.length;
|
|
104
|
+
index += newBuffer.length;
|
|
105
|
+
}
|
|
106
|
+
if (size > 0) {
|
|
107
|
+
const bytesAvailable = new Deferred_1.Deferred();
|
|
108
|
+
const bytesAvailableCallback = bytesAvailable.resolve.bind(bytesAvailable);
|
|
109
|
+
const streamEndedCallback = streamEnded.resolve.bind(streamEnded);
|
|
110
|
+
readable.once('readable', bytesAvailableCallback);
|
|
111
|
+
readable.once('end', streamEndedCallback);
|
|
112
|
+
try {
|
|
113
|
+
const endPromise = Promise.race([bytesAvailable.promise, streamEnded.promise]);
|
|
114
|
+
await (cancellationToken ? cancellationToken.racePromise(endPromise) : endPromise);
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
readable.removeListener('readable', bytesAvailableCallback);
|
|
118
|
+
readable.removeListener('end', streamEndedCallback);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return readBuffer;
|
|
123
|
+
}
|
|
124
|
+
exports.getBufferFrom = getBufferFrom;
|
|
125
|
+
function throwIfDisposed(value) {
|
|
126
|
+
if (value.isDisposed) {
|
|
127
|
+
throw new Error('disposed');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.throwIfDisposed = throwIfDisposed;
|
|
131
|
+
function requireInteger(parameterName, value, serializedByteLength, signed = 'signed') {
|
|
132
|
+
if (!Number.isInteger(value)) {
|
|
133
|
+
throw new Error(`${parameterName} must be an integer.`);
|
|
134
|
+
}
|
|
135
|
+
let bits = serializedByteLength * 8;
|
|
136
|
+
if (signed === 'signed') {
|
|
137
|
+
bits--;
|
|
138
|
+
}
|
|
139
|
+
const maxValue = Math.pow(2, bits) - 1;
|
|
140
|
+
const minValue = signed === 'signed' ? -Math.pow(2, bits) : 0;
|
|
141
|
+
if (value > maxValue || value < minValue) {
|
|
142
|
+
throw new Error(`${parameterName} must be in the range ${minValue}-${maxValue}.`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.requireInteger = requireInteger;
|
|
146
|
+
function removeFromQueue(value, queue) {
|
|
147
|
+
if (queue) {
|
|
148
|
+
const idx = queue.indexOf(value);
|
|
149
|
+
if (idx >= 0) {
|
|
150
|
+
queue.splice(idx, 1);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.removeFromQueue = removeFromQueue;
|
|
155
155
|
//# sourceMappingURL=Utilities.js.map
|
package/js/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { Channel } from './Channel';
|
|
2
|
-
export { ChannelOptions } from './ChannelOptions';
|
|
3
|
-
export { FullDuplexStream } from './FullDuplexStream';
|
|
4
|
-
export { IDisposableObservable } from './IDisposableObservable';
|
|
5
|
-
export { MultiplexingStream } from './MultiplexingStream';
|
|
6
|
-
export { MultiplexingStreamOptions } from './MultiplexingStreamOptions';
|
|
7
|
-
export { writeSubstream, readSubstream } from './Utilities';
|
|
8
|
-
export { QualifiedChannelId, ChannelSource } from './QualifiedChannelId';
|
|
1
|
+
export { Channel } from './Channel';
|
|
2
|
+
export { ChannelOptions } from './ChannelOptions';
|
|
3
|
+
export { FullDuplexStream } from './FullDuplexStream';
|
|
4
|
+
export { IDisposableObservable } from './IDisposableObservable';
|
|
5
|
+
export { MultiplexingStream } from './MultiplexingStream';
|
|
6
|
+
export { MultiplexingStreamOptions } from './MultiplexingStreamOptions';
|
|
7
|
+
export { writeSubstream, readSubstream } from './Utilities';
|
|
8
|
+
export { QualifiedChannelId, ChannelSource } from './QualifiedChannelId';
|
package/js/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChannelSource = exports.QualifiedChannelId = exports.readSubstream = exports.writeSubstream = exports.MultiplexingStream = exports.FullDuplexStream = exports.Channel = void 0;
|
|
4
|
-
var Channel_1 = require("./Channel");
|
|
5
|
-
Object.defineProperty(exports, "Channel", { enumerable: true, get: function () { return Channel_1.Channel; } });
|
|
6
|
-
var FullDuplexStream_1 = require("./FullDuplexStream");
|
|
7
|
-
Object.defineProperty(exports, "FullDuplexStream", { enumerable: true, get: function () { return FullDuplexStream_1.FullDuplexStream; } });
|
|
8
|
-
var MultiplexingStream_1 = require("./MultiplexingStream");
|
|
9
|
-
Object.defineProperty(exports, "MultiplexingStream", { enumerable: true, get: function () { return MultiplexingStream_1.MultiplexingStream; } });
|
|
10
|
-
var Utilities_1 = require("./Utilities");
|
|
11
|
-
Object.defineProperty(exports, "writeSubstream", { enumerable: true, get: function () { return Utilities_1.writeSubstream; } });
|
|
12
|
-
Object.defineProperty(exports, "readSubstream", { enumerable: true, get: function () { return Utilities_1.readSubstream; } });
|
|
13
|
-
var QualifiedChannelId_1 = require("./QualifiedChannelId");
|
|
14
|
-
Object.defineProperty(exports, "QualifiedChannelId", { enumerable: true, get: function () { return QualifiedChannelId_1.QualifiedChannelId; } });
|
|
15
|
-
Object.defineProperty(exports, "ChannelSource", { enumerable: true, get: function () { return QualifiedChannelId_1.ChannelSource; } });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChannelSource = exports.QualifiedChannelId = exports.readSubstream = exports.writeSubstream = exports.MultiplexingStream = exports.FullDuplexStream = exports.Channel = void 0;
|
|
4
|
+
var Channel_1 = require("./Channel");
|
|
5
|
+
Object.defineProperty(exports, "Channel", { enumerable: true, get: function () { return Channel_1.Channel; } });
|
|
6
|
+
var FullDuplexStream_1 = require("./FullDuplexStream");
|
|
7
|
+
Object.defineProperty(exports, "FullDuplexStream", { enumerable: true, get: function () { return FullDuplexStream_1.FullDuplexStream; } });
|
|
8
|
+
var MultiplexingStream_1 = require("./MultiplexingStream");
|
|
9
|
+
Object.defineProperty(exports, "MultiplexingStream", { enumerable: true, get: function () { return MultiplexingStream_1.MultiplexingStream; } });
|
|
10
|
+
var Utilities_1 = require("./Utilities");
|
|
11
|
+
Object.defineProperty(exports, "writeSubstream", { enumerable: true, get: function () { return Utilities_1.writeSubstream; } });
|
|
12
|
+
Object.defineProperty(exports, "readSubstream", { enumerable: true, get: function () { return Utilities_1.readSubstream; } });
|
|
13
|
+
var QualifiedChannelId_1 = require("./QualifiedChannelId");
|
|
14
|
+
Object.defineProperty(exports, "QualifiedChannelId", { enumerable: true, get: function () { return QualifiedChannelId_1.QualifiedChannelId; } });
|
|
15
|
+
Object.defineProperty(exports, "ChannelSource", { enumerable: true, get: function () { return QualifiedChannelId_1.ChannelSource; } });
|
|
16
16
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nerdbank-streams",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.69",
|
|
4
4
|
"description": "Multiplexing of streams",
|
|
5
5
|
"readme": "README.md",
|
|
6
6
|
"keywords": [
|
|
@@ -32,35 +32,35 @@
|
|
|
32
32
|
"watch": "node ./node_modules/typescript/bin/tsc -p tsconfig.json -w"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@types/jest": "^29.2
|
|
35
|
+
"@types/jest": "^29.5.2",
|
|
36
36
|
"@types/mkdirp": "^1.0.2",
|
|
37
37
|
"@types/msgpack-lite": "^0.1.8",
|
|
38
|
-
"@types/node": "^
|
|
38
|
+
"@types/node": "^16.11.6",
|
|
39
39
|
"@types/promise": "^7.1.30",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
41
|
-
"@typescript-eslint/parser": "^5.
|
|
42
|
-
"eslint": "^8.
|
|
43
|
-
"eslint-config-prettier": "8.
|
|
44
|
-
"eslint-plugin-import": "2.
|
|
45
|
-
"eslint-plugin-jsx-a11y": "6.
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^5.59.9",
|
|
41
|
+
"@typescript-eslint/parser": "^5.59.9",
|
|
42
|
+
"eslint": "^8.42.0",
|
|
43
|
+
"eslint-config-prettier": "8.8.0",
|
|
44
|
+
"eslint-plugin-import": "2.27.5",
|
|
45
|
+
"eslint-plugin-jsx-a11y": "6.7.1",
|
|
46
46
|
"eslint-plugin-prettier": "4.2.1",
|
|
47
47
|
"gulp": "^4.0.2",
|
|
48
48
|
"gulp-typescript": "^6.0.0-alpha.1",
|
|
49
|
-
"jest": "^29.
|
|
50
|
-
"jshint": "^2.13.
|
|
49
|
+
"jest": "^29.5.0",
|
|
50
|
+
"jshint": "^2.13.6",
|
|
51
51
|
"mkdirp": "^1.0.4",
|
|
52
|
-
"nerdbank-gitversioning": "^3.
|
|
52
|
+
"nerdbank-gitversioning": "^3.6.133",
|
|
53
53
|
"path": "^0.12.7",
|
|
54
|
-
"prettier": "^2.
|
|
55
|
-
"promise": "^8.
|
|
56
|
-
"ts-jest": "^29.0
|
|
54
|
+
"prettier": "^2.8.8",
|
|
55
|
+
"promise": "^8.3.0",
|
|
56
|
+
"ts-jest": "^29.1.0",
|
|
57
57
|
"ts-node": "^10.9.1",
|
|
58
|
-
"typescript": "^
|
|
59
|
-
"vscode-jsonrpc": "^8.0
|
|
58
|
+
"typescript": "^5.1.3",
|
|
59
|
+
"vscode-jsonrpc": "^8.1.0"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"await-semaphore": "^0.1.3",
|
|
63
|
-
"cancellationtoken": "^2.0
|
|
63
|
+
"cancellationtoken": "^2.2.0",
|
|
64
64
|
"caught": "^0.1.3",
|
|
65
65
|
"msgpack-lite": "^0.1.26"
|
|
66
66
|
}
|