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