diff options
author | Veetaha <[email protected]> | 2020-02-09 12:18:05 +0000 |
---|---|---|
committer | Veetaha <[email protected]> | 2020-02-09 12:18:05 +0000 |
commit | f3240e22c6de69b408a83b59e85f40fb913acfab (patch) | |
tree | 25c9a71ec7a98efe33209fcd370668610c61aa1e /editors/code/src/installation/download_file.ts | |
parent | a63659badb75d22ad834b7524e77505790c10dd0 (diff) |
vscode: move throtting of download progress to call site
Diffstat (limited to 'editors/code/src/installation/download_file.ts')
-rw-r--r-- | editors/code/src/installation/download_file.ts | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/editors/code/src/installation/download_file.ts b/editors/code/src/installation/download_file.ts index ec16dcd66..53bf46d78 100644 --- a/editors/code/src/installation/download_file.ts +++ b/editors/code/src/installation/download_file.ts | |||
@@ -1,20 +1,18 @@ | |||
1 | import fetch from "node-fetch"; | 1 | import fetch from "node-fetch"; |
2 | import { throttle } from "throttle-debounce"; | ||
3 | import * as fs from "fs"; | 2 | import * as fs from "fs"; |
4 | import { strict as assert } from "assert"; | 3 | import { strict as assert } from "assert"; |
5 | 4 | ||
6 | /** | 5 | /** |
7 | * Downloads file from `url` and stores it at `destFilePath`. | 6 | * Downloads file from `url` and stores it at `destFilePath`. |
8 | * `onProgress` callback is periodically called to track the progress of downloading, | 7 | * `onProgress` callback is called on recieveing each chunk of bytes |
9 | * it gets the already read and total amount of bytes to read as its parameters. | 8 | * to track the progress of downloading, it gets the already read and total |
9 | * amount of bytes to read as its parameters. | ||
10 | */ | 10 | */ |
11 | export async function downloadFile( | 11 | export async function downloadFile( |
12 | url: string, | 12 | url: string, |
13 | destFilePath: fs.PathLike, | 13 | destFilePath: fs.PathLike, |
14 | onProgress: (readBytes: number, totalBytes: number) => void | 14 | onProgress: (readBytes: number, totalBytes: number) => void |
15 | ): Promise<void> { | 15 | ): Promise<void> { |
16 | onProgress = throttle(200, /* noTrailing: */ true, onProgress); | ||
17 | |||
18 | const response = await fetch(url); | 16 | const response = await fetch(url); |
19 | 17 | ||
20 | const totalBytes = Number(response.headers.get('content-length')); | 18 | const totalBytes = Number(response.headers.get('content-length')); |