Skip to content

Commit

Permalink
try pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
gmrabian committed Nov 14, 2023
1 parent e03432c commit b5d37aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
7 changes: 3 additions & 4 deletions services/uploads/src/antivirus.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const clamav = require("./clamav");
const s3 = new S3Client();
const utils = require("./utils");
const constants = require("./constants");
const { pipeline } = require("stream/promises");

/**
* Retrieve the file size of S3 object without downloading.
Expand Down Expand Up @@ -72,10 +73,8 @@ async function downloadFileFromS3(s3ObjectKey, s3ObjectBucket) {

try {
const response = await s3.send(getObject);
await response.Body.transformToWebStream().pipeTo(writeStream);
utils.generateSystemMessage(
`Finished downloading new object ${s3ObjectKey}`
);
const readStream = response.Body.transformToWebStream();
return await pipeline(readStream, writeStream);
} catch (err) {
utils.generateSystemMessage(`Error downloading new object ${s3ObjectKey}`);
throw err;
Expand Down
9 changes: 3 additions & 6 deletions services/uploads/src/clamav.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const child_process = require("child_process");
const path = require("path");
const constants = require("./constants");
const utils = require("./utils");
const { pipeline } = require("stream/promises");

const S3 = new S3Client();

Expand Down Expand Up @@ -96,12 +97,8 @@ async function downloadAVDefinitions() {

try {
const response = await S3.send(getObject);
await response.Body.transformToWebStream().pipeTo(
localFileWriteStream
);
utils.generateSystemMessage(
`Finished download ${filenameToDownload}`
);
const readStream = response.Body.transformToWebStream();
return await pipeline(readStream, localFileWriteStream);
} catch (err) {
utils.generateSystemMessage(
`Error downloading definition file ${filenameToDownload}`
Expand Down

0 comments on commit b5d37aa

Please sign in to comment.