(
logPath: string,
options?: {
backend?: LogBackend;
maxEntries?: number;
include?: NetworkIncludeMode;
maxPayloadChars?: number;
maxScanLines?: number;
},
)
| 72 | } |
| 73 | |
| 74 | export function readRecentNetworkTraffic( |
| 75 | logPath: string, |
| 76 | options?: { |
| 77 | backend?: LogBackend; |
| 78 | maxEntries?: number; |
| 79 | include?: NetworkIncludeMode; |
| 80 | maxPayloadChars?: number; |
| 81 | maxScanLines?: number; |
| 82 | }, |
| 83 | ): NetworkDump { |
| 84 | const maxEntries = clampInt(options?.maxEntries, 25, 1, 200); |
| 85 | const include = options?.include ?? 'summary'; |
| 86 | const maxPayloadChars = clampInt(options?.maxPayloadChars, 2048, 64, 16_384); |
| 87 | const maxScanLines = clampInt(options?.maxScanLines, 4000, 100, 20_000); |
| 88 | if (!fs.existsSync(logPath)) { |
| 89 | return { |
| 90 | path: logPath, |
| 91 | exists: false, |
| 92 | scannedLines: 0, |
| 93 | matchedLines: 0, |
| 94 | entries: [], |
| 95 | include, |
| 96 | limits: { maxEntries, maxPayloadChars, maxScanLines }, |
| 97 | }; |
| 98 | } |
| 99 | |
| 100 | const content = fs.readFileSync(logPath, 'utf8'); |
| 101 | return readRecentNetworkTrafficFromText(content, { |
| 102 | ...options, |
| 103 | path: logPath, |
| 104 | }); |
| 105 | } |
| 106 | |
| 107 | export function readRecentNetworkTrafficFromText( |
| 108 | content: string, |
no test coverage detected