MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / writePrefixed

Function writePrefixed

scripts/guardian/shared.ts:244–257  ·  view source on GitHub ↗
(stream: NodeJS.WriteStream, buf: Buffer, tag: string)

Source from the content-addressed store, hash-verified

242}
243
244function writePrefixed(stream: NodeJS.WriteStream, buf: Buffer, tag: string): void {
245 const lines = buf.toString('utf8').split('\n')
246 // Last element is "" when buf ended with \n; preserve that the right way
247 // so partial mid-line writes aren't mangled with mid-stream prefixes.
248 for (let i = 0; i < lines.length - 1; i++) {
249 stream.write(tag + lines[i] + '\n')
250 }
251 // Trailing partial line (no terminating \n) goes through without prefix —
252 // it'll get prefixed when the next chunk completes the line. Good enough
253 // for dev orchestration; not a contract.
254 if (lines[lines.length - 1] !== '') {
255 stream.write(tag + lines[lines.length - 1])
256 }
257}
258
259/**
260 * Poll an HTTP URL until it returns 200, or until timeout. Returns true

Callers 1

spawnChildFunction · 0.85

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected