MCPcopy
hub / github.com/callstack/agent-device / createLineWriter

Function createLineWriter

src/daemon/app-log-stream.ts:26–56  ·  view source on GitHub ↗
(
  stream: fs.WriteStream,
  options: { redactionPatterns: RegExp[]; includeTokens?: string[] },
)

Source from the content-addressed store, hash-verified

24type LineWriter = { onChunk: (chunk: string) => void; flush: () => void };
25
26export function createLineWriter(
27 stream: fs.WriteStream,
28 options: { redactionPatterns: RegExp[]; includeTokens?: string[] },
29): LineWriter {
30 const includeTokens = options.includeTokens?.filter((token) => token.length > 0) ?? [];
31 let pending = '';
32
33 const writeLine = (line: string): void => {
34 if (includeTokens.length > 0) {
35 const shouldInclude = includeTokens.some((token) => line.includes(token));
36 if (!shouldInclude) return;
37 }
38 stream.write(redactChunk(line, options.redactionPatterns));
39 };
40
41 return {
42 onChunk: (chunk: string) => {
43 const combined = `${pending}${chunk}`;
44 const lines = combined.split('\n');
45 pending = lines.pop() ?? '';
46 for (const line of lines) {
47 writeLine(`${line}\n`);
48 }
49 },
50 flush: () => {
51 if (!pending) return;
52 writeLine(pending);
53 pending = '';
54 },
55 };
56}
57
58type StreamableChildProcess = {
59 killed: boolean;

Callers 2

startAndroidAppLogFunction · 0.90
startAppleAppLogStreamFunction · 0.90

Calls 1

writeLineFunction · 0.70

Tested by

no test coverage detected