MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / onData

Function onData

src/mcp/daemon.ts:1163–1185  ·  view source on GitHub ↗
(chunk: Buffer | string)

Source from the content-addressed store, hash-verified

1161 resolve(peers);
1162 };
1163 const onData = (chunk: Buffer | string) => {
1164 const buf = typeof chunk === 'string' ? Buffer.from(chunk, 'utf8') : chunk;
1165 chunks.push(buf);
1166 total += buf.length;
1167 const all = chunks.length === 1 ? buf : Buffer.concat(chunks, total);
1168 const nl = all.indexOf(0x0a); // '\n'
1169 if (nl === -1) {
1170 // No newline yet. If it's already too long to be a hello, it isn't one —
1171 // hand the bytes back as data; otherwise keep accumulating.
1172 if (total > MAX_HELLO_LINE_BYTES) finish({ pid: null, hostPid: null }, all);
1173 else chunks = [all];
1174 return;
1175 }
1176 const peers = parseClientHelloLine(all.subarray(0, nl).toString('utf8'));
1177 if (peers) {
1178 const tail = all.subarray(nl + 1);
1179 finish(peers, tail.length > 0 ? tail : undefined);
1180 } else {
1181 // First line is not a client-hello (legacy/direct client) — hand the
1182 // whole buffer back so the transport sees the message verbatim.
1183 finish({ pid: null, hostPid: null }, all);
1184 }
1185 };
1186 const onEnd = () => finish({ pid: null, hostPid: null });
1187 // On timeout, hand back whatever partial bytes accumulated — discarding
1188 // them would tear the first message the transport parses.

Callers

nothing calls this directly

Calls 4

parseClientHelloLineFunction · 0.85
fromMethod · 0.80
pushMethod · 0.80
finishFunction · 0.70

Tested by

no test coverage detected