MCPcopy
hub / github.com/TypeStrong/ts-node / getStream

Function getStream

src/test/helpers.ts:196–226  ·  view source on GitHub ↗
(stream: Readable, waitForPattern?: string | RegExp)

Source from the content-addressed store, hash-verified

194 * Will resolve early if
195 */
196export function getStream(stream: Readable, waitForPattern?: string | RegExp) {
197 let resolve: (value: string) => void;
198 const promise = new Promise<string>((res) => {
199 resolve = res;
200 });
201 const received: Buffer[] = [];
202 let combinedBuffer: Buffer = Buffer.concat([]);
203 let combinedString: string = '';
204
205 stream.on('data', (data) => {
206 received.push(data);
207 combine();
208 if (
209 (typeof waitForPattern === 'string' &&
210 combinedString.indexOf(waitForPattern) >= 0) ||
211 (waitForPattern instanceof RegExp && combinedString.match(waitForPattern))
212 )
213 resolve(combinedString);
214 combinedBuffer = Buffer.concat(received);
215 });
216 stream.on('end', () => {
217 resolve(combinedString);
218 });
219
220 return promise;
221
222 function combine() {
223 combinedBuffer = Buffer.concat(received);
224 combinedString = combinedBuffer.toString('utf8');
225 }
226}
227
228//#region Reset node environment
229

Callers 4

createSpawnFunction · 0.90
repl.spec.tsFile · 0.90
executeInReplFunction · 0.90

Calls 2

combineFunction · 0.85
resolveFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…