( client: S3Client, uri: string, destPath: string, )
| 61 | |
| 62 | /** Stream an S3 object to a local file path. Throws if the body is missing. */ |
| 63 | export async function downloadS3ObjectToFile( |
| 64 | client: S3Client, |
| 65 | uri: string, |
| 66 | destPath: string, |
| 67 | ): Promise<void> { |
| 68 | const { bucket, key } = parseS3Uri(uri); |
| 69 | const response = await client.send(new GetObjectCommand({ Bucket: bucket, Key: key })); |
| 70 | const body = response.Body as NodeJS.ReadableStream | undefined; |
| 71 | if (!body) { |
| 72 | throw new Error(`[s3Transport] s3 GetObject returned empty body for ${uri}`); |
| 73 | } |
| 74 | mkdirSync(dirname(destPath), { recursive: true }); |
| 75 | await pipeline(body, createWriteStream(destPath)); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Upload a local file's contents to an S3 URI using a streaming |
no test coverage detected