( path: string, )
| 21 | } |
| 22 | |
| 23 | export async function readWorkspaceImage( |
| 24 | path: string, |
| 25 | ): Promise<{ bytes: Uint8Array; mimeType: ImageMimeType }> { |
| 26 | const size = await stat(path).catch(() => { |
| 27 | throw new Error('Image could not be read.'); |
| 28 | }); |
| 29 | if (!size.isFile()) throw new Error('Image path is not a file.'); |
| 30 | if (size.size > MAX_READ_IMAGE_BYTES) throw imageTooLargeError(); |
| 31 | const bytes = await readFile(path).catch(() => { |
| 32 | throw new Error('Image could not be read.'); |
| 33 | }); |
| 34 | return validateImageBytes(bytes); |
| 35 | } |
| 36 | |
| 37 | export function validateImageBytes(bytes: Uint8Array): { |
| 38 | bytes: Uint8Array; |
no test coverage detected