Skip to content

Commit

Permalink
chore: Stream S3 files directly to zip (take 2) (#2495)
Browse files Browse the repository at this point in the history
* chore: Stream S3 files directly to zip (#2380)

* fix: Remove /tmp prefix in zip files
  • Loading branch information
DafyddLlyr authored Dec 11, 2023
1 parent 27c18ad commit 751d1dd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
1 change: 0 additions & 1 deletion api.planx.uk/modules/send/utils/exportZip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ jest.mock("fs", () => ({
existsSync: () => true,
unlinkSync: () => undefined,
createWriteStream: () => undefined,
writeFileSync: () => undefined,
rmSync: () => undefined,
}));

Expand Down
10 changes: 3 additions & 7 deletions api.planx.uk/modules/send/utils/exportZip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 751d1dd

Please sign in to comment.