From ed1ff8e4884e69b52e56d03954725957847557ea Mon Sep 17 00:00:00 2001 From: philmcmahon Date: Thu, 9 Jan 2025 16:06:11 +0000 Subject: [PATCH] Log progress of s3 download --- packages/backend-common/src/s3.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/backend-common/src/s3.ts b/packages/backend-common/src/s3.ts index a398f988..a9c43893 100644 --- a/packages/backend-common/src/s3.ts +++ b/packages/backend-common/src/s3.ts @@ -154,20 +154,29 @@ export const downloadObject = async ( if (!data.Body) { throw new Error(`Failed to retrieve object ${key} from bucket ${bucket}`); } - await downloadS3Data(data.Body as Readable, destinationPath, key); - return { + await downloadS3Data( + data.Body as Readable, destinationPath, - extension: data.Metadata?.['extension'], - }; + key, + data.ContentLength, + ); + return data.Metadata?.['extension']; }; const downloadS3Data = async ( data: Readable, destinationPath: string, key: string, + contentLength?: number, ) => { const stream = data.pipe(createWriteStream(destinationPath)); - + let downloadedBytes = 0; + data.on('data', (chunk) => { + downloadedBytes += chunk.length; + logger.info( + `Downloaded ${downloadedBytes} of ${contentLength} bytes so far for ${key}`, + ); + }); await new Promise((resolve, reject) => { stream .on('finish', () => {