( args: ReadAttachmentFromPathArgs, resolvedPath: string, expectedSize: number )
| 154 | } |
| 155 | |
| 156 | async function readRegularFileBytes( |
| 157 | args: ReadAttachmentFromPathArgs, |
| 158 | resolvedPath: string, |
| 159 | expectedSize: number |
| 160 | ): Promise<Buffer> { |
| 161 | if (expectedSize > MAX_ATTACH_FILE_SIZE_BYTES) { |
| 162 | throw new Error(buildTooLargeMessage(expectedSize)); |
| 163 | } |
| 164 | |
| 165 | let bytes: Buffer; |
| 166 | try { |
| 167 | bytes = await readStreamToBuffer(args.runtime.readFile(resolvedPath, args.abortSignal)); |
| 168 | } catch (error) { |
| 169 | throw buildMissingFileError(resolvedPath, error); |
| 170 | } |
| 171 | |
| 172 | assert( |
| 173 | bytes.length === expectedSize, |
| 174 | `Expected to read ${expectedSize} bytes from '${resolvedPath}', got ${bytes.length}` |
| 175 | ); |
| 176 | |
| 177 | return bytes; |
| 178 | } |
| 179 | |
| 180 | function createUnsupportedAttachmentError( |
| 181 | args: ReadAttachmentFromPathArgs, |
no test coverage detected