🐎 Improve perf by not storing chunk write status

This commit is contained in:
C-3PO 2018-07-08 19:11:28 +02:00
parent 8b1ad6f7e2
commit 82693ba3b0
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -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<Promise<void>> = [];
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);
});
});