From 82693ba3b0f5bd348a7897e40dada5a19aa3f063 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Sun, 8 Jul 2018 19:11:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=8E=20Improve=20perf=20by=20not=20stor?= =?UTF-8?q?ing=20chunk=20write=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cdn/funcs/saveResponse.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) 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); }); });