From f92bfb580780cda02f9ba8a935538f984d8a4c0d Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 21 Jun 2020 15:58:34 +0300 Subject: Gzip artifacts Co-authored-by: bjorn3 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 --- editors/code/src/main.ts | 17 +++++++++-------- editors/code/src/net.ts | 16 ++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'editors') diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index eda95ae5c..bd99d696a 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -274,13 +274,13 @@ async function getServer(config: Config, state: PersistentState): Promise true, () => false); if (!exists) { await state.updateServerVersion(undefined); @@ -309,7 +309,7 @@ async function getServer(config: Config, state: PersistentState): Promise artifact.name === binaryName); + const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`); assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error. @@ -321,6 +321,7 @@ async function getServer(config: Config, state: PersistentState): Promise { let lastPercentage = 0; - await downloadFile(opts.url, tempFile, opts.mode, (readBytes, totalBytes) => { + await downloadFile(opts.url, tempFile, opts.mode, !!opts.gunzip, (readBytes, totalBytes) => { const newPercentage = (readBytes / totalBytes) * 100; progress.report({ message: newPercentage.toFixed(0) + "%", @@ -97,16 +99,11 @@ export async function download(opts: DownloadOpts) { await fs.promises.rename(tempFile, opts.dest); } -/** - * Downloads file from `url` and stores it at `destFilePath` with `mode` (unix permissions). - * `onProgress` callback is called on recieveing each chunk of bytes - * to track the progress of downloading, it gets the already read and total - * amount of bytes to read as its parameters. - */ async function downloadFile( url: string, destFilePath: fs.PathLike, mode: number | undefined, + gunzip: boolean, onProgress: (readBytes: number, totalBytes: number) => void ): Promise { const res = await fetch(url); @@ -130,7 +127,10 @@ async function downloadFile( }); const destFileStream = fs.createWriteStream(destFilePath, { mode }); - await pipeline(res.body, destFileStream); + const srcStream = gunzip ? res.body.pipe(zlib.createGunzip()) : res.body; + + await pipeline(srcStream, destFileStream); + await new Promise(resolve => { destFileStream.on("close", resolve); destFileStream.destroy(); -- cgit v1.2.3