🐎 Improve perf by not storing chunk write status
This commit is contained in:
parent
8b1ad6f7e2
commit
82693ba3b0
1 changed files with 2 additions and 7 deletions
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue