Replace S3 streamToBuffer with pipe. (#28993)

* Replace S3 streamToBuffer with pipe.

Signed-off-by: Sydney Achinger <sydneynicoleachinger@spotify.com>
This commit is contained in:
Sydney Achinger
2025-03-19 09:12:31 -04:00
committed by GitHub
parent 638c2b6296
commit 304a422ef4
2 changed files with 17 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs-node': patch
---
Update AWS file retrieval logic from storing file in buffer array to piping to res for better memory efficiency.
@@ -483,7 +483,18 @@ export class AwsS3Publish implements PublisherBase {
res.setHeader(headerKey, headerValue);
}
res.send(await streamToBuffer(resp.Body as Readable));
(resp.Body as Readable)
.on('error', err => {
this.logger.warn(
`TechDocs S3 router failed to serve static files from bucket ${this.bucketName} at key ${filePath}: ${err.message}`,
);
if (!res.headersSent) {
res.status(404).send('File Not Found');
} else {
res.destroy();
}
})
.pipe(res);
} catch (err) {
assertError(err);
this.logger.warn(