MCPcopy
hub / github.com/apify/crawlee / streamLines

Function streamLines

test/e2e/run.mjs:65–95  ·  view source on GitHub ↗
(stream, sink)

Source from the content-addressed store, hash-verified

63
64 // Line-buffered streaming so prefixed lines stay intact across chunk boundaries.
65 const streamLines = (stream, sink) => {
66 let buffer = '';
67 stream.on('data', (chunk) => {
68 buffer += chunk.toString();
69 const lines = buffer.split('\n');
70 buffer = lines.pop();
71 for (const line of lines) {
72 if (line === '') continue;
73
74 if (!line.startsWith('[')) {
75 if (!seenFirst) {
76 console.log(
77 `${colors.red('[fatal]')} test ${colors.yellow(
78 `[${dir.name}]`,
79 )} did not call "initialize(import.meta.url)"!`,
80 );
81 worker.terminate();
82 return;
83 }
84 deferredOnSuccess.push(line);
85 continue;
86 }
87
88 seenFirst = true;
89 sink(`${prefix}${line}`);
90 }
91 });
92 stream.on('end', () => {
93 if (buffer !== '') sink(`${prefix}${buffer}`);
94 });
95 };
96
97 streamLines(worker.stdout, (line) => console.log(line));
98 streamLines(worker.stderr, (line) => console.error(line));

Callers 1

runFunction · 0.85

Calls 3

toStringMethod · 0.80
logMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…