diff options
author | Veetaha <[email protected]> | 2020-06-21 13:58:34 +0100 |
---|---|---|
committer | Veetaha <[email protected]> | 2020-07-07 21:30:11 +0100 |
commit | f92bfb580780cda02f9ba8a935538f984d8a4c0d (patch) | |
tree | fbf0e24250cc36eaa122904e78cd7cb50fe1c665 /editors/code/src/net.ts | |
parent | 980a67f44629ed67a54b603aaf9d015a81d61f7a (diff) |
Gzip artifacts
Co-authored-by: bjorn3 <[email protected]>
Override miniz_oxide to build it with optimizations
Building this crate with optimizations decreases the gzipping
part of `cargo xtask dist` from `30-40s` down to `3s`,
the overhead for `rustc` to apply optimizations is miserable on this background
Diffstat (limited to 'editors/code/src/net.ts')
-rw-r--r-- | editors/code/src/net.ts | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts index 866092882..53c9e91cd 100644 --- a/editors/code/src/net.ts +++ b/editors/code/src/net.ts | |||
@@ -3,6 +3,7 @@ import * as vscode from "vscode"; | |||
3 | import * as stream from "stream"; | 3 | import * as stream from "stream"; |
4 | import * as crypto from "crypto"; | 4 | import * as crypto from "crypto"; |
5 | import * as fs from "fs"; | 5 | import * as fs from "fs"; |
6 | import * as zlib from "zlib"; | ||
6 | import * as util from "util"; | 7 | import * as util from "util"; |
7 | import * as path from "path"; | 8 | import * as path from "path"; |
8 | import { log, assert } from "./util"; | 9 | import { log, assert } from "./util"; |
@@ -65,6 +66,7 @@ interface DownloadOpts { | |||
65 | url: string; | 66 | url: string; |
66 | dest: string; | 67 | dest: string; |
67 | mode?: number; | 68 | mode?: number; |
69 | gunzip?: boolean; | ||
68 | } | 70 | } |
69 | 71 | ||
70 | export async function download(opts: DownloadOpts) { | 72 | export async function download(opts: DownloadOpts) { |
@@ -82,7 +84,7 @@ export async function download(opts: DownloadOpts) { | |||
82 | }, | 84 | }, |
83 | async (progress, _cancellationToken) => { | 85 | async (progress, _cancellationToken) => { |
84 | let lastPercentage = 0; | 86 | let lastPercentage = 0; |
85 | await downloadFile(opts.url, tempFile, opts.mode, (readBytes, totalBytes) => { | 87 | await downloadFile(opts.url, tempFile, opts.mode, !!opts.gunzip, (readBytes, totalBytes) => { |
86 | const newPercentage = (readBytes / totalBytes) * 100; | 88 | const newPercentage = (readBytes / totalBytes) * 100; |
87 | progress.report({ | 89 | progress.report({ |
88 | message: newPercentage.toFixed(0) + "%", | 90 | message: newPercentage.toFixed(0) + "%", |
@@ -97,16 +99,11 @@ export async function download(opts: DownloadOpts) { | |||
97 | await fs.promises.rename(tempFile, opts.dest); | 99 | await fs.promises.rename(tempFile, opts.dest); |
98 | } | 100 | } |
99 | 101 | ||
100 | /** | ||
101 | * Downloads file from `url` and stores it at `destFilePath` with `mode` (unix permissions). | ||
102 | * `onProgress` callback is called on recieveing each chunk of bytes | ||
103 | * to track the progress of downloading, it gets the already read and total | ||
104 | * amount of bytes to read as its parameters. | ||
105 | */ | ||
106 | async function downloadFile( | 102 | async function downloadFile( |
107 | url: string, | 103 | url: string, |
108 | destFilePath: fs.PathLike, | 104 | destFilePath: fs.PathLike, |
109 | mode: number | undefined, | 105 | mode: number | undefined, |
106 | gunzip: boolean, | ||
110 | onProgress: (readBytes: number, totalBytes: number) => void | 107 | onProgress: (readBytes: number, totalBytes: number) => void |
111 | ): Promise<void> { | 108 | ): Promise<void> { |
112 | const res = await fetch(url); | 109 | const res = await fetch(url); |
@@ -130,7 +127,10 @@ async function downloadFile( | |||
130 | }); | 127 | }); |
131 | 128 | ||
132 | const destFileStream = fs.createWriteStream(destFilePath, { mode }); | 129 | const destFileStream = fs.createWriteStream(destFilePath, { mode }); |
133 | await pipeline(res.body, destFileStream); | 130 | const srcStream = gunzip ? res.body.pipe(zlib.createGunzip()) : res.body; |
131 | |||
132 | await pipeline(srcStream, destFileStream); | ||
133 | |||
134 | await new Promise<void>(resolve => { | 134 | await new Promise<void>(resolve => { |
135 | destFileStream.on("close", resolve); | 135 | destFileStream.on("close", resolve); |
136 | destFileStream.destroy(); | 136 | destFileStream.destroy(); |