4989: Hotfix skipping the first chunks of the artifacts r=matklad a=Veetaha

Quick hotfix.
fixes: , 


The stream starts being consumed once we put a handler for `data` event.
When extracting `stream.pipeline()` under `withTempFile` in  I didn't move it into the scope too, which due to preliminary awaiting for async operations with the file system allowed for the first chunks of the file to be skipped

Co-authored-by: Veetaha <veetaha2@gmail.com>
This commit is contained in:
bors[bot] 2020-06-22 17:25:03 +00:00 committed by GitHub
commit ceb69203b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -114,15 +114,16 @@ async function downloadFile(
log.debug("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath);
let readBytes = 0;
res.body.on("data", (chunk: Buffer) => {
readBytes += chunk.length;
onProgress(readBytes, totalBytes);
});
// Put the artifact into a temporary folder to prevent partially downloaded files when user kills vscode
await withTempFile(async tempFilePath => {
const destFileStream = fs.createWriteStream(tempFilePath, { mode });
let readBytes = 0;
res.body.on("data", (chunk: Buffer) => {
readBytes += chunk.length;
onProgress(readBytes, totalBytes);
});
await pipeline(res.body, destFileStream);
await new Promise<void>(resolve => {
destFileStream.on("close", resolve);