From 751d1dda8871532426e2c650eeb2842d27ee9c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Mon, 11 Dec 2023 13:11:41 +0000 Subject: [PATCH] chore: Stream S3 files directly to zip (take 2) (#2495) * chore: Stream S3 files directly to zip (#2380) * fix: Remove /tmp prefix in zip files --- api.planx.uk/modules/send/utils/exportZip.test.ts | 1 - api.planx.uk/modules/send/utils/exportZip.ts | 10 +++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/api.planx.uk/modules/send/utils/exportZip.test.ts b/api.planx.uk/modules/send/utils/exportZip.test.ts index cce3cc64ca..48fe1ce7dd 100644 --- a/api.planx.uk/modules/send/utils/exportZip.test.ts +++ b/api.planx.uk/modules/send/utils/exportZip.test.ts @@ -7,7 +7,6 @@ jest.mock("fs", () => ({ existsSync: () => true, unlinkSync: () => undefined, createWriteStream: () => undefined, - writeFileSync: () => undefined, rmSync: () => undefined, })); diff --git a/api.planx.uk/modules/send/utils/exportZip.ts b/api.planx.uk/modules/send/utils/exportZip.ts index 379f1bf9ec..4a15b9bef7 100644 --- a/api.planx.uk/modules/send/utils/exportZip.ts +++ b/api.planx.uk/modules/send/utils/exportZip.ts @@ -193,13 +193,9 @@ export class ExportZip { const s3Key = url.split("/").slice(-2).join("/"); const decodedS3Key = decodeURIComponent(s3Key); const { body } = await getFileFromS3(decodedS3Key); - if (!body) { - throw new Error("file not found"); - } - const filePath = path.join(this.tmpDir, name); - fs.writeFileSync(filePath, body as Buffer); - this.zip.addLocalFile(filePath); - fs.unlinkSync(filePath); + if (!body) throw new Error("file not found"); + + this.zip.addFile(name, body as Buffer); } toBuffer(): Buffer {