diff options
Diffstat (limited to 'editors/code/src/installation/download_artifact.ts')
-rw-r--r-- | editors/code/src/installation/download_artifact.ts | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/editors/code/src/installation/download_artifact.ts b/editors/code/src/installation/download_artifact.ts deleted file mode 100644 index 97e4d67c2..000000000 --- a/editors/code/src/installation/download_artifact.ts +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | import * as vscode from "vscode"; | ||
2 | import * as path from "path"; | ||
3 | import { promises as fs } from "fs"; | ||
4 | |||
5 | import { ArtifactReleaseInfo } from "./interfaces"; | ||
6 | import { downloadFile } from "./download_file"; | ||
7 | import { assert } from "../util"; | ||
8 | |||
9 | /** | ||
10 | * Downloads artifact from given `downloadUrl`. | ||
11 | * Creates `installationDir` if it is not yet created and put the artifact under | ||
12 | * `artifactFileName`. | ||
13 | * Displays info about the download progress in an info message printing the name | ||
14 | * of the artifact as `displayName`. | ||
15 | */ | ||
16 | export async function downloadArtifact( | ||
17 | { downloadUrl, releaseName }: ArtifactReleaseInfo, | ||
18 | artifactFileName: string, | ||
19 | installationDir: string, | ||
20 | displayName: string, | ||
21 | ) { | ||
22 | await fs.mkdir(installationDir).catch(err => assert( | ||
23 | err?.code === "EEXIST", | ||
24 | `Couldn't create directory "${installationDir}" to download ` + | ||
25 | `${artifactFileName} artifact: ${err?.message}` | ||
26 | )); | ||
27 | |||
28 | const installationPath = path.join(installationDir, artifactFileName); | ||
29 | |||
30 | await vscode.window.withProgress( | ||
31 | { | ||
32 | location: vscode.ProgressLocation.Notification, | ||
33 | cancellable: false, // FIXME: add support for canceling download? | ||
34 | title: `Downloading ${displayName} (${releaseName})` | ||
35 | }, | ||
36 | async (progress, _cancellationToken) => { | ||
37 | let lastPrecentage = 0; | ||
38 | const filePermissions = 0o755; // (rwx, r_x, r_x) | ||
39 | await downloadFile(downloadUrl, installationPath, filePermissions, (readBytes, totalBytes) => { | ||
40 | const newPercentage = (readBytes / totalBytes) * 100; | ||
41 | progress.report({ | ||
42 | message: newPercentage.toFixed(0) + "%", | ||
43 | increment: newPercentage - lastPrecentage | ||
44 | }); | ||
45 | |||
46 | lastPrecentage = newPercentage; | ||
47 | }); | ||
48 | } | ||
49 | ); | ||
50 | } | ||