diff --git a/src/cdn/funcs/saveResponse.ts b/src/cdn/funcs/saveResponse.ts index f3f1ab5..00e44bd 100644 --- a/src/cdn/funcs/saveResponse.ts +++ b/src/cdn/funcs/saveResponse.ts @@ -19,7 +19,6 @@ export default function saveResponse( //If we receive a part of the response, write it to disk let totalLength = 0; - const chunkPromises: Array> = []; response.on('data', (chunk: Buffer) => { totalLength += chunk.length; @@ -29,11 +28,7 @@ export default function saveResponse( } //Write chunk to disk - chunkPromises.push(new Promise((writeResolve) => { - writeStream.write(chunk, () => { - writeResolve(); - }); - })); + writeStream.write(chunk); }); //If we finished reading response, check for correctness, then return it @@ -46,7 +41,7 @@ export default function saveResponse( //wait until everything is written to disk, then return file name //TODO: need to automatically delete file once it is no longer used //TODO: need to provide methods to seek through file - Promise.all(chunkPromises).then(() => { + writeStream.end(() => { resolve(filePath); }); });