| 242 | } |
| 243 | |
| 244 | function 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 |