| 1 | import { Readable } from 'node:stream'; |
| 2 | import { buffer } |
| 3 | |
| 4 | /** In-memory stand-in for the few `S3Service` calls object uploads use. Like S3, a body shorter or longer than its `ContentLength` is refused. */ |
| 5 | export class InMemoryS3 |
| 6 | readonly bucket = |
| 7 | readonly objects = |
| 8 | /** Set to make the next `putObject` fail, as a dropped connection would. */ |
| 9 | failNextPut = false; |
| 10 | |
| 11 | async putObject({ |
| 12 | Key, |
| 13 | Body, |
| 14 | ContentLength, |
| 15 | }: { |
| 16 | Key: string |
| 17 | Body: Readable |
| 18 | ContentLength?: number |
| 19 | }) { |
| 20 | const bytes = |
| 21 | if (this.failNextPut |
| 22 | this.failNextPut = |
| 23 | throw new Error( |
| 24 | } |
| 25 | if (ContentLength !== |
| 26 | throw new Error( |
| 27 | } |
| 28 | this.objects.set |
| 29 | return {}; |
| 30 | } |
| 31 | |
| 32 | putStream(input: |
| 33 | return this.putObject |
| 34 | } |
| 35 | |
| 36 | async getObject({ |
| 37 | const bytes = |
| 38 | if (!bytes) |
| 39 | throw Object.assign( |
| 40 | return { Body: |
| 41 | } |
| 42 | |
| 43 | async deleteObject({ |
| 44 | this.objects.delete |
| 45 | return {}; |
| 46 | } |
| 47 | |
| 48 | async deleteUnder(prefix |
| 49 | for (const key |
| 50 | if (key.startsWith |
| 51 | } |
| 52 | } |
| 53 | } |