Replace S3 streamToBuffer with pipe. (#28993)
* Replace S3 streamToBuffer with pipe. Signed-off-by: Sydney Achinger <sydneynicoleachinger@spotify.com>
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user