( stdout: string, outputFilePath: string | undefined, outputFileSize: number | undefined, )
| 110 | * parse as a data URI (caller decides whether to flip isImage). |
| 111 | */ |
| 112 | export async function resizeShellImageOutput( |
| 113 | stdout: string, |
| 114 | outputFilePath: string | undefined, |
| 115 | outputFileSize: number | undefined, |
| 116 | ): Promise<string | null> { |
| 117 | let source = stdout |
| 118 | if (outputFilePath) { |
| 119 | const size = outputFileSize ?? (await stat(outputFilePath)).size |
| 120 | if (size > MAX_IMAGE_FILE_SIZE) return null |
| 121 | source = await readFile(outputFilePath, 'utf8') |
| 122 | } |
| 123 | const parsed = parseDataUri(source) |
| 124 | if (!parsed) return null |
| 125 | const buf = Buffer.from(parsed.data, 'base64') |
| 126 | const ext = parsed.mediaType.split('/')[1] || 'png' |
| 127 | const resized = await maybeResizeAndDownsampleImageBuffer( |
| 128 | buf, |
| 129 | buf.length, |
| 130 | ext, |
| 131 | ) |
| 132 | return `data:image/${resized.mediaType};base64,${resized.buffer.toString('base64')}` |
| 133 | } |
| 134 | |
| 135 | export function formatOutput(content: string): { |
| 136 | totalLines: number |
no test coverage detected